@spinajs/intl 1.0.1 → 1.2.127

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/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # `@spinajs/intl`
2
+
3
+ > TODO: description
4
+
5
+ ## Usage
6
+
7
+ ```
8
+ const intl = require('@spinajs/intl');
9
+
10
+ // TODO: DEMONSTRATE API
11
+ ```
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Localisation configuration, structure like in
3
+ * https://github.com/mashpie/i18n-node
4
+ */
5
+ declare const config: {
6
+ validation: {
7
+ defaultLocale: string;
8
+ locales: string[];
9
+ queryParameter: string;
10
+ };
11
+ };
12
+ export default config;
@@ -1,6 +1,17 @@
1
- module.exports.intl = {
2
- defaultLocale: 'pl',
3
- locales: ['en', 'pl'],
4
- queryParameter: 'lang',
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Localisation configuration, structure like in
5
+ * https://github.com/mashpie/i18n-node
6
+ */
7
+ const config = {
8
+ validation: {
9
+ defaultLocale: 'en',
10
+ // supported locales
11
+ locales: ['en'],
12
+ // query parameter to switch locale (ie. /home?lang=ch) - defaults to NULL
13
+ queryParameter: 'lang',
14
+ },
5
15
  };
16
+ exports.default = config;
6
17
  //# sourceMappingURL=locales.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"locales.js","sourceRoot":"","sources":["../../src/config/locales.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,OAAO,CAAC,IAAI,GAAG;IAEpB,aAAa,EAAE,IAAI;IAGnB,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;IAGrB,cAAc,EAAE,MAAM;CACvB,CAAC"}
1
+ {"version":3,"file":"locales.js","sourceRoot":"","sources":["../../src/config/locales.ts"],"names":[],"mappings":";;AAAA;;;GAGG;AACH,MAAM,MAAM,GAAG;IACb,UAAU,EAAE;QACV,aAAa,EAAE,IAAI;QAEnB,oBAAoB;QACpB,OAAO,EAAE,CAAC,IAAI,CAAC;QAEf,0EAA0E;QAC1E,cAAc,EAAE,MAAM;KACvB;CACF,CAAC;AAEF,kBAAe,MAAM,CAAC"}
package/lib/index.d.ts CHANGED
@@ -1,28 +1,99 @@
1
- import { IContainer, SyncModule } from "@spinajs/di";
1
+ import { AsyncModule } from '@spinajs/di';
2
2
  import { Configuration } from '@spinajs/configuration';
3
- import { Log } from "@spinajs/log";
3
+ import { Log } from '@spinajs/log';
4
+ export * from './sources';
4
5
  export interface IPhraseWithOptions {
5
6
  phrase: string;
6
7
  locale: string;
7
8
  }
8
- export declare abstract class Intl extends SyncModule {
9
- CurrentLocale: string;
10
- Locales: Map<string, any>;
9
+ export declare abstract class Intl extends AsyncModule {
10
+ private _currentLocale;
11
+ /**
12
+ * Currently selected locale
13
+ */
14
+ get CurrentLocale(): string;
15
+ /**
16
+ * Currently selected locale
17
+ */
18
+ set CurrentLocale(value: string);
19
+ /**
20
+ * Map with avaible translations, keyed by locale name
21
+ */
22
+ Locales: {};
23
+ /**
24
+ * I18n localization function. Returns localized string.
25
+ * If no translation is avaible at current selected language, then fallback to
26
+ * default language, if still no translation exists, original text is returned
27
+ *
28
+ * @param text - text to localize.
29
+ * @param args - argument passed to formatted text
30
+ */
11
31
  abstract __(text: string | IPhraseWithOptions, ...args: any[]): string;
32
+ /**
33
+ * Plurals translation of a single phrase. Singular and plural forms will get added to locales if unknown.
34
+ * Returns translated parsed and substituted string based on last count parameter.
35
+ *
36
+ * @param text - text to localize
37
+ * @param count - number of items/things
38
+ * @example use like `__n("%s cats", 1) returns `1 cat`
39
+ */
12
40
  abstract __n(text: string | IPhraseWithOptions, count: number): string;
41
+ /**
42
+ * Returns a list of translations for a given phrase in each language.
43
+ *
44
+ * @param text - text to translate
45
+ */
13
46
  abstract __l(text: string): string[];
47
+ /**
48
+ * Returns a hashed list of translations for a given phrase in each language.
49
+ *
50
+ * @param text - text to translate
51
+ */
14
52
  abstract __h(text: string): any[];
15
53
  }
54
+ /**
55
+ * Basic internationalization support. Text phrases are read from json files specified
56
+ * in system.dirs.locales
57
+ */
16
58
  export declare class SpineJsInternationalizationFromJson extends Intl {
17
- get CurrentLocale(): string;
18
- set CurrentLocale(value: string);
19
- Locales: Map<string, any>;
59
+ /**
60
+ * Map with avaible translations, keyed by locale name
61
+ */
62
+ Locales: {};
63
+ /**
64
+ * Logger for this module
65
+ */
20
66
  protected Log: Log;
21
67
  protected Configuration: Configuration;
22
- private _currentLocale;
23
- resolve(_c: IContainer): void;
68
+ resolveAsync(): Promise<void>;
69
+ /**
70
+ * I18n localization function. Returns localized string.
71
+ * If no translation is avaible at current selected language, then fallback to
72
+ * default language, if still no translation exists, original text is returned
73
+ *
74
+ * @param text - text to localize.
75
+ * @param args - argument passed to formatted text
76
+ */
24
77
  __(text: string | IPhraseWithOptions, ...args: any[]): string;
78
+ /**
79
+ * Plurals translation of a single phrase.
80
+ * Returns translated, parsed and substituted string based on count parameter.
81
+ *
82
+ * @param text - text to localize
83
+ * @param count - number of items/things
84
+ * @example use like `__n("%s cats", 1) returns '1 cat'`
85
+ */
25
86
  __n(text: string | IPhraseWithOptions, count: number): string;
87
+ /**
88
+ * Returns a list of translations for a given phrase in each language.
89
+ *
90
+ * @param text - text to translate
91
+ */
26
92
  __l(text: string): string[];
93
+ /**
94
+ * Returns a hashed list of translations for a given phrase in each language.
95
+ *
96
+ * @param text - text to translate
97
+ */
27
98
  __h(text: string): any[];
28
99
  }
package/lib/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -20,10 +24,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
20
24
  var __importStar = (this && this.__importStar) || function (mod) {
21
25
  if (mod && mod.__esModule) return mod;
22
26
  var result = {};
23
- if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
28
  __setModuleDefault(result, mod);
25
29
  return result;
26
30
  };
31
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
32
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
33
+ };
27
34
  var __metadata = (this && this.__metadata) || function (k, v) {
28
35
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
29
36
  };
@@ -33,75 +40,79 @@ const di_1 = require("@spinajs/di");
33
40
  const configuration_1 = require("@spinajs/configuration");
34
41
  const log_1 = require("@spinajs/log");
35
42
  const exceptions_1 = require("@spinajs/exceptions");
36
- const fs = __importStar(require("fs"));
37
- const glob = __importStar(require("glob"));
38
43
  const _ = __importStar(require("lodash"));
39
- const path_1 = require("path");
40
44
  const util = __importStar(require("util"));
41
45
  const MakePlural = __importStar(require("make-plural"));
42
46
  const InvervalParser = __importStar(require("math-interval-parser"));
47
+ const TranslatioSources = __importStar(require("./sources"));
48
+ __exportStar(require("./sources"), exports);
43
49
  const globalAny = global;
44
- class Intl extends di_1.SyncModule {
45
- constructor() {
46
- super(...arguments);
47
- this.Locales = new Map();
48
- }
49
- }
50
- exports.Intl = Intl;
51
- let SpineJsInternationalizationFromJson = class SpineJsInternationalizationFromJson extends Intl {
50
+ class Intl extends di_1.AsyncModule {
52
51
  constructor() {
53
52
  super(...arguments);
54
- this.Locales = new Map();
53
+ /**
54
+ * Map with avaible translations, keyed by locale name
55
+ */
56
+ this.Locales = {};
55
57
  }
58
+ /**
59
+ * Currently selected locale
60
+ */
56
61
  get CurrentLocale() {
57
62
  return this._currentLocale;
58
63
  }
64
+ /**
65
+ * Currently selected locale
66
+ */
59
67
  set CurrentLocale(value) {
60
68
  if (!value) {
61
- throw new exceptions_1.InvalidArgument("value cannot be empty or null");
69
+ throw new exceptions_1.InvalidArgument('value cannot be empty or null');
62
70
  }
63
71
  this._currentLocale = value;
64
72
  }
65
- resolve(_c) {
66
- this.CurrentLocale = this.Configuration.get("intl.defaultLocale", "en");
67
- const localeDirs = this.Configuration.get("system.dirs.locales", []);
68
- localeDirs.filter(d => fs.existsSync(d))
69
- .map(d => glob.sync(`${d}/**/*.json`))
70
- .reduce((prev, current) => {
71
- return prev.concat(_.flattenDeep(current));
72
- }, [])
73
- .map(f => path_1.normalize(path_1.resolve(f)))
74
- .map(f => {
75
- this.Log.trace(`Found localisation file at ${f}`);
76
- return f;
77
- })
78
- .forEach(f => {
79
- const lang = path_1.basename(f, '.json');
80
- let data;
81
- try {
82
- data = JSON.parse(fs.readFileSync(f, "utf-8"));
83
- }
84
- catch (ex) {
85
- this.Log.warn(ex, `Cannot load localisation data from file ${f} for lang ${lang}`);
86
- return;
87
- }
88
- if (!data) {
89
- this.Log.warn(`No localisation data at ${f} for lang ${lang}`);
90
- return;
91
- }
92
- this.Locales.set(lang, _.merge(data, this.Locales.get(lang) && {}));
93
- });
73
+ }
74
+ exports.Intl = Intl;
75
+ /**
76
+ * Basic internationalization support. Text phrases are read from json files specified
77
+ * in system.dirs.locales
78
+ */
79
+ let SpineJsInternationalizationFromJson = class SpineJsInternationalizationFromJson extends Intl {
80
+ constructor() {
81
+ super(...arguments);
82
+ /**
83
+ * Map with avaible translations, keyed by locale name
84
+ */
85
+ this.Locales = {};
86
+ }
87
+ // tslint:disable-next-line: variable-name
88
+ async resolveAsync() {
89
+ this.CurrentLocale = this.Configuration.get('intl.defaultLocale', 'en');
90
+ const sources = await di_1.DI.resolve(Array.ofType(TranslatioSources.TranslationSource));
91
+ for (const s of sources) {
92
+ const translations = await s.load();
93
+ this.Locales = _.merge(translations, this.Locales);
94
+ }
94
95
  }
96
+ /**
97
+ * I18n localization function. Returns localized string.
98
+ * If no translation is avaible at current selected language, then fallback to
99
+ * default language, if still no translation exists, original text is returned
100
+ *
101
+ * @param text - text to localize.
102
+ * @param args - argument passed to formatted text
103
+ */
95
104
  __(text, ...args) {
96
105
  var _a, _b;
97
106
  let locTable;
98
107
  let toLocalize;
108
+ if (!text)
109
+ return '';
99
110
  if (_.isString(text)) {
100
- locTable = this.Locales.get(this.CurrentLocale);
111
+ locTable = this.Locales[this.CurrentLocale];
101
112
  toLocalize = text;
102
113
  }
103
114
  else {
104
- locTable = (_a = this.Locales.get(text.locale)) !== null && _a !== void 0 ? _a : this.Locales.get(this.CurrentLocale);
115
+ locTable = (_a = this.Locales[text.locale]) !== null && _a !== void 0 ? _a : this.Locales[this.CurrentLocale];
105
116
  toLocalize = text.phrase;
106
117
  }
107
118
  if (!locTable) {
@@ -109,22 +120,32 @@ let SpineJsInternationalizationFromJson = class SpineJsInternationalizationFromJ
109
120
  }
110
121
  return util.format((_b = locTable[toLocalize]) !== null && _b !== void 0 ? _b : toLocalize, ...args);
111
122
  }
123
+ /**
124
+ * Plurals translation of a single phrase.
125
+ * Returns translated, parsed and substituted string based on count parameter.
126
+ *
127
+ * @param text - text to localize
128
+ * @param count - number of items/things
129
+ * @example use like `__n("%s cats", 1) returns '1 cat'`
130
+ */
112
131
  __n(text, count) {
113
132
  var _a, _b;
114
133
  let locTable;
115
134
  let toLocalize;
116
135
  let locale;
136
+ if (!text)
137
+ return '';
117
138
  if (_.isString(text)) {
118
139
  locale = this.CurrentLocale;
119
- locTable = this.Locales.get(this.CurrentLocale);
140
+ locTable = this.Locales[this.CurrentLocale];
120
141
  toLocalize = text;
121
142
  }
122
143
  else {
123
144
  locale = (_a = text.locale) !== null && _a !== void 0 ? _a : this.CurrentLocale;
124
- locTable = (_b = this.Locales.get(text.locale)) !== null && _b !== void 0 ? _b : this.Locales.get(this.CurrentLocale);
145
+ locTable = (_b = this.Locales[text.locale]) !== null && _b !== void 0 ? _b : this.Locales[this.CurrentLocale];
125
146
  toLocalize = text.phrase;
126
147
  }
127
- if (/%/.test(toLocalize) && this.Locales.has(locale)) {
148
+ if (/%/.test(toLocalize) && this.Locales[locale]) {
128
149
  const phrase = locTable[toLocalize];
129
150
  const pluralVerb = MakePlural[locale](count);
130
151
  if (phrase[pluralVerb]) {
@@ -139,7 +160,7 @@ let SpineJsInternationalizationFromJson = class SpineJsInternationalizationFromJ
139
160
  function _getInterval(text, count) {
140
161
  let toReturn = text;
141
162
  const phrases = text.split(/\|/);
142
- phrases.some(phrase => {
163
+ phrases.some((phrase) => {
143
164
  const matches = phrase.match(/^\s*([\(\)\[\]\d,]+)?\s*(.*)$/);
144
165
  if (matches[1] && _matchInterval(count, matches[1])) {
145
166
  toReturn = matches[2];
@@ -150,6 +171,14 @@ let SpineJsInternationalizationFromJson = class SpineJsInternationalizationFromJ
150
171
  }
151
172
  });
152
173
  return toReturn;
174
+ /**
175
+ * test a number to match mathematical interval expressions
176
+ * [0,2] - 0 to 2 (including, matches: 0, 1, 2)
177
+ * ]0,3[ - 0 to 3 (excluding, matches: 1, 2)
178
+ * [1] - 1 (matches: 1)
179
+ * [20,] - all numbers ≥20 (matches: 20, 21, 22, ...)
180
+ * [,20] - all numbers ≤20 (matches: 20, 21, 22, ...)
181
+ */
153
182
  function _matchInterval(c, eq) {
154
183
  const interval = InvervalParser.default(eq);
155
184
  if (interval) {
@@ -159,46 +188,86 @@ let SpineJsInternationalizationFromJson = class SpineJsInternationalizationFromJ
159
188
  if (interval.to.value === c) {
160
189
  return interval.from.included;
161
190
  }
162
- return (Math.min(interval.from.value, c) === interval.from.value && Math.max(interval.to.value, c) === interval.to.value);
191
+ return Math.min(interval.from.value, c) === interval.from.value && Math.max(interval.to.value, c) === interval.to.value;
163
192
  }
164
193
  return false;
165
194
  }
166
195
  }
167
196
  }
197
+ /**
198
+ * Returns a list of translations for a given phrase in each language.
199
+ *
200
+ * @param text - text to translate
201
+ */
168
202
  __l(text) {
203
+ if (!text)
204
+ return [];
169
205
  const extract = _.property(text);
170
- return Array.from(this.Locales.values()).map((v) => {
206
+ return Array.from(Object.values(this.Locales)).map((v) => {
171
207
  return extract(v);
172
208
  });
173
209
  }
210
+ /**
211
+ * Returns a hashed list of translations for a given phrase in each language.
212
+ *
213
+ * @param text - text to translate
214
+ */
174
215
  __h(text) {
216
+ if (!text)
217
+ return [];
175
218
  const extract = _.property(text);
176
- return Array.from(this.Locales.values()).map((v, locale) => {
219
+ return Array.from(Object.values(this.Locales)).map((v, locale) => {
177
220
  return { [locale]: extract(v) };
178
221
  });
179
222
  }
180
223
  };
181
224
  __decorate([
182
- log_1.Logger({ module: 'Locales' }),
183
- __metadata("design:type", Object)
225
+ (0, log_1.Logger)('Intl'),
226
+ __metadata("design:type", log_1.Log)
184
227
  ], SpineJsInternationalizationFromJson.prototype, "Log", void 0);
185
228
  __decorate([
186
- di_1.Autoinject(),
229
+ (0, di_1.Autoinject)(),
187
230
  __metadata("design:type", configuration_1.Configuration)
188
231
  ], SpineJsInternationalizationFromJson.prototype, "Configuration", void 0);
189
232
  SpineJsInternationalizationFromJson = __decorate([
190
- di_1.Injectable(Intl)
233
+ (0, di_1.Injectable)(Intl)
191
234
  ], SpineJsInternationalizationFromJson);
192
235
  exports.SpineJsInternationalizationFromJson = SpineJsInternationalizationFromJson;
236
+ /**
237
+ * I18n localization function. Returns localized string.
238
+ * If no translation is avaible at current selected language, then fallback to
239
+ * default language, if still no translation exists, original text is returned
240
+ *
241
+ * @param text - text to localize.
242
+ * @param locale - selected locale, if not specified - default locale is selected
243
+ */
193
244
  globalAny.__ = (text, ...args) => {
194
245
  return di_1.DI.get(Intl).__(text, ...args);
195
246
  };
247
+ /**
248
+ * Plurals translation of a single phrase. Singular and plural forms will get added to locales if unknown.
249
+ * Returns translated parsed and substituted string based on last count parameter.
250
+ *
251
+ * @param text - text to localize
252
+ * @param count - number of items/things
253
+ * @example use like `__n("%s cats", 1) returns `1 cat`
254
+ */
196
255
  globalAny.__n = (text, count) => {
197
256
  return di_1.DI.get(Intl).__n(text, count);
198
257
  };
258
+ /**
259
+ * Returns a list of translations for a given phrase in each language.
260
+ *
261
+ * @param text - text to translate
262
+ */
199
263
  globalAny.__l = (text) => {
200
264
  return di_1.DI.get(Intl).__l(text);
201
265
  };
266
+ /**
267
+ * Returns a hashed list of translations for a given phrase in each language.
268
+ *
269
+ * @param text - text to translate
270
+ */
202
271
  globalAny.__h = (text) => {
203
272
  return di_1.DI.get(Intl).__h(text);
204
273
  };
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAAiF;AACjF,0DAAuD;AACvD,sCAA2C;AAC3C,oDAAsD;AAEtD,uCAAyB;AACzB,2CAA6B;AAC7B,0CAA4B;AAC5B,+BAAoD;AACpD,2CAA6B;AAC7B,wDAA0C;AAC1C,qEAAuD;AAEvD,MAAM,SAAS,GAAO,MAAM,CAAC;AAO7B,MAAsB,IAAK,SAAQ,eAAU;IAA7C;;QAUW,YAAO,GAAG,IAAI,GAAG,EAAe,CAAC;IAsC5C,CAAC;CAAA;AAhDD,oBAgDC;AAOD,IAAa,mCAAmC,GAAhD,MAAa,mCAAoC,SAAQ,IAAI;IAA7D;;QAwBW,YAAO,GAAG,IAAI,GAAG,EAAe,CAAC;IAiM5C,CAAC;IApNG,IAAW,aAAa;QACpB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC/B,CAAC;IAKD,IAAW,aAAa,CAAC,KAAa;QAElC,IAAI,CAAC,KAAK,EAAE;YACR,MAAM,IAAI,4BAAe,CAAC,+BAA+B,CAAC,CAAC;SAC9D;QAED,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AAC,CAAC;AAC7C,CAAC,CAAC;AAEF;;;;GAIG;AACH,SAAS,CAAC,GAAG,GAAG,CAAC,IAAY,EAAE,EAAE;IAC/B,OAAO,OAAE,CAAC,GAAG,CAAO,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC,CAAC;AAEF;;;;GAIG;AACH,SAAS,CAAC,GAAG,GAAG,CAAC,IAAY,EAAE,EAAE;IAC/B,OAAO,OAAE,CAAC,GAAG,CAAO,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { ILog } from '@spinajs/log';
2
+ import { Configuration } from '@spinajs/configuration';
3
+ export declare abstract class TranslationSource {
4
+ protected Configuration: Configuration;
5
+ protected Log: ILog;
6
+ abstract load(): Promise<{}>;
7
+ }
8
+ export declare class JsonTranslationSource extends TranslationSource {
9
+ load(): Promise<{}>;
10
+ }
11
+ export declare class JsTranslationSource extends TranslationSource {
12
+ load(): Promise<{}>;
13
+ }
package/lib/sources.js ADDED
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
31
+ var __metadata = (this && this.__metadata) || function (k, v) {
32
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.JsTranslationSource = exports.JsonTranslationSource = exports.TranslationSource = void 0;
39
+ const configuration_1 = require("@spinajs/configuration");
40
+ const di_1 = require("@spinajs/di");
41
+ const glob_1 = __importDefault(require("glob"));
42
+ const fs = __importStar(require("fs"));
43
+ const _ = __importStar(require("lodash"));
44
+ const path_1 = require("path");
45
+ const log_1 = require("@spinajs/log");
46
+ class TranslationSource {
47
+ }
48
+ __decorate([
49
+ (0, di_1.Autoinject)(),
50
+ __metadata("design:type", configuration_1.Configuration)
51
+ ], TranslationSource.prototype, "Configuration", void 0);
52
+ __decorate([
53
+ (0, log_1.Logger)('intl'),
54
+ __metadata("design:type", Object)
55
+ ], TranslationSource.prototype, "Log", void 0);
56
+ exports.TranslationSource = TranslationSource;
57
+ let JsonTranslationSource = class JsonTranslationSource extends TranslationSource {
58
+ async load() {
59
+ const localeDirs = this.Configuration.get('system.dirs.locales', []);
60
+ let translations = {};
61
+ localeDirs
62
+ .filter((d) => fs.existsSync(d))
63
+ .map((d) => glob_1.default.sync(`${d}/**/*.json`))
64
+ .reduce((prev, current) => {
65
+ return prev.concat(_.flattenDeep(current));
66
+ }, [])
67
+ .map((f) => (0, path_1.normalize)((0, path_1.resolve)(f)))
68
+ .map((f) => {
69
+ this.Log.trace(`Found json localisation file at ${f}`);
70
+ return f;
71
+ })
72
+ .forEach((f) => {
73
+ const lang = (0, path_1.basename)(f, '.json');
74
+ let data;
75
+ try {
76
+ data = JSON.parse(fs.readFileSync(f, 'utf-8'));
77
+ }
78
+ catch (ex) {
79
+ this.Log.warn(ex, `Cannot load localisation data from file ${f} for lang ${lang}`);
80
+ return;
81
+ }
82
+ if (!data) {
83
+ this.Log.warn(`No localisation data at ${f} for lang ${lang}`);
84
+ return;
85
+ }
86
+ translations = _.merge({ [lang]: data }, translations);
87
+ });
88
+ return translations;
89
+ }
90
+ };
91
+ JsonTranslationSource = __decorate([
92
+ (0, di_1.Injectable)(TranslationSource)
93
+ ], JsonTranslationSource);
94
+ exports.JsonTranslationSource = JsonTranslationSource;
95
+ let JsTranslationSource = class JsTranslationSource extends TranslationSource {
96
+ async load() {
97
+ const localeDirs = this.Configuration.get('system.dirs.locales', []);
98
+ let translations = {};
99
+ localeDirs
100
+ .filter((d) => fs.existsSync(d))
101
+ .map((d) => glob_1.default.sync(`${d}/**/*.js`))
102
+ .reduce((prev, current) => {
103
+ return prev.concat(_.flattenDeep(current));
104
+ }, [])
105
+ .map((f) => (0, path_1.normalize)((0, path_1.resolve)(f)))
106
+ .map((f) => {
107
+ this.Log.trace(`Found json localisation file at ${f}`);
108
+ return f;
109
+ })
110
+ .forEach((f) => {
111
+ const lang = (0, path_1.basename)(f, '.js');
112
+ let data = require(f);
113
+ if (!data) {
114
+ this.Log.warn(`No localisation data at ${f} for lang ${lang}`);
115
+ return;
116
+ }
117
+ translations = _.merge({ [lang]: data }, translations);
118
+ });
119
+ return translations;
120
+ }
121
+ };
122
+ JsTranslationSource = __decorate([
123
+ (0, di_1.Injectable)(TranslationSource)
124
+ ], JsTranslationSource);
125
+ exports.JsTranslationSource = JsTranslationSource;
126
+ //# sourceMappingURL=sources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sources.js","sourceRoot":"","sources":["../src/sources.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,0DAAuD;AACvD,oCAAqD;AACrD,gDAAwB;AACxB,uCAAyB;AACzB,0CAA4B;AAC5B,+BAAoD;AACpD,sCAAsC;AAEtC,MAAsB,iBAAiB;CAQtC;AANC;IADC,IAAA,eAAU,GAAE;8BACY,6BAAa;wDAAC;AAGvC;IADC,IAAA,YAAM,EAAC,MAAM,CAAC;;8CACK;AALtB,8CAQC;AAGD,IAAa,qBAAqB,GAAlC,MAAa,qBAAsB,SAAQ,iBAAiB;IACnD,KAAK,CAAC,IAAI;QACf,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,qBAAqB,EAAE,EAAE,CAAC,CAAC;QACrE,IAAI,YAAY,GAAG,EAAE,CAAC;QAEtB,UAAU;aACP,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;aAC/B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,cAAI,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;aACvC,MAAM,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE;YACxB,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;QAC7C,CAAC,EAAE,EAAE,CAAC;aACL,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,gBAAS,EAAC,IAAA,cAAO,EAAC,CAAC,CAAC,CAAC,CAAC;aACjC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YACT,IAAI,CAAC,GA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,CAAC,EAAE,EAAE,CAAC,cAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;aACrC,MAAM,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE;YACxB,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;QAC7C,CAAC,EAAE,EAAE,CAAC;aACL,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,gBAAS,EAAC,IAAA,cAAO,EAAC,CAAC,CAAC,CAAC,CAAC;aACjC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YACT,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,mCAAmC,CAAC,EAAE,CAAC,CAAC;YACvD,OAAO,CAAC,CAAC;QACX,CAAC,CAAC;aACD,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YACb,MAAM,IAAI,GAAG,IAAA,eAAQ,EAAC,CAAC,EAAE,KAAK,CAAC,CAAC;YAChC,IAAI,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YAEtB,IAAI,CAAC,IAAI,EAAE;gBACT,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,2BAA2B,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC;gBAC/D,OAAO;aACR;YAED,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,YAAY,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;QAEL,OAAO,YAAY,CAAC;IACtB,CAAC;CACF,CAAA;AA9BY,mBAAmB;IAD/B,IAAA,eAAU,EAAC,iBAAiB,CAAC;GACjB,mBAAmB,CA8B/B;AA9BY,kDAAmB"}
package/package.json CHANGED
@@ -1,72 +1,52 @@
1
1
  {
2
2
  "name": "@spinajs/intl",
3
- "version": "1.0.1",
4
- "description": "spinajs internationalization api",
3
+ "version": "1.2.127",
4
+ "description": "internationalization for spinajs framework",
5
5
  "main": "lib/index.js",
6
+ "private": false,
6
7
  "scripts": {
8
+ "build": "npm run clean && npm run compile",
9
+ "compile": "tsc -p tsconfig.build.json",
10
+ "clean": "",
7
11
  "test": "ts-mocha -p tsconfig.json test/**/*.test.ts",
8
12
  "coverage": "nyc npm run test",
9
13
  "build-docs": "rimraf docs && typedoc --options typedoc.json src/",
10
- "build": "tsc",
11
14
  "prepare": "npm run build",
12
- "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
13
- "lint": "tslint -p tsconfig.json",
15
+ "format": "prettier --write \"src/**/*.ts\"",
16
+ "lint": "eslint -c .eslintrc.js --ext .ts src --fix",
14
17
  "prepublishOnly": "npm test && npm run lint",
15
18
  "preversion": "npm run lint",
16
19
  "version": "npm run format && git add -A src",
17
20
  "postversion": "git push && git push --tags"
18
21
  },
19
22
  "files": [
20
- "lib/**/*",
21
- "typings/**/*"
23
+ "lib/**/*"
22
24
  ],
25
+ "types": "lib",
23
26
  "repository": {
24
27
  "type": "git",
25
- "url": "git+https://github.com/spinajs/intl.git"
28
+ "url": "git+https://github.com/spinajs/main.git"
26
29
  },
27
30
  "keywords": [
28
31
  "spinajs",
29
- "internationalization",
30
32
  "intl"
31
33
  ],
32
- "author": "SpinaJS <spinajs@coderush.pl> (https://github.com/spinajs/intl)",
34
+ "author": "SpinaJS <spinajs@coderush.pl> (https://github.com/spinajs/main)",
33
35
  "license": "MIT",
34
36
  "bugs": {
35
- "url": "https://github.com/spinajs/intl/issues"
37
+ "url": "https://github.com/spinajs/main/issues"
36
38
  },
37
- "homepage": "https://github.com/spinajs/intl#readme",
39
+ "homepage": "https://github.com/spinajs/main#readme",
38
40
  "dependencies": {
39
- "@spinajs/configuration": "^1.0.5",
40
- "@spinajs/di": "^1.0.12",
41
- "@spinajs/exceptions": "^1.0.0",
42
- "@spinajs/log": "^1.0.5",
43
- "@spinajs/reflection": "^1.0.4",
41
+ "@spinajs/configuration": "^1.2.127",
42
+ "@spinajs/di": "^1.2.127",
43
+ "@spinajs/exceptions": "^1.2.127",
44
+ "@spinajs/log": "^1.2.127",
45
+ "@spinajs/reflection": "^1.2.127",
44
46
  "glob": "^7.1.6",
45
47
  "lodash": "^4.17.15",
46
48
  "make-plural": "^6.0.1",
47
49
  "math-interval-parser": "^2.0.1"
48
50
  },
49
- "devDependencies": {
50
- "@types/bunyan": "^1.8.6",
51
- "@types/chai": "^4.1.7",
52
- "@types/chai-as-promised": "^7.1.0",
53
- "@types/lodash": "^4.14.136",
54
- "@types/mocha": "^5.2.7",
55
- "@types/sinon": "^7.0.13",
56
- "chai": "^4.2.0",
57
- "chai-as-promised": "^7.1.1",
58
- "mocha": "^6.1.4",
59
- "nyc": "^14.1.1",
60
- "prettier": "^1.18.2",
61
- "sinon": "^7.3.2",
62
- "ts-mocha": "^6.0.0",
63
- "ts-node": "^8.3.0",
64
- "tslint": "^5.20.1",
65
- "tslint-circular-dependencies": "^0.1.0",
66
- "tslint-config-prettier": "^1.18.0",
67
- "tslint-config-standard": "^8.0.1",
68
- "tslint-no-unused-expression-chai": "^0.1.4",
69
- "typedoc": "^0.14.2",
70
- "typescript": "^3.7.3"
71
- }
51
+ "gitHead": "53b022d0e70b7f2689ac984578b52afb0fd9e967"
72
52
  }
@@ -1,28 +0,0 @@
1
- import { IContainer, ResolveStrategy } from "@spinajs/di";
2
- import { Configuration } from '@spinajs/configuration';
3
- import { Log } from "@spinajs/log";
4
- export interface IPhraseWithOptions {
5
- phrase: string;
6
- locale: string;
7
- }
8
- export declare abstract class Intl extends ResolveStrategy {
9
- CurrentLocale: string;
10
- Locales: Map<string, any>;
11
- abstract __(text: string | IPhraseWithOptions, ...args: any[]): string;
12
- abstract __n(text: string, count: number): string;
13
- abstract __l(text: string): string[];
14
- abstract __h(text: string): any[];
15
- }
16
- export declare class SpineJsInternationalizationFromJson extends Intl {
17
- get CurrentLocale(): string;
18
- set CurrentLocale(value: string);
19
- Locales: Map<string, any>;
20
- protected Log: Log;
21
- protected Configuration: Configuration;
22
- private _currentLocale;
23
- resolve(_c: IContainer): void;
24
- __(text: string | IPhraseWithOptions, ...args: any[]): string;
25
- __n(text: string, count: number): string;
26
- __l(text: string): string[];
27
- __h(text: string): any[];
28
- }
package/lib/src/index.js DELETED
@@ -1,179 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __importStar = (this && this.__importStar) || function (mod) {
12
- if (mod && mod.__esModule) return mod;
13
- var result = {};
14
- if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
15
- result["default"] = mod;
16
- return result;
17
- };
18
- Object.defineProperty(exports, "__esModule", { value: true });
19
- const di_1 = require("@spinajs/di");
20
- const configuration_1 = require("@spinajs/configuration");
21
- const log_1 = require("@spinajs/log");
22
- const exceptions_1 = require("@spinajs/exceptions");
23
- const fs = __importStar(require("fs"));
24
- const glob = __importStar(require("glob"));
25
- const _ = __importStar(require("lodash"));
26
- const path_1 = require("path");
27
- const util = __importStar(require("util"));
28
- const MakePlural = __importStar(require("make-plural"));
29
- const InvervalParser = __importStar(require("math-interval-parser"));
30
- const globalAny = global;
31
- class Intl extends di_1.ResolveStrategy {
32
- constructor() {
33
- super(...arguments);
34
- this.Locales = new Map();
35
- }
36
- }
37
- exports.Intl = Intl;
38
- let SpineJsInternationalizationFromJson = class SpineJsInternationalizationFromJson extends Intl {
39
- constructor() {
40
- super(...arguments);
41
- this.Locales = new Map();
42
- }
43
- get CurrentLocale() {
44
- return this._currentLocale;
45
- }
46
- set CurrentLocale(value) {
47
- if (!value) {
48
- throw new exceptions_1.ArgumentException("value cannot be empty or null");
49
- }
50
- this._currentLocale = value;
51
- }
52
- resolve(_c) {
53
- this.CurrentLocale = this.Configuration.get("intl.defaultLocale", "en");
54
- const localeDirs = this.Configuration.get("system.dirs.locales", []);
55
- localeDirs.filter(d => fs.existsSync(d))
56
- .map(d => glob.sync(`${d}/**/*.json`))
57
- .reduce((prev, current) => {
58
- return prev.concat(_.flattenDeep(current));
59
- }, [])
60
- .map(f => path_1.normalize(path_1.resolve(f)))
61
- .map(f => {
62
- this.Log.trace(`Found localisation file at ${f}`);
63
- return f;
64
- })
65
- .forEach(f => {
66
- const lang = path_1.basename(f, '.json');
67
- let data;
68
- try {
69
- data = JSON.parse(fs.readFileSync(f, "utf-8"));
70
- }
71
- catch (ex) {
72
- this.Log.warn(ex, `Cannot load localisation data from file ${f} for lang ${lang}`);
73
- return;
74
- }
75
- if (!data) {
76
- this.Log.warn(`No localisation data at ${f} for lang ${lang}`);
77
- return;
78
- }
79
- this.Locales.set(lang, _.merge(data, this.Locales.get(lang) && {}));
80
- });
81
- }
82
- __(text, ...args) {
83
- var _a, _b;
84
- let locTable;
85
- let toLocalize;
86
- if (_.isString(text)) {
87
- locTable = this.Locales.get(this.CurrentLocale);
88
- toLocalize = text;
89
- }
90
- else {
91
- locTable = (_a = this.Locales.get(text.locale)) !== null && _a !== void 0 ? _a : this.Locales.get(this.CurrentLocale);
92
- toLocalize = text.phrase;
93
- }
94
- if (!locTable) {
95
- return util.format(toLocalize, ...args);
96
- }
97
- return util.format((_b = locTable[toLocalize]) !== null && _b !== void 0 ? _b : toLocalize, ...args);
98
- }
99
- __n(text, count) {
100
- if (/%/.test(text) && this.Locales.has(this.CurrentLocale)) {
101
- const locTable = this.Locales.get(this.CurrentLocale);
102
- const phrase = locTable[text];
103
- const pluralVerb = MakePlural[this.CurrentLocale](count);
104
- if (phrase[pluralVerb]) {
105
- return util.format(phrase[pluralVerb], count);
106
- }
107
- else if (phrase.other) {
108
- return util.format(_getInterval(phrase.other, count), count);
109
- }
110
- return this.__(text, count);
111
- }
112
- return this.__(text, count);
113
- function _getInterval(text, count) {
114
- let toReturn = text;
115
- const phrases = text.split(/\|/);
116
- phrases.some(phrase => {
117
- const matches = phrase.match(/^\s*([\(\)\[\]\d,]+)?\s*(.*)$/);
118
- if (matches[1] && _matchInterval(count, matches[1])) {
119
- toReturn = matches[2];
120
- return true;
121
- }
122
- else {
123
- toReturn = phrase;
124
- }
125
- });
126
- return toReturn;
127
- function _matchInterval(c, eq) {
128
- const interval = InvervalParser.default(eq);
129
- if (interval) {
130
- if (interval.from.value === c) {
131
- return interval.from.included;
132
- }
133
- if (interval.to.value === c) {
134
- return interval.from.included;
135
- }
136
- return (Math.min(interval.from.value, c) === interval.from.value && Math.max(interval.to.value, c) === interval.to.value);
137
- }
138
- return false;
139
- }
140
- }
141
- }
142
- __l(text) {
143
- const extract = _.property(text);
144
- return Array.from(this.Locales.values()).map((v) => {
145
- return extract(v);
146
- });
147
- }
148
- __h(text) {
149
- const extract = _.property(text);
150
- return Array.from(this.Locales.values()).map((v, locale) => {
151
- return { [locale]: extract(v) };
152
- });
153
- }
154
- };
155
- __decorate([
156
- log_1.Logger({ module: 'Locales' }),
157
- __metadata("design:type", Object)
158
- ], SpineJsInternationalizationFromJson.prototype, "Log", void 0);
159
- __decorate([
160
- di_1.Autoinject(),
161
- __metadata("design:type", configuration_1.Configuration)
162
- ], SpineJsInternationalizationFromJson.prototype, "Configuration", void 0);
163
- SpineJsInternationalizationFromJson = __decorate([
164
- di_1.Injectable(Intl)
165
- ], SpineJsInternationalizationFromJson);
166
- exports.SpineJsInternationalizationFromJson = SpineJsInternationalizationFromJson;
167
- globalAny.__ = (text, ...args) => {
168
- return di_1.DI.get('Internationalization').__(text, ...args);
169
- };
170
- globalAny.__n = (text, count) => {
171
- return di_1.DI.get('Internationalization').__n(text, count);
172
- };
173
- globalAny.__l = (text) => {
174
- return di_1.DI.get('Internationalization').__l(text);
175
- };
176
- globalAny.__h = (text) => {
177
- return di_1.DI.get('Internationalization').__h(text);
178
- };
179
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,oCAAsF;AACtF,0DAAuD;AACvD,sCAA2C;AAC3C,oDAAwD;AAExD,uCAAyB;AACzB,2CAA6B;AAC7B,0CAA4B;AAC5B,+BAAoD;AACpD,2CAA6B;AAC7B,wDAA0C;AAC1C,qEAAuD;AAEvD,MAAM,SAAS,GAAO,MAAM,CAAC;AAO7B,MAAsB,IAAK,SAAQ,oBAAe;IAAlD;;QAUW,YAAO,GAAG,IAAI,GAAG,EAAe,CAAC;IAsC5C,CAAC;CAAA;AAhDD,oBAgDC;AAOD,IAAa,mCAAmC,GAAhD,MAAa,mCAAoC,SAAQ,IAAI;IAA7D;;QAwBW,YAAO,GAAG,IAAI,GAAG,EAAe,CAAC;IAoL5C,CAAC;IAvMG,IAAW,aAAa;QACpB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC/B,CAAC;IAKD,IAAW,aAAa,CAAC,KAAa;QAElC,IAAI,CAAC,KAAK,EAAE;YACR,MAAM,IAAI,8BAAiB,CAAC,+BAA+B,CAAC,CAAC;SAChE;QAED,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC;IAChC,CAAC;IAqBM,OAAO,CAAC,EAAc;QAEzB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;QAExE,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,qBAAqB,EAAE,EAAE,CAAC,CAAC;QAErE,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC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,IAAiC,EAAE,GAAG,IAAW,EAAE,EAAE;IACjE,OAAO,OAAE,CAAC,GAAG,CAAO,sBAAsB,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;AAClE,CAAC,CAAC;AAUF,SAAS,CAAC,GAAG,GAAG,CAAC,IAAY,EAAE,KAAa,EAAE,EAAE;IAC5C,OAAO,OAAE,CAAC,GAAG,CAAO,sBAAsB,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACjE,CAAC,CAAC;AAOF,SAAS,CAAC,GAAG,GAAG,CAAC,IAAY,EAAE,EAAE;IAC7B,OAAO,OAAE,CAAC,GAAG,CAAO,sBAAsB,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC1D,CAAC,CAAC;AAOF,SAAS,CAAC,GAAG,GAAG,CAAC,IAAY,EAAE,EAAE;IAC7B,OAAO,OAAE,CAAC,GAAG,CAAO,sBAAsB,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC1D,CAAC,CAAC"}
@@ -1,18 +0,0 @@
1
- declare global {
2
- namespace NodeJS {
3
- interface Global {
4
- __(text: string, locale?: string): string;
5
- __n(text: string, count: Number): string;
6
- __l(text: string): string[];
7
- __h(text: string): any[];
8
- }
9
- }
10
- interface PhraseWithOptions {
11
- phrase: string;
12
- locale: string;
13
- }
14
- function __(text: string | PhraseWithOptions, ...args: any[]): string;
15
- function __n(text: string, count: Number): string;
16
- function __l(text: string): string[];
17
- function __h(text: string): any[];
18
- }
@@ -1 +0,0 @@
1
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../typings/global/index.ts"],"names":[],"mappings":""}
@@ -1,81 +0,0 @@
1
- export {};
2
-
3
- declare global {
4
- namespace NodeJS {
5
- interface Global {
6
- /**
7
- * I18n localization function. Returns localized string.
8
- * If no translation is avaible at current selected language, then fallback to
9
- * default language, if still no translation exists, original text is returned
10
- *
11
- * @param text { string } - text to localize.
12
- * @param locale { string } - selected locale, if not specified - default locale is selected
13
- */
14
- __(text: string, locale?: string): string;
15
-
16
- /**
17
- * Plurals translation of a single phrase. Singular and plural forms will get added to locales if unknown.
18
- * Returns translated parsed and substituted string based on last count parameter.
19
- *
20
- * @param text { string } - text to localize
21
- * @param count { number } - number of items/things
22
- * @example use like `__n("%s cats", 1) returns `1 cat`
23
- */
24
- __n(text: string, count: Number): string;
25
-
26
- /**
27
- * Returns a list of translations for a given phrase in each language.
28
- *
29
- * @param text { string } - text to translate
30
- */
31
- __l(text: string): string[];
32
-
33
- /**
34
- * Returns a hashed list of translations for a given phrase in each language.
35
- *
36
- * @param text { string } - text to translate
37
- */
38
- __h(text: string): any[];
39
- }
40
- }
41
-
42
- interface PhraseWithOptions {
43
- phrase: string;
44
- locale: string;
45
- }
46
-
47
- /**
48
- * I18n localization function. Returns localized string.
49
- * If no translation is avaible at current selected language, then fallback to
50
- * default language, if still no translation exists, original text is returned
51
- *
52
- * @param text { string } - text to localize.
53
- * @param locale { string } - selected locale, if not specified - default locale is selected
54
- */
55
- function __(text: string | PhraseWithOptions, ...args: any[]): string;
56
-
57
- /**
58
- * Plurals translation of a single phrase. Singular and plural forms will get added to locales if unknown.
59
- * Returns translated parsed and substituted string based on last count parameter.
60
- *
61
- * @param text { string } - text to localize
62
- * @param count { number } - number of items/things
63
- * @example use like `__n("%s cats", 1) returns `1 cat`
64
- */
65
- function __n(text: string, count: Number): string;
66
-
67
- /**
68
- * Returns a list of translations for a given phrase in each language.
69
- *
70
- * @param text { string } - text to translate
71
- */
72
- function __l(text: string): string[];
73
-
74
- /**
75
- * Returns a hashed list of translations for a given phrase in each language.
76
- *
77
- * @param text { string } - text to translate
78
- */
79
- function __h(text: string): any[];
80
- }
81
-
@@ -1 +0,0 @@
1
- declare module 'make-plural';