@webiny/i18n 0.0.0-unstable.bca7b3e350 β†’ 0.0.0-unstable.c27f4d8a31

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.
Files changed (48) hide show
  1. package/I18n.d.ts +2 -2
  2. package/I18n.js +53 -129
  3. package/I18n.js.map +1 -1
  4. package/README.md +7 -13
  5. package/extractor/extract.js +7 -24
  6. package/extractor/extract.js.map +1 -1
  7. package/extractor/index.js +10 -37
  8. package/extractor/index.js.map +1 -1
  9. package/index.d.ts +3 -3
  10. package/index.js +9 -32
  11. package/index.js.map +1 -1
  12. package/modifiers/countModifier.d.ts +1 -1
  13. package/modifiers/countModifier.js +6 -18
  14. package/modifiers/countModifier.js.map +1 -1
  15. package/modifiers/dateModifier.d.ts +1 -1
  16. package/modifiers/dateModifier.js +2 -11
  17. package/modifiers/dateModifier.js.map +1 -1
  18. package/modifiers/dateTimeModifier.d.ts +1 -1
  19. package/modifiers/dateTimeModifier.js +2 -11
  20. package/modifiers/dateTimeModifier.js.map +1 -1
  21. package/modifiers/genderModifier.d.ts +1 -1
  22. package/modifiers/genderModifier.js +2 -11
  23. package/modifiers/genderModifier.js.map +1 -1
  24. package/modifiers/ifModifier.d.ts +1 -1
  25. package/modifiers/ifModifier.js +2 -11
  26. package/modifiers/ifModifier.js.map +1 -1
  27. package/modifiers/index.d.ts +1 -1
  28. package/modifiers/index.js +12 -30
  29. package/modifiers/index.js.map +1 -1
  30. package/modifiers/numberModifier.d.ts +1 -1
  31. package/modifiers/numberModifier.js +2 -11
  32. package/modifiers/numberModifier.js.map +1 -1
  33. package/modifiers/pluralModifier.d.ts +1 -1
  34. package/modifiers/pluralModifier.js +4 -17
  35. package/modifiers/pluralModifier.js.map +1 -1
  36. package/modifiers/priceModifier.d.ts +1 -1
  37. package/modifiers/priceModifier.js +2 -11
  38. package/modifiers/priceModifier.js.map +1 -1
  39. package/modifiers/timeModifier.d.ts +1 -1
  40. package/modifiers/timeModifier.js +2 -11
  41. package/modifiers/timeModifier.js.map +1 -1
  42. package/package.json +15 -24
  43. package/processors/default.d.ts +1 -1
  44. package/processors/default.js +7 -29
  45. package/processors/default.js.map +1 -1
  46. package/types.d.ts +3 -3
  47. package/types.js +2 -4
  48. package/types.js.map +1 -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 declare type Translated = ((values: I18NDataValues) => ProcessorResult | null) | ProcessorResult | null;
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,85 +1,57 @@
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
-
1
+ import accounting from "accounting";
2
+ import * as fecha from "fecha";
24
3
  /**
25
4
  * Package short-hash has no types.
26
5
  */
27
- // @ts-ignore
28
-
6
+ // @ts-expect-error
7
+ import hash from "short-hash";
8
+ import lodashAssign from "lodash/assign.js";
9
+ import lodashGet from "lodash/get.js";
29
10
  /**
30
11
  * Main class used for all I18n needs.
31
12
  */
