module SimplificatorInfrastructure::LocaleDetection::InstanceMethods

Private Instance Methods

available_locale_or_nil(locale) click to toggle source
# File lib/simplificator_infrastructure/locale_detection.rb, line 30
def available_locale_or_nil(locale)
  I18n.available_locales.map(&:to_s).include?(locale) ? locale.to_sym : nil
end
detect_locale() click to toggle source
# File lib/simplificator_infrastructure/locale_detection.rb, line 7
def detect_locale
  locale_from_params || locale_from_header || locale_default
end
locale_default() click to toggle source
# File lib/simplificator_infrastructure/locale_detection.rb, line 26
def locale_default
  I18n.default_locale
end
locale_from_header() click to toggle source
# File lib/simplificator_infrastructure/locale_detection.rb, line 16
def locale_from_header
  # Use "curl  -H 'Accept-language: fr' localhost:3000" to test it.

  header = request.env['HTTP_ACCEPT_LANGUAGE']
  return if header.blank?

  locale = header.scan(/^[a-z]{2}/).first
  available_locale_or_nil(locale)
end
locale_from_params() click to toggle source
# File lib/simplificator_infrastructure/locale_detection.rb, line 11
def locale_from_params
  locale = params['locale']
  available_locale_or_nil(locale)
end