v149 · JavaScript · Internationalisation

Intl.Locale.prototype.variants

Access the subtag variants of a BCP 47 locale tag as an array — and pass variants directly into the Intl.Locale constructor's options bag.

concepts

  1. Locale Inspector

    Type any BCP 47 locale tag with variants (e.g. de-1901, sl-rozaj-biske) and see locale.variants return the parsed array — along with all other locale components.

  2. Variant Builder

    Construct a locale step by step — language, script, region, and one or more variants — using the new { variants: […] } option in the Intl.Locale constructor. Outputs the canonical BCP 47 tag.

  3. Variant Tag Explorer

    Parse any BCP 47 locale tag and see its variant subtags extracted by locale.variants. Quick-load common real-world examples (traditional German, Natisone Slovenian, Ekavian Serbian) or type your own. Build tags from individual parts and watch the array update live.

  4. Round-trip Tester

    Parse any BCP 47 tag → extract language, script, region, and variants → reconstruct a new Intl.Locale from those parts → compare the output tag to the original. Confirms that .variants makes the API lossless. Shows each step with the exact code and result.

  5. Language Negotiation

    Given a user's accept-language preferences (in order) and a site's available locales, find the best match — using variant subtag matching. Scenarios for traditional German, Resian Slovenian, Serbian dialects, and English regional variants. Edit the preference and available lists to test your own scenarios.

  6. Variant Sort & Canonical Forms

    BCP 47 variant subtags form an ordered list, but Intl.Locale canonicalises their order on construction — sl-biske-rozaj and sl-rozaj-biske resolve to the same canonical tag. Enter two locale tags with the same variants in different orders and compare what new Intl.Locale() produces and what .variants returns. Presets cover the most common ordering surprises in Slovenian, German, and Serbian locales.

why it shipped

BCP 47 locale tags can include variant subtags that refine a locale beyond language, script, and region. For example, de-1901 is traditional German orthography, sl-rozaj-biske is a Resian dialect of Slovenian. Before Chrome 149, the Intl.Locale object had no way to read the variant subtags back out once a locale was constructed — and the constructor didn't accept a variants option. The Intl.Locale.prototype.variants property, standardised in the TC39 language-ID update, returns those subtags as an array and enables round-tripping locale tags that include variants.

references

implementation reference

Need the exact API surface, compatibility boundaries, errors, lifecycle, and source links? Read the matching gendn reference ↗