public function setLocaleForUnauthenticatedUser(GetResponseEvent $event)
    {
        if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
            return;
        }
        $request = $event->getRequest();
        if ('unset' == $request->getLocale()) {
            if ($locale = $request->getSession()->get('_locale')) {
                $request->setLocale($locale);
            } else {
                $request->setLocale($request->getPreferredLanguage());
            }
        }
    }
public function setLocaleForUnauthenticatedUser(GetResponseEvent $event)
    {
        if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
            return;
        }
        $request = $event->getRequest();
        if ('unset' == $request->getLocale()) {
            if ($locale = $request->getSession()->get('_locale')) {
                $request->setLocale($locale);
            } else {
                $request->setLocale($request->getPreferredLanguage());
            }
        }
    }
public function setLocaleForUnauthenticatedUser ( GetResponseEvent $ event ) { if ( HttpKernelInterface :: MASTER_REQUEST !== $ event -> getRequestType ( ) ) { return ; } $ request = $ event -> getRequest ( ) ; if ( 'unset' == $ request -> getLocale ( ) ) { if ( $ locale = $ request -> getSession ( ) -> get ( '_locale' ) ) { $ request -> setLocale ( $ locale ) ; } else { $ request -> setLocale ( $ request -> getPreferredLanguage ( ) ) ; } } }
kernel.request event. If a guest user doesn't have an opened session, locale is equal to
"undefined" as configured by default in parameters.ini. If so, set as a locale the user's
preferred language.

@param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
kernel . request event . If a guest user doesn t have an opened session locale is equal to undefined as configured by default in parameters . ini . If so set as a locale the user s preferred language .