@brightspace-ui/intl 3.19.1 → 3.20.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/lib/PluralRules.js +4 -3
- package/lib/localize.js +46 -44
- package/package.json +1 -1
package/lib/PluralRules.js
CHANGED
|
@@ -43,9 +43,6 @@ class PluralRules extends Intl.PluralRules {
|
|
|
43
43
|
return super.supportedLocalesOf(l);
|
|
44
44
|
}).flat();
|
|
45
45
|
}
|
|
46
|
-
#localeData;
|
|
47
|
-
#locale;
|
|
48
|
-
#type;
|
|
49
46
|
|
|
50
47
|
constructor(locales, options = {}) {
|
|
51
48
|
super(locales, options);
|
|
@@ -68,6 +65,10 @@ class PluralRules extends Intl.PluralRules {
|
|
|
68
65
|
}
|
|
69
66
|
}
|
|
70
67
|
|
|
68
|
+
#localeData;
|
|
69
|
+
#locale;
|
|
70
|
+
#type;
|
|
71
|
+
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
Object.defineProperty(Intl, 'PluralRules', {
|
package/lib/localize.js
CHANGED
|
@@ -16,58 +16,14 @@ const noAllowedTagsRegex = getDisallowedTagsRegex([]);
|
|
|
16
16
|
|
|
17
17
|
export const getLocalizeClass = (superclass = class {}) => class LocalizeClass extends superclass {
|
|
18
18
|
|
|
19
|
-
static #localizeMarkup;
|
|
20
19
|
static documentLocaleSettings = getDocumentLocaleSettings();
|
|
21
20
|
|
|
22
21
|
static setLocalizeMarkup(localizeMarkup) {
|
|
23
22
|
this.#localizeMarkup ??= localizeMarkup;
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
#connected = false;
|
|
27
|
-
#localeChangeCallback;
|
|
28
|
-
#resolveResourcesLoaded;
|
|
29
|
-
#resourcesPromise;
|
|
30
25
|
pristine = true;
|
|
31
26
|
|
|
32
|
-
async #localeChangeHandler() {
|
|
33
|
-
if (!this._hasResources()) return;
|
|
34
|
-
|
|
35
|
-
const resourcesPromise = this.constructor._getAllLocalizeResources(this.config);
|
|
36
|
-
this.#resourcesPromise = resourcesPromise;
|
|
37
|
-
const localizeResources = (await resourcesPromise).flat(Infinity);
|
|
38
|
-
// If the locale changed while resources were being fetched, abort
|
|
39
|
-
if (this.#resourcesPromise !== resourcesPromise) return;
|
|
40
|
-
|
|
41
|
-
const allResources = {};
|
|
42
|
-
const resolvedLocales = new Set();
|
|
43
|
-
for (const { language, resources } of localizeResources) {
|
|
44
|
-
for (const [name, value] of Object.entries(resources)) {
|
|
45
|
-
allResources[name] = { language, value };
|
|
46
|
-
resolvedLocales.add(language);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
this.localize.resources = allResources;
|
|
50
|
-
this.localize.resolvedLocale = [...resolvedLocales][0];
|
|
51
|
-
if (resolvedLocales.size > 1) {
|
|
52
|
-
console.warn(`Resolved multiple locales in '${this.constructor.name || this.tagName || ''}': ${[...resolvedLocales].join(', ')}`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (this.pristine) {
|
|
56
|
-
this.pristine = false;
|
|
57
|
-
this.#resolveResourcesLoaded();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
this.#onResourcesChange();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
#onResourcesChange() {
|
|
64
|
-
if (this.#connected) {
|
|
65
|
-
this.dispatchEvent?.(new CustomEvent('d2l-localize-resources-change'));
|
|
66
|
-
this.config?.onResourcesChange?.();
|
|
67
|
-
this.onLocalizeResourcesChange?.();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
27
|
connect() {
|
|
72
28
|
this.#localeChangeCallback = () => this.#localeChangeHandler();
|
|
73
29
|
LocalizeClass.documentLocaleSettings.addChangeListener(this.#localeChangeCallback);
|
|
@@ -139,6 +95,13 @@ export const getLocalizeClass = (superclass = class {}) => class LocalizeClass e
|
|
|
139
95
|
return formattedMessage;
|
|
140
96
|
}
|
|
141
97
|
|
|
98
|
+
static #localizeMarkup;
|
|
99
|
+
|
|
100
|
+
#connected = false;
|
|
101
|
+
#localeChangeCallback;
|
|
102
|
+
#resolveResourcesLoaded;
|
|
103
|
+
#resourcesPromise;
|
|
104
|
+
|
|
142
105
|
__resourcesLoadedPromise = new Promise(r => this.#resolveResourcesLoaded = r);
|
|
143
106
|
|
|
144
107
|
static _generatePossibleLanguages(config) {
|
|
@@ -203,6 +166,45 @@ export const getLocalizeClass = (superclass = class {}) => class LocalizeClass e
|
|
|
203
166
|
return this.constructor.localizeConfig ? Boolean(this.constructor.localizeConfig.importFunc) : this.constructor.getLocalizeResources !== undefined;
|
|
204
167
|
}
|
|
205
168
|
|
|
169
|
+
async #localeChangeHandler() {
|
|
170
|
+
if (!this._hasResources()) return;
|
|
171
|
+
|
|
172
|
+
const resourcesPromise = this.constructor._getAllLocalizeResources(this.config);
|
|
173
|
+
this.#resourcesPromise = resourcesPromise;
|
|
174
|
+
const localizeResources = (await resourcesPromise).flat(Infinity);
|
|
175
|
+
// If the locale changed while resources were being fetched, abort
|
|
176
|
+
if (this.#resourcesPromise !== resourcesPromise) return;
|
|
177
|
+
|
|
178
|
+
const allResources = {};
|
|
179
|
+
const resolvedLocales = new Set();
|
|
180
|
+
for (const { language, resources } of localizeResources) {
|
|
181
|
+
for (const [name, value] of Object.entries(resources)) {
|
|
182
|
+
allResources[name] = { language, value };
|
|
183
|
+
resolvedLocales.add(language);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
this.localize.resources = allResources;
|
|
187
|
+
this.localize.resolvedLocale = [...resolvedLocales][0];
|
|
188
|
+
if (resolvedLocales.size > 1) {
|
|
189
|
+
console.warn(`Resolved multiple locales in '${this.constructor.name || this.tagName || ''}': ${[...resolvedLocales].join(', ')}`);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (this.pristine) {
|
|
193
|
+
this.pristine = false;
|
|
194
|
+
this.#resolveResourcesLoaded();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
this.#onResourcesChange();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
#onResourcesChange() {
|
|
201
|
+
if (this.#connected) {
|
|
202
|
+
this.dispatchEvent?.(new CustomEvent('d2l-localize-resources-change'));
|
|
203
|
+
this.config?.onResourcesChange?.();
|
|
204
|
+
this.onLocalizeResourcesChange?.();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
206
208
|
};
|
|
207
209
|
|
|
208
210
|
export const Localize = class extends getLocalizeClass() {
|
package/package.json
CHANGED