Skip to content

Instantly share code, notes, and snippets.

@rummelonp
Created September 13, 2014 18:57
Show Gist options
  • Save rummelonp/86dad16372ba1e848ff7 to your computer and use it in GitHub Desktop.
Save rummelonp/86dad16372ba1e848ff7 to your computer and use it in GitHub Desktop.
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