Created
September 13, 2014 18:57
-
-
Save rummelonp/86dad16372ba1e848ff7 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
class ApplicationController | |
before_action :set_locale | |
private | |
def set_locale | |
if authenticated? | |
I18n.locale = current_user.locale | |
else | |
langs = (request.headers['HTTP_ACCEPT_LANGUAGE'] || '').split(',').map { |l| l.split(';').first } | |
I18n.locale = langs.find { |l| I18n.available_locales.include?(l.to_sym) } | |
end | |
rescue I18n::InvalidLocale | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment