@webiny/i18n 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7be00a75a9
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 +2 -2
- package/I18n.js +158 -425
- package/I18n.js.map +1 -1
- package/README.md +7 -13
- package/extractor/extract.js +24 -57
- package/extractor/extract.js.map +1 -1
- package/extractor/index.js +32 -60
- package/extractor/index.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +12 -34
- package/index.js.map +1 -1
- package/modifiers/countModifier.d.ts +1 -1
- package/modifiers/countModifier.js +17 -41
- package/modifiers/countModifier.js.map +1 -1
- package/modifiers/dateModifier.d.ts +1 -1
- package/modifiers/dateModifier.js +9 -19
- package/modifiers/dateModifier.js.map +1 -1
- package/modifiers/dateTimeModifier.d.ts +1 -1
- package/modifiers/dateTimeModifier.js +9 -19
- package/modifiers/dateTimeModifier.js.map +1 -1
- package/modifiers/genderModifier.d.ts +1 -1
- package/modifiers/genderModifier.js +9 -19
- package/modifiers/genderModifier.js.map +1 -1
- package/modifiers/ifModifier.d.ts +1 -1
- package/modifiers/ifModifier.js +9 -19
- package/modifiers/ifModifier.js.map +1 -1
- package/modifiers/index.d.ts +1 -1
- package/modifiers/index.js +23 -31
- package/modifiers/index.js.map +1 -1
- package/modifiers/numberModifier.d.ts +1 -1
- package/modifiers/numberModifier.js +9 -19
- package/modifiers/numberModifier.js.map +1 -1
- package/modifiers/pluralModifier.d.ts +1 -1
- package/modifiers/pluralModifier.js +17 -40
- package/modifiers/pluralModifier.js.map +1 -1
- package/modifiers/priceModifier.d.ts +1 -1
- package/modifiers/priceModifier.js +9 -19
- package/modifiers/priceModifier.js.map +1 -1
- package/modifiers/timeModifier.d.ts +1 -1
- package/modifiers/timeModifier.js +9 -19
- package/modifiers/timeModifier.js.map +1 -1
- package/package.json +23 -29
- package/processors/default.d.ts +1 -1
- package/processors/default.js +34 -64
- package/processors/default.js.map +1 -1
- package/types.d.ts +3 -3
- package/types.js +0 -5
- package/types.js.map +0 -1
package/I18n.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Formats, I18NDataValues, Modifier, NumberFormat, PriceFormat, Processor, ProcessorResult, Translations, Translator } from "./types";
|
|
2
|
-
export
|
|
1
|
+
import type { Formats, I18NDataValues, Modifier, NumberFormat, PriceFormat, Processor, ProcessorResult, Translations, Translator } from "./types.js";
|
|
2
|
+
export type Translated = ((values: I18NDataValues) => ProcessorResult | null) | ProcessorResult | null;
|
|
3
3
|
/**
|
|
4
4
|
* Main class used for all I18n needs.
|
|
5
5
|
*/
|
package/I18n.js
CHANGED
|
@@ -1,445 +1,178 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "__esModule", {
|
|
8
|
-
value: true
|
|
9
|
-
});
|
|
10
|
-
exports.default = void 0;
|
|
11
|
-
|
|
12
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
-
|
|
14
|
-
var _accounting = _interopRequireDefault(require("accounting"));
|
|
15
|
-
|
|
16
|
-
var fecha = _interopRequireWildcard(require("fecha"));
|
|
17
|
-
|
|
18
|
-
var _shortHash = _interopRequireDefault(require("short-hash"));
|
|
19
|
-
|
|
20
|
-
var _assign = _interopRequireDefault(require("lodash/assign"));
|
|
21
|
-
|
|
22
|
-
var _get = _interopRequireDefault(require("lodash/get"));
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Package short-hash has no types.
|
|
26
|
-
*/
|
|
27
|
-
// @ts-ignore
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Main class used for all I18n needs.
|
|
31
|
-
*/
|
|
1
|
+
import accounting from "accounting";
|
|
2
|
+
import lodash_assign from "lodash/assign.js";
|
|
3
|
+
import get from "lodash/get.js";
|
|
4
|
+
import { hash } from "ohash";
|
|
5
|
+
import * as __rspack_external_fecha from "fecha";
|
|
32
6
|
class I18N {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* If we fail to fetch formats for currently selected locale, these default formats will be used.
|
|
42
|
-
* @type {{date: string, time: string, datetime: string, number: string}}
|
|
43
|
-
*/
|
|
44
|
-
this.defaultFormats = this.getDefaultFormats();
|
|
45
|
-
/**
|
|
46
|
-
* All currently-loaded translations, for easier (synchronous) access.
|
|
47
|
-
* @type {{}}
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
this.translations = {};
|
|
51
|
-
/**
|
|
52
|
-
* All registered modifiers.
|
|
53
|
-
* @type {{}}
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
this.modifiers = {};
|
|
57
|
-
/**
|
|
58
|
-
* All registered processors.
|
|
59
|
-
* Default built-in processors are registered immediately below.
|
|
60
|
-
* @type {{}}
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
this.processors = {};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
translate(base, namespace) {
|
|
67
|
-
// Returns full translation for given base text in given namespace (optional).
|
|
68
|
-
// If translation isn't found, base text will be returned.
|
|
69
|
-
// We create a key out of given namespace and base text.
|
|
70
|
-
if (!namespace) {
|
|
71
|
-
throw Error("I18N text namespace not defined.");
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
base = (0, _get.default)(base, "raw.0", base);
|
|
75
|
-
let translation = this.getTranslation(namespace + "." + (0, _shortHash.default)(base));
|
|
76
|
-
|
|
77
|
-
if (!translation) {
|
|
78
|
-
translation = base;
|
|
7
|
+
constructor(){
|
|
8
|
+
this.locale = null;
|
|
9
|
+
this.defaultFormats = this.getDefaultFormats();
|
|
10
|
+
this.translations = {};
|
|
11
|
+
this.modifiers = {};
|
|
12
|
+
this.processors = {};
|
|
79
13
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
14
|
+
translate(base, namespace) {
|
|
15
|
+
if (!namespace) throw Error("I18N text namespace not defined.");
|
|
16
|
+
base = get(base, "raw.0", base);
|
|
17
|
+
let translation = this.getTranslation(namespace + "." + hash(base));
|
|
18
|
+
if (!translation) translation = base;
|
|
19
|
+
const hasVariables = base.includes("{") && base.includes("}");
|
|
20
|
+
if (hasVariables) {
|
|
21
|
+
const $this = this;
|
|
22
|
+
return function(values) {
|
|
23
|
+
const data = {
|
|
24
|
+
translation: translation,
|
|
25
|
+
base,
|
|
26
|
+
namespace,
|
|
27
|
+
values,
|
|
28
|
+
i18n: $this
|
|
29
|
+
};
|
|
30
|
+
for(const key in $this.processors){
|
|
31
|
+
const processor = $this.processors[key];
|
|
32
|
+
if (processor.canExecute(data)) return processor.execute(data);
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
87
37
|
const data = {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
38
|
+
translation,
|
|
39
|
+
base,
|
|
40
|
+
namespace,
|
|
41
|
+
values: {},
|
|
42
|
+
i18n: this
|
|
93
43
|
};
|
|
94
|
-
|
|
95
|
-
for (const key in $this.processors) {
|
|
96
|
-
const processor = $this.processors[key];
|
|
97
|
-
|
|
98
|
-
if (processor.canExecute(data)) {
|
|
99
|
-
return processor.execute(data);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
44
|
+
for(const key in this.processors)if (this.processors[key].canExecute(data)) return this.processors[key].execute(data);
|
|
103
45
|
return null;
|
|
104
|
-
};
|
|
105
46
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
translation,
|
|
109
|
-
base,
|
|
110
|
-
namespace,
|
|
111
|
-
values: {},
|
|
112
|
-
i18n: this
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
for (const key in this.processors) {
|
|
116
|
-
if (this.processors[key].canExecute(data)) {
|
|
117
|
-
return this.processors[key].execute(data);
|
|
118
|
-
}
|
|
47
|
+
namespace(namespace) {
|
|
48
|
+
return (base)=>this.translate(base, namespace);
|
|
119
49
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
namespace(namespace) {
|
|
125
|
-
return base => {
|
|
126
|
-
return this.translate(base, namespace);
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
ns(namespace) {
|
|
131
|
-
return this.namespace(namespace);
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Formats and outputs date.
|
|
135
|
-
* It will try to load format from currently selected locale's settings. If not defined, default formats will be used.
|
|
136
|
-
*/
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
date(value, outputFormat, inputFormat) {
|
|
140
|
-
if (!outputFormat) {
|
|
141
|
-
outputFormat = this.getDateFormat();
|
|
50
|
+
ns(namespace) {
|
|
51
|
+
return this.namespace(namespace);
|
|
142
52
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
53
|
+
date(value, outputFormat, inputFormat) {
|
|
54
|
+
if (!outputFormat) outputFormat = this.getDateFormat();
|
|
55
|
+
if (!inputFormat) inputFormat = "YYYY-MM-DDTHH:mm:ss.SSSZ";
|
|
56
|
+
let parsedValue;
|
|
57
|
+
parsedValue = "string" == typeof value ? __rspack_external_fecha.parse(value, inputFormat) : value instanceof Date ? value : new Date(value);
|
|
58
|
+
return __rspack_external_fecha.format(parsedValue, outputFormat);
|
|
146
59
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
parsedValue = value;
|
|
60
|
+
time(value, outputFormat, inputFormat) {
|
|
61
|
+
if (!outputFormat) outputFormat = this.getTimeFormat();
|
|
62
|
+
if (!inputFormat) inputFormat = "YYYY-MM-DDTHH:mm:ss.SSSZ";
|
|
63
|
+
let parsedValue;
|
|
64
|
+
parsedValue = "string" == typeof value ? __rspack_external_fecha.parse(value, inputFormat) : value instanceof Date ? value : new Date(value);
|
|
65
|
+
return __rspack_external_fecha.format(parsedValue, outputFormat);
|
|
154
66
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
*/
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
time(value, outputFormat, inputFormat) {
|
|
165
|
-
if (!outputFormat) {
|
|
166
|
-
outputFormat = this.getTimeFormat();
|
|
67
|
+
dateTime(value, outputFormat, inputFormat) {
|
|
68
|
+
if (!outputFormat) outputFormat = this.getDateTimeFormat();
|
|
69
|
+
if (!inputFormat) inputFormat = "YYYY-MM-DDTHH:mm:ss.SSSZ";
|
|
70
|
+
let parsedValue;
|
|
71
|
+
parsedValue = "string" == typeof value ? __rspack_external_fecha.parse(value, inputFormat) : value instanceof Date ? value : new Date(value);
|
|
72
|
+
return __rspack_external_fecha.format(parsedValue, outputFormat);
|
|
167
73
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
74
|
+
price(value, outputFormat) {
|
|
75
|
+
outputFormat = outputFormat ? lodash_assign({}, this.defaultFormats.price, outputFormat) : this.getPriceFormat();
|
|
76
|
+
let format = outputFormat.format;
|
|
77
|
+
format = format.replace("{symbol}", "%s");
|
|
78
|
+
format = format.replace("{amount}", "%v");
|
|
79
|
+
return accounting.formatMoney(value, outputFormat.symbol, outputFormat.precision, outputFormat.thousand, outputFormat.decimal, format);
|
|
171
80
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (typeof value === "string") {
|
|
176
|
-
parsedValue = fecha.parse(value, inputFormat);
|
|
177
|
-
} else {
|
|
178
|
-
parsedValue = value;
|
|
81
|
+
number(value, outputFormat) {
|
|
82
|
+
outputFormat = outputFormat ? lodash_assign({}, this.defaultFormats.number, outputFormat) : this.getNumberFormat();
|
|
83
|
+
return accounting.formatNumber(value, outputFormat.precision, outputFormat.thousand, outputFormat.decimal);
|
|
179
84
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Formats and outputs date/time.
|
|
185
|
-
* It will try to load format from currently selected locale's settings. If not defined, default formats will be used.
|
|
186
|
-
*/
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
dateTime(value, outputFormat, inputFormat) {
|
|
190
|
-
if (!outputFormat) {
|
|
191
|
-
outputFormat = this.getDateTimeFormat();
|
|
85
|
+
getTranslation(key) {
|
|
86
|
+
if (!key) return null;
|
|
87
|
+
return this.translations[key];
|
|
192
88
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
inputFormat = "YYYY-MM-DDTHH:mm:ss.SSSZ";
|
|
89
|
+
getTranslations() {
|
|
90
|
+
return this.translations;
|
|
196
91
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
if (typeof value === "string") {
|
|
201
|
-
parsedValue = fecha.parse(value, inputFormat);
|
|
202
|
-
} else {
|
|
203
|
-
parsedValue = value;
|
|
92
|
+
hasTranslation(key) {
|
|
93
|
+
return key in this.translations;
|
|
204
94
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Outputs formatted number as amount of price.
|
|
210
|
-
*/
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
price(value, outputFormat) {
|
|
214
|
-
if (!outputFormat) {
|
|
215
|
-
outputFormat = this.getPriceFormat();
|
|
216
|
-
} else {
|
|
217
|
-
outputFormat = (0, _assign.default)({}, this.defaultFormats.price, outputFormat);
|
|
218
|
-
} // Convert placeholders to accounting's placeholders.
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
let format = outputFormat.format;
|
|
222
|
-
format = format.replace("{symbol}", "%s");
|
|
223
|
-
format = format.replace("{amount}", "%v");
|
|
224
|
-
return _accounting.default.formatMoney(value, outputFormat.symbol, outputFormat.precision, outputFormat.thousand, outputFormat.decimal, format);
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Outputs formatted number.
|
|
228
|
-
*/
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
number(value, outputFormat) {
|
|
232
|
-
if (!outputFormat) {
|
|
233
|
-
outputFormat = this.getNumberFormat();
|
|
234
|
-
} else {
|
|
235
|
-
outputFormat = (0, _assign.default)({}, this.defaultFormats.number, outputFormat);
|
|
95
|
+
setTranslation(key, translation) {
|
|
96
|
+
this.translations[key] = translation;
|
|
97
|
+
return this;
|
|
236
98
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
99
|
+
setTranslations(translations) {
|
|
100
|
+
this.translations = translations;
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
clearTranslations() {
|
|
104
|
+
this.setTranslations({});
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
mergeTranslations(translations) {
|
|
108
|
+
return lodash_assign(this.translations, translations);
|
|
109
|
+
}
|
|
110
|
+
getLocale() {
|
|
111
|
+
return this.locale;
|
|
112
|
+
}
|
|
113
|
+
setLocale(locale) {
|
|
114
|
+
this.locale = locale;
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
registerModifier(modifier) {
|
|
118
|
+
this.modifiers[modifier.name] = modifier;
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
registerModifiers(modifiers) {
|
|
122
|
+
modifiers.forEach((modifier)=>this.registerModifier(modifier));
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
unregisterModifier(name) {
|
|
126
|
+
delete this.modifiers[name];
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
registerProcessor(processor) {
|
|
130
|
+
this.processors[processor.name] = processor;
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
registerProcessors(processors) {
|
|
134
|
+
processors.forEach((processor)=>this.registerProcessor(processor));
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
unregisterProcessor(name) {
|
|
138
|
+
delete this.processors[name];
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
getDefaultFormats() {
|
|
142
|
+
return {
|
|
143
|
+
date: "DD/MM/YYYY",
|
|
144
|
+
time: "HH:mm",
|
|
145
|
+
datetime: "DD/MM/YYYY HH:mm",
|
|
146
|
+
price: {
|
|
147
|
+
symbol: "",
|
|
148
|
+
format: "{symbol}{amount}",
|
|
149
|
+
decimal: ".",
|
|
150
|
+
thousand: ",",
|
|
151
|
+
precision: 2
|
|
152
|
+
},
|
|
153
|
+
number: {
|
|
154
|
+
decimal: ".",
|
|
155
|
+
thousand: ",",
|
|
156
|
+
precision: 2
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
getDateFormat() {
|
|
161
|
+
return get(this.locale, "formats.date", this.defaultFormats.date);
|
|
162
|
+
}
|
|
163
|
+
getTimeFormat() {
|
|
164
|
+
return get(this.locale, "formats.time", this.defaultFormats.time);
|
|
165
|
+
}
|
|
166
|
+
getDateTimeFormat() {
|
|
167
|
+
return get(this.locale, "formats.datetime", this.defaultFormats.datetime);
|
|
168
|
+
}
|
|
169
|
+
getPriceFormat() {
|
|
170
|
+
return lodash_assign({}, this.defaultFormats.price, get(this.locale, "formats.price", {}));
|
|
171
|
+
}
|
|
172
|
+
getNumberFormat() {
|
|
173
|
+
return lodash_assign({}, this.defaultFormats.number, get(this.locale, "formats.number", {}));
|
|
252
174
|
}
|
|
253
|
-
|
|
254
|
-
return this.translations[key];
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Returns all translations for current locale.
|
|
258
|
-
*/
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
getTranslations() {
|
|
262
|
-
return this.translations;
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Returns true if given key has a translation for currently set locale.
|
|
266
|
-
*/
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
hasTranslation(key) {
|
|
270
|
-
return key in this.translations;
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Sets translation for given text key.
|
|
274
|
-
*/
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
setTranslation(key, translation) {
|
|
278
|
-
this.translations[key] = translation;
|
|
279
|
-
return this;
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Sets translations that will be used.
|
|
283
|
-
*/
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
setTranslations(translations) {
|
|
287
|
-
this.translations = translations;
|
|
288
|
-
return this;
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Clears all translations.
|
|
292
|
-
*/
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
clearTranslations() {
|
|
296
|
-
this.setTranslations({});
|
|
297
|
-
return this;
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Merges given translations object with already existing.
|
|
301
|
-
*/
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
mergeTranslations(translations) {
|
|
305
|
-
return (0, _assign.default)(this.translations, translations);
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
308
|
-
* Returns currently selected locale (locale's key).
|
|
309
|
-
*/
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
getLocale() {
|
|
313
|
-
return this.locale;
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Sets current locale.
|
|
317
|
-
*/
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
setLocale(locale) {
|
|
321
|
-
this.locale = locale;
|
|
322
|
-
return this;
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* Registers single modifier.
|
|
326
|
-
*/
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
registerModifier(modifier) {
|
|
330
|
-
this.modifiers[modifier.name] = modifier;
|
|
331
|
-
return this;
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Registers all modifiers in given array.
|
|
335
|
-
*/
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
registerModifiers(modifiers) {
|
|
339
|
-
modifiers.forEach(modifier => this.registerModifier(modifier));
|
|
340
|
-
return this;
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Unregisters given modifier.
|
|
344
|
-
*/
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
unregisterModifier(name) {
|
|
348
|
-
delete this.modifiers[name];
|
|
349
|
-
return this;
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* Registers single processor.
|
|
353
|
-
*/
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
registerProcessor(processor) {
|
|
357
|
-
this.processors[processor.name] = processor;
|
|
358
|
-
return this;
|
|
359
|
-
}
|
|
360
|
-
/**
|
|
361
|
-
* Registers all processors in given array.
|
|
362
|
-
*/
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
registerProcessors(processors) {
|
|
366
|
-
processors.forEach(processor => this.registerProcessor(processor));
|
|
367
|
-
return this;
|
|
368
|
-
}
|
|
369
|
-
/**
|
|
370
|
-
* Unregisters given processor.
|
|
371
|
-
*/
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
unregisterProcessor(name) {
|
|
375
|
-
delete this.processors[name];
|
|
376
|
-
return this;
|
|
377
|
-
}
|
|
378
|
-
/**
|
|
379
|
-
* Returns default formats
|
|
380
|
-
*/
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
getDefaultFormats() {
|
|
384
|
-
return {
|
|
385
|
-
date: "DD/MM/YYYY",
|
|
386
|
-
time: "HH:mm",
|
|
387
|
-
datetime: "DD/MM/YYYY HH:mm",
|
|
388
|
-
price: {
|
|
389
|
-
symbol: "",
|
|
390
|
-
format: "{symbol}{amount}",
|
|
391
|
-
decimal: ".",
|
|
392
|
-
thousand: ",",
|
|
393
|
-
precision: 2
|
|
394
|
-
},
|
|
395
|
-
number: {
|
|
396
|
-
decimal: ".",
|
|
397
|
-
thousand: ",",
|
|
398
|
-
precision: 2
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* Returns current format to be used when outputting dates.
|
|
404
|
-
*/
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
getDateFormat() {
|
|
408
|
-
return (0, _get.default)(this.locale, "formats.date", this.defaultFormats.date);
|
|
409
|
-
}
|
|
410
|
-
/**
|
|
411
|
-
* Returns current format to be used when outputting time.
|
|
412
|
-
*/
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
getTimeFormat() {
|
|
416
|
-
return (0, _get.default)(this.locale, "formats.time", this.defaultFormats.time);
|
|
417
|
-
}
|
|
418
|
-
/**
|
|
419
|
-
* Returns current format to be used when outputting date/time.
|
|
420
|
-
*/
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
getDateTimeFormat() {
|
|
424
|
-
return (0, _get.default)(this.locale, "formats.datetime", this.defaultFormats.datetime);
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Returns current format to be used when outputting prices.
|
|
428
|
-
*/
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
getPriceFormat() {
|
|
432
|
-
return (0, _assign.default)({}, this.defaultFormats.price, (0, _get.default)(this.locale, "formats.price", {}));
|
|
433
|
-
}
|
|
434
|
-
/**
|
|
435
|
-
* Returns current format to be used when outputting numbers.
|
|
436
|
-
*/
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
getNumberFormat() {
|
|
440
|
-
return (0, _assign.default)({}, this.defaultFormats.number, (0, _get.default)(this.locale, "formats.number", {}));
|
|
441
|
-
}
|
|
442
|
-
|
|
443
175
|
}
|
|
176
|
+
export default I18N;
|
|
444
177
|
|
|
445
|
-
|
|
178
|
+
//# sourceMappingURL=I18n.js.map
|