Method: HttpAcceptLanguage#compatible_language_from

Defined in:
lib/http_accept_language.rb

#compatible_language_from(array) ⇒ Object

Returns the first of the user_preferred_languages that is included into the given array, ignoring region.

Useful with Rails’ I18n.available_locales.

Example:

Accept-Language: en;q=0.3, nl-NL, nl-be;q=0.9, en-US;q=0.5

request.compatible_language_from [:nl, :it]
# => 'nl'


74
75
76
# File 'lib/http_accept_language.rb', line 74

def compatible_language_from(array)
  (user_preferred_language_codes & strip_region_from(array)).first
end