@webiny/i18n 5.23.1 → 5.25.0-beta.0
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/I18n.d.ts +7 -40
- package/I18n.js +54 -57
- package/I18n.js.map +1 -0
- package/extractor/extract.d.ts +1 -1
- package/extractor/extract.js +5 -0
- package/extractor/extract.js.map +1 -0
- package/extractor/index.d.ts +6 -3
- package/extractor/index.js +15 -14
- package/extractor/index.js.map +1 -0
- package/index.js.map +1 -0
- package/modifiers/countModifier.d.ts +1 -1
- package/modifiers/countModifier.js +25 -21
- package/modifiers/countModifier.js.map +1 -0
- package/modifiers/dateModifier.d.ts +2 -4
- package/modifiers/dateModifier.js.map +1 -0
- package/modifiers/dateTimeModifier.d.ts +2 -4
- package/modifiers/dateTimeModifier.js.map +1 -0
- package/modifiers/genderModifier.d.ts +1 -1
- package/modifiers/genderModifier.js +9 -5
- package/modifiers/genderModifier.js.map +1 -0
- package/modifiers/ifModifier.d.ts +1 -1
- package/modifiers/ifModifier.js +9 -5
- package/modifiers/ifModifier.js.map +1 -0
- package/modifiers/index.d.ts +2 -1
- package/modifiers/index.js +1 -1
- package/modifiers/index.js.map +1 -0
- package/modifiers/numberModifier.d.ts +2 -4
- package/modifiers/numberModifier.js.map +1 -0
- package/modifiers/pluralModifier.d.ts +1 -1
- package/modifiers/pluralModifier.js +24 -20
- package/modifiers/pluralModifier.js.map +1 -0
- package/modifiers/priceModifier.d.ts +2 -4
- package/modifiers/priceModifier.js.map +1 -0
- package/modifiers/timeModifier.d.ts +2 -4
- package/modifiers/timeModifier.js.map +1 -0
- package/package.json +9 -6
- package/processors/default.js +8 -8
- package/processors/default.js.map +1 -0
- package/types.d.ts +27 -22
- package/types.js.map +1 -0
package/I18n.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Formats, Modifier, NumberFormat, PriceFormat, Processor, Translations, Translator } from "./types";
|
|
1
|
+
import { Formats, I18NDataValues, Modifier, NumberFormat, PriceFormat, Processor, ProcessorResult, Translations, Translator } from "./types";
|
|
2
|
+
export declare type Translated = ((values: I18NDataValues) => ProcessorResult | null) | ProcessorResult | null;
|
|
2
3
|
/**
|
|
3
4
|
* Main class used for all I18n needs.
|
|
4
5
|
*/
|
|
5
6
|
export default class I18N {
|
|
6
|
-
locale
|
|
7
|
+
locale: string | null;
|
|
7
8
|
defaultFormats: Formats;
|
|
8
9
|
translations: Translations;
|
|
9
10
|
modifiers: {
|
|
@@ -13,83 +14,60 @@ export default class I18N {
|
|
|
13
14
|
[name: string]: Processor;
|
|
14
15
|
};
|
|
15
16
|
constructor();
|
|
16
|
-
translate(base: string, namespace?: string):
|
|
17
|
+
translate(base: string, namespace?: string): Translated;
|
|
17
18
|
namespace(namespace: string): Translator;
|
|
18
19
|
ns(namespace: string): Translator;
|
|
19
20
|
/**
|
|
20
21
|
* Formats and outputs date.
|
|
21
22
|
* It will try to load format from currently selected locale's settings. If not defined, default formats will be used.
|
|
22
|
-
* @param value
|
|
23
|
-
* @param outputFormat
|
|
24
|
-
* @param inputFormat
|
|
25
23
|
*/
|
|
26
|
-
date(value: Date | string | number, outputFormat?: string, inputFormat?:
|
|
24
|
+
date(value: Date | string | number, outputFormat?: string, inputFormat?: string): string;
|
|
27
25
|
/**
|
|
28
26
|
* Formats and outputs time.
|
|
29
27
|
* It will try to load format from currently selected locale's settings. If not defined, default formats will be used.
|
|
30
|
-
* @param value
|
|
31
|
-
* @param outputFormat
|
|
32
|
-
* @param inputFormat
|
|
33
28
|
*/
|
|
34
29
|
time(value: Date | string | number, outputFormat?: string, inputFormat?: string): string;
|
|
35
30
|
/**
|
|
36
31
|
* Formats and outputs date/time.
|
|
37
32
|
* It will try to load format from currently selected locale's settings. If not defined, default formats will be used.
|
|
38
|
-
* @param value
|
|
39
|
-
* @param outputFormat
|
|
40
|
-
* @param inputFormat
|
|
41
33
|
*/
|
|
42
34
|
dateTime(value: Date | string | number, outputFormat?: string, inputFormat?: string): string;
|
|
43
35
|
/**
|
|
44
36
|
* Outputs formatted number as amount of price.
|
|
45
|
-
* @param value
|
|
46
|
-
* @param outputFormat
|
|
47
37
|
*/
|
|
48
38
|
price(value: string | number, outputFormat?: any): string;
|
|
49
39
|
/**
|
|
50
40
|
* Outputs formatted number.
|
|
51
|
-
* @param value
|
|
52
|
-
* @param outputFormat
|
|
53
41
|
*/
|
|
54
42
|
number(value: string | number, outputFormat?: NumberFormat): string;
|
|
55
43
|
/**
|
|
56
44
|
* Returns translation for given text key.
|
|
57
|
-
* @param key
|
|
58
|
-
* @returns {*|string}
|
|
59
45
|
*/
|
|
60
|
-
getTranslation(key?: string): string;
|
|
46
|
+
getTranslation(key?: string): string | null;
|
|
61
47
|
/**
|
|
62
48
|
* Returns all translations for current locale.
|
|
63
|
-
* @returns {*|{}}
|
|
64
49
|
*/
|
|
65
50
|
getTranslations(): Translations;
|
|
66
51
|
/**
|
|
67
52
|
* Returns true if given key has a translation for currently set locale.
|
|
68
|
-
* @param key
|
|
69
53
|
*/
|
|
70
54
|
hasTranslation(key: string): boolean;
|
|
71
55
|
/**
|
|
72
56
|
* Sets translation for given text key.
|
|
73
|
-
* @param key
|
|
74
|
-
* @param translation
|
|
75
|
-
* @returns {I18N}
|
|
76
57
|
*/
|
|
77
58
|
setTranslation(key: string, translation: string): I18N;
|
|
78
59
|
/**
|
|
79
60
|
* Sets translations that will be used.
|
|
80
|
-
* @returns {*|{}}
|
|
81
61
|
*/
|
|
82
62
|
setTranslations(translations: Translations): I18N;
|
|
83
63
|
/**
|
|
84
64
|
* Clears all translations.
|
|
85
|
-
* @returns {*|{}}
|
|
86
65
|
*/
|
|
87
66
|
clearTranslations(): I18N;
|
|
88
67
|
/**
|
|
89
68
|
* Merges given translations object with already existing.
|
|
90
|
-
* @returns {*|{}}
|
|
91
69
|
*/
|
|
92
|
-
mergeTranslations(translations: Translations):
|
|
70
|
+
mergeTranslations(translations: Translations): Translations;
|
|
93
71
|
/**
|
|
94
72
|
* Returns currently selected locale (locale's key).
|
|
95
73
|
*/
|
|
@@ -100,41 +78,30 @@ export default class I18N {
|
|
|
100
78
|
setLocale(locale: string): I18N;
|
|
101
79
|
/**
|
|
102
80
|
* Registers single modifier.
|
|
103
|
-
* @returns {I18N}
|
|
104
81
|
*/
|
|
105
82
|
registerModifier(modifier: Modifier): I18N;
|
|
106
83
|
/**
|
|
107
84
|
* Registers all modifiers in given array.
|
|
108
|
-
* @param modifiers
|
|
109
|
-
* @returns {I18N}
|
|
110
85
|
*/
|
|
111
86
|
registerModifiers(modifiers: Array<Modifier>): I18N;
|
|
112
87
|
/**
|
|
113
88
|
* Unregisters given modifier.
|
|
114
|
-
* @param name
|
|
115
|
-
* @returns {I18N}
|
|
116
89
|
*/
|
|
117
90
|
unregisterModifier(name: string): I18N;
|
|
118
91
|
/**
|
|
119
92
|
* Registers single processor.
|
|
120
|
-
* @returns {I18N}
|
|
121
93
|
*/
|
|
122
94
|
registerProcessor(processor: Processor): I18N;
|
|
123
95
|
/**
|
|
124
96
|
* Registers all processors in given array.
|
|
125
|
-
* @param processors
|
|
126
|
-
* @returns {I18N}
|
|
127
97
|
*/
|
|
128
98
|
registerProcessors(processors: Array<Processor>): I18N;
|
|
129
99
|
/**
|
|
130
100
|
* Unregisters given processor.
|
|
131
|
-
* @param name
|
|
132
|
-
* @returns {I18N}
|
|
133
101
|
*/
|
|
134
102
|
unregisterProcessor(name: string): I18N;
|
|
135
103
|
/**
|
|
136
104
|
* Returns default formats
|
|
137
|
-
* @returns {{date: string, time: string, datetime: string, number: string}}
|
|
138
105
|
*/
|
|
139
106
|
getDefaultFormats(): Formats;
|
|
140
107
|
/**
|
package/I18n.js
CHANGED
|
@@ -9,36 +9,40 @@ exports.default = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _accounting = _interopRequireDefault(require("accounting"));
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var fecha = _interopRequireWildcard(require("fecha"));
|
|
15
15
|
|
|
16
16
|
var _shortHash = _interopRequireDefault(require("short-hash"));
|
|
17
17
|
|
|
18
|
-
var
|
|
18
|
+
var _assign = _interopRequireDefault(require("lodash/assign"));
|
|
19
19
|
|
|
20
|
-
var
|
|
20
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
|
21
21
|
|
|
22
22
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
23
23
|
|
|
24
24
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Package short-hash has no types.
|
|
28
|
+
*/
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
|
|
26
31
|
/**
|
|
27
32
|
* Main class used for all I18n needs.
|
|
28
33
|
*/
|
|
29
34
|
class I18N {
|
|
30
35
|
constructor() {
|
|
31
|
-
(0, _defineProperty2.default)(this, "locale",
|
|
36
|
+
(0, _defineProperty2.default)(this, "locale", null);
|
|
32
37
|
(0, _defineProperty2.default)(this, "defaultFormats", void 0);
|
|
33
38
|
(0, _defineProperty2.default)(this, "translations", void 0);
|
|
34
39
|
(0, _defineProperty2.default)(this, "modifiers", void 0);
|
|
35
40
|
(0, _defineProperty2.default)(this, "processors", void 0);
|
|
36
|
-
|
|
41
|
+
|
|
37
42
|
/**
|
|
38
43
|
* If we fail to fetch formats for currently selected locale, these default formats will be used.
|
|
39
44
|
* @type {{date: string, time: string, datetime: string, number: string}}
|
|
40
45
|
*/
|
|
41
|
-
|
|
42
46
|
this.defaultFormats = this.getDefaultFormats();
|
|
43
47
|
/**
|
|
44
48
|
* All currently-loaded translations, for easier (synchronous) access.
|
|
@@ -69,7 +73,7 @@ class I18N {
|
|
|
69
73
|
throw Error("I18N text namespace not defined.");
|
|
70
74
|
}
|
|
71
75
|
|
|
72
|
-
base = (0,
|
|
76
|
+
base = (0, _get.default)(base, "raw.0", base);
|
|
73
77
|
let translation = this.getTranslation(namespace + "." + (0, _shortHash.default)(base));
|
|
74
78
|
|
|
75
79
|
if (!translation) {
|
|
@@ -79,10 +83,9 @@ class I18N {
|
|
|
79
83
|
const hasVariables = base.includes("{") && base.includes("}");
|
|
80
84
|
|
|
81
85
|
if (hasVariables) {
|
|
82
|
-
// @ts-ignore
|
|
83
86
|
return values => {
|
|
84
87
|
const data = {
|
|
85
|
-
translation,
|
|
88
|
+
translation: translation,
|
|
86
89
|
base,
|
|
87
90
|
namespace,
|
|
88
91
|
values,
|
|
@@ -90,8 +93,10 @@ class I18N {
|
|
|
90
93
|
};
|
|
91
94
|
|
|
92
95
|
for (const key in this.processors) {
|
|
93
|
-
|
|
94
|
-
|
|
96
|
+
const processor = this.processors[key];
|
|
97
|
+
|
|
98
|
+
if (processor.canExecute(data)) {
|
|
99
|
+
return processor.execute(data);
|
|
95
100
|
}
|
|
96
101
|
}
|
|
97
102
|
|
|
@@ -128,9 +133,6 @@ class I18N {
|
|
|
128
133
|
/**
|
|
129
134
|
* Formats and outputs date.
|
|
130
135
|
* It will try to load format from currently selected locale's settings. If not defined, default formats will be used.
|
|
131
|
-
* @param value
|
|
132
|
-
* @param outputFormat
|
|
133
|
-
* @param inputFormat
|
|
134
136
|
*/
|
|
135
137
|
|
|
136
138
|
|
|
@@ -139,10 +141,16 @@ class I18N {
|
|
|
139
141
|
outputFormat = this.getDateFormat();
|
|
140
142
|
}
|
|
141
143
|
|
|
144
|
+
if (!inputFormat) {
|
|
145
|
+
inputFormat = "YYYY-MM-DDTHH:mm:ss.SSSZ";
|
|
146
|
+
}
|
|
147
|
+
|
|
142
148
|
let parsedValue;
|
|
143
149
|
|
|
144
150
|
if (typeof value === "string") {
|
|
145
151
|
parsedValue = fecha.parse(value, inputFormat);
|
|
152
|
+
} else {
|
|
153
|
+
parsedValue = value;
|
|
146
154
|
}
|
|
147
155
|
|
|
148
156
|
return fecha.format(parsedValue, outputFormat);
|
|
@@ -150,21 +158,24 @@ class I18N {
|
|
|
150
158
|
/**
|
|
151
159
|
* Formats and outputs time.
|
|
152
160
|
* It will try to load format from currently selected locale's settings. If not defined, default formats will be used.
|
|
153
|
-
* @param value
|
|
154
|
-
* @param outputFormat
|
|
155
|
-
* @param inputFormat
|
|
156
161
|
*/
|
|
157
162
|
|
|
158
163
|
|
|
159
|
-
time(value, outputFormat
|
|
164
|
+
time(value, outputFormat, inputFormat) {
|
|
160
165
|
if (!outputFormat) {
|
|
161
166
|
outputFormat = this.getTimeFormat();
|
|
162
167
|
}
|
|
163
168
|
|
|
169
|
+
if (!inputFormat) {
|
|
170
|
+
inputFormat = "YYYY-MM-DDTHH:mm:ss.SSSZ";
|
|
171
|
+
}
|
|
172
|
+
|
|
164
173
|
let parsedValue;
|
|
165
174
|
|
|
166
175
|
if (typeof value === "string") {
|
|
167
176
|
parsedValue = fecha.parse(value, inputFormat);
|
|
177
|
+
} else {
|
|
178
|
+
parsedValue = value;
|
|
168
179
|
}
|
|
169
180
|
|
|
170
181
|
return fecha.format(parsedValue, outputFormat);
|
|
@@ -172,29 +183,30 @@ class I18N {
|
|
|
172
183
|
/**
|
|
173
184
|
* Formats and outputs date/time.
|
|
174
185
|
* It will try to load format from currently selected locale's settings. If not defined, default formats will be used.
|
|
175
|
-
* @param value
|
|
176
|
-
* @param outputFormat
|
|
177
|
-
* @param inputFormat
|
|
178
186
|
*/
|
|
179
187
|
|
|
180
188
|
|
|
181
|
-
dateTime(value, outputFormat
|
|
189
|
+
dateTime(value, outputFormat, inputFormat) {
|
|
182
190
|
if (!outputFormat) {
|
|
183
191
|
outputFormat = this.getDateTimeFormat();
|
|
184
192
|
}
|
|
185
193
|
|
|
194
|
+
if (!inputFormat) {
|
|
195
|
+
inputFormat = "YYYY-MM-DDTHH:mm:ss.SSSZ";
|
|
196
|
+
}
|
|
197
|
+
|
|
186
198
|
let parsedValue;
|
|
187
199
|
|
|
188
200
|
if (typeof value === "string") {
|
|
189
201
|
parsedValue = fecha.parse(value, inputFormat);
|
|
202
|
+
} else {
|
|
203
|
+
parsedValue = value;
|
|
190
204
|
}
|
|
191
205
|
|
|
192
206
|
return fecha.format(parsedValue, outputFormat);
|
|
193
207
|
}
|
|
194
208
|
/**
|
|
195
209
|
* Outputs formatted number as amount of price.
|
|
196
|
-
* @param value
|
|
197
|
-
* @param outputFormat
|
|
198
210
|
*/
|
|
199
211
|
|
|
200
212
|
|
|
@@ -202,7 +214,7 @@ class I18N {
|
|
|
202
214
|
if (!outputFormat) {
|
|
203
215
|
outputFormat = this.getPriceFormat();
|
|
204
216
|
} else {
|
|
205
|
-
outputFormat = (0,
|
|
217
|
+
outputFormat = (0, _assign.default)({}, this.defaultFormats.price, outputFormat);
|
|
206
218
|
} // Convert placeholders to accounting's placeholders.
|
|
207
219
|
|
|
208
220
|
|
|
@@ -213,8 +225,6 @@ class I18N {
|
|
|
213
225
|
}
|
|
214
226
|
/**
|
|
215
227
|
* Outputs formatted number.
|
|
216
|
-
* @param value
|
|
217
|
-
* @param outputFormat
|
|
218
228
|
*/
|
|
219
229
|
|
|
220
230
|
|
|
@@ -222,24 +232,29 @@ class I18N {
|
|
|
222
232
|
if (!outputFormat) {
|
|
223
233
|
outputFormat = this.getNumberFormat();
|
|
224
234
|
} else {
|
|
225
|
-
outputFormat = (0,
|
|
235
|
+
outputFormat = (0, _assign.default)({}, this.defaultFormats.number, outputFormat);
|
|
226
236
|
}
|
|
227
237
|
|
|
228
|
-
return _accounting.default.formatNumber(
|
|
238
|
+
return _accounting.default.formatNumber(
|
|
239
|
+
/**
|
|
240
|
+
* Cast as number because method transforms it internally.
|
|
241
|
+
*/
|
|
242
|
+
value, outputFormat.precision, outputFormat.thousand, outputFormat.decimal);
|
|
229
243
|
}
|
|
230
244
|
/**
|
|
231
245
|
* Returns translation for given text key.
|
|
232
|
-
* @param key
|
|
233
|
-
* @returns {*|string}
|
|
234
246
|
*/
|
|
235
247
|
|
|
236
248
|
|
|
237
249
|
getTranslation(key) {
|
|
250
|
+
if (!key) {
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
|
|
238
254
|
return this.translations[key];
|
|
239
255
|
}
|
|
240
256
|
/**
|
|
241
257
|
* Returns all translations for current locale.
|
|
242
|
-
* @returns {*|{}}
|
|
243
258
|
*/
|
|
244
259
|
|
|
245
260
|
|
|
@@ -248,7 +263,6 @@ class I18N {
|
|
|
248
263
|
}
|
|
249
264
|
/**
|
|
250
265
|
* Returns true if given key has a translation for currently set locale.
|
|
251
|
-
* @param key
|
|
252
266
|
*/
|
|
253
267
|
|
|
254
268
|
|
|
@@ -257,9 +271,6 @@ class I18N {
|
|
|
257
271
|
}
|
|
258
272
|
/**
|
|
259
273
|
* Sets translation for given text key.
|
|
260
|
-
* @param key
|
|
261
|
-
* @param translation
|
|
262
|
-
* @returns {I18N}
|
|
263
274
|
*/
|
|
264
275
|
|
|
265
276
|
|
|
@@ -269,7 +280,6 @@ class I18N {
|
|
|
269
280
|
}
|
|
270
281
|
/**
|
|
271
282
|
* Sets translations that will be used.
|
|
272
|
-
* @returns {*|{}}
|
|
273
283
|
*/
|
|
274
284
|
|
|
275
285
|
|
|
@@ -279,7 +289,6 @@ class I18N {
|
|
|
279
289
|
}
|
|
280
290
|
/**
|
|
281
291
|
* Clears all translations.
|
|
282
|
-
* @returns {*|{}}
|
|
283
292
|
*/
|
|
284
293
|
|
|
285
294
|
|
|
@@ -289,12 +298,11 @@ class I18N {
|
|
|
289
298
|
}
|
|
290
299
|
/**
|
|
291
300
|
* Merges given translations object with already existing.
|
|
292
|
-
* @returns {*|{}}
|
|
293
301
|
*/
|
|
294
302
|
|
|
295
303
|
|
|
296
304
|
mergeTranslations(translations) {
|
|
297
|
-
return (0,
|
|
305
|
+
return (0, _assign.default)(this.translations, translations);
|
|
298
306
|
}
|
|
299
307
|
/**
|
|
300
308
|
* Returns currently selected locale (locale's key).
|
|
@@ -315,7 +323,6 @@ class I18N {
|
|
|
315
323
|
}
|
|
316
324
|
/**
|
|
317
325
|
* Registers single modifier.
|
|
318
|
-
* @returns {I18N}
|
|
319
326
|
*/
|
|
320
327
|
|
|
321
328
|
|
|
@@ -325,8 +332,6 @@ class I18N {
|
|
|
325
332
|
}
|
|
326
333
|
/**
|
|
327
334
|
* Registers all modifiers in given array.
|
|
328
|
-
* @param modifiers
|
|
329
|
-
* @returns {I18N}
|
|
330
335
|
*/
|
|
331
336
|
|
|
332
337
|
|
|
@@ -336,8 +341,6 @@ class I18N {
|
|
|
336
341
|
}
|
|
337
342
|
/**
|
|
338
343
|
* Unregisters given modifier.
|
|
339
|
-
* @param name
|
|
340
|
-
* @returns {I18N}
|
|
341
344
|
*/
|
|
342
345
|
|
|
343
346
|
|
|
@@ -347,7 +350,6 @@ class I18N {
|
|
|
347
350
|
}
|
|
348
351
|
/**
|
|
349
352
|
* Registers single processor.
|
|
350
|
-
* @returns {I18N}
|
|
351
353
|
*/
|
|
352
354
|
|
|
353
355
|
|
|
@@ -357,8 +359,6 @@ class I18N {
|
|
|
357
359
|
}
|
|
358
360
|
/**
|
|
359
361
|
* Registers all processors in given array.
|
|
360
|
-
* @param processors
|
|
361
|
-
* @returns {I18N}
|
|
362
362
|
*/
|
|
363
363
|
|
|
364
364
|
|
|
@@ -368,8 +368,6 @@ class I18N {
|
|
|
368
368
|
}
|
|
369
369
|
/**
|
|
370
370
|
* Unregisters given processor.
|
|
371
|
-
* @param name
|
|
372
|
-
* @returns {I18N}
|
|
373
371
|
*/
|
|
374
372
|
|
|
375
373
|
|
|
@@ -379,7 +377,6 @@ class I18N {
|
|
|
379
377
|
}
|
|
380
378
|
/**
|
|
381
379
|
* Returns default formats
|
|
382
|
-
* @returns {{date: string, time: string, datetime: string, number: string}}
|
|
383
380
|
*/
|
|
384
381
|
|
|
385
382
|
|
|
@@ -408,7 +405,7 @@ class I18N {
|
|
|
408
405
|
|
|
409
406
|
|
|
410
407
|
getDateFormat() {
|
|
411
|
-
return (0,
|
|
408
|
+
return (0, _get.default)(this.locale, "formats.date", this.defaultFormats.date);
|
|
412
409
|
}
|
|
413
410
|
/**
|
|
414
411
|
* Returns current format to be used when outputting time.
|
|
@@ -416,7 +413,7 @@ class I18N {
|
|
|
416
413
|
|
|
417
414
|
|
|
418
415
|
getTimeFormat() {
|
|
419
|
-
return (0,
|
|
416
|
+
return (0, _get.default)(this.locale, "formats.time", this.defaultFormats.time);
|
|
420
417
|
}
|
|
421
418
|
/**
|
|
422
419
|
* Returns current format to be used when outputting date/time.
|
|
@@ -424,7 +421,7 @@ class I18N {
|
|
|
424
421
|
|
|
425
422
|
|
|
426
423
|
getDateTimeFormat() {
|
|
427
|
-
return (0,
|
|
424
|
+
return (0, _get.default)(this.locale, "formats.datetime", this.defaultFormats.datetime);
|
|
428
425
|
}
|
|
429
426
|
/**
|
|
430
427
|
* Returns current format to be used when outputting prices.
|
|
@@ -432,7 +429,7 @@ class I18N {
|
|
|
432
429
|
|
|
433
430
|
|
|
434
431
|
getPriceFormat() {
|
|
435
|
-
return (0,
|
|
432
|
+
return (0, _assign.default)({}, this.defaultFormats.price, (0, _get.default)(this.locale, "formats.price", {}));
|
|
436
433
|
}
|
|
437
434
|
/**
|
|
438
435
|
* Returns current format to be used when outputting numbers.
|
|
@@ -440,7 +437,7 @@ class I18N {
|
|
|
440
437
|
|
|
441
438
|
|
|
442
439
|
getNumberFormat() {
|
|
443
|
-
return (0,
|
|
440
|
+
return (0, _assign.default)({}, this.defaultFormats.number, (0, _get.default)(this.locale, "formats.number", {}));
|
|
444
441
|
}
|
|
445
442
|
|
|
446
443
|
}
|
package/I18n.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["I18n.ts"],"names":["I18N","constructor","defaultFormats","getDefaultFormats","translations","modifiers","processors","translate","base","namespace","Error","translation","getTranslation","hasVariables","includes","values","data","i18n","key","processor","canExecute","execute","ns","date","value","outputFormat","inputFormat","getDateFormat","parsedValue","fecha","parse","format","time","getTimeFormat","dateTime","getDateTimeFormat","price","getPriceFormat","replace","accounting","formatMoney","symbol","precision","thousand","decimal","number","getNumberFormat","formatNumber","getTranslations","hasTranslation","setTranslation","setTranslations","clearTranslations","mergeTranslations","getLocale","locale","setLocale","registerModifier","modifier","name","registerModifiers","forEach","unregisterModifier","registerProcessor","registerProcessors","unregisterProcessor","datetime"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAKA;;AACA;;AACA;;;;;;AANA;AACA;AACA;AACA;;AAsBA;AACA;AACA;AACe,MAAMA,IAAN,CAAW;AAWfC,EAAAA,WAAW,GAAG;AAAA,kDAVU,IAUV;AAAA;AAAA;AAAA;AAAA;;AACjB;AACR;AACA;AACA;AACQ,SAAKC,cAAL,GAAsB,KAAKC,iBAAL,EAAtB;AAEA;AACR;AACA;AACA;;AACQ,SAAKC,YAAL,GAAoB,EAApB;AAEA;AACR;AACA;AACA;;AACQ,SAAKC,SAAL,GAAiB,EAAjB;AAEA;AACR;AACA;AACA;AACA;;AACQ,SAAKC,UAAL,GAAkB,EAAlB;AACH;;AAEMC,EAAAA,SAAS,CAACC,IAAD,EAAeC,SAAf,EAA+C;AAC3D;AACA;AACA;AAEA,QAAI,CAACA,SAAL,EAAgB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AKH;;AA/YqB","sourcesContent":["import accounting from \"accounting\";\nimport * as fecha from \"fecha\";\n/**\n * Package short-hash has no types.\n */\n// @ts-ignore\nimport hash from \"short-hash\";\nimport lodashAssign from \"lodash/assign\";\nimport lodashGet from \"lodash/get\";\n\nimport {\n Formats,\n I18NData,\n I18NDataValues,\n Modifier,\n NumberFormat,\n PriceFormat,\n Processor,\n ProcessorResult,\n Translations,\n Translator\n} from \"./types\";\n\nexport type Translated =\n | ((values: I18NDataValues) => ProcessorResult | null)\n | ProcessorResult\n | null;\n/**\n * Main class used for all I18n needs.\n */\nexport default class I18N {\n public locale: string | null = null;\n public defaultFormats: Formats;\n public translations: Translations;\n public modifiers: {\n [name: string]: Modifier;\n };\n public processors: {\n [name: string]: Processor;\n };\n\n public constructor() {\n /**\n * If we fail to fetch formats for currently selected locale, these default formats will be used.\n * @type {{date: string, time: string, datetime: string, number: string}}\n */\n this.defaultFormats = this.getDefaultFormats();\n\n /**\n * All currently-loaded translations, for easier (synchronous) access.\n * @type {{}}\n */\n this.translations = {};\n\n /**\n * All registered modifiers.\n * @type {{}}\n */\n this.modifiers = {};\n\n /**\n * All registered processors.\n * Default built-in processors are registered immediately below.\n * @type {{}}\n */\n this.processors = {};\n }\n\n public translate(base: string, namespace?: string): Translated {\n // Returns full translation for given base text in given namespace (optional).\n // If translation isn't found, base text will be returned.\n // We create a key out of given namespace and base text.\n\n if (!namespace) {\n throw Error(\"I18N text namespace not defined.\");\n }\n\n base = lodashGet(base, \"raw.0\", base);\n\n let translation: string | null = this.getTranslation(namespace + \".\" + hash(base));\n\n if (!translation) {\n translation = base;\n }\n\n const hasVariables = base.includes(\"{\") && base.includes(\"}\");\n if (hasVariables) {\n return (values: I18NDataValues) => {\n const data: I18NData = {\n translation: translation as string,\n base,\n namespace,\n values,\n i18n: this\n };\n for (const key in this.processors) {\n const processor = this.processors[key];\n if (processor.canExecute(data)) {\n return processor.execute(data);\n }\n }\n return null;\n };\n }\n\n const data: I18NData = { translation, base, namespace, values: {}, i18n: this };\n for (const key in this.processors) {\n if (this.processors[key].canExecute(data)) {\n return this.processors[key].execute(data);\n }\n }\n return null;\n }\n\n public namespace(namespace: string): Translator {\n return base => {\n return this.translate(base as string, namespace);\n };\n }\n\n public ns(namespace: string): Translator {\n return this.namespace(namespace);\n }\n\n /**\n * Formats and outputs date.\n * It will try to load format from currently selected locale's settings. If not defined, default formats will be used.\n */\n public date(\n value: Date | string | number,\n outputFormat?: string,\n inputFormat?: string\n ): string {\n if (!outputFormat) {\n outputFormat = this.getDateFormat();\n }\n if (!inputFormat) {\n inputFormat = \"YYYY-MM-DDTHH:mm:ss.SSSZ\";\n }\n\n let parsedValue: number | Date;\n\n if (typeof value === \"string\") {\n parsedValue = fecha.parse(value, inputFormat) as Date;\n } else {\n parsedValue = value;\n }\n\n return fecha.format(parsedValue, outputFormat);\n }\n\n /**\n * Formats and outputs time.\n * It will try to load format from currently selected locale's settings. If not defined, default formats will be used.\n */\n public time(\n value: Date | string | number,\n outputFormat?: string,\n inputFormat?: string\n ): string {\n if (!outputFormat) {\n outputFormat = this.getTimeFormat();\n }\n if (!inputFormat) {\n inputFormat = \"YYYY-MM-DDTHH:mm:ss.SSSZ\";\n }\n\n let parsedValue: number | Date;\n\n if (typeof value === \"string\") {\n parsedValue = fecha.parse(value, inputFormat) as Date;\n } else {\n parsedValue = value;\n }\n\n return fecha.format(parsedValue, outputFormat);\n }\n\n /**\n * Formats and outputs date/time.\n * It will try to load format from currently selected locale's settings. If not defined, default formats will be used.\n */\n dateTime(value: Date | string | number, outputFormat?: string, inputFormat?: string): string {\n if (!outputFormat) {\n outputFormat = this.getDateTimeFormat();\n }\n if (!inputFormat) {\n inputFormat = \"YYYY-MM-DDTHH:mm:ss.SSSZ\";\n }\n\n let parsedValue: number | Date;\n\n if (typeof value === \"string\") {\n parsedValue = fecha.parse(value, inputFormat) as Date;\n } else {\n parsedValue = value;\n }\n\n return fecha.format(parsedValue, outputFormat);\n }\n\n /**\n * Outputs formatted number as amount of price.\n */\n public price(value: string | number, outputFormat?: any): string {\n if (!outputFormat) {\n outputFormat = this.getPriceFormat();\n } else {\n outputFormat = lodashAssign({}, this.defaultFormats.price, outputFormat);\n }\n\n // Convert placeholders to accounting's placeholders.\n let format = outputFormat.format;\n format = format.replace(\"{symbol}\", \"%s\");\n format = format.replace(\"{amount}\", \"%v\");\n\n return accounting.formatMoney(\n value,\n outputFormat.symbol,\n outputFormat.precision,\n outputFormat.thousand,\n outputFormat.decimal,\n format\n );\n }\n\n /**\n * Outputs formatted number.\n */\n public number(value: string | number, outputFormat?: NumberFormat): string {\n if (!outputFormat) {\n outputFormat = this.getNumberFormat();\n } else {\n outputFormat = lodashAssign({}, this.defaultFormats.number, outputFormat);\n }\n return accounting.formatNumber(\n /**\n * Cast as number because method transforms it internally.\n */\n value as number,\n outputFormat.precision,\n outputFormat.thousand,\n outputFormat.decimal\n );\n }\n\n /**\n * Returns translation for given text key.\n */\n public getTranslation(key?: string): string | null {\n if (!key) {\n return null;\n }\n return this.translations[key];\n }\n\n /**\n * Returns all translations for current locale.\n */\n public getTranslations(): Translations {\n return this.translations;\n }\n\n /**\n * Returns true if given key has a translation for currently set locale.\n */\n public hasTranslation(key: string): boolean {\n return key in this.translations;\n }\n\n /**\n * Sets translation for given text key.\n */\n public setTranslation(key: string, translation: string): I18N {\n this.translations[key] = translation;\n return this;\n }\n\n /**\n * Sets translations that will be used.\n */\n public setTranslations(translations: Translations): I18N {\n this.translations = translations;\n return this;\n }\n\n /**\n * Clears all translations.\n */\n public clearTranslations(): I18N {\n this.setTranslations({});\n return this;\n }\n\n /**\n * Merges given translations object with already existing.\n */\n\n public mergeTranslations(translations: Translations): Translations {\n return lodashAssign(this.translations, translations);\n }\n\n /**\n * Returns currently selected locale (locale's key).\n */\n public getLocale(): null | string {\n return this.locale;\n }\n\n /**\n * Sets current locale.\n */\n public setLocale(locale: string): I18N {\n this.locale = locale;\n return this;\n }\n\n /**\n * Registers single modifier.\n */\n public registerModifier(modifier: Modifier): I18N {\n this.modifiers[modifier.name] = modifier;\n return this;\n }\n\n /**\n * Registers all modifiers in given array.\n */\n public registerModifiers(modifiers: Array<Modifier>): I18N {\n modifiers.forEach(modifier => this.registerModifier(modifier));\n return this;\n }\n\n /**\n * Unregisters given modifier.\n */\n public unregisterModifier(name: string): I18N {\n delete this.modifiers[name];\n return this;\n }\n\n /**\n * Registers single processor.\n */\n public registerProcessor(processor: Processor): I18N {\n this.processors[processor.name] = processor;\n return this;\n }\n\n /**\n * Registers all processors in given array.\n */\n public registerProcessors(processors: Array<Processor>): I18N {\n processors.forEach(processor => this.registerProcessor(processor));\n return this;\n }\n\n /**\n * Unregisters given processor.\n */\n public unregisterProcessor(name: string): I18N {\n delete this.processors[name];\n return this;\n }\n\n /**\n * Returns default formats\n */\n public getDefaultFormats(): Formats {\n return {\n date: \"DD/MM/YYYY\",\n time: \"HH:mm\",\n datetime: \"DD/MM/YYYY HH:mm\",\n price: {\n symbol: \"\",\n format: \"{symbol}{amount}\",\n decimal: \".\",\n thousand: \",\",\n precision: 2\n },\n number: {\n decimal: \".\",\n thousand: \",\",\n precision: 2\n }\n };\n }\n\n /**\n * Returns current format to be used when outputting dates.\n */\n public getDateFormat(): string {\n return lodashGet(this.locale, \"formats.date\", this.defaultFormats.date);\n }\n\n /**\n * Returns current format to be used when outputting time.\n */\n public getTimeFormat(): string {\n return lodashGet(this.locale, \"formats.time\", this.defaultFormats.time);\n }\n\n /**\n * Returns current format to be used when outputting date/time.\n */\n public getDateTimeFormat(): string {\n return lodashGet(this.locale, \"formats.datetime\", this.defaultFormats.datetime);\n }\n\n /**\n * Returns current format to be used when outputting prices.\n */\n public getPriceFormat(): PriceFormat {\n return lodashAssign(\n {},\n this.defaultFormats.price,\n lodashGet(this.locale, \"formats.price\", {})\n );\n }\n\n /**\n * Returns current format to be used when outputting numbers.\n */\n public getNumberFormat(): NumberFormat {\n return lodashAssign(\n {},\n this.defaultFormats.number,\n lodashGet(this.locale, \"formats.number\", {})\n );\n }\n}\n"]}
|
package/extractor/extract.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: (source: string) =>
|
|
1
|
+
declare const _default: (source: string) => Record<string, string>;
|
|
2
2
|
export default _default;
|
package/extractor/extract.js
CHANGED
|
@@ -9,6 +9,11 @@ exports.default = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _shortHash = _interopRequireDefault(require("short-hash"));
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Package short-hash has no types.
|
|
14
|
+
*/
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
|
|
12
17
|
/**
|
|
13
18
|
* Searches for all declared namespaces.
|
|
14
19
|
* Result contains an object with identifiers as keys, and namespaces they represent as values, for example:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["extract.ts"],"names":["getNamespaces","source","regex","m","results","exec","index","lastIndex","allDeclaredNamespaces","variable","RegExp","matchedText","key"],"mappings":";;;;;;;;;AAIA;;AAJA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,aAAa,GAAIC,MAAD,IAAoB;AACtC,QAAMC,KAAK,GAAG,qEAAd;AACA,MAAIC,CAAJ;AAEA,QAAMC,OAA+B,GAAG,EAAxC;;AAEA,SAAO,CAACD,CAAC,GAAGD,KAAK,CAACG,IAAN,CAAWJ,MAAX,CAAL,MAA6B,IAApC,EAA0C;AACtC,QAAIE,CAAC,CAACG,KAAF,KAAYJ,KAAK,CAACK,SAAtB,EAAiC;AAC7BL,MAAAA,KAAK,CAACK,SAAN;AACH;;AAEDH,IAAAA,OAAO,CAACD,CAAC,CAAC,CAAD,CAAF,CAAP,GAAgBA,CAAC,CAAC,CAAD,CAAjB;AACH;;AAED,SAAOC,OAAP;AACH,CAfD;;eAiBgBH,MAAD,IAAoB;AAC/B,QAAMG,OAA+B,GAAG,EAAxC;AACA,QAAMI,qBAAqB,GAAGR,aAAa,CAACC,MAAD,CAA3C;;AAEA,OAAK,MAAMQ,QAAX,IAAuBD,qBAAvB,EAA8C;AAC1C,UAAMN,KAAK,GAAG,IAAIQ,MAAJ,CAAWD,QAAQ,GAAG,SAAtB,EAAiC,GAAjC,CAAd;AAEA,QAAIN,CAAJ;;AACA,WAAO,CAACA,CAAC,GAAGD,KAAK,CAACG,IAAN,CAAWJ,MAAX,CAAL,MAA6B,IAApC,EAA0C;AACtC,UAAIE,CAAC,CAACG,KAAF,KAAYJ,KAAK,CAACK,SAAtB,EAAiC;AAC7BL,QAAAA,KAAK,CAACK,SAAN;AACH,OAHqC,CAKtC;;;AACA,YAAMI,WAAW,GAAGR,CAAC,CAAC,CAAD,CAArB;AACA,YAAMS,GAAG,GAAGJ,qBAAqB,CAACC,QAAD,CAArB,GAAkC,GAAlC,GAAwC,wBAAKE,WAAL,CAApD;AACAP,MAAAA,OAAO,CAACQ,GAAD,CAAP,GAAeD,WAAf;AACH;AACJ;;AAED,SAAOP,OAAP;AACH,C","sourcesContent":["/**\n * Package short-hash has no types.\n */\n// @ts-ignore\nimport hash from \"short-hash\";\n\n/**\n * Searches for all declared namespaces.\n * Result contains an object with identifiers as keys, and namespaces they represent as values, for example:\n * {ns1: 'Webiny.Ns1', ns2: 'Webiny.Ns2', i18n: 'NewNamespace', t: 'Some.Other.Namespace'}\n * @param source\n */\nconst getNamespaces = (source: string) => {\n const regex = /([a-zA-Z0-9]+)[ ]+=[ ]+i18n.namespace\\(['\"`]([a-zA-Z0-9.]+)['\"`]\\)/g;\n let m;\n\n const results: Record<string, string> = {};\n\n while ((m = regex.exec(source)) !== null) {\n if (m.index === regex.lastIndex) {\n regex.lastIndex++;\n }\n\n results[m[1]] = m[2];\n }\n\n return results;\n};\n\nexport default (source: string) => {\n const results: Record<string, string> = {};\n const allDeclaredNamespaces = getNamespaces(source);\n\n for (const variable in allDeclaredNamespaces) {\n const regex = new RegExp(variable + \"`(.*?)`\", \"g\");\n\n let m;\n while ((m = regex.exec(source)) !== null) {\n if (m.index === regex.lastIndex) {\n regex.lastIndex++;\n }\n\n // This is the key - namespace + hash of matched label.\n const matchedText = m[1];\n const key = allDeclaredNamespaces[variable] + \".\" + hash(matchedText);\n results[key] = matchedText;\n }\n }\n\n return results;\n};\n"]}
|
package/extractor/index.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
export interface ExtractorResults {
|
|
2
|
+
[key: string]: string;
|
|
3
|
+
}
|
|
1
4
|
declare class Extractor {
|
|
2
|
-
glob
|
|
5
|
+
private glob;
|
|
3
6
|
content: string;
|
|
4
7
|
listOnly: boolean;
|
|
5
|
-
setGlob(
|
|
8
|
+
setGlob(value: string): Extractor;
|
|
6
9
|
setContent(content: string): Extractor;
|
|
7
|
-
execute():
|
|
10
|
+
execute(): ExtractorResults;
|
|
8
11
|
setListOnly(flag?: boolean): Extractor;
|
|
9
12
|
}
|
|
10
13
|
export default Extractor;
|
package/extractor/index.js
CHANGED
|
@@ -18,12 +18,12 @@ var _fs = _interopRequireDefault(require("fs"));
|
|
|
18
18
|
class Extractor {
|
|
19
19
|
constructor() {
|
|
20
20
|
(0, _defineProperty2.default)(this, "glob", void 0);
|
|
21
|
-
(0, _defineProperty2.default)(this, "content",
|
|
22
|
-
(0, _defineProperty2.default)(this, "listOnly",
|
|
21
|
+
(0, _defineProperty2.default)(this, "content", "");
|
|
22
|
+
(0, _defineProperty2.default)(this, "listOnly", false);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
setGlob(
|
|
26
|
-
this.glob =
|
|
25
|
+
setGlob(value) {
|
|
26
|
+
this.glob = value;
|
|
27
27
|
return this;
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -35,20 +35,21 @@ class Extractor {
|
|
|
35
35
|
execute() {
|
|
36
36
|
const results = {};
|
|
37
37
|
|
|
38
|
-
if (this.glob) {
|
|
39
|
-
|
|
38
|
+
if (!this.glob) {
|
|
39
|
+
return results;
|
|
40
|
+
}
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
const contents = _fs.default.readFileSync(path, "utf8");
|
|
42
|
+
const paths = _glob.default.sync(this.glob);
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
paths.forEach(path => {
|
|
45
|
+
const contents = _fs.default.readFileSync(path, "utf8");
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
results[key] = parsed[key];
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
47
|
+
const parsed = (0, _extract.default)(contents);
|
|
51
48
|
|
|
49
|
+
for (const key in parsed) {
|
|
50
|
+
results[key] = parsed[key];
|
|
51
|
+
}
|
|
52
|
+
});
|
|
52
53
|
return results;
|
|
53
54
|
}
|
|
54
55
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["Extractor","setGlob","value","glob","setContent","content","execute","results","paths","sync","forEach","path","contents","fs","readFileSync","parsed","key","setListOnly","flag","listOnly"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AAKA,MAAMA,SAAN,CAAgB;AAAA;AAAA;AAAA,mDAEK,EAFL;AAAA,oDAGM,KAHN;AAAA;;AAKLC,EAAAA,OAAO,CAACC,KAAD,EAA2B;AACrC,SAAKC,IAAL,GAAYD,KAAZ;AACA,WAAO,IAAP;AACH;;AAEME,EAAAA,UAAU,CAACC,OAAD,EAA6B;AAC1C,SAAKA,OAAL,GAAeA,OAAf;AACA,WAAO,IAAP;AACH;;AAEMC,EAAAA,OAAO,GAAqB;AAC/B,UAAMC,OAAyB,GAAG,EAAlC;;AAEA,QAAI,CAAC,KAAKJ,IAAV,EAAgB;AACZ,aAAOI,OAAP;AACH;;AACD,UAAMC,KAAK,GAAGL,cAAKM,IAAL,CAAU,KAAKN,IAAf,CAAd;;AACAK,IAAAA,KAAK,CAACE,OAAN,CAAcC,IAAI,IAAI;AAClB,YAAMC,QAAQ,GAAGC,YAAGC,YAAH,CAAgBH,IAAhB,EAAsB,MAAtB,CAAjB;;AACA,YAAMI,MAAM,GAAG,sBAAQH,QAAR,CAAf;;AACA,WAAK,MAAMI,GAAX,IAAkBD,MAAlB,EAA0B;AACtBR,QAAAA,OAAO,CAACS,GAAD,CAAP,GAAeD,MAAM,CAACC,GAAD,CAArB;AACH;AACJ,KAND;AAQA,WAAOT,OAAP;AACH;;AAEMU,EAAAA,WAAW,CAACC,IAAI,GAAG,IAAR,EAAyB;AACvC,SAAKC,QAAL,GAAgBD,IAAhB;AACA,WAAO,IAAP;AACH;;AApCW;;eAuCDlB,S","sourcesContent":["import extract from \"./extract\";\nimport glob from \"glob\";\nimport fs from \"fs\";\n\nexport interface ExtractorResults {\n [key: string]: string;\n}\nclass Extractor {\n private glob: string | undefined;\n public content = \"\";\n public listOnly = false;\n\n public setGlob(value: string): Extractor {\n this.glob = value;\n return this;\n }\n\n public setContent(content: string): Extractor {\n this.content = content;\n return this;\n }\n\n public execute(): ExtractorResults {\n const results: ExtractorResults = {};\n\n if (!this.glob) {\n return results;\n }\n const paths = glob.sync(this.glob);\n paths.forEach(path => {\n const contents = fs.readFileSync(path, \"utf8\");\n const parsed = extract(contents);\n for (const key in parsed) {\n results[key] = parsed[key];\n }\n });\n\n return results;\n }\n\n public setListOnly(flag = true): Extractor {\n this.listOnly = flag;\n return this;\n }\n}\n\nexport default Extractor;\n"]}
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["i18n","I18n","defaultModifiers"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA,MAAMA,IAAI,GAAG,IAAIC,aAAJ,EAAb;AAEA,MAAMC,gBAAgB,GAAG,wBAAiB;AAAEF,EAAAA;AAAF,CAAjB,CAAzB;;eAEeA,I","sourcesContent":["import I18n from \"./I18n\";\nimport defaultProcessor from \"./processors/default\";\nimport modifiersFactory from \"./modifiers\";\n\nconst i18n = new I18n();\n\nconst defaultModifiers = modifiersFactory({ i18n });\n\nexport default i18n;\n\nexport { I18n, defaultModifiers, defaultProcessor };\n"]}
|
|
@@ -4,36 +4,40 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _default = {
|
|
8
|
-
name: "count",
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const current = parameters[i];
|
|
8
|
+
var _default = () => {
|
|
9
|
+
return {
|
|
10
|
+
name: "count",
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
execute(value, parameters) {
|
|
13
|
+
// Numbers can be single number or ranges.
|
|
14
|
+
for (let i = 0; i < parameters.length; i = i + 2) {
|
|
15
|
+
const current = parameters[i];
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (numbers.length === 2) {
|
|
22
|
-
if (value >= numbers[0] && value <= numbers[1]) {
|
|
17
|
+
if (current === "default") {
|
|
23
18
|
return value + " " + parameters[i + 1];
|
|
24
19
|
}
|
|
25
20
|
|
|
26
|
-
|
|
27
|
-
}
|
|
21
|
+
const numbers = current.split("-"); // If we are dealing with a numbers range, then let's check if we are in it.
|
|
28
22
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
if (numbers.length === 2) {
|
|
24
|
+
if (value >= numbers[0] && value <= numbers[1]) {
|
|
25
|
+
return value + " " + parameters[i + 1];
|
|
26
|
+
}
|
|
33
27
|
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
34
30
|
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
if (String(value) === numbers[0]) {
|
|
32
|
+
return value + " " + parameters[i + 1];
|
|
33
|
+
}
|
|
34
|
+
} // If we didn't match any condition, let's just remove the received value.
|
|
37
35
|
|
|
36
|
+
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
};
|
|
38
41
|
};
|
|
42
|
+
|
|
39
43
|
exports.default = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["countModifier.ts"],"names":["name","execute","value","parameters","i","length","current","numbers","split","String"],"mappings":";;;;;;;eAEe,MAAgB;AAC3B,SAAO;AACHA,IAAAA,IAAI,EAAE,OADH;;AAEHC,IAAAA,OAAO,CAACC,KAAD,EAAgBC,UAAhB,EAA2C;AAC9C;AACA,WAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGD,UAAU,CAACE,MAA/B,EAAuCD,CAAC,GAAGA,CAAC,GAAG,CAA/C,EAAkD;AAC9C,cAAME,OAAO,GAAGH,UAAU,CAACC,CAAD,CAA1B;;AACA,YAAIE,OAAO,KAAK,SAAhB,EAA2B;AACvB,iBAAOJ,KAAK,GAAG,GAAR,GAAcC,UAAU,CAACC,CAAC,GAAG,CAAL,CAA/B;AACH;;AAED,cAAMG,OAAO,GAAGD,OAAO,CAACE,KAAR,CAAc,GAAd,CAAhB,CAN8C,CAQ9C;;AACA,YAAID,OAAO,CAACF,MAAR,KAAmB,CAAvB,EAA0B;AACtB,cAAIH,KAAK,IAAIK,OAAO,CAAC,CAAD,CAAhB,IAAuBL,KAAK,IAAIK,OAAO,CAAC,CAAD,CAA3C,EAAgD;AAC5C,mBAAOL,KAAK,GAAG,GAAR,GAAcC,UAAU,CAACC,CAAC,GAAG,CAAL,CAA/B;AACH;;AACD;AACH;;AAED,YAAIK,MAAM,CAACP,KAAD,CAAN,KAAkBK,OAAO,CAAC,CAAD,CAA7B,EAAkC;AAC9B,iBAAOL,KAAK,GAAG,GAAR,GAAcC,UAAU,CAACC,CAAC,GAAG,CAAL,CAA/B;AACH;AACJ,OArB6C,CAuB9C;;;AACA,aAAOF,KAAP;AACH;;AA3BE,GAAP;AA6BH,C","sourcesContent":["import { Modifier } from \"~/types\";\n\nexport default (): Modifier => {\n return {\n name: \"count\",\n execute(value: string, parameters: Array<string>) {\n // Numbers can be single number or ranges.\n for (let i = 0; i < parameters.length; i = i + 2) {\n const current = parameters[i];\n if (current === \"default\") {\n return value + \" \" + parameters[i + 1];\n }\n\n const numbers = current.split(\"-\");\n\n // If we are dealing with a numbers range, then let's check if we are in it.\n if (numbers.length === 2) {\n if (value >= numbers[0] && value <= numbers[1]) {\n return value + \" \" + parameters[i + 1];\n }\n continue;\n }\n\n if (String(value) === numbers[0]) {\n return value + \" \" + parameters[i + 1];\n }\n }\n\n // If we didn't match any condition, let's just remove the received value.\n return value;\n }\n };\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["dateModifier.ts"],"names":["i18n","name","execute","value","date"],"mappings":";;;;;;;eAEe,CAAC;AAAEA,EAAAA;AAAF,CAAD,MAA0C;AACrDC,EAAAA,IAAI,EAAE,MAD+C;;AAErDC,EAAAA,OAAO,CAACC,KAAD,EAAQ;AACX,WAAOH,IAAI,CAACI,IAAL,CAAUD,KAAV,CAAP;AACH;;AAJoD,CAA1C,C","sourcesContent":["import { Modifier, ModifierOptions } from \"~/types\";\n\nexport default ({ i18n }: ModifierOptions): Modifier => ({\n name: \"date\",\n execute(value) {\n return i18n.date(value);\n }\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["dateTimeModifier.ts"],"names":["i18n","name","execute","value","dateTime"],"mappings":";;;;;;;eAEe,CAAC;AAAEA,EAAAA;AAAF,CAAD,MAA0C;AACrDC,EAAAA,IAAI,EAAE,UAD+C;;AAErDC,EAAAA,OAAO,CAACC,KAAD,EAAgB;AACnB,WAAOH,IAAI,CAACI,QAAL,CAAcD,KAAd,CAAP;AACH;;AAJoD,CAA1C,C","sourcesContent":["import { Modifier, ModifierOptions } from \"~/types\";\n\nexport default ({ i18n }: ModifierOptions): Modifier => ({\n name: \"dateTime\",\n execute(value: string) {\n return i18n.dateTime(value);\n }\n});\n"]}
|
|
@@ -4,12 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _default = {
|
|
8
|
-
name: "gender",
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
var _default = () => {
|
|
9
|
+
return {
|
|
10
|
+
name: "gender",
|
|
13
11
|
|
|
12
|
+
execute(value, parameters) {
|
|
13
|
+
return value === "male" ? parameters[0] : parameters[1];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
};
|
|
14
17
|
};
|
|
18
|
+
|
|
15
19
|
exports.default = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["genderModifier.ts"],"names":["name","execute","value","parameters"],"mappings":";;;;;;;eAEe,MAAgB;AAC3B,SAAO;AACHA,IAAAA,IAAI,EAAE,QADH;;AAEHC,IAAAA,OAAO,CAACC,KAAD,EAAgBC,UAAhB,EAA2C;AAC9C,aAAOD,KAAK,KAAK,MAAV,GAAmBC,UAAU,CAAC,CAAD,CAA7B,GAAmCA,UAAU,CAAC,CAAD,CAApD;AACH;;AAJE,GAAP;AAMH,C","sourcesContent":["import { Modifier } from \"~/types\";\n\nexport default (): Modifier => {\n return {\n name: \"gender\",\n execute(value: string, parameters: Array<string>) {\n return value === \"male\" ? parameters[0] : parameters[1];\n }\n };\n};\n"]}
|
package/modifiers/ifModifier.js
CHANGED
|
@@ -4,12 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _default = {
|
|
8
|
-
name: "if",
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
var _default = () => {
|
|
9
|
+
return {
|
|
10
|
+
name: "if",
|
|
13
11
|
|
|
12
|
+
execute(value, parameters) {
|
|
13
|
+
return value === parameters[0] ? parameters[1] : parameters[2] || "";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
};
|
|
14
17
|
};
|
|
18
|
+
|
|
15
19
|
exports.default = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["ifModifier.ts"],"names":["name","execute","value","parameters"],"mappings":";;;;;;;eAEe,MAAgB;AAC3B,SAAO;AACHA,IAAAA,IAAI,EAAE,IADH;;AAEHC,IAAAA,OAAO,CAACC,KAAD,EAAgBC,UAAhB,EAA2C;AAC9C,aAAOD,KAAK,KAAKC,UAAU,CAAC,CAAD,CAApB,GAA0BA,UAAU,CAAC,CAAD,CAApC,GAA0CA,UAAU,CAAC,CAAD,CAAV,IAAiB,EAAlE;AACH;;AAJE,GAAP;AAMH,C","sourcesContent":["import { Modifier } from \"~/types\";\n\nexport default (): Modifier => {\n return {\n name: \"if\",\n execute(value: string, parameters: Array<string>) {\n return value === parameters[0] ? parameters[1] : parameters[2] || \"\";\n }\n };\n};\n"]}
|
package/modifiers/index.d.ts
CHANGED
package/modifiers/index.js
CHANGED
|
@@ -26,6 +26,6 @@ var _numberModifier = _interopRequireDefault(require("./numberModifier"));
|
|
|
26
26
|
var _priceModifier = _interopRequireDefault(require("./priceModifier"));
|
|
27
27
|
|
|
28
28
|
// Built-in modifiers
|
|
29
|
-
var _default = options => [_countModifier.default, _genderModifier.default, _ifModifier.default, _pluralModifier.default, (0, _dateModifier.default)(options), (0, _dateTimeModifier.default)(options), (0, _timeModifier.default)(options), (0, _numberModifier.default)(options), (0, _priceModifier.default)(options)];
|
|
29
|
+
var _default = options => [(0, _countModifier.default)(), (0, _genderModifier.default)(), (0, _ifModifier.default)(), (0, _pluralModifier.default)(), (0, _dateModifier.default)(options), (0, _dateTimeModifier.default)(options), (0, _timeModifier.default)(options), (0, _numberModifier.default)(options), (0, _priceModifier.default)(options)];
|
|
30
30
|
|
|
31
31
|
exports.default = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["options"],"mappings":";;;;;;;;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AATA;eAYgBA,OAAD,IAA0C,CACrD,6BADqD,EAErD,8BAFqD,EAGrD,0BAHqD,EAIrD,8BAJqD,EAKrD,2BAAaA,OAAb,CALqD,EAMrD,+BAAiBA,OAAjB,CANqD,EAOrD,2BAAaA,OAAb,CAPqD,EAQrD,6BAAeA,OAAf,CARqD,EASrD,4BAAcA,OAAd,CATqD,C","sourcesContent":["// Built-in modifiers\nimport countModifiers from \"./countModifier\";\nimport genderModifier from \"./genderModifier\";\nimport ifModifier from \"./ifModifier\";\nimport pluralModifier from \"./pluralModifier\";\nimport dateModifier from \"./dateModifier\";\nimport dateTimeModifier from \"./dateTimeModifier\";\nimport timeModifier from \"./timeModifier\";\nimport numberModifier from \"./numberModifier\";\nimport priceModifier from \"./priceModifier\";\nimport { Modifier, ModifierOptions } from \"~/types\";\n\nexport default (options: ModifierOptions): Modifier[] => [\n countModifiers(),\n genderModifier(),\n ifModifier(),\n pluralModifier(),\n dateModifier(options),\n dateTimeModifier(options),\n timeModifier(options),\n numberModifier(options),\n priceModifier(options)\n];\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["numberModifier.ts"],"names":["i18n","name","execute","value","number"],"mappings":";;;;;;;eAEe,CAAC;AAAEA,EAAAA;AAAF,CAAD,MAA0C;AACrDC,EAAAA,IAAI,EAAE,QAD+C;;AAErDC,EAAAA,OAAO,CAACC,KAAD,EAAgB;AACnB,WAAOH,IAAI,CAACI,MAAL,CAAYD,KAAZ,CAAP;AACH;;AAJoD,CAA1C,C","sourcesContent":["import { Modifier, ModifierOptions } from \"~/types\";\n\nexport default ({ i18n }: ModifierOptions): Modifier => ({\n name: \"number\",\n execute(value: string) {\n return i18n.number(value);\n }\n});\n"]}
|
|
@@ -4,35 +4,39 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _default = {
|
|
8
|
-
name: "plural",
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const current = parameters[i];
|
|
8
|
+
var _default = () => {
|
|
9
|
+
return {
|
|
10
|
+
name: "plural",
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const numbers = current.split("-"); // If we are dealing with a numbers range, then let's check if we are in it.
|
|
12
|
+
execute(value, parameters) {
|
|
13
|
+
// Numbers can be single number or ranges.
|
|
14
|
+
for (let i = 0; i < parameters.length; i = i + 2) {
|
|
15
|
+
const current = parameters[i];
|
|
20
16
|
|
|
21
|
-
|
|
22
|
-
if (value >= numbers[0] && value <= numbers[1]) {
|
|
17
|
+
if (current === "default") {
|
|
23
18
|
return parameters[i + 1];
|
|
24
19
|
}
|
|
25
20
|
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
const numbers = current.split("-"); // If we are dealing with a numbers range, then let's check if we are in it.
|
|
22
|
+
|
|
23
|
+
if (numbers.length === 2) {
|
|
24
|
+
if (value >= numbers[0] && value <= numbers[1]) {
|
|
25
|
+
return parameters[i + 1];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
if (String(value) === numbers[0]) {
|
|
32
|
+
return parameters[i + 1];
|
|
33
|
+
}
|
|
31
34
|
}
|
|
32
|
-
}
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
return "";
|
|
37
|
+
}
|
|
36
38
|
|
|
39
|
+
};
|
|
37
40
|
};
|
|
41
|
+
|
|
38
42
|
exports.default = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["pluralModifier.ts"],"names":["name","execute","value","parameters","i","length","current","numbers","split","String"],"mappings":";;;;;;;eAEe,MAAgB;AAC3B,SAAO;AACHA,IAAAA,IAAI,EAAE,QADH;;AAEHC,IAAAA,OAAO,CAACC,KAAD,EAAgBC,UAAhB,EAA2C;AAC9C;AACA,WAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGD,UAAU,CAACE,MAA/B,EAAuCD,CAAC,GAAGA,CAAC,GAAG,CAA/C,EAAkD;AAC9C,cAAME,OAAO,GAAGH,UAAU,CAACC,CAAD,CAA1B;;AACA,YAAIE,OAAO,KAAK,SAAhB,EAA2B;AACvB,iBAAOH,UAAU,CAACC,CAAC,GAAG,CAAL,CAAjB;AACH;;AAED,cAAMG,OAAO,GAAGD,OAAO,CAACE,KAAR,CAAc,GAAd,CAAhB,CAN8C,CAQ9C;;AACA,YAAID,OAAO,CAACF,MAAR,KAAmB,CAAvB,EAA0B;AACtB,cAAIH,KAAK,IAAIK,OAAO,CAAC,CAAD,CAAhB,IAAuBL,KAAK,IAAIK,OAAO,CAAC,CAAD,CAA3C,EAAgD;AAC5C,mBAAOJ,UAAU,CAACC,CAAC,GAAG,CAAL,CAAjB;AACH;;AACD;AACH;;AAED,YAAIK,MAAM,CAACP,KAAD,CAAN,KAAkBK,OAAO,CAAC,CAAD,CAA7B,EAAkC;AAC9B,iBAAOJ,UAAU,CAACC,CAAC,GAAG,CAAL,CAAjB;AACH;AACJ;;AAED,aAAO,EAAP;AACH;;AA1BE,GAAP;AA4BH,C","sourcesContent":["import { Modifier } from \"~/types\";\n\nexport default (): Modifier => {\n return {\n name: \"plural\",\n execute(value: string, parameters: Array<string>) {\n // Numbers can be single number or ranges.\n for (let i = 0; i < parameters.length; i = i + 2) {\n const current = parameters[i];\n if (current === \"default\") {\n return parameters[i + 1];\n }\n\n const numbers = current.split(\"-\");\n\n // If we are dealing with a numbers range, then let's check if we are in it.\n if (numbers.length === 2) {\n if (value >= numbers[0] && value <= numbers[1]) {\n return parameters[i + 1];\n }\n continue;\n }\n\n if (String(value) === numbers[0]) {\n return parameters[i + 1];\n }\n }\n\n return \"\";\n }\n };\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["priceModifier.ts"],"names":["i18n","name","execute","value","price"],"mappings":";;;;;;;eAEe,CAAC;AAAEA,EAAAA;AAAF,CAAD,MAA0C;AACrDC,EAAAA,IAAI,EAAE,OAD+C;;AAErDC,EAAAA,OAAO,CAACC,KAAD,EAAgB;AACnB,WAAOH,IAAI,CAACI,KAAL,CAAWD,KAAX,CAAP;AACH;;AAJoD,CAA1C,C","sourcesContent":["import { Modifier, ModifierOptions } from \"~/types\";\n\nexport default ({ i18n }: ModifierOptions): Modifier => ({\n name: \"price\",\n execute(value: string) {\n return i18n.price(value);\n }\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["timeModifier.ts"],"names":["i18n","name","execute","value","time"],"mappings":";;;;;;;eAEe,CAAC;AAAEA,EAAAA;AAAF,CAAD,MAA0C;AACrDC,EAAAA,IAAI,EAAE,MAD+C;;AAErDC,EAAAA,OAAO,CAACC,KAAD,EAAgB;AACnB,WAAOH,IAAI,CAACI,IAAL,CAAUD,KAAV,CAAP;AACH;;AAJoD,CAA1C,C","sourcesContent":["import { Modifier, ModifierOptions } from \"~/types\";\n\nexport default ({ i18n }: ModifierOptions): Modifier => ({\n name: \"time\",\n execute(value: string) {\n return i18n.time(value);\n }\n});\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/i18n",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.25.0-beta.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
],
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@babel/runtime": "7.
|
|
16
|
+
"@babel/runtime": "7.17.2",
|
|
17
17
|
"accounting": "0.4.1",
|
|
18
18
|
"fecha": "2.3.3",
|
|
19
19
|
"lodash": "4.17.21",
|
|
@@ -29,12 +29,15 @@
|
|
|
29
29
|
"@babel/preset-env": "^7.16.4",
|
|
30
30
|
"@babel/preset-typescript": "^7.16.0",
|
|
31
31
|
"@babel/register": "^7.16.0",
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
32
|
+
"@types/accounting": "^0.4.2",
|
|
33
|
+
"@types/lodash": "^4.14.178",
|
|
34
|
+
"@webiny/cli": "^5.25.0-beta.0",
|
|
35
|
+
"@webiny/project-utils": "^5.25.0-beta.0",
|
|
34
36
|
"babel-plugin-lodash": "^3.3.4",
|
|
35
37
|
"glob": "^7.1.2",
|
|
36
38
|
"rimraf": "^3.0.2",
|
|
37
|
-
"
|
|
39
|
+
"ttypescript": "^1.5.13",
|
|
40
|
+
"typescript": "4.5.5"
|
|
38
41
|
},
|
|
39
42
|
"publishConfig": {
|
|
40
43
|
"access": "public",
|
|
@@ -44,5 +47,5 @@
|
|
|
44
47
|
"build": "yarn webiny run build",
|
|
45
48
|
"watch": "yarn webiny run watch"
|
|
46
49
|
},
|
|
47
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "2d3e7833575e88fde77d84e5490e746933a5ec28"
|
|
48
51
|
}
|
package/processors/default.js
CHANGED
|
@@ -7,21 +7,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
var _trim2 = _interopRequireDefault(require("lodash/trim"));
|
|
13
|
-
|
|
14
|
-
var _startsWith2 = _interopRequireDefault(require("lodash/startsWith"));
|
|
10
|
+
var _trim = _interopRequireDefault(require("lodash/trim"));
|
|
15
11
|
|
|
16
12
|
const processTextPart = (part, values, modifiers) => {
|
|
17
|
-
if (
|
|
13
|
+
if (part.startsWith("{") === false) {
|
|
18
14
|
return part;
|
|
19
15
|
}
|
|
20
16
|
|
|
21
|
-
const parts = (0,
|
|
17
|
+
const parts = (0, _trim.default)(part, "{}").split("|");
|
|
22
18
|
const [variable, modifier] = parts;
|
|
23
19
|
|
|
24
|
-
if (!
|
|
20
|
+
if (!values[variable]) {
|
|
25
21
|
return `{${variable}}`;
|
|
26
22
|
}
|
|
27
23
|
|
|
@@ -33,6 +29,10 @@ const processTextPart = (part, values, modifiers) => {
|
|
|
33
29
|
const parameters = modifier.split(":");
|
|
34
30
|
const name = parameters.shift();
|
|
35
31
|
|
|
32
|
+
if (!name) {
|
|
33
|
+
return output.value;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
36
|
if (modifiers[name]) {
|
|
37
37
|
const modifier = modifiers[name];
|
|
38
38
|
output.value = modifier.execute(output.value, parameters);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["default.ts"],"names":["processTextPart","part","values","modifiers","startsWith","parts","split","variable","modifier","output","value","parameters","name","shift","execute","processor","canExecute","data","key","Date","translation","reduce","carry","i18n"],"mappings":";;;;;;;;;AAAA;;AAGA,MAAMA,eAAe,GAAG,CACpBC,IADoB,EAEpBC,MAFoB,EAGpBC,SAHoB,KAIX;AACT,MAAIF,IAAI,CAACG,UAAL,CAAgB,GAAhB,MAAyB,KAA7B,EAAoC;AAChC,WAAOH,IAAP;AACH;;AAED,QAAMI,KAAK,GAAG,mBAAWJ,IAAX,EAAiB,IAAjB,EAAuBK,KAAvB,CAA6B,GAA7B,CAAd;AAEA,QAAM,CAACC,QAAD,EAAWC,QAAX,IAAuBH,KAA7B;;AAEA,MAAI,CAACH,MAAM,CAACK,QAAD,CAAX,EAAuB;AACnB,WAAQ,IAAGA,QAAS,GAApB;AACH;;AAED,QAAME,MAAM,GAAG;AACXC,IAAAA,KAAK,EAAER,MAAM,CAACK,QAAD;AADF,GAAf;;AAIA,MAAIC,QAAJ,EAAc;AACV,UAAMG,UAAoB,GAAGH,QAAQ,CAACF,KAAT,CAAe,GAAf,CAA7B;AACA,UAAMM,IAAI,GAAGD,UAAU,CAACE,KAAX,EAAb;;AACA,QAAI,CAACD,IAAL,EAAW;AACP,aAAOH,MAAM,CAACC,KAAd;AACH;;AACD,QAAIP,SAAS,CAACS,IAAD,CAAb,EAAqB;AACjB,YAAMJ,QAAQ,GAAGL,SAAS,CAACS,IAAD,CAA1B;AACAH,MAAAA,MAAM,CAACC,KAAP,GAAeF,QAAQ,CAACM,OAAT,CAAiBL,MAAM,CAACC,KAAxB,EAA+BC,UAA/B,CAAf;AACH;AACJ;;AAED,SAAOF,MAAM,CAACC,KAAd;AACH,CAlCD;;AAoCA,MAAMK,SAAoB,GAAG;AACzBH,EAAAA,IAAI,EAAE,SADmB;;AAEzBI,EAAAA,UAAU,CAACC,IAAD,EAAO;AACb,SAAK,MAAMC,GAAX,IAAkBD,IAAI,CAACf,MAAvB,EAA+B;AAC3B,YAAMQ,KAAK,GAAGO,IAAI,CAACf,MAAL,CAAYgB,GAAZ,CAAd;;AACA,UACI,OAAOR,KAAP,KAAiB,QAAjB,IACA,OAAOA,KAAP,KAAiB,QADjB,IAEAA,KAAK,KAAK,IAFV,IAGAA,KAAK,YAAYS,IAJrB,EAKE;AACE;AACH;;AACD,aAAO,KAAP;AACH;;AAED,WAAO,IAAP;AACH,GAjBwB;;AAkBzBL,EAAAA,OAAO,CAACG,IAAD,EAAO;AACV,UAAMZ,KAAK,GAAGY,IAAI,CAACG,WAAL,CAAiBd,KAAjB,CAAuB,SAAvB,CAAd;AACA,WAAOD,KAAK,CAACgB,MAAN,CACH,CAACC,KAAD,EAAQrB,IAAR,KAAiBqB,KAAK,GAAGtB,eAAe,CAACC,IAAD,EAAOgB,IAAI,CAACf,MAAZ,EAAoBe,IAAI,CAACM,IAAL,CAAUpB,SAA9B,CADrC,EAEH,EAFG,CAAP;AAIH;;AAxBwB,CAA7B;eA2BeY,S","sourcesContent":["import lodashTrim from \"lodash/trim\";\nimport { Modifier, Processor } from \"~/types\";\n\nconst processTextPart = (\n part: string,\n values: Record<string, any>,\n modifiers: Record<string, Modifier>\n): string => {\n if (part.startsWith(\"{\") === false) {\n return part;\n }\n\n const parts = lodashTrim(part, \"{}\").split(\"|\");\n\n const [variable, modifier] = parts;\n\n if (!values[variable]) {\n return `{${variable}}`;\n }\n\n const output = {\n value: values[variable]\n };\n\n if (modifier) {\n const parameters: string[] = modifier.split(\":\");\n const name = parameters.shift();\n if (!name) {\n return output.value;\n }\n if (modifiers[name]) {\n const modifier = modifiers[name];\n output.value = modifier.execute(output.value, parameters);\n }\n }\n\n return output.value;\n};\n\nconst processor: Processor = {\n name: \"default\",\n canExecute(data) {\n for (const key in data.values) {\n const value = data.values[key];\n if (\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n value === null ||\n value instanceof Date\n ) {\n continue;\n }\n return false;\n }\n\n return true;\n },\n execute(data) {\n const parts = data.translation.split(/({.*?})/);\n return parts.reduce(\n (carry, part) => carry + processTextPart(part, data.values, data.i18n.modifiers),\n \"\"\n );\n }\n};\n\nexport default processor;\n"]}
|
package/types.d.ts
CHANGED
|
@@ -1,51 +1,56 @@
|
|
|
1
1
|
import I18N from "./I18n";
|
|
2
2
|
import { ReactElement } from "react";
|
|
3
|
-
export
|
|
3
|
+
export interface I18NDataValues {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}
|
|
6
|
+
export interface I18NData {
|
|
4
7
|
translation: string;
|
|
5
8
|
base: string;
|
|
6
9
|
namespace: string;
|
|
7
|
-
values:
|
|
8
|
-
[key: string]: any;
|
|
9
|
-
};
|
|
10
|
+
values: I18NDataValues;
|
|
10
11
|
i18n: I18N;
|
|
11
|
-
}
|
|
12
|
+
}
|
|
13
|
+
export interface ModifierOptions {
|
|
14
|
+
i18n: I18N;
|
|
15
|
+
}
|
|
12
16
|
/**
|
|
13
|
-
* @name Modifier
|
|
14
17
|
* @description I18N Modifier - used for modifying text dynamically.
|
|
15
18
|
*/
|
|
16
|
-
export
|
|
19
|
+
export interface Modifier {
|
|
17
20
|
name: string;
|
|
18
21
|
execute: (...args: any[]) => string;
|
|
19
|
-
}
|
|
22
|
+
}
|
|
23
|
+
export declare type ProcessorResult = string | ReactElement;
|
|
20
24
|
/**
|
|
21
|
-
* @name Processor
|
|
22
25
|
* @description I18N Processor - used for outputting text.
|
|
23
26
|
*/
|
|
24
|
-
export
|
|
27
|
+
export interface Processor {
|
|
25
28
|
name: string;
|
|
26
|
-
canExecute
|
|
27
|
-
execute: (data: I18NData) =>
|
|
28
|
-
}
|
|
29
|
-
export
|
|
29
|
+
canExecute: (data: I18NData) => boolean;
|
|
30
|
+
execute: (data: I18NData) => ProcessorResult;
|
|
31
|
+
}
|
|
32
|
+
export interface NumberFormat {
|
|
30
33
|
decimal: string;
|
|
31
34
|
thousand: string;
|
|
32
35
|
precision: number;
|
|
33
|
-
}
|
|
34
|
-
export
|
|
36
|
+
}
|
|
37
|
+
export interface PriceFormat {
|
|
35
38
|
symbol: string;
|
|
36
39
|
format: string;
|
|
37
40
|
decimal: string;
|
|
38
41
|
thousand: string;
|
|
39
42
|
precision: number;
|
|
40
|
-
}
|
|
41
|
-
export
|
|
43
|
+
}
|
|
44
|
+
export interface Formats {
|
|
42
45
|
date: string;
|
|
43
46
|
time: string;
|
|
44
47
|
datetime: string;
|
|
45
48
|
price: PriceFormat;
|
|
46
49
|
number: NumberFormat;
|
|
47
|
-
}
|
|
48
|
-
export
|
|
49
|
-
|
|
50
|
+
}
|
|
51
|
+
export interface Translator {
|
|
52
|
+
(base: any): any;
|
|
53
|
+
}
|
|
54
|
+
export interface Translations {
|
|
50
55
|
[key: string]: string;
|
|
51
|
-
}
|
|
56
|
+
}
|
package/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|