Created
October 19, 2011 22:05
-
-
Save chrisb/1299837 to your computer and use it in GitHub Desktop.
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 current_language | |
# if a "lang" URL parameter is specified, force it | |
return params[:lang] if params[:lang].present? | |
# if the user is logged in, use their language preference stored in the DB | |
return current_user.language if logged_in? | |
# if the user has manually selected a language, return that | |
return cookies[:language_code] if cookies[:language_code] | |
# if the user is not logged in or has not selected a language | |
# attempt to determine a language based on their IP | |
LANGUAGE_TO_COUNTRY_MAPPINGS.keys.each { |lang| return lang if LANGUAGE_TO_COUNTRY_MAPPINGS[lang].include?(current_country) } | |
# if all else fails, return english | |
return 'eng' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment