Created
August 17, 2010 10:01
-
-
Save fguillen/529148 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# application_controller.rb | |
before_filter :set_locale | |
private | |
def set_locale | |
new_locale = params[:locale] || cookies[:locale] || extract_locale_from_accept_language_header || I18n.default_locale | |
if I18n.available_locales.include?( new_locale.to_sym ) | |
I18n.locale = new_locale | |
cookies[:locale] = {:value => new_locale, :expires => 10.years.from_now} | |
end | |
end | |
def extract_locale_from_accept_language_header | |
return nil if !request.env['HTTP_ACCEPT_LANGUAGE'] | |
request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment