@webiny/i18n 0.0.0-ee-vpcs.549378cf03
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 +127 -0
- package/I18n.js +445 -0
- package/I18n.js.map +1 -0
- package/LICENSE +21 -0
- package/README.md +17 -0
- package/extractor/extract.d.ts +2 -0
- package/extractor/extract.js +62 -0
- package/extractor/extract.js.map +1 -0
- package/extractor/index.d.ts +13 -0
- package/extractor/index.js +64 -0
- package/extractor/index.js.map +1 -0
- package/index.d.ts +6 -0
- package/index.js +34 -0
- package/index.js.map +1 -0
- package/modifiers/countModifier.d.ts +3 -0
- package/modifiers/countModifier.js +43 -0
- package/modifiers/countModifier.js.map +1 -0
- package/modifiers/dateModifier.d.ts +3 -0
- package/modifiers/dateModifier.js +19 -0
- package/modifiers/dateModifier.js.map +1 -0
- package/modifiers/dateTimeModifier.d.ts +3 -0
- package/modifiers/dateTimeModifier.js +19 -0
- package/modifiers/dateTimeModifier.js.map +1 -0
- package/modifiers/genderModifier.d.ts +3 -0
- package/modifiers/genderModifier.js +19 -0
- package/modifiers/genderModifier.js.map +1 -0
- package/modifiers/ifModifier.d.ts +3 -0
- package/modifiers/ifModifier.js +19 -0
- package/modifiers/ifModifier.js.map +1 -0
- package/modifiers/index.d.ts +3 -0
- package/modifiers/index.js +31 -0
- package/modifiers/index.js.map +1 -0
- package/modifiers/numberModifier.d.ts +3 -0
- package/modifiers/numberModifier.js +19 -0
- package/modifiers/numberModifier.js.map +1 -0
- package/modifiers/pluralModifier.d.ts +3 -0
- package/modifiers/pluralModifier.js +42 -0
- package/modifiers/pluralModifier.js.map +1 -0
- package/modifiers/priceModifier.d.ts +3 -0
- package/modifiers/priceModifier.js +19 -0
- package/modifiers/priceModifier.js.map +1 -0
- package/modifiers/timeModifier.d.ts +3 -0
- package/modifiers/timeModifier.js +19 -0
- package/modifiers/timeModifier.js.map +1 -0
- package/package.json +51 -0
- package/processors/default.d.ts +3 -0
- package/processors/default.js +69 -0
- package/processors/default.js.map +1 -0
- package/types.d.ts +56 -0
- package/types.js +5 -0
- package/types.js.map +1 -0
package/I18n.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Formats, I18NDataValues, Modifier, NumberFormat, PriceFormat, Processor, ProcessorResult, Translations, Translator } from "./types";
|
|
2
|
+
export declare type Translated = ((values: I18NDataValues) => ProcessorResult | null) | ProcessorResult | null;
|
|
3
|
+
/**
|
|
4
|
+
* Main class used for all I18n needs.
|
|
5
|
+
*/
|
|
6
|
+
export default class I18N {
|
|
7
|
+
locale: string | null;
|
|
8
|
+
defaultFormats: Formats;
|
|
9
|
+
translations: Translations;
|
|
10
|
+
modifiers: {
|
|
11
|
+
[name: string]: Modifier;
|
|
12
|
+
};
|
|
13
|
+
processors: {
|
|
14
|
+
[name: string]: Processor;
|
|
15
|
+
};
|
|
16
|
+
constructor();
|
|
17
|
+
translate(base: string, namespace?: string): Translated;
|
|
18
|
+
namespace(namespace: string): Translator;
|
|
19
|
+
ns(namespace: string): Translator;
|
|
20
|
+
/**
|
|
21
|
+
* Formats and outputs date.
|
|
22
|
+
* It will try to load format from currently selected locale's settings. If not defined, default formats will be used.
|
|
23
|
+
*/
|
|
24
|
+
date(value: Date | string | number, outputFormat?: string, inputFormat?: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Formats and outputs time.
|
|
27
|
+
* It will try to load format from currently selected locale's settings. If not defined, default formats will be used.
|
|
28
|
+
*/
|
|
29
|
+
time(value: Date | string | number, outputFormat?: string, inputFormat?: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Formats and outputs date/time.
|
|
32
|
+
* It will try to load format from currently selected locale's settings. If not defined, default formats will be used.
|
|
33
|
+
*/
|
|
34
|
+
dateTime(value: Date | string | number, outputFormat?: string, inputFormat?: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Outputs formatted number as amount of price.
|
|
37
|
+
*/
|
|
38
|
+
price(value: string | number, outputFormat?: any): string;
|
|
39
|
+
/**
|
|
40
|
+
* Outputs formatted number.
|
|
41
|
+
*/
|
|
42
|
+
number(value: string | number, outputFormat?: NumberFormat): string;
|
|
43
|
+
/**
|
|
44
|
+
* Returns translation for given text key.
|
|
45
|
+
*/
|
|
46
|
+
getTranslation(key?: string): string | null;
|
|
47
|
+
/**
|
|
48
|
+
* Returns all translations for current locale.
|
|
49
|
+
*/
|
|
50
|
+
getTranslations(): Translations;
|
|
51
|
+
/**
|
|
52
|
+
* Returns true if given key has a translation for currently set locale.
|
|
53
|
+
*/
|
|
54
|
+
hasTranslation(key: string): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Sets translation for given text key.
|
|
57
|
+
*/
|
|
58
|
+
setTranslation(key: string, translation: string): I18N;
|
|
59
|
+
/**
|
|
60
|
+
* Sets translations that will be used.
|
|
61
|
+
*/
|
|
62
|
+
setTranslations(translations: Translations): I18N;
|
|
63
|
+
/**
|
|
64
|
+
* Clears all translations.
|
|
65
|
+
*/
|
|
66
|
+
clearTranslations(): I18N;
|
|
67
|
+
/**
|
|
68
|
+
* Merges given translations object with already existing.
|
|
69
|
+
*/
|
|
70
|
+
mergeTranslations(translations: Translations): Translations;
|
|
71
|
+
/**
|
|
72
|
+
* Returns currently selected locale (locale's key).
|
|
73
|
+
*/
|
|
74
|
+
getLocale(): null | string;
|
|
75
|
+
/**
|
|
76
|
+
* Sets current locale.
|
|
77
|
+
*/
|
|
78
|
+
setLocale(locale: string): I18N;
|
|
79
|
+
/**
|
|
80
|
+
* Registers single modifier.
|
|
81
|
+
*/
|
|
82
|
+
registerModifier(modifier: Modifier): I18N;
|
|
83
|
+
/**
|
|
84
|
+
* Registers all modifiers in given array.
|
|
85
|
+
*/
|
|
86
|
+
registerModifiers(modifiers: Array<Modifier>): I18N;
|
|
87
|
+
/**
|
|
88
|
+
* Unregisters given modifier.
|
|
89
|
+
*/
|
|
90
|
+
unregisterModifier(name: string): I18N;
|
|
91
|
+
/**
|
|
92
|
+
* Registers single processor.
|
|
93
|
+
*/
|
|
94
|
+
registerProcessor(processor: Processor): I18N;
|
|
95
|
+
/**
|
|
96
|
+
* Registers all processors in given array.
|
|
97
|
+
*/
|
|
98
|
+
registerProcessors(processors: Array<Processor>): I18N;
|
|
99
|
+
/**
|
|
100
|
+
* Unregisters given processor.
|
|
101
|
+
*/
|
|
102
|
+
unregisterProcessor(name: string): I18N;
|
|
103
|
+
/**
|
|
104
|
+
* Returns default formats
|
|
105
|
+
*/
|
|
106
|
+
getDefaultFormats(): Formats;
|
|
107
|
+
/**
|
|
108
|
+
* Returns current format to be used when outputting dates.
|
|
109
|
+
*/
|
|
110
|
+
getDateFormat(): string;
|
|
111
|
+
/**
|
|
112
|
+
* Returns current format to be used when outputting time.
|
|
113
|
+
*/
|
|
114
|
+
getTimeFormat(): string;
|
|
115
|
+
/**
|
|
116
|
+
* Returns current format to be used when outputting date/time.
|
|
117
|
+
*/
|
|
118
|
+
getDateTimeFormat(): string;
|
|
119
|
+
/**
|
|
120
|
+
* Returns current format to be used when outputting prices.
|
|
121
|
+
*/
|
|
122
|
+
getPriceFormat(): PriceFormat;
|
|
123
|
+
/**
|
|
124
|
+
* Returns current format to be used when outputting numbers.
|
|
125
|
+
*/
|
|
126
|
+
getNumberFormat(): NumberFormat;
|
|
127
|
+
}
|
package/I18n.js
ADDED
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
+
|
|
5
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
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
|
+
*/
|
|
32
|
+
class I18N {
|
|
33
|
+
constructor() {
|
|
34
|
+
(0, _defineProperty2.default)(this, "locale", null);
|
|
35
|
+
(0, _defineProperty2.default)(this, "defaultFormats", void 0);
|
|
36
|
+
(0, _defineProperty2.default)(this, "translations", void 0);
|
|
37
|
+
(0, _defineProperty2.default)(this, "modifiers", void 0);
|
|
38
|
+
(0, _defineProperty2.default)(this, "processors", void 0);
|
|
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;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const hasVariables = base.includes("{") && base.includes("}");
|
|
82
|
+
|
|
83
|
+
if (hasVariables) {
|
|
84
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
85
|
+
const $this = this;
|
|
86
|
+
return function i18n(values) {
|
|
87
|
+
const data = {
|
|
88
|
+
translation: translation,
|
|
89
|
+
base,
|
|
90
|
+
namespace,
|
|
91
|
+
values,
|
|
92
|
+
i18n: $this
|
|
93
|
+
};
|
|
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
|
+
|
|
103
|
+
return null;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const data = {
|
|
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
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return null;
|
|
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();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (!inputFormat) {
|
|
145
|
+
inputFormat = "YYYY-MM-DDTHH:mm:ss.SSSZ";
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
let parsedValue;
|
|
149
|
+
|
|
150
|
+
if (typeof value === "string") {
|
|
151
|
+
parsedValue = fecha.parse(value, inputFormat);
|
|
152
|
+
} else {
|
|
153
|
+
parsedValue = value;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return fecha.format(parsedValue, outputFormat);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Formats and outputs time.
|
|
160
|
+
* It will try to load format from currently selected locale's settings. If not defined, default formats will be used.
|
|
161
|
+
*/
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
time(value, outputFormat, inputFormat) {
|
|
165
|
+
if (!outputFormat) {
|
|
166
|
+
outputFormat = this.getTimeFormat();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (!inputFormat) {
|
|
170
|
+
inputFormat = "YYYY-MM-DDTHH:mm:ss.SSSZ";
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
let parsedValue;
|
|
174
|
+
|
|
175
|
+
if (typeof value === "string") {
|
|
176
|
+
parsedValue = fecha.parse(value, inputFormat);
|
|
177
|
+
} else {
|
|
178
|
+
parsedValue = value;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return fecha.format(parsedValue, outputFormat);
|
|
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();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (!inputFormat) {
|
|
195
|
+
inputFormat = "YYYY-MM-DDTHH:mm:ss.SSSZ";
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
let parsedValue;
|
|
199
|
+
|
|
200
|
+
if (typeof value === "string") {
|
|
201
|
+
parsedValue = fecha.parse(value, inputFormat);
|
|
202
|
+
} else {
|
|
203
|
+
parsedValue = value;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return fecha.format(parsedValue, outputFormat);
|
|
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);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return _accounting.default.formatNumber(
|
|
239
|
+
/**
|
|
240
|
+
* Cast as number because method transforms it internally.
|
|
241
|
+
*/
|
|
242
|
+
value, outputFormat.precision, outputFormat.thousand, outputFormat.decimal);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Returns translation for given text key.
|
|
246
|
+
*/
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
getTranslation(key) {
|
|
250
|
+
if (!key) {
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
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
|
+
}
|
|
444
|
+
|
|
445
|
+
exports.default = I18N;
|
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;I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C,MAFjB,EAGH,IAAAtC,YAAA,EAAU,KAAKgD,MAAf,EAAuB,gBAAvB,EAAyC,EAAzC,CAHG,CAAP;EAKH;;AAjZqB"}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @webiny/i18n
|
|
2
|
+
[](https://www.npmjs.com/package/@webiny/i18n)
|
|
3
|
+
[](https://www.npmjs.com/package/@webiny/i18n)
|
|
4
|
+
[](https://github.com/prettier/prettier)
|
|
5
|
+
[](http://makeapullrequest.com)
|
|
6
|
+
|
|
7
|
+
A simple I18N library, for frontend and backend apps.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
```
|
|
11
|
+
npm install --save @webiny/i18n
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Or if you prefer yarn:
|
|
15
|
+
```
|
|
16
|
+
yarn add @webiny/i18n
|
|
17
|
+
```
|