Class HttpAcceptLanguage::Parser
In: lib/http_accept_language/parser.rb
Parent: Object

Methods

Attributes

header  [RW] 

Public Class methods

Public Instance methods

Returns the first of the user_preferred_languages that is compatible with the available locales. Ignores region.

Example:

  request.compatible_language_from I18n.available_locales

Returns the first of the user preferred languages that is also found in available languages. Finds best fit by matching on primary language first and secondarily on region. If no matching region is found, return the first language in the group matching that primary language.

Example:

  request.language_region_compatible(available_languages)

Finds the locale specifically requested by the browser.

Example:

  request.preferred_language_from I18n.available_locales
  # => 'nl'

Returns a supplied list of available locals without any extra application info that may be attached to the locale for storage in the application.

Example:

ja_JP-x1, en-US-x4, en_UK-x5, fr-FR-x3
=> [ja-JP, en-US, en-UK, fr-FR]

Returns a sorted array based on user preference in HTTP_ACCEPT_LANGUAGE. Browsers send this HTTP header, so don‘t think this is holy.

Example:

  request.user_preferred_languages
  # => [ 'nl-NL', 'nl-BE', 'nl', 'en-US', 'en' ]

Sets the user languages preference, overriding the browser

[Validate]