For AI agents: the complete documentation index is available at /tc39-atlas/en/llms.txt, the full documentation bundle is available at /tc39-atlas/en/llms-full.txt, and this page is available as Markdown at /tc39-atlas/en/proposals/stage/unstaged/proposal-intl-localematcher.md.
  • English
  • Intl LocaleMatcher ?

    Proposal details
    Proposal overview

    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.

    Note

    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

    const available = ['fr', 'en'];
    const matcher = new Intl.LocaleMatcher(available, {algorithm: 'lookup'});
    
    matcher.match(['fr-CA', 'en']); // {locale: 'fr', requestedLocale: 'fr-CA'}
    matcher.match(['ja']); // undefined
    const locale = matcher.match(navigator.languages)?.locale ?? 'en';
    MethodResultUse case
    match(requested)One result or undefinedApp translation
    matchAll(requested)One winner per request, deduplicatedMultilingual spellchecking
    filter(requested)All acceptable available localesLocale picker
    const regional = new Intl.LocaleMatcher(['fr', 'en', 'fr-CA'], {algorithm: 'lookup'});
    regional.matchAll(['fr-CA']);
    // [{locale: 'fr-CA', requestedLocale: 'fr-CA'}]
    regional.filter(['fr-CA']);
    // [{locale: 'fr', requestedLocale: 'fr-CA'},
    //  {locale: 'fr-CA', requestedLocale: 'fr-CA'}]

    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.
    • lookup uses RFC 4647 prefix lookup. best fit (default) reuses ECMA-402's implementation-defined matching, without requiring CLDR/ICU data or scores.
    • match returns {locale, requestedLocale} or undefined. locale is a canonical available tag; requestedLocale is the canonical winning request, including its extensions. Requested u extensions do not affect matching or get appended to locale. No implicit default or formatting locale is supplied.
    • Inputs follow CanonicalizeLocaleList: strings, Intl.Locale objects, and array-like lists. Generic iterables are not consumed. Available u extensions 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

    npm ci
    npm run build

    Strict ecmarkup build checks syntax, references, and algorithm lint rules. Runtime conformance tests are planned, not implemented here.

    References