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