@brightspace-ui/intl 3.18.0 → 3.19.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 +78 -0
- package/lib/localize.js +3 -2
- package/package.json +2 -3
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const localeData = {
|
|
2
|
+
mi: {
|
|
3
|
+
aliases: ['mri', 'mao'],
|
|
4
|
+
options: {
|
|
5
|
+
cardinal: {
|
|
6
|
+
locale: 'mi',
|
|
7
|
+
pluralCategories : [ 'one', 'other' ],
|
|
8
|
+
shim: true
|
|
9
|
+
},
|
|
10
|
+
ordinal: {
|
|
11
|
+
locale: 'mi',
|
|
12
|
+
pluralCategories : [ 'other' ],
|
|
13
|
+
shim: true
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
select(n, ord) {
|
|
17
|
+
return !ord && n === 1 ? 'one' : 'other';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function getCanonicalLocales(locales) {
|
|
23
|
+
const mappedLocales = [locales].flat().map(locale => {
|
|
24
|
+
for (const canonicalLocale in localeData) {
|
|
25
|
+
if (localeData[canonicalLocale].aliases.includes(locale)) {
|
|
26
|
+
return canonicalLocale;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return locale;
|
|
30
|
+
});
|
|
31
|
+
return Intl.getCanonicalLocales(mappedLocales);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
class PluralRules extends Intl.PluralRules {
|
|
35
|
+
|
|
36
|
+
static shim = true;
|
|
37
|
+
static supportedLocalesOf(locales) {
|
|
38
|
+
return [locales].flat().map(l => {
|
|
39
|
+
const canonicalLocale = getCanonicalLocales(l)[0];
|
|
40
|
+
if (localeData[canonicalLocale]) {
|
|
41
|
+
return canonicalLocale;
|
|
42
|
+
}
|
|
43
|
+
return super.supportedLocalesOf(l);
|
|
44
|
+
}).flat();
|
|
45
|
+
}
|
|
46
|
+
#localeData;
|
|
47
|
+
#locale;
|
|
48
|
+
#type;
|
|
49
|
+
|
|
50
|
+
constructor(locales, options = {}) {
|
|
51
|
+
super(locales, options);
|
|
52
|
+
this.#locale = PluralRules.supportedLocalesOf(locales)[0];
|
|
53
|
+
this.#type = options.type ?? 'cardinal';
|
|
54
|
+
if (localeData[this.#locale]) {
|
|
55
|
+
this.#localeData = localeData[this.#locale];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
resolvedOptions() {
|
|
60
|
+
return { ...super.resolvedOptions(), ...this.#localeData?.options[this.#type] };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
select(n) {
|
|
64
|
+
if (this.#localeData) {
|
|
65
|
+
return this.#localeData.select(n, this.#type === 'ordinal');
|
|
66
|
+
} else {
|
|
67
|
+
return super.select(n);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
Object.defineProperty(Intl, 'PluralRules', {
|
|
74
|
+
value: PluralRules,
|
|
75
|
+
writable: true,
|
|
76
|
+
enumerable: false,
|
|
77
|
+
configurable: true,
|
|
78
|
+
});
|
package/lib/localize.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import '
|
|
2
|
-
import { defaultLocale as fallbackLang, getDocumentLocaleSettings, supportedLangpacks } from '
|
|
1
|
+
import './PluralRules.js';
|
|
2
|
+
import { defaultLocale as fallbackLang, getDocumentLocaleSettings, supportedLangpacks } from './common.js';
|
|
3
3
|
import { getLocalizeOverrideResources } from '../helpers/getLocalizeResources.js';
|
|
4
4
|
import IntlMessageFormat from 'intl-messageformat';
|
|
5
5
|
|
|
@@ -214,6 +214,7 @@ export const Localize = class extends getLocalizeClass() {
|
|
|
214
214
|
constructor(config) {
|
|
215
215
|
super();
|
|
216
216
|
super.constructor.setLocalizeMarkup(localizeMarkup);
|
|
217
|
+
this.localize = (...args) => super.localize(...args);
|
|
217
218
|
this.config = config;
|
|
218
219
|
this.connect();
|
|
219
220
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brightspace-ui/intl",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.19.1",
|
|
4
4
|
"description": "Internationalization APIs for number, date, time and file size formatting and parsing in D2L Brightspace.",
|
|
5
5
|
"main": "lib/number.js",
|
|
6
6
|
"type": "module",
|
|
@@ -41,10 +41,9 @@
|
|
|
41
41
|
"@brightspace-ui/testing": "^1",
|
|
42
42
|
"eslint": "^8",
|
|
43
43
|
"eslint-config-brightspace": "^1",
|
|
44
|
-
"sinon": "^
|
|
44
|
+
"sinon": "^19.0.2"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@formatjs/intl-pluralrules": "^1",
|
|
48
47
|
"intl-messageformat": "^10"
|
|
49
48
|
}
|
|
50
49
|
}
|