Fix locale switcher

pull/15/head
Clément FRÉVILLE 11 months ago
parent 4cff543f7d
commit 9d380e7a5a

@ -5,13 +5,18 @@ namespace App\EventListener;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener; use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Translation\LocaleSwitcher;
final class LocaleListener final readonly class LocaleListener
{ {
public function __construct(private LocaleSwitcher $localeSwitcher)
{
}
#[AsEventListener(event: KernelEvents::REQUEST)] #[AsEventListener(event: KernelEvents::REQUEST)]
public function onKernelRequest(RequestEvent $event): void public function onKernelRequest(RequestEvent $event): void
{ {
$request = $event->getRequest(); $request = $event->getRequest();
$request->setLocale($request->getSession()->get('_locale', 'en')); $this->localeSwitcher->setLocale($request->getSession()->get('_locale', 'en'));
} }
} }

Loading…
Cancel
Save