So I’m using the language detection / cookie method for setting the user language:
- User arrives on page
- Check if user has a cookie user_lang set
- If set, use that language
- If not set use language detection function and set cookie
Language switch:
-
User goes to /change/language/[languageshortcode]
-
Verify the language shortcode is valid, delete/change previous cookie and update with new language
-
load page
The problem is that I can see that the user_lang cookie has indeed changed from e.g. EN to FR but the actual language switch only happens if I manually refresh the page.
On my local setup the change is immediately, on my remote server I have to refresh.
Thinks I’ve changed that I thought caused this:
- Disabled all forms of page caching
- Disabled Varnish Cache serverside using htaccess
- Actually delete the cookie and set a new one instead of just changing the cookie
Any suggestions?
Since no code is posted, I’m going to just provide a few thoughts. One solution would be to add a JS page reload but only if some condition is true. The better solution, however, is ensuring that if the user has made a change to the language, don’t read the cookie to detect language for that page load (as it doesn’t completely set until the script completes). If the user has made a change, use the value that was used to set the cookie and ignore the cookie, if no changes were made, simply detect the cookie. Does that make sense?