<?php
namespace App\EventListener;
use Symfony\Component\HttpKernel\Event\RequestEvent;
class LocaleListener
{
public function __invoke(RequestEvent $event)
{
$request = $event->getRequest();
if (!$request->hasPreviousSession()) {
return;
}
$locale = $request->getSession()->get('user_lang');
if(is_null($locale) || $locale == '') {
$locale = 'en';
}
$request->setLocale($locale);
}
}