A spec-compliant ponyfill for Intl.LocaleMatcher. Since this is only stage-1 this package is a ponyfill instead of polyfill.
Installation#
npm i @formatjs/intl-localematcher
Requirements#
Usage#
Simple#
match(['fr-XX', 'en'], ['fr', 'en'], 'en') // 'fr'
match(['zh'], ['fr', 'en'], 'en') // 'en'
Supported locale filtering#
LookupSupportedLocales(availableLocales, requestedLocales) returns supported
requested tags in their original order, preserving region subtags and Unicode
extensions even when matching falls back to a parent locale.
LookupSupportedLocales(['de'], ['de-AT-u-co-phonebk']) // ['de-AT-u-co-phonebk']
Locale resolution uses an internal record isolated from inherited extension-key
setters on Object.prototype.
Locale matching extracts only the Unicode u extension. Private-use subtags
remain intact, including text resembling u-co-phonebk; trailing extensions
are preserved separately from Unicode keywords.