title: symfony change locale in route during login
body: <p>I'm stumbling upon an issue on changing the locale during the login event on a symfony (2.7) application. I was following the sticky locale symfony article <a href="http://symfony.com/doc/current/cookbook/session/locale_sticky_session.html" rel="nofollow">http://symfony.com/doc/current/cookbook/session/locale_sticky_session.html</a>, but not using the session at all.</p>
  
  <p>I'm using the approach that every URI contains one representation only. Therefore all routes contain the {_locale} (and no need of a session variable for sticky locales).</p>
  
  <p>I'm just using the UserLocaleListener part to get the users locale and tried to set it into the route like on this github issue <a href="https://github.com/FriendsOfSymfony/FOSUserBundle/issues/829" rel="nofollow">https://github.com/FriendsOfSymfony/FOSUserBundle/issues/829</a>.</p>
  
  <p>My problem possibly is, that on login is already a URI locale set. During the login event, I need/want to overwrite this locale value. As mentioned by the github article, I added the <em>router context</em>.</p>
  
  <p>UserLocaleListener InteractiveLoginEvent</p>
  
  <pre><code>/**
   * @param InteractiveLoginEvent $event
   */
  public function onInteractiveLogin(InteractiveLoginEvent $event)
  {
      $request = $event-&gt;getRequest();
      $user = $event-&gt;getAuthenticationToken()-&gt;getUser();
      $locale = $user-&gt;getLocale();
  
      if (null !== $locale) {
          $request-&gt;setLocale($locale);
          $this-&gt;router-&gt;getContext()-&gt;setParameter('_locale', $locale);
  
          //var_dump(); die;
      }
  }
  </code></pre>
  
  <p>Unfortunately, it doesn't work (at least on my symfony 2.7).</p>
  
  <p>If I dump the requests locale or the router context locale, the correct user locale was applied to the context, but not changed/applied on redirecting to the <em>default_target_path</em> or any other path.</p>
  
  <p>Is the <em>onInteractiveLoginEvent</em> already too late to change the locale in an URI? Or how do I best change the locale in the URI during a (form based) login?</p>
  
  <p>Many thanks for any hint.</p>