Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Nyholm left a comment
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.5ja-JP,fr_CA;q=0.7Both of them should go tofr_FR, right?
How about these?
ja-JP,fr_CA;q=0.7,fr;q=0.5,en_US;q=0.3ja-JP,fr;q=0.5,en_US;q=0.3ja-JP,fr_CA;q=0.7,en_US;q=0.3ja-JP,fr_CA;q=0.7,en;q=0.5welcoMattic commentedDec 11, 2023
Maybe for another PR, but shouldn't we add support for |
Spomky commentedDec 11, 2023
Many thanks for your comments. Indeed there is something wrong with some casessuch as this one where |
48c8c98 tob1525a3Comparef8b2126 to4ed69e0CompareSpomky commentedDec 11, 2023
Hi, I updated the PR and changed the comparison logic:
Please note that the In addition, the returned locale value is always |
10b0a45 to85e3a7fCompareSpomky commentedFeb 1, 2024
Many thanks for the last suggestions. |
nicolas-grekas left a comment
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 ;)
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
16a03e4 to1d5e821Compare1d5e821 tof67a5d7Comparestof commentedApr 3, 2024
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 inhttps://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. |
nicolas-grekas left a comment
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.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
8a259ab tofbe44f0CompareUh oh!
There was an error while loading.Please reload this page.
fbe44f0 toef73505Comparefabpot commentedApr 5, 2024
Thank you@Spomky. |
Uh oh!
There was an error while loading.Please reload this page.
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_USis returned.In this situation, I would expect to use
fr_FRas the browser indicates French is a possible choice (fr_CAandfr).With this change, and if no exact match is found, a similar language is selected. In this example,
fr_FRis acceptable and then returned.