tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

variant-with-preferred-value.js (2253B)


      1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
      2 
      3 // Per UTS 35, computing the canonical form for Unicode BCP 47 locale identifiers
      4 // includes replacing deprecated variant mappings. The other UTS 35 canonicalisation
      5 // algorithm ("BCP 47 Language Tag to Unicode BCP 47 Locale Identifier") doesn't
      6 // support deprecated variant mappings.
      7 // https://github.com/tc39/ecma402/issues/330
      8 
      9 const languageTags = {
     10    // The preferred value of "hy-arevela" is "hy" per CLDR.
     11    "hy-arevela": "hy",
     12    "hy-Armn-arevela": "hy-Armn",
     13    "hy-AM-arevela": "hy-AM",
     14    "hy-arevela-fonipa": "hy-fonipa",
     15    "hy-fonipa-arevela": "hy-fonipa",
     16 
     17    // The preferred value of "hy-arevmda" is "hyw" per CLDR.
     18    "hy-arevmda": "hyw",
     19    "hy-Armn-arevmda": "hyw-Armn",
     20    "hy-AM-arevmda": "hyw-AM",
     21    "hy-arevmda-fonipa": "hyw-fonipa",
     22    "hy-fonipa-arevmda": "hyw-fonipa",
     23 
     24    // The preferred value of "ja-Latn-hepburn-heploc" is "ja-Latn-alalc97" per CLDR and
     25    // IANA.
     26    "ja-Latn-hepburn-heploc": "ja-Latn-alalc97",
     27    "ja-Latn-JP-hepburn-heploc": "ja-Latn-JP-alalc97",
     28 
     29    // Variant subtag replacements not present in IANA.
     30    "sv-aaland": "sv-AX",
     31    "el-polytoni": "el-polyton",
     32 
     33    // Additional cases when more variant subtags are present.
     34 
     35    // 1. The preferred variant is already present.
     36    "ja-Latn-alalc97-hepburn-heploc": "ja-Latn-alalc97",
     37    "ja-Latn-hepburn-alalc97-heploc": "ja-Latn-alalc97",
     38    "ja-Latn-hepburn-heploc-alalc97": "ja-Latn-alalc97",
     39 
     40    // 2. The variant subtags aren't in the expected order per IANA. (CLDR doesn't care
     41    //    about the order of variant subtags.)
     42    "ja-Latn-heploc-hepburn": "ja-Latn-alalc97",
     43 
     44    // 3. IANA expects both variant subtags to be present, CLDR also accepts single "heploc".
     45    "ja-Latn-heploc": "ja-Latn-alalc97",
     46 
     47    // 4. Test for cases when the same variant subtag position needs to be checked more
     48    //    than once when replacing deprecated variant subtags.
     49    "ja-Latn-aaland-heploc": "ja-Latn-AX-alalc97",
     50    "ja-Latn-heploc-polytoni": "ja-Latn-alalc97-polyton",
     51 };
     52 
     53 for (let [tag, canonical] of Object.entries(languageTags)) {
     54    assertEq(Intl.getCanonicalLocales(tag)[0], canonical);
     55 }
     56 
     57 if (typeof reportCompare === "function")
     58    reportCompare(0, 0);