Skip to content

Instantly share code, notes, and snippets.

@hemalich
Created January 19, 2011 10:36
Show Gist options
  • Select an option

  • Save hemalich/785987 to your computer and use it in GitHub Desktop.

Select an option

Save hemalich/785987 to your computer and use it in GitHub Desktop.
Using Accept-Language HTTP header
def set_locale
logger.debug "* Accept-Language: #{request.env['HTTP_ACCEPT_LANGUAGE']}"
I18n.locale = extract_locale_from_accept_language_header
logger.debug "* Locale set to '#{I18n.locale}'"
end
private
def extract_locale_from_accept_language_header
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