Each function akes a List of Strings in the BCP47 locale ID format. If in an invalid format, they will be ignored. The list requestedLocales
List should be in preference order The availableLocales
is a List of Strings also in BCP47 locale ID format, unsorted. The defaultLocale
should be a String in BCP47 locale ID format and isused as a last resort locale.
It returns an Array of strings with BCP47 locale IDs sorted according to the user preferences.
filter : { requestedLocales : List String, availableLocales : List String, defaultLocale : Maybe String } -> List String
Looks for the best matching available locale for each requested locale.
Localization.Negotiation.filter
{ requestedLocales = [ "de-DE", "fr-FR" ]
, availableLocales = [ "it", "de", "en-US", "fr-CA", "de-DE", "fr", "de-AU" ]
, defaultLocale = Nothing
}
-- supported: [ "de-DE", "fr" ]
lookup : { requestedLocales : List String, availableLocales : List String, defaultLocale : String } -> List String
Will try to find the single best locale for the requested locale list among the available locales. If none is found it will fallback to the defaultLocale
.
Localization.Negotiation.lookup
{ requestedLocales = [ "de-DE", "fr-FR" ]
, availableLocales = [ "it", "de", "en-US", "fr-CA", "de-DE", "fr", "de-AU" ]
, defaultLocale = "en-US"
}
-- supported: [ "de-DE" ]
match : { requestedLocales : List String, availableLocales : List String, defaultLocale : Maybe String } -> List String
Will try to match as many available locales as possible for each of the requested locale.
Localization.Negotiation.match
{ requestedLocales = [ "de-DE", "fr-FR" ]
, availableLocales = [ "it", "de", "en-US", "fr-CA", "de-DE", "fr", "de-AU" ]
, defaultLocale = Nothing
}
-- supported: [ "de-DE", "de", "fr", "fr-CA" ]