32
- class I18N {
13
+ export default class I18N {
14
+ locale = null;
33
15
  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
16
  /**
41
17
  * If we fail to fetch formats for currently selected locale, these default formats will be used.
42
18
  * @type {{date: string, time: string, datetime: string, number: string}}
43
19
  */
44
20
  this.defaultFormats = this.getDefaultFormats();
21
+
45
22
  /**
46
23
  * All currently-loaded translations, for easier (synchronous) access.
47
24
  * @type {{}}
48
25
  */
49
-
50
26
  this.translations = {};
27
+
51
28
  /**
52
29
  * All registered modifiers.
53
30
  * @type {{}}
54
31
  */
55
-
56
32
  this.modifiers = {};
33
+
57
34
  /**
58
35
  * All registered processors.
59
36
  * Default built-in processors are registered immediately below.
60
37
  * @type {{}}
61
38
  */
62
-
63
39
  this.processors = {};
64
40
  }
65
-
66
41
  translate(base, namespace) {
67
42
  // Returns full translation for given base text in given namespace (optional).
68
43
  // If translation isn't found, base text will be returned.
69
44
  // We create a key out of given namespace and base text.
45
+
70
46
  if (!namespace) {
71
47
  throw Error("I18N text namespace not defined.");
72
48
  }
73
-
74
- base = (0, _get.default)(base, "raw.0", base);
75
- let translation = this.getTranslation(namespace + "." + (0, _shortHash.default)(base));
76
-
49
+ base = lodashGet(base, "raw.0", base);
50
+ let translation = this.getTranslation(namespace + "." + hash(base));
77
51
  if (!translation) {
78
52
  translation = base;
79
53
  }
80
-
81
54
  const hasVariables = base.includes("{") && base.includes("}");
82
-
83
55
  if (hasVariables) {
84
56
  // eslint-disable-next-line @typescript-eslint/no-this-alias
85
57
  const $this = this;
@@ -91,19 +63,15 @@ class I18N {
91
63
  values,
92
64
  i18n: $this
93
65
  };
94
-
95
66
  for (const key in $this.processors) {
96
67
  const processor = $this.processors[key];
97
-
98
68
  if (processor.canExecute(data)) {
99
69
  return processor.execute(data);
100
70
  }
101
71
  }
102
-
103
72
  return null;
104
73
  };
105
74
  }
106
-
107
75
  const data = {
108
76
  translation,
109
77
  base,
@@ -111,275 +79,237 @@ class I18N {
111
79
  values: {},
112
80
  i18n: this
113
81
  };
114
-
115
82
  for (const key in this.processors) {
116
83
  if (this.processors[key].canExecute(data)) {
117
84
  return this.processors[key].execute(data);
118
85
  }
119
86
  }
120
-
121
87
  return null;
122
88
  }
123
-
124
89
  namespace(namespace) {
125
90
  return base => {
126
91
  return this.translate(base, namespace);
127
92
  };
128
93
  }
129
-
130
94
  ns(namespace) {
131
95
  return this.namespace(namespace);
132
96
  }
97
+
133
98
  /**
134
99
  * Formats and outputs date.
135
100
  * It will try to load format from currently selected locale's settings. If not defined, default formats will be used.
136
101
  */
137
-
138
-
139
102
  date(value, outputFormat, inputFormat) {
140
103
  if (!outputFormat) {
141
104
  outputFormat = this.getDateFormat();
142
105
  }
143
-
144
106
  if (!inputFormat) {
145
107
  inputFormat = "YYYY-MM-DDTHH:mm:ss.SSSZ";
146
108
  }
147
-
148
109
  let parsedValue;
149
-
150
110
  if (typeof value === "string") {
151
111
  parsedValue = fecha.parse(value, inputFormat);
152
112
  } else {
153
113
  parsedValue = value;
154
114
  }
155
-
156
115
  return fecha.format(parsedValue, outputFormat);
157
116
  }
117
+
158
118
  /**
159
119
  * Formats and outputs time.
160
120
  * It will try to load format from currently selected locale's settings. If not defined, default formats will be used.
161
121
  */
162
-
163
-
164
122
  time(value, outputFormat, inputFormat) {
165
123
  if (!outputFormat) {
166
124
  outputFormat = this.getTimeFormat();
167
125
  }
168
-
169
126
  if (!inputFormat) {
170
127
  inputFormat = "YYYY-MM-DDTHH:mm:ss.SSSZ";
171
128
  }
172
-
173
129
  let parsedValue;
174
-
175
130
  if (typeof value === "string") {
176
131
  parsedValue = fecha.parse(value, inputFormat);
177
132
  } else {
178
133
  parsedValue = value;
179
134
  }
180
-
181
135
  return fecha.format(parsedValue, outputFormat);
182
136
  }
137
+
183
138
  /**
184
139
  * Formats and outputs date/time.
185
140
  * It will try to load format from currently selected locale's settings. If not defined, default formats will be used.
186
141
  */
187
-
188
-
189
142
  dateTime(value, outputFormat, inputFormat) {
190
143
  if (!outputFormat) {
191
144
  outputFormat = this.getDateTimeFormat();
192
145
  }
193
-
194
146
  if (!inputFormat) {
195
147
  inputFormat = "YYYY-MM-DDTHH:mm:ss.SSSZ";
196
148
  }
197
-
198
149
  let parsedValue;
199
-
200
150
  if (typeof value === "string") {
201
151
  parsedValue = fecha.parse(value, inputFormat);
202
152
  } else {
203
153
  parsedValue = value;
204
154
  }
205
-
206
155
  return fecha.format(parsedValue, outputFormat);
207
156
  }
157
+
208
158
  /**
209
159
  * Outputs formatted number as amount of price.
210
160
  */
211
-
212
-
213
161
  price(value, outputFormat) {
214
162
  if (!outputFormat) {
215
163
  outputFormat = this.getPriceFormat();
216
164
  } else {
217
- outputFormat = (0, _assign.default)({}, this.defaultFormats.price, outputFormat);
218
- } // Convert placeholders to accounting's placeholders.
219
-
165
+ outputFormat = lodashAssign({}, this.defaultFormats.price, outputFormat);
166
+ }
220
167
 
168
+ // Convert placeholders to accounting's placeholders.
221
169
  let format = outputFormat.format;
222
170
  format = format.replace("{symbol}", "%s");
223
171
  format = format.replace("{amount}", "%v");
224
- return _accounting.default.formatMoney(value, outputFormat.symbol, outputFormat.precision, outputFormat.thousand, outputFormat.decimal, format);
172
+ return accounting.formatMoney(value, outputFormat.symbol, outputFormat.precision, outputFormat.thousand, outputFormat.decimal, format);
225
173
  }
174
+
226
175
  /**
227
176
  * Outputs formatted number.
228
177
  */
229
-
230
-
231
178
  number(value, outputFormat) {
232
179
  if (!outputFormat) {
233
180
  outputFormat = this.getNumberFormat();
234
181
  } else {
235
- outputFormat = (0, _assign.default)({}, this.defaultFormats.number, outputFormat);
182
+ outputFormat = lodashAssign({}, this.defaultFormats.number, outputFormat);
236
183
  }
237
-
238
- return _accounting.default.formatNumber(
184
+ return accounting.formatNumber(
239
185
  /**
240
186
  * Cast as number because method transforms it internally.
241
187
  */
242
188
  value, outputFormat.precision, outputFormat.thousand, outputFormat.decimal);
243
189
  }
190
+
244
191
  /**
245
192
  * Returns translation for given text key.
246
193
  */
247
-
248
-
249
194
  getTranslation(key) {
250
195
  if (!key) {
251
196
  return null;
252
197
  }
253
-
254
198
  return this.translations[key];
255
199
  }
200
+
256
201
  /**
257
202
  * Returns all translations for current locale.
258
203
  */
259
-
260
-
261
204
  getTranslations() {
262
205
  return this.translations;
263
206
  }
207
+
264
208
  /**
265
209
  * Returns true if given key has a translation for currently set locale.
266
210
  */
267
-
268
-
269
211
  hasTranslation(key) {
270
212
  return key in this.translations;
271
213
  }
214
+
272
215
  /**
273
216
  * Sets translation for given text key.
274
217
  */
275
-
276
-
277
218
  setTranslation(key, translation) {
278
219
  this.translations[key] = translation;
279
220
  return this;
280
221
  }
222
+
281
223
  /**
282
224
  * Sets translations that will be used.
283
225
  */
284
-
285
-
286
226
  setTranslations(translations) {
287
227
  this.translations = translations;
288
228
  return this;
289
229
  }
230
+
290
231
  /**
291
232
  * Clears all translations.
292
233
  */
293
-
294
-
295
234
  clearTranslations() {
296
235
  this.setTranslations({});
297
236
  return this;
298
237
  }
238
+
299
239
  /**
300
240
  * Merges given translations object with already existing.
301
241
  */
302
242
 
303
-
304
243
  mergeTranslations(translations) {
305
- return (0, _assign.default)(this.translations, translations);
244
+ return lodashAssign(this.translations, translations);
306
245
  }
246
+
307
247
  /**
308
248
  * Returns currently selected locale (locale's key).
309
249
  */
310
-
311
-
312
250
  getLocale() {
313
251
  return this.locale;
314
252
  }
253
+
315
254
  /**
316
255
  * Sets current locale.
317
256
  */
318
-
319
-
320
257
  setLocale(locale) {
321
258
  this.locale = locale;
322
259
  return this;
323
260
  }
261
+
324
262
  /**
325
263
  * Registers single modifier.
326
264
  */
327
-
328
-
329
265
  registerModifier(modifier) {
330
266
  this.modifiers[modifier.name] = modifier;
331
267
  return this;
332
268
  }
269
+
333
270
  /**
334
271
  * Registers all modifiers in given array.
335
272
  */
336
-
337
-
338
273
  registerModifiers(modifiers) {
339
274
  modifiers.forEach(modifier => this.registerModifier(modifier));
340
275
  return this;
341
276
  }
277
+
342
278
  /**
343
279
  * Unregisters given modifier.
344
280
  */
345
-
346
-
347
281
  unregisterModifier(name) {
348
282
  delete this.modifiers[name];
349
283
  return this;
350
284
  }
285
+
351
286
  /**
352
287
  * Registers single processor.
353
288
  */
354
-
355
-
356
289
  registerProcessor(processor) {
357
290
  this.processors[processor.name] = processor;
358
291
  return this;
359
292
  }
293
+
360
294
  /**
361
295
  * Registers all processors in given array.
362
296
  */
363
-
364
-
365
297
  registerProcessors(processors) {
366
298
  processors.forEach(processor => this.registerProcessor(processor));
367
299
  return this;
368
300
  }
301
+
369
302
  /**
370
303
  * Unregisters given processor.
371
304
  */
372
-
373
-
374
305
  unregisterProcessor(name) {
375
306
  delete this.processors[name];
376
307
  return this;
377
308
  }
309
+
378
310
  /**
379
311
  * Returns default formats
380
312
  */
381
-
382
-
383
313
  getDefaultFormats() {
384
314
  return {
385
315
  date: "DD/MM/YYYY",
@@ -399,47 +329,41 @@ class I18N {
399
329
  }
400
330
  };
401
331
  }
332
+
402
333
  /**
403
334
  * Returns current format to be used when outputting dates.
404
335
  */
405
-
406
-
407
336
  getDateFormat() {
408
- return (0, _get.default)(this.locale, "formats.date", this.defaultFormats.date);
337
+ return lodashGet(this.locale, "formats.date", this.defaultFormats.date);
409
338
  }
339
+
410
340
  /**
411
341
  * Returns current format to be used when outputting time.
412
342
  */
413
-
414
-
415
343
  getTimeFormat() {
416
- return (0, _get.default)(this.locale, "formats.time", this.defaultFormats.time);
344
+ return lodashGet(this.locale, "formats.time", this.defaultFormats.time);
417
345
  }
346
+
418
347
  /**
419
348
  * Returns current format to be used when outputting date/time.
420
349
  */
421
-
422
-
423
350
  getDateTimeFormat() {
424
- return (0, _get.default)(this.locale, "formats.datetime", this.defaultFormats.datetime);
351
+ return lodashGet(this.locale, "formats.datetime", this.defaultFormats.datetime);
425
352
  }
353
+
426
354
  /**
427
355
  * Returns current format to be used when outputting prices.
428
356
  */
429
-
430
-
431
357
  getPriceFormat() {
432
- return (0, _assign.default)({}, this.defaultFormats.price, (0, _get.default)(this.locale, "formats.price", {}));
358
+ return lodashAssign({}, this.defaultFormats.price, lodashGet(this.locale, "formats.price", {}));
433
359
  }
360
+
434
361
  /**
435
362
  * Returns current format to be used when outputting numbers.
436
363
  */
437
-
438
-
439
364
  getNumberFormat() {
440
- return (0, _assign.default)({}, this.defaultFormats.number, (0, _get.default)(this.locale, "formats.number", {}));
365
+ return lodashAssign({}, this.defaultFormats.number, lodashGet(this.locale, "formats.number", {}));
441
366
  }
442
-
443
367
  }
