preferred-variant.js (2503B)
1 // Copyright (C) 2017 André Bargull. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-intl.getcanonicallocales 6 description: > 7 Call Intl.getCanonicalLocales function with grandfathered language tags. 8 info: | 9 8.2.1 Intl.getCanonicalLocales (locales) 10 1. Let ll be ? CanonicalizeLocaleList(locales). 11 2. Return CreateArrayFromList(ll). 12 13 9.2.1 CanonicalizeLocaleList (locales) 14 ... 15 7. Repeat, while k < len 16 ... 17 c. If kPresent is true, then 18 ... 19 v. Let canonicalizedTag be CanonicalizeLanguageTag(tag). 20 ... 21 22 6.2.3 CanonicalizeLanguageTag ( locale ) 23 The CanonicalizeLanguageTag abstract operation returns the canonical and case-regularized 24 form of the locale argument (which must be a String value that is a structurally valid 25 BCP 47 language tag as verified by the IsStructurallyValidLanguageTag abstract operation). 26 A conforming implementation shall take the steps specified in RFC 5646 section 4.5, or 27 successor, to bring the language tag into canonical form, and to regularize the case of 28 the subtags. Furthermore, a conforming implementation shall not take the steps to bring 29 a language tag into "extlang form", nor shall it reorder variant subtags. 30 31 The specifications for extensions to BCP 47 language tags, such as RFC 6067, may include 32 canonicalization rules for the extension subtag sequences they define that go beyond the 33 canonicalization rules of RFC 5646 section 4.5. Implementations are allowed, but not 34 required, to apply these additional rules. 35 36 includes: [testIntl.js] 37 ---*/ 38 39 // https://github.com/unicode-org/cldr/blame/master/common/supplemental/supplementalMetadata.xml#L531 40 // http://unicode.org/reports/tr35/#LocaleId_Canonicalization 41 var canonicalizedTags = { 42 "ja-latn-hepburn-heploc": "ja-Latn-alalc97", 43 }; 44 45 // make sure the data above is correct 46 Object.getOwnPropertyNames(canonicalizedTags).forEach(function (tag) { 47 var canonicalizedTag = canonicalizedTags[tag]; 48 assert( 49 isCanonicalizedStructurallyValidLanguageTag(canonicalizedTag), 50 "Test data \"" + canonicalizedTag + "\" is not canonicalized and structurally valid language tag." 51 ); 52 }); 53 54 Object.getOwnPropertyNames(canonicalizedTags).forEach(function (tag) { 55 var canonicalLocales = Intl.getCanonicalLocales(tag); 56 assert.sameValue(canonicalLocales.length, 1); 57 assert.sameValue(canonicalLocales[0], canonicalizedTags[tag]); 58 }); 59 60 reportCompare(0, 0);