src/Sulu/Bundle/SecurityBundle/EventListener/UserLocaleListener.php
public function copyUserLocaleToRequest(GetResponseEvent $event)
    {
        $token = $this->tokenStorage->getToken();
        if (!$token) {
            return;
        }

        $user = $token->getUser();
        if (!$user instanceof UserInterface) {
            return;
        }

        $locale = $user->getLocale();
        $event->getRequest()->setLocale($locale);
        $this->translator->setLocale($locale);
    }
public function copyUserLocaleToRequest(GetResponseEvent $event)
    {
        $token = $this->tokenStorage->getToken();
        if (!$token) {
            return;
        }

        $user = $token->getUser();
        if (!$user instanceof UserInterface) {
            return;
        }

        $locale = $user->getLocale();
        $event->getRequest()->setLocale($locale);
        $this->translator->setLocale($locale);
    }
public function copyUserLocaleToRequest ( GetResponseEvent $ event ) { $ token = $ this -> tokenStorage -> getToken ( ) ; if ( ! $ token ) { return ; } $ user = $ token -> getUser ( ) ; if ( ! $ user instanceof UserInterface ) { return ; } $ locale = $ user -> getLocale ( ) ; $ event -> getRequest ( ) -> setLocale ( $ locale ) ; $ this -> translator -> setLocale ( $ locale ) ; }
Sets the locale of the current User to the request, if a User is logged in.

@param GetResponseEvent $event
Sets the locale of the current User to the request if a User is logged in .