<?php
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class LocaleSubscriber implements EventSubscriberInterface
{
public function onKernelRequest(RequestEvent $event)
{
$x = $event->getRequest()->headers->get('X-localization');
if (in_array($x, ['en', 'tr'])) {
$event->getRequest()->setLocale($x);
} else {
$event->getRequest()->setLocale('en');
}
}
public static function getSubscribedEvents()
{
return [
KernelEvents::REQUEST => [
[ 'onKernelRequest', 20 ],
],
];
}
}