Forum Discussion

mdfw's avatar
mdfw
Genius
2 years ago

Set the visitor UI language automatically

Background:

  1. Our instance supports 8 different languages for the user interface.
  2. Our CDN/Reverse Proxy detects a user's location and can set a user's language based on that. It will, at a minimum, set a cookie.
  3. In the past, in the page.init, we would detect if the cookie language was different than the session language and and return a redirect while adding the "?profile.language=xx" parameter. Unfortunately, this caused significant delays for users in China because of the extra round trip.
  4. Currently our CDN/reverse proxy rewrites all URLs as they pass through, adding the profile.language parameter to *every* page load. This causes some odd side-effects, especially in the admin panel. It's also very challenging to debug when something is off.

 

Does anyone know the recommended approach to making sure that a user (including anonymous users) gets the Khoros page UI in their translated language? Our CDN/reverse proxy does place a cookie that we can read or it could deliver a special header. I imagine we could read this in page.init, but I don't see anywhere in the docs where we can tell the session to switch languages. 

This all gives hints:

Other related threads I have read:

 

Thanks!

Mark

12 Replies

  • A little excerpt from the code docs of my own Khoros framework as we are dealing with multilanguage communities every day:

     

    The cookie interesting to us regarding language logic is `lia.anon.profile.language` which stores the community-wide language setting for anonymous users and is set and changed whenever the URL parameter `?profile.language=<lang>` is provided, although
    this only happens when the ancient config `enable.PersistentAnonymousUserSettings = true` is set (has to be requested from support, not true by default!). This automatically
    set cookie is a common source of issues, as the cookie is only written when a user is NOT logged in! We can take care of that by updating the cookie manually right after the language is set via REST API for an authenticated user.
    
    A custom cookie + attributes can be created and set in the page init script like follows:
    
    ```
    	<#assign cookie = http.request.createCookie('<cookiename>', '<cookievalue>') />
    	${cookie.setMaxAge(365*24*60*60)}
    	${cookie.setDomain('.domain.com')}
    	${cookie.setPath('/')}
    	${cookie.setValue('your cookie value')}
    	${cookie.setHttpOnly(true)}
    	${cookie.setSecure(true)}
    	${cookie.setComment('Describes what this cookie does')}
    	${http.response.addCookie(cookie)}
    ```
    
    and be checked with `${http.request.cookies.name.get('<cookiename>')}`.

     

     

    Key takeaway here is to use that cookie lia.anon.profile.language and use it as the main source of "language-truth" AND keep it updated when a user is logged in and changes languages. Keeping it up-to-date is also important to KEEP the logged-in language when a user logs out, because if the logged-in language differs from the value of the cookie, the user will experience a "nice" language switch when logging out ğŸ˜‰

  • IanKl's avatar
    IanKl
    Khoros Alumni (Retired)
    2 years ago

    Make sure the folks in Costa Rica are logged out before trying the

    ?profile.language=xx

    parameter. 

    What luk added also looks very helpful. 

    How are things coming along with this?