class Citrine::I18n::Parser
- Citrine::I18n::Parser
- Reference
- Object
Overview
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
Defined in:
citrine-i18n/parser.crConstructors
Instance Method Summary
-
#compatible_language_from(available_languages)
Returns the first of the user_preferred_languages that is compatible with the available locales.
- #header : String
-
#language_region_compatible_from(available_languages)
Returns the first of the user preferred languages that is also found in available languages.
-
#preferred_language_from(array)
Finds the locale specifically requested by the browser.
-
#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.
-
#user_preferred_languages
Returns a sorted array based on user preference in HTTP_ACCEPT_LANGUAGE.
-
#user_preferred_languages=(languages : Nil | Array(String))
Sets the user languages preference, overriding the browser
Constructor Detail
Instance Method Detail
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