<?php
/**
* Created by IntelliJ IDEA.
* User: dogukan
* Date: 2019-02-25
* Time: 22:07
*/
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class LocaleSubscriber implements EventSubscriberInterface
{
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return [
KernelEvents::REQUEST => [ 'setLocale', 17 ]
];
}
/**
* @param GetResponseEvent $event
*/
public function setLocale(GetResponseEvent $event)
{
$request = $event->getRequest();
if (null !== $locale = $request->getPreferredLanguage()) {
$request->setLocale($locale);
}
}
}