-
Notifications
You must be signed in to change notification settings - Fork 37
Safari selects wrong language with two common roots #234
Comments
Hi, and thanks for this (detailed) issue. The problem is that Safari seems to be sending lowercase values in the Accept-Language header. MultilingualPress, however, is matching against HTTP codes with the language part being lowercase, while the region part is uppercase. I did a quick search and learned that a lowercase value seems to be perfectly valid. MultilingualPress is trying to match If you are a developer, you could try the following changes to
so you have the following: foreach ( $fields as $name => $priority ) {
// The following line is the new one.
$name = strtolower( $name );
$out[ $name ] = $priority;
// ...
}
$lang_http = $language->get_name( 'http_name' );
// The following line is the first of the new ones.
$lang_http = strtolower( $lang_http );
// ...
$lang_short = $language->get_name( 'language_short' );
// The following line is the second and last of the new ones.
$lang_short = strtolower( $lang_short ); This should do the trick. If it really does, it will soon get shipped in a new release. Thanks, |
Hi Thorsten, Thanks for the code. I've made the necessary modifications, but unfortunately that doesn't seem to do it. in
|
Hi, thanks for reporting back. I will try this locally with faked data for both Accept-Language and possible translations. The problem, as I see it now, is that MultilingualPress does not differentiate between language codes that match with their language and region parts, and the ones that only match with their language part. This is, of course, not ideal. |
It does seem that way. I am guessing that in the Firefox and Chrome cases it work out better because they report the language with a lower priority. (region = 1, language = .5/.8). In that way the priority is then properly modified (priority * browser_priority) and the correct site locale can then be selected. With Safari, MultilingualPress adds the non-region language entry because Safari doesn't provide it, and copies the priority, so both end up equal. Side note: MultilingualPress also adds an empty entry on for Firefox and Chrome, though it doesn't seem to have any ill effect in my setup. I wasn't able to look into why that is.
Safari Firefox Chrome |
Thanks for looking into it. You made the same observations as I did. :) Currently, I'm thinking about adding a language-only match with a lower priority than the full one. This lower value could be calculated by the original priority of the full language, multiplied with a filterable factor, which defaults to maybe 0.7. I also saw the entry with the empty key. This happens because MultilingualPress returns Thanks again! |
Hey @dboune, I finally managed to give this a try. If you have time, feel free to check out the new feature branch. All changes were made in The commit includes all changes like proposed:
Thanks, |
@tfrommen This worked for me! Thank you! Safari on IOS also had the same issue (not unexpected), and both are now working as expected for my particular scenario. I have not tested more than two locales with the same root. |
Great! Thanks for testing, @dboune - I will merge this and release it sometime soon. |
Version Information
Steps to Reproduce
What I Expected
With system/browser language set to US english, no redirect occurs. This is the case in Chrome and in Firefox.
What Happened Instead
In Safari only, redirect occurs to en-GB despite system language set to US English.
*Note that not setting equal priority will cause the higher priority site to always load in any browser, regardless of system language.
Overall expectation
The larger desired behavior here is that if a user comes to the site with US English, no redirection occurs. If they come to the site with en-GB, they are redirected to the en-GB site.
Browser Information (all current versions on OS X)
Here are the Accept-Language header values for various browsers with a US English configuration
Safari
[en-us] => 1
Firefox
[en-US] => 1
[en] => 0.5
Chrome
[en-US] => 1
[en] => 0.8
The text was updated successfully, but these errors were encountered: