Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #52986 [HttpFoundation] Similar locale selection (Spomky)
This PR was merged into the 7.1 branch. Discussion ---------- [HttpFoundation] Similar locale selection | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Issues | none | License | MIT 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: ```php #[Route('/', name: 'app_root', methods: [Request::METHOD_GET])] public function indexNoLocale(Request $request): Response { $locale = $request->getPreferredLanguage($this->supportedLocales) ?? $this->defaultLocale; return $this->redirectToRoute('app_homepage', [ '_locale' => $locale, ], Response::HTTP_SEE_OTHER); } ``` 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 locale `en_US` is returned. In this situation, I would expect to use `fr_FR` as the browser indicates French is a possible choice (`fr_CA` and `fr`). 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. Commits ------- ef73505 Allow the nearest locale to be selected instead the default one.
- Loading branch information
Showing
2 changed files
with
146 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters