demo · v149
Variant Sort & Canonical Forms
BCP 47 variant subtags are ordered: sl-rozaj-biske and sl-biske-rozaj are the same locale, but canonical form requires alphabetical ordering. Intl.Locale canonicalises the tag on construction — .variants always returns the browser-normalised array. Compare a user-supplied tag to its canonical form and see how reordering subtags is handled.
Enter any BCP 47 locale tag with two or more variant subtags in different orders. Compare how
new Intl.Locale(input) normalises the tag and what .variants returns. Presets show the most common ordering surprises.
Original tag (user-supplied):
Reordered tag (same variants):
Presets:
Tag A (input)
—
Tag B (input)
—
// Intl.Locale canonicalises variant subtag order on construction
// BCP 47 canonical form: alphabetically sorted within a prefix group
const a = new Intl.Locale('sl-biske-rozaj');
const b = new Intl.Locale('sl-rozaj-biske');
console.log(a.toString()); // "sl-Latn-SI-biske-rozaj" (canonical)
console.log(b.toString()); // "sl-Latn-SI-biske-rozaj" (same canonical!)
console.log(a.variants); // ["biske", "rozaj"] (sorted)
console.log(b.variants); // ["biske", "rozaj"] (sorted)
// They resolve to the same locale object
console.log(a.toString() === b.toString()); // true
// .variants always returns the canonically ordered array —
// no need for manual sorting in application code
see also
implementation reference
Need the exact API surface, compatibility boundaries, errors, lifecycle, and source links? Read the matching gendn reference ↗