Automatic language detection bug?

When I set the automatic language detection to true. Clear my cookies and go to the website, it ships me to the correct language the first time around. In my case english. And the default is set to brazilian. But when I start navigate the website and change the language manually, and go back to home. I get a strange error. And it happens all times I change languages manually. To get back to home, I need to clear my cookies and refresh the page. And in that way I get back to the home page. But that render the automatic language detection not very useful right now.

c::set('language.detect', true);

I tested this with a fresh Langkit and couldn’t reproduce it, maybe it happens because of the routes?

This is with all the routes disabled. So that is odd. Also it is so stable, I can provoke it and make it happen in my local dev. env. and on the server. I do run the last Kirby core 2.5.12.

But this is a low priority issue for me. Cause of the lack of a better language switch. The current behaviour in Europe is working ok, but for other places like brazil it will always fail. This cause the “pt_BR” or “pt-br” witch is used in brazilian browsers and that do not match /br route. And this is also an issue for similar languages like spanish etc. https://github.com/getkirby/kirby/issues/510

I disabled the language.detect and replaced it with routing in the .htaccess

This is how I fix this, I added this code after the # RewriteBase / and modify the langauges:

# redirect to br
RewriteCond %{HTTP:HOST} www.xyz.com
RewriteCond %{HTTP:Accept-Language} ^br [NC]
RewriteRule ^$ https://www.xyz.com/br [L,R=301]

# redirect to pt
RewriteCond %{HTTP:HOST} www.xyz.com
RewriteCond %{HTTP:Accept-Language} ^pt [NC]
RewriteRule ^$ https://www.xyz.com/br [L,R=301]

# redirect to en
RewriteCond %{HTTP:HOST} www.xyz.com
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteRule ^$ https://www.xyz.com/en [L,R=301]

# for everyone else
RewriteCond %{HTTP:HOST} www.xyz.com
RewriteRule ^$ https://www.xyz.com/en [L,R=301]

Here you also find the codes: https://www.metamodpro.com/browser-language-codes

Please don’t delete solved posts. They are helpful for future members of the community.

I am not aware of that “solved” posts get deleted. I added the solution with the intention to help others. :wink:

No, solved posts are not deleted and I think you can‘t even delete a thread that has answers as a normal user, only your own posts.

Confirmed. Not possible. :slight_smile: