Module: I18nStrategy::Strategy

Defined in:
lib/i18n_strategy/strategy.rb

Instance Method Summary collapse

Instance Method Details

#detect_localeObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/i18n_strategy/strategy.rb', line 5

def detect_locale
  lang      = nil
  available = I18nStrategy.available_locales || []

  if params[:locale] && available.include?(params[:locale])
    lang = params[:locale]
  else
    parser = HttpAcceptLanguage::Parser.new(request.env['HTTP_ACCEPT_LANGUAGE'])
    lang   = parser.preferred_language_from(available)
  end

  lang || I18n.default_locale
end