public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if (!$request->hasPreviousSession()) {
         return;
     }
     $request->setLocale($this->localeService->getLocale()->getLocale());
 }
 /**
  * @param ChangeLocaleCommand $changeLocaleCommand
  */
 public function changeLocale(ChangeLocaleCommand $changeLocaleCommand)
 {
     $user = $this->getUser();
     $user->switchLocaleTo(new Locale($changeLocaleCommand->newLocale));
     $this->localeService->saveLocaleOf($user);
 }
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $availableLocales = $this->localeService->getAvailableLocales();
     $localeChoices = $this->formatLocaleChoices($availableLocales);
     $builder->setAction($this->urlGenerator->generate('profile.locale_switch_locale', ['return-url' => $options['return_url']]))->add('newLocale', 'choice', ['choices' => $localeChoices, 'data' => $this->localeService->getLocale()->getLocale(), 'attr' => ['data-locale-options' => '']])->add('changeLocale', 'submit', ['label' => 'profile.locale.choose_locale']);
 }