Created
January 19, 2011 10:36
-
-
Save hemalich/785987 to your computer and use it in GitHub Desktop.
Using Accept-Language HTTP header
This file contains hidden or 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
| 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