8000 Set the default locale early · symfony/symfony@c499c47 · GitHub
[go: up one dir, main page]

Skip to content

Commit c499c47

Browse files
Set the default locale early
1 parent 317a2f9 commit c499c47

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,14 @@ public function __construct(RequestStack $requestStack, $defaultLocale = 'en', R
4242
$this->router = $router;
4343
}
4444

45+
public function onKernelRequestEarly(GetResponseEvent $event)
46+
{
47+
$event->getRequest()->setDefaultLocale($this->defaultLocale);
48+
}
49+
4550
public function onKernelRequest(GetResponseEvent $event)
4651
{
4752
$request = $event->getRequest();
48-
$request->setDefaultLocale($this->defaultLocale);
4953

5054
$this->setLocale($request);
5155
$this->setRouterContext($request);
@@ -75,6 +79,7 @@ private function setRouterContext(Request $request)
7579
public static function getSubscribedEvents()
7680
{
7781
return array(
82+
KernelEvents::REQUEST => array(array('onKernelRequestEarly', 100)),
7883
// must be registered after the Router to have access to the _locale
7984
KernelEvents::REQUEST => array(array('onKernelRequest', 16)),
8085
KernelEvents::FINISH_REQUEST => array(array('onKernelFinishRequest', 0)),

src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleListenerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testDefaultLocaleWithoutSession()
3131
$listener = new LocaleListener($this->requestStack, 'fr');
3232
$event = $this->getEvent($request = Request::create('/'));
3333

34-
$listener->onKernelRequest($event);
34+
$listener->onKernelRequestEarly($event);
3535
$this->assertEquals('fr', $request->getLocale());
3636
}
3737

0 commit comments

Comments
 (0)
0