Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[2.3] Improve preferred language detection #6928

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

Closed
wants to merge 1 commit into from
Closed

[2.3] Improve preferred language detection #6928

wants to merge 1 commit into from

Conversation

mweimerskirch
Copy link
Contributor

getPreferredLanguage does a simple intersect between the given languages and the ones from the request.
e.g. if you call getPreferredLanguage(array('fr', 'de', 'en')) and your Browser sends "en-US,en" as the accepted languages, the expected behaviour would be to have it return "en". This works most of the time. However, Safari (and possibly other browsers) only send the longer version (in the above example it would only send "en-us"), so getPreferredLanguage would not return "en" but the first result, which would be "fr".

This patch adds the shorter language code to the array of requested languages in order to fix this. I'm not sure if this patch is the best approach, so I'd appreciate feedback.

@vicb
Copy link
Contributor

vicb commented Jan 31, 2013

@mweimerskirch you should add a unit test, and conform to http://symfony.com/doc/current/contributing/code/patches.html - it might also be good to check when this bug first appear and fix it there (ie 2.0 or 2.1). Thanks.

@jfsimon
Copy link
Contributor

jfsimon commented Mar 13, 2013

@mweimerskirch it seems right, but as said @vicb, without any unit test, this wont be merged.
Could you add one please?

fabpot added a commit that referenced this pull request Mar 18, 2013
This PR was squashed before being merged into the 2.1 branch (closes #7378).

Commits
-------

17dc2ff [HttpRequest] fixes Request::getLanguages() bug

Discussion
----------

[HttpRequest] fixes Request::getLanguages() bug

This PR adds to suported languages the first segment of all compouds languages codes.
When receiving `Accept-Language: en-us` header, accepted languages will now be `en, en_US`.

This should not be a BC break as most browsers already send the long **and** short versions of language codes... but some dont.

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #6928
@fabpot fabpot closed this Mar 18, 2013
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

Successfully merging this pull request may close these issues.

4 participants