@formatjs/intl-getcanonicallocales 2.3.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/index.js +2 -2
- package/package.json +2 -2
- package/polyfill.iife.js +122 -113
- package/should-polyfill.js +1 -2
- package/src/canonicalizer.js +2 -3
- package/src/emitter.js +2 -3
- package/src/parser.js +8 -8
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2023 FormatJS
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
6
|
|
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isUnicodeLanguageSubtag = exports.isUnicodeScriptSubtag = exports.isUnicodeRegionSubtag = exports.isStructurallyValidLanguageTag = exports.parseUnicodeLanguageId = exports.parseUnicodeLocaleId =
|
|
3
|
+
exports.isUnicodeLanguageSubtag = exports.isUnicodeScriptSubtag = exports.isUnicodeRegionSubtag = exports.isStructurallyValidLanguageTag = exports.parseUnicodeLanguageId = exports.parseUnicodeLocaleId = void 0;
|
|
4
|
+
exports.getCanonicalLocales = getCanonicalLocales;
|
|
4
5
|
var tslib_1 = require("tslib");
|
|
5
6
|
var parser_1 = require("./src/parser");
|
|
6
7
|
var emitter_1 = require("./src/emitter");
|
|
@@ -29,7 +30,6 @@ function CanonicalizeLocaleList(locales) {
|
|
|
29
30
|
function getCanonicalLocales(locales) {
|
|
30
31
|
return CanonicalizeLocaleList(locales);
|
|
31
32
|
}
|
|
32
|
-
exports.getCanonicalLocales = getCanonicalLocales;
|
|
33
33
|
var parser_2 = require("./src/parser");
|
|
34
34
|
Object.defineProperty(exports, "parseUnicodeLocaleId", { enumerable: true, get: function () { return parser_2.parseUnicodeLocaleId; } });
|
|
35
35
|
Object.defineProperty(exports, "parseUnicodeLanguageId", { enumerable: true, get: function () { return parser_2.parseUnicodeLanguageId; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/intl-getcanonicallocales",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "Intl.getCanonicalLocales polyfill",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"intl",
|
|
@@ -25,6 +25,6 @@
|
|
|
25
25
|
"url": "https://github.com/formatjs/formatjs/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"tslib": "^2.
|
|
28
|
+
"tslib": "^2.7.0"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/polyfill.iife.js
CHANGED
|
@@ -1,30 +1,22 @@
|
|
|
1
1
|
(() => {
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __spreadValues = (a, b) => {
|
|
8
|
+
for (var prop in b || (b = {}))
|
|
9
|
+
if (__hasOwnProp.call(b, prop))
|
|
10
|
+
__defNormalProp(a, prop, b[prop]);
|
|
11
|
+
if (__getOwnPropSymbols)
|
|
12
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
13
|
+
if (__propIsEnum.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
15
|
}
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
return __assign.apply(this, arguments);
|
|
16
|
+
return a;
|
|
14
17
|
};
|
|
15
|
-
function __spreadArray(to, from, pack) {
|
|
16
|
-
if (pack || arguments.length === 2)
|
|
17
|
-
for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
18
|
-
if (ar || !(i in from)) {
|
|
19
|
-
if (!ar)
|
|
20
|
-
ar = Array.prototype.slice.call(from, 0, i);
|
|
21
|
-
ar[i] = from[i];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
25
|
-
}
|
|
26
18
|
|
|
27
|
-
//
|
|
19
|
+
// packages/intl-getcanonicallocales/src/parser.ts
|
|
28
20
|
var ALPHANUM_1_8 = /^[a-z0-9]{1,8}$/i;
|
|
29
21
|
var ALPHANUM_2_8 = /^[a-z0-9]{2,8}$/i;
|
|
30
22
|
var ALPHANUM_3_8 = /^[a-z0-9]{3,8}$/i;
|
|
@@ -53,7 +45,7 @@
|
|
|
53
45
|
if (typeof chunks === "string") {
|
|
54
46
|
chunks = chunks.split(SEPARATOR);
|
|
55
47
|
}
|
|
56
|
-
|
|
48
|
+
const lang = chunks.shift();
|
|
57
49
|
if (!lang) {
|
|
58
50
|
throw new RangeError("Missing unicode_language_subtag");
|
|
59
51
|
}
|
|
@@ -63,19 +55,19 @@
|
|
|
63
55
|
if (!isUnicodeLanguageSubtag(lang)) {
|
|
64
56
|
throw new RangeError("Malformed unicode_language_subtag");
|
|
65
57
|
}
|
|
66
|
-
|
|
58
|
+
let script;
|
|
67
59
|
if (chunks.length && isUnicodeScriptSubtag(chunks[0])) {
|
|
68
60
|
script = chunks.shift();
|
|
69
61
|
}
|
|
70
|
-
|
|
62
|
+
let region;
|
|
71
63
|
if (chunks.length && isUnicodeRegionSubtag(chunks[0])) {
|
|
72
64
|
region = chunks.shift();
|
|
73
65
|
}
|
|
74
|
-
|
|
66
|
+
const variants = {};
|
|
75
67
|
while (chunks.length && isUnicodeVariantSubtag(chunks[0])) {
|
|
76
|
-
|
|
68
|
+
const variant = chunks.shift();
|
|
77
69
|
if (variant in variants) {
|
|
78
|
-
throw new RangeError(
|
|
70
|
+
throw new RangeError(`Duplicate variant "${variant}"`);
|
|
79
71
|
}
|
|
80
72
|
variants[variant] = 1;
|
|
81
73
|
}
|
|
@@ -87,8 +79,8 @@
|
|
|
87
79
|
};
|
|
88
80
|
}
|
|
89
81
|
function parseUnicodeExtension(chunks) {
|
|
90
|
-
|
|
91
|
-
|
|
82
|
+
const keywords = [];
|
|
83
|
+
let keyword;
|
|
92
84
|
while (chunks.length && (keyword = parseKeyword(chunks))) {
|
|
93
85
|
keywords.push(keyword);
|
|
94
86
|
}
|
|
@@ -99,7 +91,7 @@
|
|
|
99
91
|
attributes: []
|
|
100
92
|
};
|
|
101
93
|
}
|
|
102
|
-
|
|
94
|
+
const attributes = [];
|
|
103
95
|
while (chunks.length && ALPHANUM_3_8.test(chunks[0])) {
|
|
104
96
|
attributes.push(chunks.shift());
|
|
105
97
|
}
|
|
@@ -116,36 +108,36 @@
|
|
|
116
108
|
throw new RangeError("Malformed unicode_extension");
|
|
117
109
|
}
|
|
118
110
|
function parseKeyword(chunks) {
|
|
119
|
-
|
|
111
|
+
let key;
|
|
120
112
|
if (!KEY_REGEX.test(chunks[0])) {
|
|
121
113
|
return;
|
|
122
114
|
}
|
|
123
115
|
key = chunks.shift();
|
|
124
|
-
|
|
116
|
+
const type = [];
|
|
125
117
|
while (chunks.length && TYPE_REGEX.test(chunks[0])) {
|
|
126
118
|
type.push(chunks.shift());
|
|
127
119
|
}
|
|
128
|
-
|
|
120
|
+
let value = "";
|
|
129
121
|
if (type.length) {
|
|
130
122
|
value = type.join(SEPARATOR);
|
|
131
123
|
}
|
|
132
124
|
return [key, value];
|
|
133
125
|
}
|
|
134
126
|
function parseTransformedExtension(chunks) {
|
|
135
|
-
|
|
127
|
+
let lang;
|
|
136
128
|
try {
|
|
137
129
|
lang = parseUnicodeLanguageId(chunks);
|
|
138
130
|
} catch (e) {
|
|
139
131
|
}
|
|
140
|
-
|
|
132
|
+
const fields = [];
|
|
141
133
|
while (chunks.length && TKEY_REGEX.test(chunks[0])) {
|
|
142
|
-
|
|
143
|
-
|
|
134
|
+
const key = chunks.shift();
|
|
135
|
+
const value = [];
|
|
144
136
|
while (chunks.length && ALPHANUM_3_8.test(chunks[0])) {
|
|
145
137
|
value.push(chunks.shift());
|
|
146
138
|
}
|
|
147
139
|
if (!value.length) {
|
|
148
|
-
throw new RangeError(
|
|
140
|
+
throw new RangeError(`Missing tvalue for tkey "${key}"`);
|
|
149
141
|
}
|
|
150
142
|
fields.push([key, value.join(SEPARATOR)]);
|
|
151
143
|
}
|
|
@@ -159,7 +151,7 @@
|
|
|
159
151
|
throw new RangeError("Malformed transformed_extension");
|
|
160
152
|
}
|
|
161
153
|
function parsePuExtension(chunks) {
|
|
162
|
-
|
|
154
|
+
const exts = [];
|
|
163
155
|
while (chunks.length && ALPHANUM_1_8.test(chunks[0])) {
|
|
164
156
|
exts.push(chunks.shift());
|
|
165
157
|
}
|
|
@@ -172,7 +164,7 @@
|
|
|
172
164
|
throw new RangeError("Malformed private_use_extension");
|
|
173
165
|
}
|
|
174
166
|
function parseOtherExtensionValue(chunks) {
|
|
175
|
-
|
|
167
|
+
const exts = [];
|
|
176
168
|
while (chunks.length && ALPHANUM_2_8.test(chunks[0])) {
|
|
177
169
|
exts.push(chunks.shift());
|
|
178
170
|
}
|
|
@@ -185,13 +177,13 @@
|
|
|
185
177
|
if (!chunks.length) {
|
|
186
178
|
return { extensions: [] };
|
|
187
179
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
180
|
+
const extensions = [];
|
|
181
|
+
let unicodeExtension;
|
|
182
|
+
let transformedExtension;
|
|
183
|
+
let puExtension;
|
|
184
|
+
const otherExtensionMap = {};
|
|
193
185
|
do {
|
|
194
|
-
|
|
186
|
+
const type = chunks.shift();
|
|
195
187
|
switch (type) {
|
|
196
188
|
case "u":
|
|
197
189
|
case "U":
|
|
@@ -222,9 +214,9 @@
|
|
|
222
214
|
throw new RangeError("Malformed extension type");
|
|
223
215
|
}
|
|
224
216
|
if (type in otherExtensionMap) {
|
|
225
|
-
throw new RangeError(
|
|
217
|
+
throw new RangeError(`There can only be 1 -${type}- extension`);
|
|
226
218
|
}
|
|
227
|
-
|
|
219
|
+
const extension = {
|
|
228
220
|
type,
|
|
229
221
|
value: parseOtherExtensionValue(chunks)
|
|
230
222
|
};
|
|
@@ -236,34 +228,39 @@
|
|
|
236
228
|
return { extensions };
|
|
237
229
|
}
|
|
238
230
|
function parseUnicodeLocaleId(locale) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
return
|
|
231
|
+
const chunks = locale.split(SEPARATOR);
|
|
232
|
+
const lang = parseUnicodeLanguageId(chunks);
|
|
233
|
+
return __spreadValues({
|
|
234
|
+
lang
|
|
235
|
+
}, parseExtensions(chunks));
|
|
242
236
|
}
|
|
243
237
|
|
|
244
|
-
//
|
|
238
|
+
// packages/intl-getcanonicallocales/src/emitter.ts
|
|
245
239
|
function emitUnicodeLanguageId(lang) {
|
|
246
240
|
if (!lang) {
|
|
247
241
|
return "";
|
|
248
242
|
}
|
|
249
|
-
return
|
|
243
|
+
return [lang.lang, lang.script, lang.region, ...lang.variants || []].filter(Boolean).join("-");
|
|
250
244
|
}
|
|
251
|
-
function emitUnicodeLocaleId(
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
245
|
+
function emitUnicodeLocaleId({
|
|
246
|
+
lang,
|
|
247
|
+
extensions
|
|
248
|
+
}) {
|
|
249
|
+
const chunks = [emitUnicodeLanguageId(lang)];
|
|
250
|
+
for (const ext of extensions) {
|
|
256
251
|
chunks.push(ext.type);
|
|
257
252
|
switch (ext.type) {
|
|
258
253
|
case "u":
|
|
259
|
-
chunks.push
|
|
260
|
-
|
|
261
|
-
|
|
254
|
+
chunks.push(
|
|
255
|
+
...ext.attributes,
|
|
256
|
+
...ext.keywords.reduce((all, kv) => all.concat(kv), [])
|
|
257
|
+
);
|
|
262
258
|
break;
|
|
263
259
|
case "t":
|
|
264
|
-
chunks.push
|
|
265
|
-
|
|
266
|
-
|
|
260
|
+
chunks.push(
|
|
261
|
+
emitUnicodeLanguageId(ext.lang),
|
|
262
|
+
...ext.fields.reduce((all, kv) => all.concat(kv), [])
|
|
263
|
+
);
|
|
267
264
|
break;
|
|
268
265
|
default:
|
|
269
266
|
chunks.push(ext.value);
|
|
@@ -273,7 +270,7 @@
|
|
|
273
270
|
return chunks.filter(Boolean).join("-");
|
|
274
271
|
}
|
|
275
272
|
|
|
276
|
-
//
|
|
273
|
+
// packages/intl-getcanonicallocales/src/aliases.generated.ts
|
|
277
274
|
var languageAlias = {
|
|
278
275
|
"aa-saaho": "ssy",
|
|
279
276
|
"aam": "aas",
|
|
@@ -1414,7 +1411,7 @@
|
|
|
1414
1411
|
"polytoni": "polyton"
|
|
1415
1412
|
};
|
|
1416
1413
|
|
|
1417
|
-
//
|
|
1414
|
+
// packages/intl-getcanonicallocales/src/likelySubtags.generated.ts
|
|
1418
1415
|
var likelySubtags = {
|
|
1419
1416
|
"aa": "aa-Latn-ET",
|
|
1420
1417
|
"aaa": "aaa-Latn-NG",
|
|
@@ -9452,18 +9449,19 @@
|
|
|
9452
9449
|
"zzj": "zzj-Hani-CN"
|
|
9453
9450
|
};
|
|
9454
9451
|
|
|
9455
|
-
//
|
|
9452
|
+
// packages/intl-getcanonicallocales/src/canonicalizer.ts
|
|
9456
9453
|
function canonicalizeAttrs(strs) {
|
|
9457
|
-
return Object.keys(
|
|
9458
|
-
all
|
|
9459
|
-
|
|
9460
|
-
|
|
9454
|
+
return Object.keys(
|
|
9455
|
+
strs.reduce((all, str) => {
|
|
9456
|
+
all[str.toLowerCase()] = 1;
|
|
9457
|
+
return all;
|
|
9458
|
+
}, {})
|
|
9459
|
+
).sort();
|
|
9461
9460
|
}
|
|
9462
9461
|
function canonicalizeKVs(arr) {
|
|
9463
|
-
|
|
9464
|
-
|
|
9465
|
-
for (
|
|
9466
|
-
var kv = arr_1[_i];
|
|
9462
|
+
const all = {};
|
|
9463
|
+
const result = [];
|
|
9464
|
+
for (const kv of arr) {
|
|
9467
9465
|
if (kv[0] in all) {
|
|
9468
9466
|
continue;
|
|
9469
9467
|
}
|
|
@@ -9483,9 +9481,8 @@
|
|
|
9483
9481
|
return e1.type < e2.type ? -1 : e1.type > e2.type ? 1 : 0;
|
|
9484
9482
|
}
|
|
9485
9483
|
function mergeVariants(v1, v2) {
|
|
9486
|
-
|
|
9487
|
-
for (
|
|
9488
|
-
var v = v2_1[_i];
|
|
9484
|
+
const result = [...v1];
|
|
9485
|
+
for (const v of v2) {
|
|
9489
9486
|
if (v1.indexOf(v) < 0) {
|
|
9490
9487
|
result.push(v);
|
|
9491
9488
|
}
|
|
@@ -9493,35 +9490,41 @@
|
|
|
9493
9490
|
return result;
|
|
9494
9491
|
}
|
|
9495
9492
|
function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
|
|
9496
|
-
|
|
9493
|
+
let finalLangAst = unicodeLanguageId;
|
|
9497
9494
|
if (unicodeLanguageId.variants.length) {
|
|
9498
|
-
|
|
9499
|
-
for (
|
|
9500
|
-
|
|
9501
|
-
if (replacedLang_1 = languageAlias[emitUnicodeLanguageId({
|
|
9495
|
+
let replacedLang2 = "";
|
|
9496
|
+
for (const variant of unicodeLanguageId.variants) {
|
|
9497
|
+
if (replacedLang2 = languageAlias[emitUnicodeLanguageId({
|
|
9502
9498
|
lang: unicodeLanguageId.lang,
|
|
9503
9499
|
variants: [variant]
|
|
9504
9500
|
})]) {
|
|
9505
|
-
|
|
9501
|
+
const replacedLangAst = parseUnicodeLanguageId(
|
|
9502
|
+
replacedLang2.split(SEPARATOR)
|
|
9503
|
+
);
|
|
9506
9504
|
finalLangAst = {
|
|
9507
9505
|
lang: replacedLangAst.lang,
|
|
9508
9506
|
script: finalLangAst.script || replacedLangAst.script,
|
|
9509
9507
|
region: finalLangAst.region || replacedLangAst.region,
|
|
9510
|
-
variants: mergeVariants(
|
|
9508
|
+
variants: mergeVariants(
|
|
9509
|
+
finalLangAst.variants,
|
|
9510
|
+
replacedLangAst.variants
|
|
9511
|
+
)
|
|
9511
9512
|
};
|
|
9512
9513
|
break;
|
|
9513
9514
|
}
|
|
9514
9515
|
}
|
|
9515
9516
|
}
|
|
9516
9517
|
if (finalLangAst.script && finalLangAst.region) {
|
|
9517
|
-
|
|
9518
|
+
const replacedLang2 = languageAlias[emitUnicodeLanguageId({
|
|
9518
9519
|
lang: finalLangAst.lang,
|
|
9519
9520
|
script: finalLangAst.script,
|
|
9520
9521
|
region: finalLangAst.region,
|
|
9521
9522
|
variants: []
|
|
9522
9523
|
})];
|
|
9523
|
-
if (
|
|
9524
|
-
|
|
9524
|
+
if (replacedLang2) {
|
|
9525
|
+
const replacedLangAst = parseUnicodeLanguageId(
|
|
9526
|
+
replacedLang2.split(SEPARATOR)
|
|
9527
|
+
);
|
|
9525
9528
|
finalLangAst = {
|
|
9526
9529
|
lang: replacedLangAst.lang,
|
|
9527
9530
|
script: replacedLangAst.script,
|
|
@@ -9531,13 +9534,15 @@
|
|
|
9531
9534
|
}
|
|
9532
9535
|
}
|
|
9533
9536
|
if (finalLangAst.region) {
|
|
9534
|
-
|
|
9537
|
+
const replacedLang2 = languageAlias[emitUnicodeLanguageId({
|
|
9535
9538
|
lang: finalLangAst.lang,
|
|
9536
9539
|
region: finalLangAst.region,
|
|
9537
9540
|
variants: []
|
|
9538
9541
|
})];
|
|
9539
|
-
if (
|
|
9540
|
-
|
|
9542
|
+
if (replacedLang2) {
|
|
9543
|
+
const replacedLangAst = parseUnicodeLanguageId(
|
|
9544
|
+
replacedLang2.split(SEPARATOR)
|
|
9545
|
+
);
|
|
9541
9546
|
finalLangAst = {
|
|
9542
9547
|
lang: replacedLangAst.lang,
|
|
9543
9548
|
script: finalLangAst.script || replacedLangAst.script,
|
|
@@ -9546,12 +9551,14 @@
|
|
|
9546
9551
|
};
|
|
9547
9552
|
}
|
|
9548
9553
|
}
|
|
9549
|
-
|
|
9554
|
+
const replacedLang = languageAlias[emitUnicodeLanguageId({
|
|
9550
9555
|
lang: finalLangAst.lang,
|
|
9551
9556
|
variants: []
|
|
9552
9557
|
})];
|
|
9553
9558
|
if (replacedLang) {
|
|
9554
|
-
|
|
9559
|
+
const replacedLangAst = parseUnicodeLanguageId(
|
|
9560
|
+
replacedLang.split(SEPARATOR)
|
|
9561
|
+
);
|
|
9555
9562
|
finalLangAst = {
|
|
9556
9563
|
lang: replacedLangAst.lang,
|
|
9557
9564
|
script: finalLangAst.script || replacedLangAst.script,
|
|
@@ -9560,19 +9567,21 @@
|
|
|
9560
9567
|
};
|
|
9561
9568
|
}
|
|
9562
9569
|
if (finalLangAst.region) {
|
|
9563
|
-
|
|
9564
|
-
|
|
9565
|
-
|
|
9570
|
+
const region = finalLangAst.region.toUpperCase();
|
|
9571
|
+
const regionAlias = territoryAlias[region];
|
|
9572
|
+
let replacedRegion;
|
|
9566
9573
|
if (regionAlias) {
|
|
9567
|
-
|
|
9574
|
+
const regions = regionAlias.split(" ");
|
|
9568
9575
|
replacedRegion = regions[0];
|
|
9569
|
-
|
|
9576
|
+
const likelySubtag = likelySubtags[emitUnicodeLanguageId({
|
|
9570
9577
|
lang: finalLangAst.lang,
|
|
9571
9578
|
script: finalLangAst.script,
|
|
9572
9579
|
variants: []
|
|
9573
9580
|
})];
|
|
9574
9581
|
if (likelySubtag) {
|
|
9575
|
-
|
|
9582
|
+
const { region: likelyRegion } = parseUnicodeLanguageId(
|
|
9583
|
+
likelySubtag.split(SEPARATOR)
|
|
9584
|
+
);
|
|
9576
9585
|
if (likelyRegion && regions.indexOf(likelyRegion) > -1) {
|
|
9577
9586
|
replacedRegion = likelyRegion;
|
|
9578
9587
|
}
|
|
@@ -9590,10 +9599,10 @@
|
|
|
9590
9599
|
}
|
|
9591
9600
|
}
|
|
9592
9601
|
if (finalLangAst.variants.length) {
|
|
9593
|
-
for (
|
|
9594
|
-
|
|
9602
|
+
for (let i = 0; i < finalLangAst.variants.length; i++) {
|
|
9603
|
+
let variant = finalLangAst.variants[i].toLowerCase();
|
|
9595
9604
|
if (variantAlias[variant]) {
|
|
9596
|
-
|
|
9605
|
+
const alias = variantAlias[variant];
|
|
9597
9606
|
if (isUnicodeVariantSubtag(alias)) {
|
|
9598
9607
|
finalLangAst.variants[i] = alias;
|
|
9599
9608
|
} else if (isUnicodeLanguageSubtag(alias)) {
|
|
@@ -9608,8 +9617,7 @@
|
|
|
9608
9617
|
function canonicalizeUnicodeLocaleId(locale) {
|
|
9609
9618
|
locale.lang = canonicalizeUnicodeLanguageId(locale.lang);
|
|
9610
9619
|
if (locale.extensions) {
|
|
9611
|
-
for (
|
|
9612
|
-
var extension = _a[_i];
|
|
9620
|
+
for (const extension of locale.extensions) {
|
|
9613
9621
|
switch (extension.type) {
|
|
9614
9622
|
case "u":
|
|
9615
9623
|
extension.keywords = canonicalizeKVs(extension.keywords);
|
|
@@ -9633,18 +9641,19 @@
|
|
|
9633
9641
|
return locale;
|
|
9634
9642
|
}
|
|
9635
9643
|
|
|
9636
|
-
//
|
|
9644
|
+
// packages/intl-getcanonicallocales/index.ts
|
|
9637
9645
|
function CanonicalizeLocaleList(locales) {
|
|
9638
9646
|
if (locales === void 0) {
|
|
9639
9647
|
return [];
|
|
9640
9648
|
}
|
|
9641
|
-
|
|
9649
|
+
const seen = [];
|
|
9642
9650
|
if (typeof locales === "string") {
|
|
9643
9651
|
locales = [locales];
|
|
9644
9652
|
}
|
|
9645
|
-
for (
|
|
9646
|
-
|
|
9647
|
-
|
|
9653
|
+
for (const locale of locales) {
|
|
9654
|
+
const canonicalizedTag = emitUnicodeLocaleId(
|
|
9655
|
+
canonicalizeUnicodeLocaleId(parseUnicodeLocaleId(locale))
|
|
9656
|
+
);
|
|
9648
9657
|
if (seen.indexOf(canonicalizedTag) < 0) {
|
|
9649
9658
|
seen.push(canonicalizedTag);
|
|
9650
9659
|
}
|
|
@@ -9655,14 +9664,14 @@
|
|
|
9655
9664
|
return CanonicalizeLocaleList(locales);
|
|
9656
9665
|
}
|
|
9657
9666
|
|
|
9658
|
-
//
|
|
9667
|
+
// packages/intl-getcanonicallocales/should-polyfill.ts
|
|
9659
9668
|
function shouldPolyfill() {
|
|
9660
9669
|
return typeof Intl === "undefined" || !("getCanonicalLocales" in Intl) || // Native Intl.getCanonicalLocales is just buggy
|
|
9661
9670
|
// https://bugs.chromium.org/p/v8/issues/detail?id=10682
|
|
9662
9671
|
Intl.getCanonicalLocales("und-x-private")[0] === "x-private";
|
|
9663
9672
|
}
|
|
9664
9673
|
|
|
9665
|
-
//
|
|
9674
|
+
// packages/intl-getcanonicallocales/polyfill.ts
|
|
9666
9675
|
if (typeof Intl === "undefined") {
|
|
9667
9676
|
if (typeof window !== "undefined") {
|
|
9668
9677
|
Object.defineProperty(window, "Intl", {
|
package/should-polyfill.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.shouldPolyfill =
|
|
3
|
+
exports.shouldPolyfill = shouldPolyfill;
|
|
4
4
|
function shouldPolyfill() {
|
|
5
5
|
return (typeof Intl === 'undefined' ||
|
|
6
6
|
!('getCanonicalLocales' in Intl) ||
|
|
@@ -9,4 +9,3 @@ function shouldPolyfill() {
|
|
|
9
9
|
Intl.getCanonicalLocales('und-x-private')[0] ===
|
|
10
10
|
'x-private');
|
|
11
11
|
}
|
|
12
|
-
exports.shouldPolyfill = shouldPolyfill;
|
package/src/canonicalizer.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.canonicalizeUnicodeLanguageId = canonicalizeUnicodeLanguageId;
|
|
4
|
+
exports.canonicalizeUnicodeLocaleId = canonicalizeUnicodeLocaleId;
|
|
4
5
|
var tslib_1 = require("tslib");
|
|
5
6
|
var aliases_generated_1 = require("./aliases.generated");
|
|
6
7
|
var parser_1 = require("./parser");
|
|
@@ -186,7 +187,6 @@ function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
|
|
|
186
187
|
}
|
|
187
188
|
return finalLangAst;
|
|
188
189
|
}
|
|
189
|
-
exports.canonicalizeUnicodeLanguageId = canonicalizeUnicodeLanguageId;
|
|
190
190
|
/**
|
|
191
191
|
* Canonicalize based on
|
|
192
192
|
* https://www.unicode.org/reports/tr35/tr35.html#Canonical_Unicode_Locale_Identifiers
|
|
@@ -221,4 +221,3 @@ function canonicalizeUnicodeLocaleId(locale) {
|
|
|
221
221
|
}
|
|
222
222
|
return locale;
|
|
223
223
|
}
|
|
224
|
-
exports.canonicalizeUnicodeLocaleId = canonicalizeUnicodeLocaleId;
|
package/src/emitter.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.emitUnicodeLanguageId = emitUnicodeLanguageId;
|
|
4
|
+
exports.emitUnicodeLocaleId = emitUnicodeLocaleId;
|
|
4
5
|
var tslib_1 = require("tslib");
|
|
5
6
|
function emitUnicodeLanguageId(lang) {
|
|
6
7
|
if (!lang) {
|
|
@@ -9,7 +10,6 @@ function emitUnicodeLanguageId(lang) {
|
|
|
9
10
|
return tslib_1.__spreadArray([lang.lang, lang.script, lang.region], (lang.variants || []), true).filter(Boolean)
|
|
10
11
|
.join('-');
|
|
11
12
|
}
|
|
12
|
-
exports.emitUnicodeLanguageId = emitUnicodeLanguageId;
|
|
13
13
|
function emitUnicodeLocaleId(_a) {
|
|
14
14
|
var lang = _a.lang, extensions = _a.extensions;
|
|
15
15
|
var chunks = [emitUnicodeLanguageId(lang)];
|
|
@@ -30,4 +30,3 @@ function emitUnicodeLocaleId(_a) {
|
|
|
30
30
|
}
|
|
31
31
|
return chunks.filter(Boolean).join('-');
|
|
32
32
|
}
|
|
33
|
-
exports.emitUnicodeLocaleId = emitUnicodeLocaleId;
|
package/src/parser.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SEPARATOR = void 0;
|
|
4
|
+
exports.isUnicodeLanguageSubtag = isUnicodeLanguageSubtag;
|
|
5
|
+
exports.isStructurallyValidLanguageTag = isStructurallyValidLanguageTag;
|
|
6
|
+
exports.isUnicodeRegionSubtag = isUnicodeRegionSubtag;
|
|
7
|
+
exports.isUnicodeScriptSubtag = isUnicodeScriptSubtag;
|
|
8
|
+
exports.isUnicodeVariantSubtag = isUnicodeVariantSubtag;
|
|
9
|
+
exports.parseUnicodeLanguageId = parseUnicodeLanguageId;
|
|
10
|
+
exports.parseUnicodeLocaleId = parseUnicodeLocaleId;
|
|
4
11
|
var tslib_1 = require("tslib");
|
|
5
12
|
var ALPHANUM_1_8 = /^[a-z0-9]{1,8}$/i;
|
|
6
13
|
var ALPHANUM_2_8 = /^[a-z0-9]{2,8}$/i;
|
|
@@ -18,7 +25,6 @@ exports.SEPARATOR = '-';
|
|
|
18
25
|
function isUnicodeLanguageSubtag(lang) {
|
|
19
26
|
return UNICODE_LANGUAGE_SUBTAG_REGEX.test(lang);
|
|
20
27
|
}
|
|
21
|
-
exports.isUnicodeLanguageSubtag = isUnicodeLanguageSubtag;
|
|
22
28
|
function isStructurallyValidLanguageTag(tag) {
|
|
23
29
|
try {
|
|
24
30
|
parseUnicodeLanguageId(tag.split(exports.SEPARATOR));
|
|
@@ -28,19 +34,15 @@ function isStructurallyValidLanguageTag(tag) {
|
|
|
28
34
|
}
|
|
29
35
|
return true;
|
|
30
36
|
}
|
|
31
|
-
exports.isStructurallyValidLanguageTag = isStructurallyValidLanguageTag;
|
|
32
37
|
function isUnicodeRegionSubtag(region) {
|
|
33
38
|
return UNICODE_REGION_SUBTAG_REGEX.test(region);
|
|
34
39
|
}
|
|
35
|
-
exports.isUnicodeRegionSubtag = isUnicodeRegionSubtag;
|
|
36
40
|
function isUnicodeScriptSubtag(script) {
|
|
37
41
|
return ALPHA_4.test(script);
|
|
38
42
|
}
|
|
39
|
-
exports.isUnicodeScriptSubtag = isUnicodeScriptSubtag;
|
|
40
43
|
function isUnicodeVariantSubtag(variant) {
|
|
41
44
|
return UNICODE_VARIANT_SUBTAG_REGEX.test(variant);
|
|
42
45
|
}
|
|
43
|
-
exports.isUnicodeVariantSubtag = isUnicodeVariantSubtag;
|
|
44
46
|
function parseUnicodeLanguageId(chunks) {
|
|
45
47
|
if (typeof chunks === 'string') {
|
|
46
48
|
chunks = chunks.split(exports.SEPARATOR);
|
|
@@ -81,7 +83,6 @@ function parseUnicodeLanguageId(chunks) {
|
|
|
81
83
|
variants: Object.keys(variants),
|
|
82
84
|
};
|
|
83
85
|
}
|
|
84
|
-
exports.parseUnicodeLanguageId = parseUnicodeLanguageId;
|
|
85
86
|
function parseUnicodeExtension(chunks) {
|
|
86
87
|
var keywords = [];
|
|
87
88
|
var keyword;
|
|
@@ -240,4 +241,3 @@ function parseUnicodeLocaleId(locale) {
|
|
|
240
241
|
var lang = parseUnicodeLanguageId(chunks);
|
|
241
242
|
return tslib_1.__assign({ lang: lang }, parseExtensions(chunks));
|
|
242
243
|
}
|
|
243
|
-
exports.parseUnicodeLocaleId = parseUnicodeLocaleId;
|