title: Detect the user's locale automatically
body: <p>My goal is to recognize the local user's browser and automatically set the language.</p>
  
  <p>Then allow the user to change language and keep it on other pages.</p>
  
  <p>At the time I set the routes in this way:</p>
  
  <pre><code># homepage not localized: load the homepage with default language
  index_not_localized:
     path:   /
     defaults:  { _controller: "AcmeSiteBundle:Default:index", _locale: %locale% }
  
  
  acme_site:
     resource: "@AcmeSiteBundle/Controller/"
     type:     annotation
     prefix:   /{_locale}
     defaults:  { _locale: %locale% }
     requirements:
          _locale:  %route_locale_requirements%
  </code></pre>
  
  <p>When the user enters the page example.com without specifying the language in the local route is set by default, and the page there is a switcher that allows you to change the language:</p>
  
  <pre><code>&lt;ul class="dropdown-menu"&gt;
       {% for locale in ['en', 'it'] %}
           &lt;li&gt;
               &lt;a href="{{ path('homepage', {'_locale': locale}) }}"&gt;
           &lt;/li&gt;
       {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>How do I do what I want?</p>
  
  <p>I have to create a listener? I have put the local session?</p>
  
  <p>I'm confused, I read several answers but have not found a clear answer!</p>