-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] Similar locale selection #52986
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. It looks cool.
Can you also test these:
ja-JP,fr;q=0.5
ja-JP,fr_CA;q=0.7
Both of them should go to fr_FR
, right?
How about these?
ja-JP,fr_CA;q=0.7,fr;q=0.5,en_US;q=0.3
ja-JP,fr;q=0.5,en_US;q=0.3
ja-JP,fr_CA;q=0.7,en_US;q=0.3
ja-JP,fr_CA;q=0.7,en;q=0.5
Maybe for another PR, but shouldn't we add support for |
Many thanks for your comments. Indeed there is something wrong with some cases such as this one where |
48c8c98
to
b1525a3
Compare
f8b2126
to
4ed69e0
Compare
Hi, I updated the PR and changed the comparison logic:
Please note that the In addition, the returned locale value is always |
10b0a45
to
85e3a7f
Compare
Many thanks for the last suggestions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an improvement, for 7.1 ;)
16a03e4
to
1d5e821
Compare
1d5e821
to
f67a5d7
Compare
PHP already has a locale matching algorithm in ext-intl: https://www.php.net/manual/fr/locale.lookup.php (or maybe some of the other methods there) Would this algorithm help for this PR ? If yes, the proper way to solve it might be to implement them in the polyfill in https://github.com/symfony/polyfill/blob/1.x/src/Intl/Icu/Locale.php (where it currently throw an exception saying it is not implemented) and to use it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks
PHP already has a locale matching algorithm in ext-intl [...] the proper way to solve it might be to implement them in the polyfill
Good idea! I suggest merging this PR, and switch to the polyfill once we have it. Nothing is public here so the switch should be easy.
8a259ab
to
fbe44f0
Compare
fbe44f0
to
ef73505
Compare
Thank you @Spomky. |
Allow the nearest locale to be selected instead the default one.
Ping @welcoMattic
I noted a non-optimized locale selection. Let say I have the following controller and root route:
And the following parameters:
$this->supportedLocales
=['fr_FR', 'en_US']
$this->defaultLocale
='en_US'
When a user arrives on this page with the header
accept-language: ja-JP,fr_CA;q=0.7,fr;q=0.5
, the default localeen_US
is returned.In this situation, I would expect to use
fr_FR
as the browser indicates French is a possible choice (fr_CA
andfr
).With this change, and if no exact match is found, a similar language is selected. In this example,
fr_FR
is acceptable and then returned.