1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | import {
|
13 | defineProperty,
|
14 | hop,
|
15 | arrPush,
|
16 | arrShift,
|
17 | internals,
|
18 | } from "./util.js";
|
19 |
|
20 | import {
|
21 | IsStructurallyValidLanguageTag,
|
22 | defaultLocale,
|
23 | setDefaultLocale,
|
24 | } from "./6.locales-currencies-tz.js";
|
25 |
|
26 | import {
|
27 | Intl,
|
28 | } from "./8.intl.js";
|
29 |
|
30 | import "./11.numberformat.js";
|
31 |
|
32 | import "./12.datetimeformat.js";
|
33 |
|
34 | import ls from "./13.locale-sensitive-functions.js";
|
35 |
|
36 | defineProperty(Intl, '__applyLocaleSensitivePrototypes', {
|
37 | writable: true,
|
38 | configurable: true,
|
39 | value: function () {
|
40 | defineProperty(Number.prototype, 'toLocaleString', { writable: true, configurable: true, value: ls.Number.toLocaleString });
|
41 |
|
42 | defineProperty(Date.prototype, 'toLocaleString', { writable: true, configurable: true, value: ls.Date.toLocaleString });
|
43 |
|
44 | for (let k in ls.Date) {
|
45 | if (hop.call(ls.Date, k))
|
46 | defineProperty(Date.prototype, k, { writable: true, configurable: true, value: ls.Date[k] });
|
47 | }
|
48 | },
|
49 | });
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | defineProperty(Intl, '__addLocaleData', {
|
57 | value: function (data) {
|
58 | if (!IsStructurallyValidLanguageTag(data.locale))
|
59 | throw new Error("Object passed doesn't identify itself with a valid language tag");
|
60 |
|
61 | addLocaleData(data, data.locale);
|
62 | },
|
63 | });
|
64 |
|
65 | function addLocaleData (data, tag) {
|
66 |
|
67 | if (!data.number)
|
68 | throw new Error("Object passed doesn't contain locale data for Intl.NumberFormat");
|
69 |
|
70 | let locale,
|
71 | locales = [ tag ],
|
72 | parts = tag.split('-');
|
73 |
|
74 |
|
75 | if (parts.length > 2 && parts[1].length === 4)
|
76 | arrPush.call(locales, parts[0] + '-' + parts[2]);
|
77 |
|
78 | while ((locale = arrShift.call(locales))) {
|
79 |
|
80 | arrPush.call(internals.NumberFormat['[[availableLocales]]'], locale);
|
81 | internals.NumberFormat['[[localeData]]'][locale] = data.number;
|
82 |
|
83 |
|
84 | if (data.date) {
|
85 | data.date.nu = data.number.nu;
|
86 | arrPush.call(internals.DateTimeFormat['[[availableLocales]]'], locale);
|
87 | internals.DateTimeFormat['[[localeData]]'][locale] = data.date;
|
88 | }
|
89 | }
|
90 |
|
91 |
|
92 | if (defaultLocale === undefined)
|
93 | setDefaultLocale(tag);
|
94 | }
|
95 |
|
96 | export default Intl;
|