Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browser Language Detection not working on Mobile Safari / iOS #6

Closed
twiro opened this issue Apr 14, 2014 · 8 comments
Closed

Browser Language Detection not working on Mobile Safari / iOS #6

twiro opened this issue Apr 14, 2014 · 8 comments

Comments

@twiro
Copy link

twiro commented Apr 14, 2014

A client told me they had troubles with the default language on mobile safari - I just checked that and it seems not to work for me too.

My configuration seems fine, everything works as expected on Firefox, Chrome and Safari at my desktop - whenever I delete the page-cookies and access the base-url ('domain.org') without language code, the site gets redirected based on my default browser language (german) : 'domain.org/de/'

But mobile Safari ignores the default browser language when no language is preselected (cookies are deleted too) and always shows the page content in 'en' (which is my default language set in symphony).

This is a Screenshot of my Browser User Agent String:

screen shot 2014-04-14 at 15 39 17

Is this a bug or might there be a mistake on my side...?

By the way - it would be awesome if the detection method could be added to the readme - as far as I understand this is what's going on:

  1. Check the cookie. If a language is set use that one. Cookie expires after 14 days?
  2. Check the Browser. If a prefered language is detected use that one.
  3. Use the default language set in Symphony

Am I right? Or am I missing something...?

@nitriques
Copy link
Member

Hum... this is strange as I do not experience this bug in mobile safari (but I am on ios7).

Adding a redirection method header is a good idea.

But I really think the bug is elsewhere since I use vlad's lib for getting the browser value.

See: https://github.com/DeuxHuitHuit/flang_redirection/blob/master/events/event.flang_redirect.php#L54

@nitriques
Copy link
Member

And yes you're totally right about how it works!

@twiro
Copy link
Author

twiro commented Apr 15, 2014

Thanks for your feedback!

I did some further investigation and noticed that my problem also appears on iOS7.
Then I had a look at the code and noticed the following:

The check for the browser languages seems to be done by the function getBrowserLanguages() in this extension: https://github.com/DeuxHuitHuit/flang_redirection/blob/master/events/event.flang_redirect.php#L86

There I noticed that on my Desktop-Browsers I get an array of languages that's looking like this:

Array ( [0] => de [1] => en-us [2] => en ) 

But on mobile Safari I don't get de but only de-de as a language-code:

Array ( [0] => de-de ) 

And the problem seems to be that this isn't recognized as the de-language set in my symphony-setup. Instead the extension falls back to the default language en.

So the thing missing in this process is that the full locale-code is stripped down to my language code set in symphony. So that every de-de, de-at or de-ch redirects to 'domain.org/de/' instead of 'domain.org/en/' when no language-code is set in the url.

I managed to get this working by changing lines 90-96 to the following:

foreach ($browser_languages as $language) {
    // extraxt language bits
    $language_bits = FLang::extractLanguageBits($language);
    $language_code = $language_bits[0];
    // check if language code is a valid symphony language
    if (FLang::validateLangCode($language_code)) {
        $in_browser_languages = true;
        $browser_language = $language_code;
        break;
    };
}

By extracting the language bits of the complete locale-code I managed to get all different "flavors" of german fall back to de. Exactly what I wanted, but I am not sure if this is fixing a general problem or bringing up some new ones for pages with multiple 'dialects' set in symphony.

Would be great If you could have a look at this and include it if it makes sense :)

Thanks a lot!

@nitriques
Copy link
Member

Wow! Awesome debugging-fu :) I'll see what I can do.

nitriques added a commit that referenced this issue Apr 15, 2014
@nitriques
Copy link
Member

I can confirm that your patch does solve the problem. Thanks again. Version 1.2 is out, just for you !

@nitriques
Copy link
Member

@twiro Did you had the chance to test it ?

@twiro
Copy link
Author

twiro commented Jun 2, 2014

I implemented it a while ago and haven't had any more complaints since then - so I guess it's running just fine. Thanks again!

@nitriques
Copy link
Member

Cool! I have deployed it myself and nobody complained! Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants