Open agryson opened 5 years ago
I have the same problem.
My website is French and English. I did choose “include_default_lang: true” so the /fr doesn’t appear, only /en for English content.
I wanted to activate “http_accept_language: true” so it switch to the language of my visitor. But as soon as I do that my website redirect me always on the /en, the english version.
That what I wanted, as my browser is not in French. But when I click on the French language link to see the French content, I’m still being redirected to English.
I manage to make it work by putting “include_default_lang: false” and having the /fr in the url.
I didn't find a way to use "include_default_lang: true" and "http_accept_language: true" together.
@agryson Does this happen only on clicking the lang switcher or if you attempt to change url via the browser url bar too? Just in case it's not a plugin issue but a Grav issue
@agryson Does this happen only on clicking the lang switcher or if you attempt to change url via the browser url bar too? Just in case it's not a plugin issue but a Grav issue
Attempting to change url via the browser works.
I'm also running into this issue and exactly like the op determined, session_store: true
seems to be the culprit of this behaviour, in combination with include_default_lang: false
.
The langswitcher templates follow the include_default_lang
system setting, by using grav.language.getLanguageURLPrefix()
, which then leaves out the default language, causing Grav to revert back to its stored language.
So I think the fix could simply be to always include the language instead of using getLanguagePrefix()
. The drawback of that however, is that it triggers an extra request due to the 302 redirect.
P.S. For reference, it looks like #12 described this same issue.
Can this be tested with latest develop branch? that logic has been rewritten.
Context
I have a site set up so that English is the default language and French is a second language.
When the user switches to French,
/fr/
is inserted just after the rootme.net/page
->me.net/fr/page
.With
session_store_active : false
this behaviour works as expected both ways, changing language will add or remove the/fr/
appropriately.Issue
However, setting
session_store: true
"traps" the user in French: trying to change the language to English points the user tome.net/page
as expected but a302
redirect bounces them back tome.net/fr/page
.Changing just the
session_store
setting and nothing else makes this behaviour systematically repeatable.Useful data