title: Remove "?locale=en" from URL
body: <h2>The goal</h2>
  
  <p>Remove <code>?locale=en</code> of browser's URL bar when I click on a link.</p>
  
  <p><sub>Note: there's no any asynchronous mechanism behind the process. I mean, there's no <a href="https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history" rel="nofollow noreferrer"><code>window.history.pushState</code></a> modifying URL dynamically when I click something.</sub></p>
  
  <h2>The problem</h2>
  
  <p>Everything I'm doing isn't solving my problem.</p>
  
  <h2>What I've tried</h2>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/5261521/how-to-avoid-adding-the-default-locale-in-generated-urls">How to avoid adding the default Locale in generated URLs?</a></li>
  </ul>
  
  <p><sub><em>I'm still searching further solutions.</em></sub></p>
  
  <h2>Scenario</h2>
  
  <p>I don't want to have a localized admin panel, then, my routing are the following:</p>
  
  <pre><code>scope '/(:locale)', locale: /#{I18n.available_locales.join("|")}/ do
    root to: 'welcome#index'
  end
  
  namespace :admin do
    get '/' =&gt; 'home#index'
  
    resources :products
  end
  </code></pre>
  
  <p>But I'm still always getting <code>?locale=en</code> when I click on a link inside the admin's panel. This is how I set the locale:</p>
  
  <pre><code># /app/controllers/application_controller.rb
  def set_locale
    extracted_locale = params[:locale] || extract_locale_from_accept_language_header
  
    I18n.locale = (I18n::available_locales.include? extracted_locale.to_sym) ? 
                  extracted_locale : I18n.default_locale
  end
  </code></pre>
  
  <p>This is my <em>private</em> <code>extract_locale_from_accept_language_header</code> method:</p>
  
  <pre><code># /app/controllers/application_controller.rb
  private
  def extract_locale_from_accept_language_header
    request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first
  end
  </code></pre>
  
  <h2>Diagnose reaction</h2>
  
  <p>If I change this:</p>
  
  <pre><code>I18n.locale = (I18n::available_locales.include? extracted_locale.to_sym) ? 
                extracted_locale : I18n.default_locale
  </code></pre>
  
  <p>for this:</p>
  
  <pre><code>I18n.locale = params[:locale] || I18n.default_locale
  </code></pre>
  
  <p>the issue is <em>partially</em> solved. Unfortunately, this is not what I really want. I'm dealing with browser's language if there's no other option to resolve the user's locale (a.k.a. URL's locale-parameter is explicitly set).</p>