@entropic-bond/localize-react 1.6.4 → 1.6.5
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/locale.d.ts +8 -0
- package/lib/locale.js +19 -4
- package/lib/locale.js.map +1 -1
- package/package.json +9 -9
package/lib/locale.d.ts
CHANGED
|
@@ -6,6 +6,14 @@ type Rule = (word: string, locale: string) => string | undefined;
|
|
|
6
6
|
export declare class Locale {
|
|
7
7
|
private constructor();
|
|
8
8
|
static get instance(): Locale;
|
|
9
|
+
/**
|
|
10
|
+
* Returns the plural form of a word
|
|
11
|
+
*
|
|
12
|
+
* @param word to pluralize
|
|
13
|
+
* @param amount if the word to pluralize is a number, the amount is used to determine the plural form
|
|
14
|
+
* @param pluralizer a map of words to their plural form or a function that returns the plural form
|
|
15
|
+
* @returns the plural form of the word
|
|
16
|
+
*/
|
|
9
17
|
pluralize(word: string, amount?: number, pluralizer?: Record<string, string> | Rule): string;
|
|
10
18
|
static config(config: LocaleConfig): void;
|
|
11
19
|
get(component: string): Promise<{}>;
|
package/lib/locale.js
CHANGED
|
@@ -25,7 +25,16 @@ class Locale {
|
|
|
25
25
|
}
|
|
26
26
|
return this._instance;
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns the plural form of a word
|
|
30
|
+
*
|
|
31
|
+
* @param word to pluralize
|
|
32
|
+
* @param amount if the word to pluralize is a number, the amount is used to determine the plural form
|
|
33
|
+
* @param pluralizer a map of words to their plural form or a function that returns the plural form
|
|
34
|
+
* @returns the plural form of the word
|
|
35
|
+
*/
|
|
28
36
|
pluralize(word, amount = 0, pluralizer) {
|
|
37
|
+
var _a;
|
|
29
38
|
if (amount === 1)
|
|
30
39
|
return word;
|
|
31
40
|
let plural;
|
|
@@ -40,9 +49,9 @@ class Locale {
|
|
|
40
49
|
let i = 0;
|
|
41
50
|
const rules = Locale._registeredRules[this._lang];
|
|
42
51
|
while (!plural && rules && i < rules.length) {
|
|
43
|
-
plural = rules[i++](word, this._lang);
|
|
52
|
+
plural = (_a = rules[i++]) === null || _a === void 0 ? void 0 : _a.call(rules, word, this._lang);
|
|
44
53
|
}
|
|
45
|
-
return plural
|
|
54
|
+
return plural !== null && plural !== void 0 ? plural : word;
|
|
46
55
|
}
|
|
47
56
|
static config(config) {
|
|
48
57
|
this._registeredConfig = Object.assign(Object.assign({}, this._registeredConfig), config);
|
|
@@ -78,9 +87,10 @@ class Locale {
|
|
|
78
87
|
static useRule(rule, locale) {
|
|
79
88
|
if (!Locale._registeredRules[locale])
|
|
80
89
|
Locale._registeredRules[locale] = [];
|
|
81
|
-
Locale._registeredRules[locale].
|
|
90
|
+
Locale._registeredRules[locale].unshift(rule);
|
|
82
91
|
}
|
|
83
92
|
}
|
|
93
|
+
exports.Locale = Locale;
|
|
84
94
|
Locale.rules = [
|
|
85
95
|
(word, locale) => {
|
|
86
96
|
if (locale !== 'en')
|
|
@@ -91,10 +101,15 @@ Locale.rules = [
|
|
|
91
101
|
if (locale !== 'en')
|
|
92
102
|
return;
|
|
93
103
|
return word.slice(-1) === 's' ? word + 'es' : undefined;
|
|
104
|
+
},
|
|
105
|
+
(word, locale) => {
|
|
106
|
+
const mainLang = locale.slice(0, 2);
|
|
107
|
+
if (!(mainLang === 'en' || mainLang === 'es'))
|
|
108
|
+
return;
|
|
109
|
+
return word + 's';
|
|
94
110
|
}
|
|
95
111
|
];
|
|
96
112
|
Locale._instance = undefined;
|
|
97
113
|
Locale._registeredConfig = {};
|
|
98
114
|
Locale._registeredRules = { en: Locale.rules };
|
|
99
|
-
exports.Locale = Locale;
|
|
100
115
|
//# sourceMappingURL=locale.js.map
|
package/lib/locale.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locale.js","sourceRoot":"","sources":["../src/locale.ts"],"names":[],"mappings":";;;;;;;;;;;;AAOA,MAAa,MAAM;IAClB,YAAqB,MAAoB;
|
|
1
|
+
{"version":3,"file":"locale.js","sourceRoot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kB,AAAnC,CAAmC;AACpD,uBAAgB,GAAkC,EAAE,EAAE,EAAE,MAAM,CAAC,KAAK,EAAE,AAAtD,CAAsD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entropic-bond/localize-react",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.5",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"branches": [
|
|
@@ -49,19 +49,19 @@
|
|
|
49
49
|
"@testing-library/jest-dom": "^5.16.5",
|
|
50
50
|
"@testing-library/react": "^14.0.0",
|
|
51
51
|
"@testing-library/user-event": "^14.4.3",
|
|
52
|
-
"@types/jest": "^29.5.
|
|
53
|
-
"@types/react": "^18.
|
|
54
|
-
"@types/react-dom": "^18.
|
|
52
|
+
"@types/jest": "^29.5.3",
|
|
53
|
+
"@types/react": "^18.2.15",
|
|
54
|
+
"@types/react-dom": "^18.2.7",
|
|
55
55
|
"fetch-mock": "^9.11.0",
|
|
56
56
|
"git-branch-is": "^4.0.0",
|
|
57
57
|
"husky": "^8.0.3",
|
|
58
|
-
"jest": "^29.
|
|
59
|
-
"jest-environment-jsdom": "^29.
|
|
58
|
+
"jest": "^29.6.1",
|
|
59
|
+
"jest-environment-jsdom": "^29.6.1",
|
|
60
60
|
"react": "^18.2.0",
|
|
61
61
|
"react-dom": "^18.2.0",
|
|
62
|
-
"semantic-release": "^21.0.
|
|
63
|
-
"ts-jest": "^29.1.
|
|
64
|
-
"typescript": "^5.
|
|
62
|
+
"semantic-release": "^21.0.7",
|
|
63
|
+
"ts-jest": "^29.1.1",
|
|
64
|
+
"typescript": "^5.1.6"
|
|
65
65
|
},
|
|
66
66
|
"husky": {
|
|
67
67
|
"hooks": {
|