pachisaez
9/21/2014 - 4:57 PM

Internationalization for two languages: EN (english) and ES (spanish), taking EN by default.

Internationalization for two languages: EN (english) and ES (spanish), taking EN by default.

class ApplicationController < ActionController::Base
  before_filter :set_locale
  
protected 
  def set_locale
    locale =  params[:locale] || session[:locale] || 
      (extact_locale_from_accept_language_header=='es' ? 'es' : 'en')
    session[:locale] = locale
    I18n.locale = locale
  end

private
  def extact_locale_from_accept_language_header
    request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first rescue "en"
  end
  
end