Fix 9.2.3 LookupMatcher algorithm S0
- Stage: Stage 0
- Status: Active
- ECMAScript edition: —
- Synchronized: Aug 28, 2026
- 中文译文 · Source repository
This proposal aims to fix the LookupMatcher algorithm in ECMA-402, which currently fails to correctly resolve locales like az-IR or zh-AU to their proper language/script variants. The issue is that the current algorithm truncates subtags too aggressively, causing incorrect fallbacks.
The README below comes from the upstream repository and may contain outdated stage or status metadata. Use the proposal details above as the current source of truth.
Update
Stage 0
Ecma-402 has a specification for Lookup Matching, described by LookupMatcher (9.2.3) and BestAvailableLocale (9.2.2). It's based on the Lookup algorithm described in RFC 4647 section 3.4. But, both Ecma-402 specification and RFC 4647 algorithm fail to perform such task in some cases. For example:
az-IRmaps toaz(default foraz-Latn-AZ), not to the correctaz-Arab-IR.en-Latn-GBanden-Latn-INmap toen(default foren-Latn-US), not to the correcten-GBanden-INrespectively.ha-CMandha-SDmap toha(default forha-Latn-NG), not the correctha-Arab-*.kk-CN,kk-IR, andkk-MNmap tokk(default forkk-Cyrl-KZ), not the correctkk-Arab-*.sr-ME,sr-RO,sr-RU,sr-TRmap tosr(default forsr-Cyrl-RS), not to the correctsr-Latn-*.uz-AFmaps touz(default foruz-Latn-UZ), not to the correctuz-Arab-AF.zh-AU,zh-BN,zh-GB,zh-GF,zh-ID,zh-MO,zh-MY,zh-PA,zh-PF,zh-PH,zh-SR,zh-TH,zh-US, andzh-VNmap tozh(default forzh-Hans-CN), not to the correctzh-Hant-*.
Impact
The wrong specification can be observed in today's implementations.
Cause
The algorithm specified is too simplistic. It basically instruct implementations to perform subtags truncation until it finds a locale, which is wrong. Related issues and more details can be found on:
- Fixing Inheritance by Mark Davis
- Cldrjs issue #17
- Cldrjs's Lookup Matcher
- Globalize issue #357
- ICU issue #11404
- Improving Locale/LanguageMatcher by Mark Davis
- BestFitAvailableLocale in ibm-js/ecma402
Fix
According to Mark Davis, "the recommended methodology for Bundle lookup is to use Language Matching". Therefore, there are two options:
- Follow the Language Matching algorithm specified by the Unicode Technical Standard #35.
- Follow the quicker algorithm from cldrjs, which produces the same result as the Language Matching considering a score threshold of 100%.