src/Locale/EventSubscriber/LocaleSubscriber.php line 17
<?phpnamespace App\Locale\EventSubscriber;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\HttpKernel\Event\RequestEvent;use Symfony\Component\HttpKernel\KernelEvents;class LocaleSubscriber implements EventSubscriberInterface{private string $defaultLocale;public function __construct($defaultLocale = 'cs'){$this->defaultLocale = $defaultLocale;}public function onKernelRequest(RequestEvent $event): void{$request = $event->getRequest();if (!$request->hasPreviousSession()) {return;}$session = $request->getSession();if ($locale = $request->get('_locale')) {$session->set('_locale', $locale);$request->setLocale($locale);} else {$request->setLocale($session->get('_locale', $this->defaultLocale));}}public static function getSubscribedEvents(): array{return [KernelEvents::REQUEST => ['onKernelRequest', 20],];}}