/**
* @var list<string>
*/
private array
$installerLanguages =
['de', 'en'
];
#[AsEventListener(RequestEvent::class, priority: 15)]
public function __invoke(RequestEvent
$event): void
{ $request =
$event->
getRequest();
$locale =
$this->
detectLanguage($request);
$request->attributes->
set('_locale',
$locale);
$request->
setLocale($locale);
} private function detectLanguage(Request
$request): string
{ $session =
$request->
getSession();
// language is changed
if ($request->query->
has('language'
) && \
in_array((string) $request->query->
get('language'
),
$this->installerLanguages, true
)) { $session->
set('language',
(string) $request->query->
get('language'
));