This repository was archived by the owner on Apr 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 215
/
Copy path6.locales-currencies-tz.js
509 lines (474 loc) · 14.9 KB
/
6.locales-currencies-tz.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
// Sect 6.2 Language Tags
// ======================
import {
expBCP47Syntax,
expExtSequences,
expVariantDupes,
expSingletonDupes
} from './exp';
import {
hop,
arrJoin,
arrSlice
} from "./util.js";
// Default locale is the first-added locale data for us
export let defaultLocale;
export function setDefaultLocale(locale) {
defaultLocale = locale;
}
// IANA Subtag Registry redundant tag and subtag maps
const redundantTags = {
tags: {
"art-lojban": "jbo",
"i-ami": "ami",
"i-bnn": "bnn",
"i-hak": "hak",
"i-klingon": "tlh",
"i-lux": "lb",
"i-navajo": "nv",
"i-pwn": "pwn",
"i-tao": "tao",
"i-tay": "tay",
"i-tsu": "tsu",
"no-bok": "nb",
"no-nyn": "nn",
"sgn-BE-FR": "sfb",
"sgn-BE-NL": "vgt",
"sgn-CH-DE": "sgg",
"zh-guoyu": "cmn",
"zh-hakka": "hak",
"zh-min-nan": "nan",
"zh-xiang": "hsn",
"sgn-BR": "bzs",
"sgn-CO": "csn",
"sgn-DE": "gsg",
"sgn-DK": "dsl",
"sgn-ES": "ssp",
"sgn-FR": "fsl",
"sgn-GB": "bfi",
"sgn-GR": "gss",
"sgn-IE": "isg",
"sgn-IT": "ise",
"sgn-JP": "jsl",
"sgn-MX": "mfs",
"sgn-NI": "ncs",
"sgn-NL": "dse",
"sgn-NO": "nsl",
"sgn-PT": "psr",
"sgn-SE": "swl",
"sgn-US": "ase",
"sgn-ZA": "sfs",
"zh-cmn": "cmn",
"zh-cmn-Hans": "cmn-Hans",
"zh-cmn-Hant": "cmn-Hant",
"zh-gan": "gan",
"zh-wuu": "wuu",
"zh-yue": "yue"
},
subtags: {
BU: "MM",
DD: "DE",
FX: "FR",
TP: "TL",
YD: "YE",
ZR: "CD",
heploc: "alalc97",
'in': "id",
iw: "he",
ji: "yi",
jw: "jv",
mo: "ro",
ayx: "nun",
bjd: "drl",
ccq: "rki",
cjr: "mom",
cka: "cmr",
cmk: "xch",
drh: "khk",
drw: "prs",
gav: "dev",
hrr: "jal",
ibi: "opa",
kgh: "kml",
lcq: "ppr",
mst: "mry",
myt: "mry",
sca: "hle",
tie: "ras",
tkk: "twm",
tlw: "weo",
tnf: "prs",
ybd: "rki",
yma: "lrr"
},
extLang: {
aao: ["aao", "ar"],
abh: ["abh", "ar"],
abv: ["abv", "ar"],
acm: ["acm", "ar"],
acq: ["acq", "ar"],
acw: ["acw", "ar"],
acx: ["acx", "ar"],
acy: ["acy", "ar"],
adf: ["adf", "ar"],
ads: ["ads", "sgn"],
aeb: ["aeb", "ar"],
aec: ["aec", "ar"],
aed: ["aed", "sgn"],
aen: ["aen", "sgn"],
afb: ["afb", "ar"],
afg: ["afg", "sgn"],
ajp: ["ajp", "ar"],
apc: ["apc", "ar"],
apd: ["apd", "ar"],
arb: ["arb", "ar"],
arq: ["arq", "ar"],
ars: ["ars", "ar"],
ary: ["ary", "ar"],
arz: ["arz", "ar"],
ase: ["ase", "sgn"],
asf: ["asf", "sgn"],
asp: ["asp", "sgn"],
asq: ["asq", "sgn"],
asw: ["asw", "sgn"],
auz: ["auz", "ar"],
avl: ["avl", "ar"],
ayh: ["ayh", "ar"],
ayl: ["ayl", "ar"],
ayn: ["ayn", "ar"],
ayp: ["ayp", "ar"],
bbz: ["bbz", "ar"],
bfi: ["bfi", "sgn"],
bfk: ["bfk", "sgn"],
bjn: ["bjn", "ms"],
bog: ["bog", "sgn"],
bqn: ["bqn", "sgn"],
bqy: ["bqy", "sgn"],
btj: ["btj", "ms"],
bve: ["bve", "ms"],
bvl: ["bvl", "sgn"],
bvu: ["bvu", "ms"],
bzs: ["bzs", "sgn"],
cdo: ["cdo", "zh"],
cds: ["cds", "sgn"],
cjy: ["cjy", "zh"],
cmn: ["cmn", "zh"],
coa: ["coa", "ms"],
cpx: ["cpx", "zh"],
csc: ["csc", "sgn"],
csd: ["csd", "sgn"],
cse: ["cse", "sgn"],
csf: ["csf", "sgn"],
csg: ["csg", "sgn"],
csl: ["csl", "sgn"],
csn: ["csn", "sgn"],
csq: ["csq", "sgn"],
csr: ["csr", "sgn"],
czh: ["czh", "zh"],
czo: ["czo", "zh"],
doq: ["doq", "sgn"],
dse: ["dse", "sgn"],
dsl: ["dsl", "sgn"],
dup: ["dup", "ms"],
ecs: ["ecs", "sgn"],
esl: ["esl", "sgn"],
esn: ["esn", "sgn"],
eso: ["eso", "sgn"],
eth: ["eth", "sgn"],
fcs: ["fcs", "sgn"],
fse: ["fse", "sgn"],
fsl: ["fsl", "sgn"],
fss: ["fss", "sgn"],
gan: ["gan", "zh"],
gds: ["gds", "sgn"],
gom: ["gom", "kok"],
gse: ["gse", "sgn"],
gsg: ["gsg", "sgn"],
gsm: ["gsm", "sgn"],
gss: ["gss", "sgn"],
gus: ["gus", "sgn"],
hab: ["hab", "sgn"],
haf: ["haf", "sgn"],
hak: ["hak", "zh"],
hds: ["hds", "sgn"],
hji: ["hji", "ms"],
hks: ["hks", "sgn"],
hos: ["hos", "sgn"],
hps: ["hps", "sgn"],
hsh: ["hsh", "sgn"],
hsl: ["hsl", "sgn"],
hsn: ["hsn", "zh"],
icl: ["icl", "sgn"],
ils: ["ils", "sgn"],
inl: ["inl", "sgn"],
ins: ["ins", "sgn"],
ise: ["ise", "sgn"],
isg: ["isg", "sgn"],
isr: ["isr", "sgn"],
jak: ["jak", "ms"],
jax: ["jax", "ms"],
jcs: ["jcs", "sgn"],
jhs: ["jhs", "sgn"],
jls: ["jls", "sgn"],
jos: ["jos", "sgn"],
jsl: ["jsl", "sgn"],
jus: ["jus", "sgn"],
kgi: ["kgi", "sgn"],
knn: ["knn", "kok"],
kvb: ["kvb", "ms"],
kvk: ["kvk", "sgn"],
kvr: ["kvr", "ms"],
kxd: ["kxd", "ms"],
lbs: ["lbs", "sgn"],
lce: ["lce", "ms"],
lcf: ["lcf", "ms"],
liw: ["liw", "ms"],
lls: ["lls", "sgn"],
lsg: ["lsg", "sgn"],
lsl: ["lsl", "sgn"],
lso: ["lso", "sgn"],
lsp: ["lsp", "sgn"],
lst: ["lst", "sgn"],
lsy: ["lsy", "sgn"],
ltg: ["ltg", "lv"],
lvs: ["lvs", "lv"],
lzh: ["lzh", "zh"],
max: ["max", "ms"],
mdl: ["mdl", "sgn"],
meo: ["meo", "ms"],
mfa: ["mfa", "ms"],
mfb: ["mfb", "ms"],
mfs: ["mfs", "sgn"],
min: ["min", "ms"],
mnp: ["mnp", "zh"],
mqg: ["mqg", "ms"],
mre: ["mre", "sgn"],
msd: ["msd", "sgn"],
msi: ["msi", "ms"],
msr: ["msr", "sgn"],
mui: ["mui", "ms"],
mzc: ["mzc", "sgn"],
mzg: ["mzg", "sgn"],
mzy: ["mzy", "sgn"],
nan: ["nan", "zh"],
nbs: ["nbs", "sgn"],
ncs: ["ncs", "sgn"],
nsi: ["nsi", "sgn"],
nsl: ["nsl", "sgn"],
nsp: ["nsp", "sgn"],
nsr: ["nsr", "sgn"],
nzs: ["nzs", "sgn"],
okl: ["okl", "sgn"],
orn: ["orn", "ms"],
ors: ["ors", "ms"],
pel: ["pel", "ms"],
pga: ["pga", "ar"],
pks: ["pks", "sgn"],
prl: ["prl", "sgn"],
prz: ["prz", "sgn"],
psc: ["psc", "sgn"],
psd: ["psd", "sgn"],
pse: ["pse", "ms"],
psg: ["psg", "sgn"],
psl: ["psl", "sgn"],
pso: ["pso", "sgn"],
psp: ["psp", "sgn"],
psr: ["psr", "sgn"],
pys: ["pys", "sgn"],
rms: ["rms", "sgn"],
rsi: ["rsi", "sgn"],
rsl: ["rsl", "sgn"],
sdl: ["sdl", "sgn"],
sfb: ["sfb", "sgn"],
sfs: ["sfs", "sgn"],
sgg: ["sgg", "sgn"],
sgx: ["sgx", "sgn"],
shu: ["shu", "ar"],
slf: ["slf", "sgn"],
sls: ["sls", "sgn"],
sqk: ["sqk", "sgn"],
sqs: ["sqs", "sgn"],
ssh: ["ssh", "ar"],
ssp: ["ssp", "sgn"],
ssr: ["ssr", "sgn"],
svk: ["svk", "sgn"],
swc: ["swc", "sw"],
swh: ["swh", "sw"],
swl: ["swl", "sgn"],
syy: ["syy", "sgn"],
tmw: ["tmw", "ms"],
tse: ["tse", "sgn"],
tsm: ["tsm", "sgn"],
tsq: ["tsq", "sgn"],
tss: ["tss", "sgn"],
tsy: ["tsy", "sgn"],
tza: ["tza", "sgn"],
ugn: ["ugn", "sgn"],
ugy: ["ugy", "sgn"],
ukl: ["ukl", "sgn"],
uks: ["uks", "sgn"],
urk: ["urk", "ms"],
uzn: ["uzn", "uz"],
uzs: ["uzs", "uz"],
vgt: ["vgt", "sgn"],
vkk: ["vkk", "ms"],
vkt: ["vkt", "ms"],
vsi: ["vsi", "sgn"],
vsl: ["vsl", "sgn"],
vsv: ["vsv", "sgn"],
wuu: ["wuu", "zh"],
xki: ["xki", "sgn"],
xml: ["xml", "sgn"],
xmm: ["xmm", "ms"],
xms: ["xms", "sgn"],
yds: ["yds", "sgn"],
ysl: ["ysl", "sgn"],
yue: ["yue", "zh"],
zib: ["zib", "sgn"],
zlm: ["zlm", "ms"],
zmi: ["zmi", "ms"],
zsl: ["zsl", "sgn"],
zsm: ["zsm", "ms"]
}
};
/**
* Convert only a-z to uppercase as per section 6.1 of the spec
*/
export function toLatinUpperCase (str) {
let i = str.length;
while (i--) {
let ch = str.charAt(i);
if (ch >= "a" && ch <= "z")
str = str.slice(0, i) + ch.toUpperCase() + str.slice(i+1);
}
return str;
}
/**
* The IsStructurallyValidLanguageTag abstract operation verifies that the locale
* argument (which must be a String value)
*
* - represents a well-formed BCP 47 language tag as specified in RFC 5646 section
* 2.1, or successor,
* - does not include duplicate variant subtags, and
* - does not include duplicate singleton subtags.
*
* The abstract operation returns true if locale can be generated from the ABNF
* grammar in section 2.1 of the RFC, starting with Language-Tag, and does not
* contain duplicate variant or singleton subtags (other than as a private use
* subtag). It returns false otherwise. Terminal value characters in the grammar are
* interpreted as the Unicode equivalents of the ASCII octet values given.
*/
export function /* 6.2.2 */IsStructurallyValidLanguageTag(locale) {
// represents a well-formed BCP 47 language tag as specified in RFC 5646
if (!expBCP47Syntax.test(locale))
return false;
// does not include duplicate variant subtags, and
if (expVariantDupes.test(locale))
return false;
// does not include duplicate singleton subtags.
if (expSingletonDupes.test(locale))
return false;
return true;
}
/**
* The CanonicalizeLanguageTag abstract operation returns the canonical and case-
* regularized form of the locale argument (which must be a String value that is
* a structurally valid BCP 47 language tag as verified by the
* IsStructurallyValidLanguageTag abstract operation). It takes the steps
* specified in RFC 5646 section 4.5, or successor, to bring the language tag
* into canonical form, and to regularize the case of the subtags, but does not
* take the steps to bring a language tag into “extlang form” and to reorder
* variant subtags.
* The specifications for extensions to BCP 47 language tags, such as RFC 6067,
* may include canonicalization rules for the extension subtag sequences they
* define that go beyond the canonicalization rules of RFC 5646 section 4.5.
* Implementations are allowed, but not required, to apply these additional rules.
*/
export function /* 6.2.3 */CanonicalizeLanguageTag (locale) {
let match, parts;
// A language tag is in 'canonical form' when the tag is well-formed
// according to the rules in Sections 2.1 and 2.2
// Section 2.1 says all subtags use lowercase...
locale = locale.toLowerCase();
// ...with 2 exceptions: 'two-letter and four-letter subtags that neither
// appear at the start of the tag nor occur after singletons. Such two-letter
// subtags are all uppercase (as in the tags "en-CA-x-ca" or "sgn-BE-FR") and
// four-letter subtags are titlecase (as in the tag "az-Latn-x-latn").
parts = locale.split('-');
for (let i = 1, max = parts.length; i < max; i++) {
// Two-letter subtags are all uppercase
if (parts[i].length === 2)
parts[i] = parts[i].toUpperCase();
// Four-letter subtags are titlecase
else if (parts[i].length === 4)
parts[i] = parts[i].charAt(0).toUpperCase() + parts[i].slice(1);
// Is it a singleton?
else if (parts[i].length === 1 && parts[i] !== 'x')
break;
}
locale = arrJoin.call(parts, '-');
// The steps laid out in RFC 5646 section 4.5 are as follows:
// 1. Extension sequences are ordered into case-insensitive ASCII order
// by singleton subtag.
if ((match = locale.match(expExtSequences)) && match.length > 1) {
// The built-in sort() sorts by ASCII order, so use that
match.sort();
// Replace all extensions with the joined, sorted array
locale = locale.replace(
RegExp('(?:' + expExtSequences.source + ')+', 'i'),
arrJoin.call(match, '')
);
}
// 2. Redundant or grandfathered tags are replaced by their 'Preferred-
// Value', if there is one.
if (hop.call(redundantTags.tags, locale))
locale = redundantTags.tags[locale];
// 3. Subtags are replaced by their 'Preferred-Value', if there is one.
// For extlangs, the original primary language subtag is also
// replaced if there is a primary language subtag in the 'Preferred-
// Value'.
parts = locale.split('-');
for (let i = 1, max = parts.length; i < max; i++) {
if (hop.call(redundantTags.subtags, parts[i]))
parts[i] = redundantTags.subtags[parts[i]];
else if (hop.call(redundantTags.extLang, parts[i])) {
parts[i] = redundantTags.extLang[parts[i]][0];
// For extlang tags, the prefix needs to be removed if it is redundant
if (i === 1 && redundantTags.extLang[parts[1]][1] === parts[0]) {
parts = arrSlice.call(parts, i++);
max -= 1;
}
}
}
return arrJoin.call(parts, '-');
}
/**
* The DefaultLocale abstract operation returns a String value representing the
* structurally valid (6.2.2) and canonicalized (6.2.3) BCP 47 language tag for the
* host environment’s current locale.
*/
export function /* 6.2.4 */DefaultLocale () {
return defaultLocale;
}
// Sect 6.3 Currency Codes
// =======================
const expCurrencyCode = /^[A-Z]{3}$/;
/**
* The IsWellFormedCurrencyCode abstract operation verifies that the currency argument
* (after conversion to a String value) represents a well-formed 3-letter ISO currency
* code. The following steps are taken:
*/
export function /* 6.3.1 */IsWellFormedCurrencyCode(currency) {
// 1. Let `c` be ToString(currency)
let c = String(currency);
// 2. Let `normalized` be the result of mapping c to upper case as described
// in 6.1.
let normalized = toLatinUpperCase(c);
// 3. If the string length of normalized is not 3, return false.
// 4. If normalized contains any character that is not in the range "A" to "Z"
// (U+0041 to U+005A), return false.
if (expCurrencyCode.test(normalized) === false)
return false;
// 5. Return true
return true;
}