@webiny/i18n 0.0.0-mt-2 → 0.0.0-unstable.5e7233243f
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 +59 -60
- 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 +16 -13
- 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,19 +83,22 @@ class I18N {
|
|
|
79
83
|
const hasVariables = base.includes("{") && base.includes("}");
|
|
80
84
|
|
|
81
85
|
if (hasVariables) {
|
|
82
|
-
// @
|
|
83
|
-
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
87
|
+
const $this = this;
|
|
88
|
+
return function i18n(values) {
|
|
84
89
|
const data = {
|
|
85
|
-
translation,
|
|
90
|
+
translation: translation,
|
|
86
91
|
base,
|
|
87
92
|
namespace,
|
|
88
93
|
values,
|
|
89
|
-
i18n: this
|
|
94
|
+
i18n: $this
|
|
90
95
|
};
|
|
91
96
|
|
|
92
|
-
for (const key in this.processors) {
|
|
93
|
-
|
|
94
|
-
|
|
97
|
+
for (const key in $this.processors) {
|
|
98
|
+
const processor = $this.processors[key];
|
|
99
|
+
|
|
100
|
+
if (processor.canExecute(data)) {
|
|
101
|
+
return processor.execute(data);
|
|
95
102
|
}
|
|
96
103
|
}
|
|
97
104
|
|
|
@@ -128,9 +135,6 @@ class I18N {
|
|
|
128
135
|
/**
|
|
129
136
|
* Formats and outputs date.
|
|
130
137
|
* 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
138
|
*/
|
|
135
139
|
|
|
136
140
|
|
|
@@ -139,10 +143,16 @@ class I18N {
|
|
|
139
143
|
outputFormat = this.getDateFormat();
|
|
140
144
|
}
|
|
141
145
|
|
|
146
|
+
if (!inputFormat) {
|
|
147
|
+
inputFormat = "YYYY-MM-DDTHH:mm:ss.SSSZ";
|
|
148
|
+
}
|
|
149
|
+
|
|
142
150
|
let parsedValue;
|
|
143
151
|
|
|
144
152
|
if (typeof value === "string") {
|
|
145
153
|
parsedValue = fecha.parse(value, inputFormat);
|
|
154
|
+
} else {
|
|
155
|
+
parsedValue = value;
|
|
146
156
|
}
|
|
147
157
|
|
|
148
158
|
return fecha.format(parsedValue, outputFormat);
|
|
@@ -150,21 +160,24 @@ class I18N {
|
|
|
150
160
|
/**
|
|
151
161
|
* Formats and outputs time.
|
|
152
162
|
* 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
163
|
*/
|
|
157
164
|
|
|
158
165
|
|
|
159
|
-
time(value, outputFormat
|
|
166
|
+
time(value, outputFormat, inputFormat) {
|
|
160
167
|
if (!outputFormat) {
|
|
161
168
|
outputFormat = this.getTimeFormat();
|
|
162
169
|
}
|
|
163
170
|
|
|
171
|
+
if (!inputFormat) {
|
|
172
|
+
inputFormat = "YYYY-MM-DDTHH:mm:ss.SSSZ";
|
|
173
|
+
}
|
|
174
|
+
|
|
164
175
|
let parsedValue;
|
|
165
176
|
|
|
166
177
|
if (typeof value === "string") {
|
|
167
178
|
parsedValue = fecha.parse(value, inputFormat);
|
|
179
|
+
} else {
|
|
180
|
+
parsedValue = value;
|
|
168
181
|
}
|
|
169
182
|
|
|
170
183
|
return fecha.format(parsedValue, outputFormat);
|
|
@@ -172,29 +185,30 @@ class I18N {
|
|
|
172
185
|
/**
|
|
173
186
|
* Formats and outputs date/time.
|
|
174
187
|
* 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
188
|
*/
|
|
179
189
|
|
|
180
190
|
|
|
181
|
-
dateTime(value, outputFormat
|
|
191
|
+
dateTime(value, outputFormat, inputFormat) {
|
|
182
192
|
if (!outputFormat) {
|
|
183
193
|
outputFormat = this.getDateTimeFormat();
|
|
184
194
|
}
|
|
185
195
|
|
|
196
|
+
if (!inputFormat) {
|
|
197
|
+
inputFormat = "YYYY-MM-DDTHH:mm:ss.SSSZ";
|
|
198
|
+
}
|
|
199
|
+
|
|
186
200
|
let parsedValue;
|
|
187
201
|
|
|
188
202
|
if (typeof value === "string") {
|
|
189
203
|
parsedValue = fecha.parse(value, inputFormat);
|
|
204
|
+
} else {
|
|
205
|
+
parsedValue = value;
|
|
190
206
|
}
|
|
191
207
|
|
|
192
208
|
return fecha.format(parsedValue, outputFormat);
|
|
193
209
|
}
|
|
194
210
|
/**
|
|
195
211
|
* Outputs formatted number as amount of price.
|
|
196
|
-
* @param value
|
|
197
|
-
* @param outputFormat
|
|
198
212
|
*/
|
|
199
213
|
|
|
200
214
|
|
|
@@ -202,7 +216,7 @@ class I18N {
|
|
|
202
216
|
if (!outputFormat) {
|
|
203
217
|
outputFormat = this.getPriceFormat();
|
|
204
218
|
} else {
|
|
205
|
-
outputFormat = (0,
|
|
219
|
+
outputFormat = (0, _assign.default)({}, this.defaultFormats.price, outputFormat);
|
|
206
220
|
} // Convert placeholders to accounting's placeholders.
|
|
207
221
|
|
|
208
222
|
|
|
@@ -213,8 +227,6 @@ class I18N {
|
|
|
213
227
|
}
|
|
214
228
|
/**
|
|
215
229
|
* Outputs formatted number.
|
|
216
|
-
* @param value
|
|
217
|
-
* @param outputFormat
|
|
218
230
|
*/
|
|
219
231
|
|
|
220
232
|
|
|
@@ -222,24 +234,29 @@ class I18N {
|
|
|
222
234
|
if (!outputFormat) {
|
|
223
235
|
outputFormat = this.getNumberFormat();
|
|
224
236
|
} else {
|
|
225
|
-
outputFormat = (0,
|
|
237
|
+
outputFormat = (0, _assign.default)({}, this.defaultFormats.number, outputFormat);
|
|
226
238
|
}
|
|
227
239
|
|
|
228
|
-
return _accounting.default.formatNumber(
|
|
240
|
+
return _accounting.default.formatNumber(
|
|
241
|
+
/**
|
|
242
|
+
* Cast as number because method transforms it internally.
|
|
243
|
+
*/
|
|
244
|
+
value, outputFormat.precision, outputFormat.thousand, outputFormat.decimal);
|
|
229
245
|
}
|
|
230
246
|
/**
|
|
231
247
|
* Returns translation for given text key.
|
|
232
|
-
* @param key
|
|
233
|
-
* @returns {*|string}
|
|
234
248
|
*/
|
|
235
249
|
|
|
236
250
|
|
|
237
251
|
getTranslation(key) {
|
|
252
|
+
if (!key) {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
|
|
238
256
|
return this.translations[key];
|
|
239
257
|
}
|
|
240
258
|
/**
|
|
241
259
|
* Returns all translations for current locale.
|
|
242
|
-
* @returns {*|{}}
|
|
243
260
|
*/
|
|
244
261
|
|
|
245
262
|
|
|
@@ -248,7 +265,6 @@ class I18N {
|
|
|
248
265
|
}
|
|
249
266
|
/**
|
|
250
267
|
* Returns true if given key has a translation for currently set locale.
|
|
251
|
-
* @param key
|
|
252
268
|
*/
|
|
253
269
|
|
|
254
270
|
|
|
@@ -257,9 +273,6 @@ class I18N {
|
|
|
257
273
|
}
|
|
258
274
|
/**
|
|
259
275
|
* Sets translation for given text key.
|
|
260
|
-
* @param key
|
|
261
|
-
* @param translation
|
|
262
|
-
* @returns {I18N}
|
|
263
276
|
*/
|
|
264
277
|
|
|
265
278
|
|
|
@@ -269,7 +282,6 @@ class I18N {
|
|
|
269
282
|
}
|
|
270
283
|
/**
|
|
271
284
|
* Sets translations that will be used.
|
|
272
|
-
* @returns {*|{}}
|
|
273
285
|
*/
|
|
274
286
|
|
|
275
287
|
|
|
@@ -279,7 +291,6 @@ class I18N {
|
|
|
279
291
|
}
|
|
280
292
|
/**
|
|
281
293
|
* Clears all translations.
|
|
282
|
-
* @returns {*|{}}
|
|
283
294
|
*/
|
|
284
295
|
|
|
285
296
|
|
|
@@ -289,12 +300,11 @@ class I18N {
|
|
|
289
300
|
}
|
|
290
301
|
/**
|
|
291
302
|
* Merges given translations object with already existing.
|
|
292
|
-
* @returns {*|{}}
|
|
293
303
|
*/
|
|
294
304
|
|
|
295
305
|
|
|
296
306
|
mergeTranslations(translations) {
|
|
297
|
-
return (0,
|
|
307
|
+
return (0, _assign.default)(this.translations, translations);
|
|
298
308
|
}
|
|
299
309
|
/**
|
|
300
310
|
* Returns currently selected locale (locale's key).
|
|
@@ -315,7 +325,6 @@ class I18N {
|
|
|
315
325
|
}
|
|
316
326
|
/**
|
|
317
327
|
* Registers single modifier.
|
|
318
|
-
* @returns {I18N}
|
|
319
328
|
*/
|
|
320
329
|
|
|
321
330
|
|
|
@@ -325,8 +334,6 @@ class I18N {
|
|
|
325
334
|
}
|
|
326
335
|
/**
|
|
327
336
|
* Registers all modifiers in given array.
|
|
328
|
-
* @param modifiers
|
|
329
|
-
* @returns {I18N}
|
|
330
337
|
*/
|
|
331
338
|
|
|
332
339
|
|
|
@@ -336,8 +343,6 @@ class I18N {
|
|
|
336
343
|
}
|
|
337
344
|
/**
|
|
338
345
|
* Unregisters given modifier.
|
|
339
|
-
* @param name
|
|
340
|
-
* @returns {I18N}
|
|
341
346
|
*/
|
|
342
347
|
|
|
343
348
|
|
|
@@ -347,7 +352,6 @@ class I18N {
|
|
|
347
352
|
}
|
|
348
353
|
/**
|
|
349
354
|
* Registers single processor.
|
|
350
|
-
* @returns {I18N}
|
|
351
355
|
*/
|
|
352
356
|
|
|
353
357
|
|
|
@@ -357,8 +361,6 @@ class I18N {
|
|
|
357
361
|
}
|
|
358
362
|
/**
|
|
359
363
|
* Registers all processors in given array.
|
|
360
|
-
* @param processors
|
|
361
|
-
* @returns {I18N}
|
|
362
364
|
*/
|
|
363
365
|
|
|
364
366
|
|
|
@@ -368,8 +370,6 @@ class I18N {
|
|
|
368
370
|
}
|
|
369
371
|
/**
|
|
370
372
|
* Unregisters given processor.
|
|
371
|
-
* @param name
|
|
372
|
-
* @returns {I18N}
|
|
373
373
|
*/
|
|
374
374
|
|
|
375
375
|
|
|
@@ -379,7 +379,6 @@ class I18N {
|
|
|
379
379
|
}
|
|
380
380
|
/**
|
|
381
381
|
* Returns default formats
|
|
382
|
-
* @returns {{date: string, time: string, datetime: string, number: string}}
|
|
383
382
|
*/
|
|
384
383
|
|
|
385
384
|
|
|
@@ -408,7 +407,7 @@ class I18N {
|
|
|
408
407
|
|
|
409
408
|
|
|
410
409
|
getDateFormat() {
|
|
411
|
-
return (0,
|
|
410
|
+
return (0, _get.default)(this.locale, "formats.date", this.defaultFormats.date);
|
|
412
411
|
}
|
|
413
412
|
/**
|
|
414
413
|
* Returns current format to be used when outputting time.
|
|
@@ -416,7 +415,7 @@ class I18N {
|
|
|
416
415
|
|
|
417
416
|
|
|
418
417
|
getTimeFormat() {
|
|
419
|
-
return (0,
|
|
418
|
+
return (0, _get.default)(this.locale, "formats.time", this.defaultFormats.time);
|
|
420
419
|
}
|
|
421
420
|
/**
|
|
422
421
|
* Returns current format to be used when outputting date/time.
|
|
@@ -424,7 +423,7 @@ class I18N {
|
|
|
424
423
|
|
|
425
424
|
|
|
426
425
|
getDateTimeFormat() {
|
|
427
|
-
return (0,
|
|
426
|
+
return (0, _get.default)(this.locale, "formats.datetime", this.defaultFormats.datetime);
|
|
428
427
|
}
|
|
429
428
|
/**
|
|
430
429
|
* Returns current format to be used when outputting prices.
|
|
@@ -432,7 +431,7 @@ class I18N {
|
|
|
432
431
|
|
|
433
432
|
|
|
434
433
|
getPriceFormat() {
|
|
435
|
-
return (0,
|
|
434
|
+
return (0, _assign.default)({}, this.defaultFormats.price, (0, _get.default)(this.locale, "formats.price", {}));
|
|
436
435
|
}
|
|
437
436
|
/**
|
|
438
437
|
* Returns current format to be used when outputting numbers.
|
|
@@ -440,7 +439,7 @@ class I18N {
|
|
|
440
439
|
|
|
441
440
|
|
|
442
441
|
getNumberFormat() {
|
|
443
|
-
return (0,
|
|
442
|
+
return (0, _assign.default)({}, this.defaultFormats.number, (0, _get.default)(this.locale, "formats.number", {}));
|
|
444
443
|
}
|
|
445
444
|
|
|
446
445
|
}
|
package/I18n.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["I18N","constructor","defaultFormats","getDefaultFormats","translations","modifiers","processors","translate","base","namespace","Error","lodashGet","translation","getTranslation","hash","hasVariables","includes","$this","i18n","values","data","key","processor","canExecute","execute","ns","date","value","outputFormat","inputFormat","getDateFormat","parsedValue","fecha","parse","format","time","getTimeFormat","dateTime","getDateTimeFormat","price","getPriceFormat","lodashAssign","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"],"sources":["I18n.ts"],"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 // eslint-disable-next-line @typescript-eslint/no-this-alias\n const $this = this;\n return function i18n(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"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAKA;;AACA;;AACA;;;;;;AANA;AACA;AACA;AACA;;AAsBA;AACA;AACA;AACe,MAAMA,IAAN,CAAW;EAWfC,WAAW,GAAG;IAAA,8CAVU,IAUV;IAAA;IAAA;IAAA;IAAA;;IACjB;AACR;AACA;AACA;IACQ,KAAKC,cAAL,GAAsB,KAAKC,iBAAL,EAAtB;IAEA;AACR;AACA;AACA;;IACQ,KAAKC,YAAL,GAAoB,EAApB;IAEA;AACR;AACA;AACA;;IACQ,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
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,"names":["getNamespaces","source","regex","m","results","exec","index","lastIndex","allDeclaredNamespaces","variable","RegExp","matchedText","key","hash"],"sources":["extract.ts"],"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(matched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H;EACJ;;EAED,OAAOP,OAAP;AACH,C"}
|
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,"names":["Extractor","setGlob","value","glob","setContent","content","execute","results","paths","sync","forEach","path","contents","fs","readFileSync","parsed","extract","key","setListOnly","flag","listOnly"],"sources":["index.ts"],"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"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AAKA,MAAMA,SAAN,CAAgB;EAAA;IAAA;IAAA,+CAEK,EAFL;IAAA,gDAGM,KAHN;EAAA;;EAKLC,OAAO,CAACC,KAAD,EAA2B;IACrC,KAAKC,IAAL,GAAYD,KAAZ;IACA,OAAO,IAAP;EACH;;EAEME,UAAU,CAACC,OAAD,EAA6B;IAC1C,KAAKA,OAAL,GAAeA,OAAf;IACA,OAAO,IAAP;EACH;;EAEMC,OAAO,GAAqB;IAC/B,MAAMC,OAAyB,GAAG,EAAlC;;IAEA,IAAI,CAAC,KAAKJ,IAAV,EAAgB;MACZ,OAAOI,OAAP;IACH;;IACD,MAAMC,KAAK,GAAGL,aAAA,CAAKM,IAAL,CAAU,KAAKN,IAAf,CAAd;;IACAK,KAAK,CAACE,OAAN,CAAcC,IAAI,IAAI;MAClB,MAAMC,QAAQ,GAAGC,WAAA,CAAGC,YAAH,CAAgBH,IAAhB,EAAsB,MAAtB,CAAjB;;MACA,MAAMI,MAAM,GAAG,IAAAC,gBAAA,EAAQJ,QAAR,CAAf;;MACA,KAAK,MAAMK,GAAX,IAAkBF,MAAlB,EAA0B;QACtBR,OAAO,CAACU,GAAD,CAAP,GAAeF,MAAM,CAACE,GAAD,CAArB;MACH;IACJ,CAND;IAQA,OAAOV,OAAP;EACH;;EAEMW,WAAW,CAACC,IAAI,GAAG,IAAR,EAAyB;IACvC,KAAKC,QAAL,GAAgBD,IAAhB;IACA,OAAO,IAAP;EACH;;AApCW;;eAuCDnB,S"}
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["i18n","I18n","defaultModifiers","modifiersFactory"],"sources":["index.ts"],"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"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA,MAAMA,IAAI,GAAG,IAAIC,aAAJ,EAAb;AAEA,MAAMC,gBAAgB,GAAG,IAAAC,kBAAA,EAAiB;EAAEH;AAAF,CAAjB,CAAzB;;eAEeA,I"}
|
|
@@ -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,"names":["name","execute","value","parameters","i","length","current","numbers","split","String"],"sources":["countModifier.ts"],"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"],"mappings":";;;;;;;eAEe,MAAgB;EAC3B,OAAO;IACHA,IAAI,EAAE,OADH;;IAEHC,OAAO,CAACC,KAAD,EAAgBC,UAAhB,EAA2C;MAC9C;MACA,KAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGD,UAAU,CAACE,MAA/B,EAAuCD,CAAC,GAAGA,CAAC,GAAG,CAA/C,EAAkD;QAC9C,MAAME,OAAO,GAAGH,UAAU,CAACC,CAAD,CAA1B;;QACA,IAAIE,OAAO,KAAK,SAAhB,EAA2B;UACvB,OAAOJ,KAAK,GAAG,GAAR,GAAcC,UAAU,CAACC,CAAC,GAAG,CAAL,CAA/B;QACH;;QAED,MAAMG,OAAO,GAAGD,OAAO,CAACE,KAAR,CAAc,GAAd,CAAhB,CAN8C,CAQ9C;;QACA,IAAID,OAAO,CAACF,MAAR,KAAmB,CAAvB,EAA0B;UACtB,IAAIH,KAAK,IAAIK,OAAO,CAAC,CAAD,CAAhB,IAAuBL,KAAK,IAAIK,OAAO,CAAC,CAAD,CAA3C,EAAgD;YAC5C,OAAOL,KAAK,GAAG,GAAR,GAAcC,UAAU,CAACC,CAAC,GAAG,CAAL,CAA/B;UACH;;UACD;QACH;;QAED,IAAIK,MAAM,CAACP,KAAD,CAAN,KAAkBK,OAAO,CAAC,CAAD,CAA7B,EAAkC;UAC9B,OAAOL,KAAK,GAAG,GAAR,GAAcC,UAAU,CAACC,CAAC,GAAG,CAAL,CAA/B;QACH;MACJ,CArB6C,CAuB9C;;;MACA,OAAOF,KAAP;IACH;;EA3BE,CAAP;AA6BH,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["i18n","name","execute","value","date"],"sources":["dateModifier.ts"],"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"],"mappings":";;;;;;;eAEe,CAAC;EAAEA;AAAF,CAAD,MAA0C;EACrDC,IAAI,EAAE,MAD+C;;EAErDC,OAAO,CAACC,KAAD,EAAQ;IACX,OAAOH,IAAI,CAACI,IAAL,CAAUD,KAAV,CAAP;EACH;;AAJoD,CAA1C,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["i18n","name","execute","value","dateTime"],"sources":["dateTimeModifier.ts"],"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"],"mappings":";;;;;;;eAEe,CAAC;EAAEA;AAAF,CAAD,MAA0C;EACrDC,IAAI,EAAE,UAD+C;;EAErDC,OAAO,CAACC,KAAD,EAAgB;IACnB,OAAOH,IAAI,CAACI,QAAL,CAAcD,KAAd,CAAP;EACH;;AAJoD,CAA1C,C"}
|
|
@@ -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,"names":["name","execute","value","parameters"],"sources":["genderModifier.ts"],"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"],"mappings":";;;;;;;eAEe,MAAgB;EAC3B,OAAO;IACHA,IAAI,EAAE,QADH;;IAEHC,OAAO,CAACC,KAAD,EAAgBC,UAAhB,EAA2C;MAC9C,OAAOD,KAAK,KAAK,MAAV,GAAmBC,UAAU,CAAC,CAAD,CAA7B,GAAmCA,UAAU,CAAC,CAAD,CAApD;IACH;;EAJE,CAAP;AAMH,C"}
|
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,"names":["name","execute","value","parameters"],"sources":["ifModifier.ts"],"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"],"mappings":";;;;;;;eAEe,MAAgB;EAC3B,OAAO;IACHA,IAAI,EAAE,IADH;;IAEHC,OAAO,CAACC,KAAD,EAAgBC,UAAhB,EAA2C;MAC9C,OAAOD,KAAK,KAAKC,UAAU,CAAC,CAAD,CAApB,GAA0BA,UAAU,CAAC,CAAD,CAApC,GAA0CA,UAAU,CAAC,CAAD,CAAV,IAAiB,EAAlE;IACH;;EAJE,CAAP;AAMH,C"}
|
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,"names":["options","countModifiers","genderModifier","ifModifier","pluralModifier","dateModifier","dateTimeModifier","timeModifier","numberModifier","priceModifier"],"sources":["index.ts"],"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"],"mappings":";;;;;;;;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AATA;eAYgBA,OAAD,IAA0C,CACrD,IAAAC,sBAAA,GADqD,EAErD,IAAAC,uBAAA,GAFqD,EAGrD,IAAAC,mBAAA,GAHqD,EAIrD,IAAAC,uBAAA,GAJqD,EAKrD,IAAAC,qBAAA,EAAaL,OAAb,CALqD,EAMrD,IAAAM,yBAAA,EAAiBN,OAAjB,CANqD,EAOrD,IAAAO,qBAAA,EAAaP,OAAb,CAPqD,EAQrD,IAAAQ,uBAAA,EAAeR,OAAf,CARqD,EASrD,IAAAS,sBAAA,EAAcT,OAAd,CATqD,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["i18n","name","execute","value","number"],"sources":["numberModifier.ts"],"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"],"mappings":";;;;;;;eAEe,CAAC;EAAEA;AAAF,CAAD,MAA0C;EACrDC,IAAI,EAAE,QAD+C;;EAErDC,OAAO,CAACC,KAAD,EAAgB;IACnB,OAAOH,IAAI,CAACI,MAAL,CAAYD,KAAZ,CAAP;EACH;;AAJoD,CAA1C,C"}
|
|
@@ -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,"names":["name","execute","value","parameters","i","length","current","numbers","split","String"],"sources":["pluralModifier.ts"],"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"],"mappings":";;;;;;;eAEe,MAAgB;EAC3B,OAAO;IACHA,IAAI,EAAE,QADH;;IAEHC,OAAO,CAACC,KAAD,EAAgBC,UAAhB,EAA2C;MAC9C;MACA,KAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGD,UAAU,CAACE,MAA/B,EAAuCD,CAAC,GAAGA,CAAC,GAAG,CAA/C,EAAkD;QAC9C,MAAME,OAAO,GAAGH,UAAU,CAACC,CAAD,CAA1B;;QACA,IAAIE,OAAO,KAAK,SAAhB,EAA2B;UACvB,OAAOH,UAAU,CAACC,CAAC,GAAG,CAAL,CAAjB;QACH;;QAED,MAAMG,OAAO,GAAGD,OAAO,CAACE,KAAR,CAAc,GAAd,CAAhB,CAN8C,CAQ9C;;QACA,IAAID,OAAO,CAACF,MAAR,KAAmB,CAAvB,EAA0B;UACtB,IAAIH,KAAK,IAAIK,OAAO,CAAC,CAAD,CAAhB,IAAuBL,KAAK,IAAIK,OAAO,CAAC,CAAD,CAA3C,EAAgD;YAC5C,OAAOJ,UAAU,CAACC,CAAC,GAAG,CAAL,CAAjB;UACH;;UACD;QACH;;QAED,IAAIK,MAAM,CAACP,KAAD,CAAN,KAAkBK,OAAO,CAAC,CAAD,CAA7B,EAAkC;UAC9B,OAAOJ,UAAU,CAACC,CAAC,GAAG,CAAL,CAAjB;QACH;MACJ;;MAED,OAAO,EAAP;IACH;;EA1BE,CAAP;AA4BH,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["i18n","name","execute","value","price"],"sources":["priceModifier.ts"],"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"],"mappings":";;;;;;;eAEe,CAAC;EAAEA;AAAF,CAAD,MAA0C;EACrDC,IAAI,EAAE,OAD+C;;EAErDC,OAAO,CAACC,KAAD,EAAgB;IACnB,OAAOH,IAAI,CAACI,KAAL,CAAWD,KAAX,CAAP;EACH;;AAJoD,CAA1C,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["i18n","name","execute","value","time"],"sources":["timeModifier.ts"],"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"],"mappings":";;;;;;;eAEe,CAAC;EAAEA;AAAF,CAAD,MAA0C;EACrDC,IAAI,EAAE,MAD+C;;EAErDC,OAAO,CAACC,KAAD,EAAgB;IACnB,OAAOH,IAAI,CAACI,IAAL,CAAUD,KAAV,CAAP;EACH;;AAJoD,CAA1C,C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/i18n",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-unstable.5e7233243f",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,28 +13,31 @@
|
|
|
13
13
|
],
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@babel/runtime": "7.
|
|
16
|
+
"@babel/runtime": "7.18.9",
|
|
17
17
|
"accounting": "0.4.1",
|
|
18
18
|
"fecha": "2.3.3",
|
|
19
19
|
"lodash": "4.17.21",
|
|
20
20
|
"short-hash": "1.0.0",
|
|
21
|
-
"yargs": "
|
|
21
|
+
"yargs": "17.5.1"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"react": "
|
|
24
|
+
"react": "^17.0.2"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@babel/cli": "^7.
|
|
28
|
-
"@babel/core": "^7.
|
|
29
|
-
"@babel/preset-env": "^7.
|
|
30
|
-
"@babel/preset-typescript": "^7.
|
|
31
|
-
"@babel/register": "^7.
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
27
|
+
"@babel/cli": "^7.16.0",
|
|
28
|
+
"@babel/core": "^7.16.0",
|
|
29
|
+
"@babel/preset-env": "^7.16.4",
|
|
30
|
+
"@babel/preset-typescript": "^7.16.0",
|
|
31
|
+
"@babel/register": "^7.16.0",
|
|
32
|
+
"@types/accounting": "^0.4.2",
|
|
33
|
+
"@types/lodash": "^4.14.178",
|
|
34
|
+
"@webiny/cli": "^0.0.0-unstable.5e7233243f",
|
|
35
|
+
"@webiny/project-utils": "^0.0.0-unstable.5e7233243f",
|
|
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.7.4"
|
|
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": "995a4b337db9b8497c6615e335dcd206afe26f8f"
|
|
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,"names":["processTextPart","part","values","modifiers","startsWith","parts","lodashTrim","split","variable","modifier","output","value","parameters","name","shift","execute","processor","canExecute","data","key","Date","translation","reduce","carry","i18n"],"sources":["default.ts"],"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"],"mappings":";;;;;;;;;AAAA;;AAGA,MAAMA,eAAe,GAAG,CACpBC,IADoB,EAEpBC,MAFoB,EAGpBC,SAHoB,KAIX;EACT,IAAIF,IAAI,CAACG,UAAL,CAAgB,GAAhB,MAAyB,KAA7B,EAAoC;IAChC,OAAOH,IAAP;EACH;;EAED,MAAMI,KAAK,GAAG,IAAAC,aAAA,EAAWL,IAAX,EAAiB,IAAjB,EAAuBM,KAAvB,CAA6B,GAA7B,CAAd;EAEA,MAAM,CAACC,QAAD,EAAWC,QAAX,IAAuBJ,KAA7B;;EAEA,IAAI,CAACH,MAAM,CAACM,QAAD,CAAX,EAAuB;IACnB,OAAQ,IAAGA,QAAS,GAApB;EACH;;EAED,MAAME,MAAM,GAAG;IACXC,KAAK,EAAET,MAAM,CAACM,QAAD;EADF,CAAf;;EAIA,IAAIC,QAAJ,EAAc;IACV,MAAMG,UAAoB,GAAGH,QAAQ,CAACF,KAAT,CAAe,GAAf,CAA7B;IACA,MAAMM,IAAI,GAAGD,UAAU,CAACE,KAAX,EAAb;;IACA,IAAI,CAACD,IAAL,EAAW;MACP,OAAOH,MAAM,CAACC,KAAd;IACH;;IACD,IAAIR,SAAS,CAACU,IAAD,CAAb,EAAqB;MACjB,MAAMJ,QAAQ,GAAGN,SAAS,CAACU,IAAD,CAA1B;MACAH,MAAM,CAACC,KAAP,GAAeF,QAAQ,CAACM,OAAT,CAAiBL,MAAM,CAACC,KAAxB,EAA+BC,UAA/B,CAAf;IACH;EACJ;;EAED,OAAOF,MAAM,CAACC,KAAd;AACH,CAlCD;;AAoCA,MAAMK,SAAoB,GAAG;EACzBH,IAAI,EAAE,SADmB;;EAEzBI,UAAU,CAACC,IAAD,EAAO;IACb,KAAK,MAAMC,GAAX,IAAkBD,IAAI,CAAChB,MAAvB,EAA+B;MAC3B,MAAMS,KAAK,GAAGO,IAAI,CAAChB,MAAL,CAAYiB,GAAZ,CAAd;;MACA,IACI,OAAOR,KAAP,KAAiB,QAAjB,IACA,OAAOA,KAAP,KAAiB,QADjB,IAEAA,KAAK,KAAK,IAFV,IAGAA,KAAK,YAAYS,IAJrB,EAKE;QACE;MACH;;MACD,OAAO,KAAP;IACH;;IAED,OAAO,IAAP;EACH,CAjBwB;;EAkBzBL,OAAO,CAACG,IAAD,EAAO;IACV,MAAMb,KAAK,GAAGa,IAAI,CAACG,WAAL,CAAiBd,KAAjB,CAAuB,SAAvB,CAAd;IACA,OAAOF,KAAK,CAACiB,MAAN,CACH,CAACC,KAAD,EAAQtB,IAAR,KAAiBsB,KAAK,GAAGvB,eAAe,CAACC,IAAD,EAAOiB,IAAI,CAAChB,MAAZ,EAAoBgB,IAAI,CAACM,IAAL,CAAUrB,SAA9B,CADrC,EAEH,EAFG,CAAP;EAIH;;AAxBwB,CAA7B;eA2Bea,S"}
|
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,"names":[],"sources":["types.ts"],"sourcesContent":["import I18N from \"./I18n\";\nimport { ReactElement } from \"react\";\n\nexport interface I18NDataValues {\n [key: string]: any;\n}\nexport interface I18NData {\n translation: string;\n base: string;\n namespace: string;\n values: I18NDataValues;\n i18n: I18N;\n}\n\nexport interface ModifierOptions {\n i18n: I18N;\n}\n/**\n * @description I18N Modifier - used for modifying text dynamically.\n */\nexport interface Modifier {\n name: string;\n execute: (...args: any[]) => string;\n}\n\nexport type ProcessorResult = string | ReactElement;\n/**\n * @description I18N Processor - used for outputting text.\n */\nexport interface Processor {\n name: string;\n canExecute: (data: I18NData) => boolean;\n execute: (data: I18NData) => ProcessorResult;\n}\n\nexport interface NumberFormat {\n decimal: string;\n thousand: string;\n precision: number;\n}\n\nexport interface PriceFormat {\n symbol: string;\n format: string;\n decimal: string;\n thousand: string;\n precision: number;\n}\n\nexport interface Formats {\n date: string;\n time: string;\n datetime: string;\n price: PriceFormat;\n number: NumberFormat;\n}\n\nexport interface Translator {\n (base: any): any;\n}\n\nexport interface Translations {\n [key: string]: string;\n}\n"],"mappings":""}
|