Module: HttpLanguageParser

Defined in:
lib/http_language_parser.rb

Class Method Summary collapse

Class Method Details

.parse(header) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/http_language_parser.rb', line 4

def self.parse(header)
  # Rails I18n uses underscores between the locale and the region; the request
  # headers use hyphens.
  require "http_accept_language" unless defined?(HttpAcceptLanguage)
  available_locales = I18n.available_locales.map { |locale| locale.to_s.tr("_", "-") }
  parser = HttpAcceptLanguage::Parser.new(header)
  matched = parser.language_region_compatible_from(available_locales)&.tr("-", "_")
  matched || SiteSetting.default_locale
end