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

Stop Symfony from overwriting the localefrom the query string when set_locale_from_accept_language is true #3397

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Event/Subscriber/LocaleSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ public function onKernelRequest(RequestEvent $event): void
$locale = $request->query->get('_locale');
$request->getSession()->set('_locale', $locale);
$request->setLocale($locale);

// Symfony does not take this query parameter into account in its own subscriber.
// Symfony's listener has a lower priority and will thus be called later.
// It will not check that the locale was set already and in case useAcceptLanguageHeader
// (see https://symfony.com/doc/5.4/reference/configuration/framework.html#set-locale-from-accept-language) is set, it will
// overwrite the locale that was just set.
// @see https://github.com/symfony/symfony/blob/5.4/src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php#L71
$request->attributes->set('_locale', $locale);
} elseif ($request->attributes->get('zone', false) === 'backend' && $request->getSession()->has('_backend_locale')) {
$request->setLocale($request->getSession()->get('_backend_locale'));
} else {
Expand Down