module RailsSetLocale::InstanceMethods

Private Instance Methods

set_locale() click to toggle source
# File lib/rails_set_locale.rb, line 18
def set_locale
  locale_to_set = session[:locale]

  if locale_to_set.blank?
    # try to get it from the HTTP ACCEPT LANGUAGE header
    locale_to_set = http_accept_language.compatible_language_from(I18n.available_locales)
  end

  locale_to_set = I18n.default_locale if locale_to_set.blank?

  I18n.locale = locale_to_set

  session[:locale] = locale_to_set
end