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
-
Locale Inspector
Type any BCP 47 locale tag with variants (e.g.
de-1901,sl-rozaj-biske) and seelocale.variantsreturn the parsed array — along with all other locale components. -
Variant Builder
Construct a locale step by step — language, script, region, and one or more variants — using the new
{ variants: […] }option in theIntl.Localeconstructor. Outputs the canonical BCP 47 tag. -
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. -
Round-trip Tester
Parse any BCP 47 tag → extract language, script, region, and variants → reconstruct a new
Intl.Localefrom those parts → compare the output tag to the original. Confirms that.variantsmakes the API lossless. Shows each step with the exact code and result. -
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.
-
Variant Sort & Canonical Forms
BCP 47 variant subtags form an ordered list, but
Intl.Localecanonicalises their order on construction —sl-biske-rozajandsl-rozaj-biskeresolve to the same canonical tag. Enter two locale tags with the same variants in different orders and compare whatnew Intl.Locale()produces and what.variantsreturns. 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 ↗