title: Symfony 2, switching language does not work
body: <p>I wonder why when I click the links on the view to switch the language it doesn't work. If I set default locale to en or km, it will show English language or Khmer language respectively. What wrong with me, I can not click links below to switch the language? Please help me ! Many thanks in advanced for any answer.</p>
  
  <p>In the view</p>
  
  <pre><code>&lt;div class="col-sm-3 language-switcher"&gt;
      &lt;a href="{{ path('ngs_locale', {locale: 'en'}) }}"&gt;English&lt;/a&gt; |
      &lt;a href="{{ path('ngs_locale', {locale: 'km'}) }}"&gt;ខ្មែរ&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>routing.yml</p>
  
  <pre><code>ngs_locale:
  path:     locale/{locale}
  defaults: { _controller: NGSHomeBundle:Locale:locale }
  </code></pre>
  
  <p>LocaleController.php</p>
  
  <pre><code>namespace NGS\HomeBundle\Controller;
  
  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  
  class LocaleController extends Controller
  {
      public function localeAction(Request $request, $locale)
      {
          /** ======== dump ========== **/
          dump($locale); //"km"
          $request-&gt;getSession()-&gt;set('_locale', $locale);
  
          /** ======== dump ========== **/
          dump($request-&gt;getLocale()); //"en"
  
          $referer = $request-&gt;headers-&gt;get('referer');
  
          /** ======== dump ========== **/
          dump($referer);die; // null
  
          if (empty($referer)) {
              throw $this-&gt;createNotFoundException('ngs_not_found');
          }
  
          return $this-&gt;redirect($referer);
      }
  }
  </code></pre>
  
  <p>LocaleListener.php</p>
  
  <pre><code>namespace NGS\HomeBundle\EventListener;
  
  use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  use Symfony\Component\HttpKernel\KernelEvents;
  use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  
  class LocaleListener implements EventSubscriberInterface
  {
      private $defaultLocale;
  
      public function __construct($defaultLocale = 'en')
      {
          $this-&gt;defaultLocale = $defaultLocale;
      }
  
      public function onKernelRequest(GetResponseEvent $event)
      {
          $request = $event-&gt;getRequest();
          if (!$request-&gt;hasPreviousSession()) {
              return;
          }
  
          // try to see if the locale has been set as a _locale routing parameter
          if ($locale = $request-&gt;attributes-&gt;get('_locale')) {
              $request-&gt;getSession()-&gt;set('_locale', $locale);
          } else {
              // if no explicit locale has been set on this request, use one from the session
              $request-&gt;setLocale($request-&gt;getSession()-&gt;get('_locale', $this-&gt;defaultLocale));
          }
      }
  
      public static function getSubscribedEvents()
      {
          return array(
              // must be registered before the default Locale listener
              KernelEvents::REQUEST =&gt; array(array('onKernelRequest', 17)),
          );
      }
  }
  </code></pre>
  
  <p>Service.yml</p>
  
  <pre><code>services:
  ngs_home.locale_listener:
      class: NGS\HomeBundle\EventListener\LocaleListener
      arguments: ["%kernel.default_locale%"]
      tags:
          - { name: kernel.event_subscriber }
  </code></pre>