title: How to change the locale through URL?
body: <p>In my bi-lingual Rails 4 application I have a <code>LocalesController</code> like this:</p>
  
  <pre><code>class LocalesController &lt; ApplicationController
  
    def change_locale
      if params[:set_locale]
        session[:locale] = params[:set_locale] 
        url_hash = Rails.application.routes.recognize_path URI(request.referer).path
        url_hash[:locale] = params[:set_locale]
        redirect_to url_hash
      end
    end
  
  end
  </code></pre>
  
  <p>A User can change his locale through this form:</p>
  
  <pre><code>def locale_switcher
    form_tag url_for(:controller =&gt; 'locales', :action =&gt; 'change_locale'), :method =&gt; 'get', :id =&gt; 'locale_switcher' do
    select_tag 'set_locale', options_for_select(LANGUAGES, I18n.locale.to_s)
  end
  </code></pre>
  
  <p>This works.</p>
  
  <p>However, right now there's no way for the user to change the language via the URL.</p>
  
  <p>E.g. if a user is on the page <code>www.app.com/en/projects</code> and then manually changes the URL to <code>www.app.com/fr/projects</code>, he <em>should</em> see the French version of the page, but instead nothing happens.</p>
  
  <p>This may not matter in many Rails apps but in mine it is quite important.</p>
  
  <p>How can it be fixed?</p>
  
  <p>Thanks for any help.</p>