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

Use default locale when not explicitly stated #2313

Merged
merged 1 commit into from
Jan 14, 2021
Merged
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
12 changes: 9 additions & 3 deletions src/Event/Subscriber/LocaleSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@

class LocaleSubscriber implements EventSubscriberInterface
{
/** @var string */
private $defaultLocale;

public function __construct(string $defaultLocale)
{
$this->defaultLocale = $defaultLocale;
}

public function onKernelRequest(RequestEvent $event): void
{
$request = $event->getRequest();
Expand All @@ -29,9 +37,7 @@ public function onKernelRequest(RequestEvent $event): void
} elseif ($request->attributes->get('zone', false) === 'backend' && $request->getSession()->has('_backend_locale')) {
$request->setLocale($request->getSession()->get('_backend_locale'));
} elseif ($request->getSession()->has('_locale')) {
// @todo: This is probably never reached. Remove if you're brave enough ;-)
// if no explicit locale has been set on this request, use one from the session
$request->setLocale($request->getSession()->get('_locale'));
$request->setLocale($this->defaultLocale);
}
}

Expand Down