Intl LocaleMatcher ?
- Stage: Unstaged
- Status: Active
- ECMAScript edition: —
- Synchronized: Nov 28, 2026
- 中文译文 · Source repository
The proposal defines Intl.LocaleMatcher for preparing a set of available locales once and using it to select candidates for translation, spellchecking, or locale pickers. A matcher is constructed from an available-locale list and options, and exposes match, matchAll, and filter instance methods. It supports RFC 4647 lookup and an implementation-defined best-fit algorithm, with individual matches represented as objects containing locale and requestedLocale.
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.
Intl.LocaleMatcher
Prepare available locales once, then select translations, spellcheckers, or picker candidates.
Stage 1. Champion: Long Ho.
Specification · Source · Research and open issues · FormatJS ponyfill
Proposed API
matchAll keeps the first result for each resource, in request order. It does not
search for alternatives when winners repeat. filter groups resources by their
earliest accepting request, preserving available order within each group. Neither
method defines a message-fallback chain; no matches returns [].
Resource selection does not establish formatter support. Downstream operations
may need the original requests, not only the selected resource. Both multi-result
methods currently deduplicate resources, which can discard distinct accepted
requests such as en-US and en-GB matching en. Request-preserving output remains
an open design question.
Lookup filtering tests prefix lookup against each candidate alone. Best fit uses shared pairwise acceptance, independent of other candidates and request-priority penalties. Filter results are not sorted by linguistic distance.
- Constructor snapshots and canonicalizes available locales; later mutations
don't affect it. Options are read once and require an object or
undefined. lookupuses RFC 4647 prefix lookup.best fit(default) reuses ECMA-402's implementation-defined matching, without requiring CLDR/ICU data or scores.matchreturns{locale, requestedLocale}orundefined.localeis a canonical available tag;requestedLocaleis the canonical winning request, including its extensions. Requesteduextensions do not affect matching or get appended tolocale. No implicit default or formatting locale is supplied.- Inputs follow
CanonicalizeLocaleList: strings, Intl.Locale objects, and array-like lists. Generic iterables are not consumed. Availableuextensions remain rejected provisionally; private-use tone matching remains unspecified.
Draft API changes: instance method replaces static Intl.LocaleMatcher.match;
an object separates resource selection from the winning user preference and leaves
room for future metadata.
The FormatJS ponyfill currently implements the older stateless API.
HTTP parsing, message fallback, weights, scores, and resource indices stay outside this draft. Open decisions and foundational precedents are in design notes.
Build
Strict ecmarkup build checks syntax, references, and algorithm lint rules. Runtime conformance tests are planned, not implemented here.