Forum Discussion
luk
2 years agoBoss
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 😉
Related Content
- 12 months ago
- 13 years ago
- 10 years ago