444
368
 
445
- exports.default = I18N;
369
+ //# sourceMappingURL=I18n.js.map
package/I18n.js.map CHANGED
@@ -1 +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,KA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EAKH;;AAjZqB"}
1
+ {"version":3,"names":["accounting","fecha","hash","lodashAssign","lodashGet","I18N","locale","constructor","defaultFormats","getDefaultFormats","translations","modifiers","processors","translate","base","namespace","Error","translation","getTranslation","hasVariables","includes","$this","i18n","values","data","key","processor","canExecute","execute","ns","date","value","outputFormat","inputFormat","getDateFormat","parsedValue","parse","format","time","getTimeFormat","dateTime","getDateTimeFormat","price","getPriceFormat","replace","formatMoney","symbol","precision","thousand","decimal","number","getNumberFormat","formatNumber","getTranslations","hasTranslation","setTranslation","setTranslations","clearTranslations","mergeTranslations","getLocale","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-expect-error\nimport hash from \"short-hash\";\nimport lodashAssign from \"lodash/assign.js\";\nimport lodashGet from \"lodash/get.js\";\n\nimport type {\n Formats,\n I18NData,\n I18NDataValues,\n Modifier,\n NumberFormat,\n PriceFormat,\n Processor,\n ProcessorResult,\n Translations,\n Translator\n} from \"./types.js\";\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,OAAOA,UAAU,MAAM,YAAY;AACnC,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B;AACA;AACA;AACA;AACA,OAAOC,IAAI,MAAM,YAAY;AAC7B,OAAOC,YAAY,MAAM,kBAAkB;AAC3C,OAAOC,SAAS,MAAM,eAAe;AAmBrC;AACA;AACA;AACA,eAAe,MAAMC,IAAI,CAAC;EACfC,MAAM,GAAkB,IAAI;EAU5BC,WAAWA,CAAA,EAAG;IACjB;AACR;AACA;AACA;IACQ,IAAI,CAACC,cAAc,GAAG,IAAI,CAACC,iBAAiB,CAAC,CAAC;;IAE9C;AACR;AACA;AACA;IACQ,IAAI,CAACC,YAAY,GAAG,CAAC,CAAC;;IAEtB;AACR;AACA;AACA;IACQ,IAAI,CAACC,SAAS,GAAG,CAAC,CAAC;;IAEnB;AACR;AACA;AACA;AACA;IACQ,IAAI,CAACC,UAAU,GAAG,CAAC,CAAC;EACxB;EAEOC,SAASA,CAACC,IAAY,EAAEC,SAAkB,EAAc;IAC3D;IACA;IACA;;IAEA,IAAI,CAACA,SAAS,EAAE;MACZ,MAAMC,KAAK,CAAC,kCAAkC,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AE,kBAAkB;QAC1BY,OAAO,EAAE,GAAG;QACZD,QAAQ,EAAE,GAAG;QACbD,SAAS,EAAE;MACf,CAAC;MACDG,MAAM,EAAE;QACJD,OAAO,EAAE,GAAG;QACZD,QAAQ,EAAE,GAAG;QACbD,SAAS,EAAE;MACf;IACJ,CAAC;EACL;;EAEA;AACJ;AACA;EACWb,aAAaA,CAAA,EAAW;IAC3B,OAAO9B,SAAS,CAAC,IAAI,CAACE,MAAM,EAAE,cAAc,EAAE,IAAI,CAACE,cAAc,CAACsB,IAAI,CAAC;EAC3E;;EAEA;AACJ;AACA;EACWS,aAAaA,CAAA,EAAW;IAC3B,OAAOnC,SAAS,CAAC,IAAI,CAACE,MAAM,EAAE,cAAc,EAAE,IAAI,CAACE,cAAc,CAAC8B,IAAI,CAAC;EAC3E;;EAEA;AACJ;AACA;EACWG,iBAAiBA,CAAA,EAAW;IAC/B,OAAOrC,SAAS,CAAC,IAAI,CAACE,MAAM,EAAE,kBAAkB,EAAE,IAAI,CAACE,cAAc,CAAC8D,QAAQ,CAAC;EACnF;;EAEA;AACJ;AACA;EACW3B,cAAcA,CAAA,EAAgB;IACjC,OAAOxC,YAAY,CACf,CAAC,CAAC,EACF,IAAI,CAACK,cAAc,CAACkC,KAAK,EACzBtC,SAAS,CAAC,IAAI,CAACE,MAAM,EAAE,eAAe,EAAE,CAAC,CAAC,CAC9C,CAAC;EACL;;EAEA;AACJ;AACA;EACW6C,eAAeA,CAAA,EAAiB;IACnC,OAAOhD,YAAY,CACf,CAAC,CAAC,EACF,IAAI,CAACK,cAAc,CAAC0C,MAAM,EAC1B9C,SAAS,CAAC,IAAI,CAACE,MAAM,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAC/C,CAAC;EACL;AACJ","ignoreList":[]}
package/README.md CHANGED
@@ -1,17 +1,11 @@
1
1
  # @webiny/i18n
2
- [![](https://img.shields.io/npm/dw/@webiny/i18n.svg)](https://www.npmjs.com/package/@webiny/i18n)
3
- [![](https://img.shields.io/npm/v/@webiny/i18n.svg)](https://www.npmjs.com/package/@webiny/i18n)
4
- [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
5
- [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
6
2
 
7
- A simple I18N library, for frontend and backend apps.
3
+ > [!NOTE]
4
+ > This package is part of the [Webiny](https://www.webiny.com) monorepo.
5
+ > It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
8
6
 
9
- ## Install
10
- ```
11
- npm install --save @webiny/i18n
12
- ```
7
+ πŸ“˜ **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
13
8
 
14
- Or if you prefer yarn:
15
- ```
16
- yarn add @webiny/i18n
17
- ```
9
+ ---
10
+
11
+ _This README file is automatically generated during the publish process._
@@ -1,18 +1,8 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = void 0;
9
-
10
- var _shortHash = _interopRequireDefault(require("short-hash"));
11
-
12
1
  /**
13
2
  * Package short-hash has no types.
14
3
  */
15
- // @ts-ignore
4
+ // @ts-expect-error
5
+ import hash from "short-hash";
16
6
 
17
7
  /**
18
8
  * Searches for all declared namespaces.
@@ -24,39 +14,32 @@ const getNamespaces = source => {
24
14
  const regex = /([a-zA-Z0-9]+)[ ]+=[ ]+i18n.namespace\(['"`]([a-zA-Z0-9.]+)['"`]\)/g;
25
15
  let m;
26
16
  const results = {};
27
-
28
17
  while ((m = regex.exec(source)) !== null) {
29
18
  if (m.index === regex.lastIndex) {
30
19
  regex.lastIndex++;
31
20
  }
32
-
33
21
  results[m[1]] = m[2];
34
22
  }
35
-
36
23
  return results;
37
24
  };
38
-
39
- var _default = source => {
25
+ export default source => {
40
26
  const results = {};
41
27
  const allDeclaredNamespaces = getNamespaces(source);
42
-
43
28
  for (const variable in allDeclaredNamespaces) {
44
29
  const regex = new RegExp(variable + "`(.*?)`", "g");
45
30
  let m;
46
-
47
31
  while ((m = regex.exec(source)) !== null) {
48
32
  if (m.index === regex.lastIndex) {
49
33
  regex.lastIndex++;
50
- } // This is the key - namespace + hash of matched label.
51
-
34
+ }
52
35
 
36
+ // This is the key - namespace + hash of matched label.
53
37
  const matchedText = m[1];
54
- const key = allDeclaredNamespaces[variable] + "." + (0, _shortHash.default)(matchedText);
38
+ const key = allDeclaredNamespaces[variable] + "." + hash(matchedText);
55
39
  results[key] = matchedText;
56
40
  }
57
41
  }
58
-
59
42
  return results;
60
43
  };
61
44
 
62
- exports.default = _default;
45
+ //# sourceMappingURL=extract.js.map