Function: matchLocale()
matchLocale(
requested,available,fallback?):string
Defined in: src/lib/i18n/index.ts:67
The best available locale for the requested ones (e.g. the device's navigator.languages, most preferred first):
the same tag, then the same language and script (zh-TW → zh-Hant), then the same language (British regions
prefer en-GB, other English en-US), otherwise fallback.
Parameters
requested
readonly string[]
available
readonly string[]
fallback?
string = FALLBACK_LOCALE
Returns
string
Example
matchLocale(["zh-TW", "en"], ["en-US", "zh-Hans", "zh-Hant"]); // "zh-Hant"
matchLocale(["en-AU"], ["en-US", "en-GB"]); // "en-GB"
matchLocale(["fr-FR"], ["en-US", "ja"]); // "en-US"