maximeschoeni / sublanguage

Multilanguage plugin for wordpress
42 stars 13 forks source link

Auto detect language not working #28

Closed AdrienPoupa closed 6 years ago

AdrienPoupa commented 6 years ago

Hello, I have set up your plugin on my blog. I use French and English. The options are set as follows: image Everything works if I go on myblog/fr or myblog/en. If I go to myblog, it redirects me to myblog/fr. However, on a device configured in English, I am still redirected to myblog/fr while I expected to be redirected to myblog/en. Is it normal? Thank you! Test URL: https://adrien.poupa.fr/

maximeschoeni commented 6 years ago

Thanks for submitting this issue. I'll check the language detection function and see if it can be improved.

https://github.com/maximeschoeni/sublanguage/blob/6208385787e329d98daedda4a923b12c1882186e/class-site.php#L1043-L1055

AdrienPoupa commented 6 years ago

I solved it. It was (mostly) my fault.

First, I did not have the php7.1-intl extension installed. Therefore, if (class_exists('Locale')) { could not work. It might be worth it to add this info to the documentation.

Then, for some reason, the "English" language in the "Languages" settings page had the slug set to "en" but the locale was missing. I set it to en_US.

It is working now, whether HTTP_ACCEPT_LANGUAGE returns en-US, en-GB or simply en.