locale-util.js (1683B)
1 const valid_language_tags = { 2 en: [ 3 'en-Latn', 4 'en-Latn-GB', 5 'en-GB', 6 'en-fonipa-scouse', 7 'en-Latn-fonipa-scouse', 8 'en-Latn-GB-fonipa-scouse', 9 'en-Latn-x-this-is-a-private-use-extensio-n', 10 'EN', 11 'en-lATN', 12 'EN-lATN-gb', 13 'EN-gb', 14 'EN-scouse-fonipa', 15 'EN-lATN-scouse-fonipa', 16 'EN-lATN-gb-scouse-fonipa', 17 ], 18 es: [ 19 'es-419', 20 'es-ES', 21 'es-ES-1979', 22 ], 23 }; 24 25 const invalid_language_tags = [ 26 'e', 27 'Latn', 28 'enLatnGBfonipa', 29 '11', 30 'en_Latn', 31 'en-Lat', 32 'en-A999', 33 ]; 34 35 function assert_is_canonical(language_tag) { 36 const locale = new Intl.Locale(language_tag); 37 assert_equals(locale.toString(), language_tag); 38 } 39 40 function assert_is_variation(variation_language_tag, expected_language_tag) { 41 const variation_locale = new Intl.Locale(variation_language_tag); 42 const expected_locale = new Intl.Locale(expected_language_tag); 43 assert_equals(variation_locale.language, expected_locale.language); 44 } 45 46 function assert_availability_consistent( 47 language_subtag_availability, variation_availability) { 48 if (variation_availability == 'unavailable') { 49 // If the language subtag is not available then no variation of it should 50 // be available. 51 assert_equals(language_subtag_availability, 'unavailable'); 52 } else { 53 // If the language subtag is available, then it definitely shouldn't be 54 // unavailable since whatever backing it has could support any variation of 55 // it. A variation could have a different availability if a more specific 56 // backing is required. 57 assert_in_array( 58 language_subtag_availability, 59 ['downloadable', 'downloading', 'available']); 60 } 61 }