unicode-bcp47-locale-ids-variants-legacy-mappings.js (1911B)
1 // |reftest| skip-if(!this.hasOwnProperty("Intl")) 2 3 // ECMA-402 includes mapping of legacy variants, as long as they're also present 4 // in <variantAlias> in CLDR's supplementalMetadata.xml 5 // <https://www.unicode.org/reports/tr35/#Legacy_Variants> 6 7 assertEq(Intl.getCanonicalLocales("sv-AALAND")[0], "sv-AX"); 8 assertEq(Intl.getCanonicalLocales("no-BOKMAL")[0], "nb"); 9 assertEq(Intl.getCanonicalLocales("no-NYNORSK")[0], "nn"); 10 assertEq(Intl.getCanonicalLocales("en-POSIX")[0], "en-posix"); 11 assertEq(Intl.getCanonicalLocales("el-POLYTONI")[0], "el-polyton"); 12 assertEq(Intl.getCanonicalLocales("aa-SAAHO")[0], "ssy"); 13 14 // Additional cases from CLDR, version 38. 15 16 assertEq(Intl.getCanonicalLocales("aar-saaho")[0], "ssy"); 17 assertEq(Intl.getCanonicalLocales("arm-arevmda")[0], "hyw"); 18 assertEq(Intl.getCanonicalLocales("hy-arevmda")[0], "hyw"); 19 assertEq(Intl.getCanonicalLocales("hye-arevmda")[0], "hyw"); 20 21 for (let language of ["chi", "cmn", "zh", "zho"]) { 22 assertEq(Intl.getCanonicalLocales(language)[0], "zh"); 23 24 let mapping = { 25 "guoyu-hakka": "hak", 26 "guoyu-xiang": "hsn", 27 "guoyu": "zh", 28 "hakka": "hak", 29 "xiang": "hsn", 30 }; 31 for (let [variant, canonical] of Object.entries(mapping)) { 32 assertEq(Intl.getCanonicalLocales(`${language}-${variant}`)[0], canonical); 33 } 34 } 35 36 // Most legacy variant subtags are simply removed in contexts they don't apply. 37 for (let variant of ["arevela", "arevmda", "bokmal", "hakka", "lojban", "nynorsk", "saaho", "xiang"]) { 38 assertEq(Intl.getCanonicalLocales(`en-${variant}`)[0], "en"); 39 } 40 41 // Except these three, whose replacement is always applied. 42 assertEq(Intl.getCanonicalLocales("en-aaland")[0], "en-AX"); 43 assertEq(Intl.getCanonicalLocales("en-heploc")[0], "en-alalc97"); 44 assertEq(Intl.getCanonicalLocales("en-polytoni")[0], "en-polyton"); 45 46 if (typeof reportCompare === "function") 47 reportCompare(true, true);