class

Citrine::I18n::Parser

Inherits Reference < Object

Taken from https://github.com/iain/http_accept_language/blob/master/lib/http_accept_language/parser.rb Taken from https://github.com/TechMagister/kemalyst-i18n/src/kemalyst-i18n/parser.cr

Constructors

new(header : String)
Source

Instance methods

compatible_language_from(available_languages)

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

Source
header
Source
language_region_compatible_from(available_languages)

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)

Source
preferred_language_from(array)

Finds the locale specifically requested by the browser.

Example:

request.preferred_language_from I18n.available_locales

=> 'nl'

Source
sanitize_available_locales(available_languages)

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]

Source
user_preferred_languages

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' ]

Source
user_preferred_languages=(languages : Nil | Array(String))

Sets the user languages preference, overriding the browser

Source