class Citrine::I18n::Parser

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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(header : String) #

[View source]

Instance Method Detail

def 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


[View source]
def header : String #

[View source]
def 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)


[View source]
def preferred_language_from(array) #

Finds the locale specifically requested by the browser.

Example:

request.preferred_language_from I18n.available_locales

=> 'nl'


[View source]
def 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]


[View source]
def 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' ]


[View source]
def user_preferred_languages=(languages : Nil | Array(String)) #

Sets the user languages preference, overriding the browser


[View source]