Intl.LocaleMatcher ponyfill providing comprehensive locale matching algorithms with support for 'lookup' and 'best fit' strategies
94
A utility that enriches incomplete locale identifiers by expanding them into their full canonical forms with language, script, and region information based on cultural and linguistic defaults.
Implement a locale enrichment system that takes partial locale identifiers (such as language-only codes or language-region pairs without scripts) and expands them into complete locale identifiers with full language-script-region information.
The system should accept:
en, zh, ja)zh-TW, zh-CN, sr-RS)zh-Hant, ar-Arab)en-Latn-US)For each input locale, the system should produce:
en, the enricher expands it to en-Latn-US @testja, the enricher expands it to ja-Jpan-JP @testar, the enricher expands it to ar-Arab-EG @testzh-CN, the enricher expands it to zh-Hans-CN (Simplified Chinese) @testzh-TW, the enricher expands it to zh-Hant-TW (Traditional Chinese) @testsr-RS, the enricher expands it to sr-Cyrl-RS (Serbian with Cyrillic script) @test['en', 'zh', 'fr', 'ja'], the enricher processes all locales and returns an array of expanded forms @test@generates
/**
* Enriches a single locale identifier by expanding it to include
* language, script, and region components.
*
* @param locale - A BCP 47 locale identifier (e.g., 'en', 'zh-TW', 'ja-Jpan-JP')
* @returns The expanded locale identifier with all components
*/
export function enrichLocale(locale: string): string;
/**
* Enriches multiple locale identifiers.
*
* @param locales - An array of BCP 47 locale identifiers
* @returns An array of expanded locale identifiers
*/
export function enrichLocales(locales: string[]): string[];Provides locale matching and manipulation capabilities including locale maximization based on CLDR data.
Install with Tessl CLI
npx tessl i tessl/npm-formatjs--intl-localematcherdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10