@spinajs/intl 1.2.103 → 1.2.112

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/lib/index.d.ts CHANGED
@@ -1,11 +1,12 @@
1
- import { SyncModule } from '@spinajs/di';
1
+ import { AsyncModule } from '@spinajs/di';
2
2
  import { Configuration } from '@spinajs/configuration';
3
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
+ export declare abstract class Intl extends AsyncModule {
9
10
  private _currentLocale;
10
11
  /**
11
12
  * Currently selected locale
@@ -18,7 +19,7 @@ export declare abstract class Intl extends SyncModule {
18
19
  /**
19
20
  * Map with avaible translations, keyed by locale name
20
21
  */
21
- Locales: Map<string, any>;
22
+ Locales: {};
22
23
  /**
23
24
  * I18n localization function. Returns localized string.
24
25
  * If no translation is avaible at current selected language, then fallback to
@@ -58,13 +59,13 @@ export declare class SpineJsInternationalizationFromJson extends Intl {
58
59
  /**
59
60
  * Map with avaible translations, keyed by locale name
60
61
  */
61
- Locales: Map<string, any>;
62
+ Locales: {};
62
63
  /**
63
64
  * Logger for this module
64
65
  */
65
66
  protected Log: Log;
66
67
  protected Configuration: Configuration;
67
- resolve(): void;
68
+ resolveAsync(): Promise<void>;
68
69
  /**
69
70
  * I18n localization function. Returns localized string.
70
71
  * If no translation is avaible at current selected language, then fallback to
package/lib/index.js CHANGED
@@ -28,6 +28,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
28
28
  __setModuleDefault(result, mod);
29
29
  return result;
30
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
+ };
31
34
  var __metadata = (this && this.__metadata) || function (k, v) {
32
35
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33
36
  };
@@ -37,21 +40,20 @@ const di_1 = require("@spinajs/di");
37
40
  const configuration_1 = require("@spinajs/configuration");
38
41
  const log_1 = require("@spinajs/log");
39
42
  const exceptions_1 = require("@spinajs/exceptions");
40
- const fs = __importStar(require("fs"));
41
- const glob = __importStar(require("glob"));
42
43
  const _ = __importStar(require("lodash"));
43
- const path_1 = require("path");
44
44
  const util = __importStar(require("util"));
45
45
  const MakePlural = __importStar(require("make-plural"));
46
46
  const InvervalParser = __importStar(require("math-interval-parser"));
47
+ const TranslatioSources = __importStar(require("./sources"));
48
+ __exportStar(require("./sources"), exports);
47
49
  const globalAny = global;
48
- class Intl extends di_1.SyncModule {
50
+ class Intl extends di_1.AsyncModule {
49
51
  constructor() {
50
52
  super(...arguments);
51
53
  /**
52
54
  * Map with avaible translations, keyed by locale name
53
55
  */
54
- this.Locales = new Map();
56
+ this.Locales = {};
55
57
  }
56
58
  /**
57
59
  * Currently selected locale
@@ -80,39 +82,16 @@ let SpineJsInternationalizationFromJson = class SpineJsInternationalizationFromJ
80
82
  /**
81
83
  * Map with avaible translations, keyed by locale name
82
84
  */
83
- this.Locales = new Map();
85
+ this.Locales = {};
84
86
  }
85
87
  // tslint:disable-next-line: variable-name
86
- resolve() {
88
+ async resolveAsync() {
87
89
  this.CurrentLocale = this.Configuration.get('intl.defaultLocale', 'en');
88
- const localeDirs = this.Configuration.get('system.dirs.locales', []);
89
- localeDirs
90
- .filter((d) => fs.existsSync(d))
91
- .map((d) => glob.sync(`${d}/**/*.json`))
92
- .reduce((prev, current) => {
93
- return prev.concat(_.flattenDeep(current));
94
- }, [])
95
- .map((f) => (0, path_1.normalize)((0, path_1.resolve)(f)))
96
- .map((f) => {
97
- this.Log.trace(`Found localisation file at ${f}`);
98
- return f;
99
- })
100
- .forEach((f) => {
101
- const lang = (0, path_1.basename)(f, '.json');
102
- let data;
103
- try {
104
- data = JSON.parse(fs.readFileSync(f, 'utf-8'));
105
- }
106
- catch (ex) {
107
- this.Log.warn(ex, `Cannot load localisation data from file ${f} for lang ${lang}`);
108
- return;
109
- }
110
- if (!data) {
111
- this.Log.warn(`No localisation data at ${f} for lang ${lang}`);
112
- return;
113
- }
114
- this.Locales.set(lang, _.merge(data, this.Locales.get(lang) && {}));
115
- });
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
+ }
116
95
  }
117
96
  /**
118
97
  * I18n localization function. Returns localized string.
@@ -129,11 +108,11 @@ let SpineJsInternationalizationFromJson = class SpineJsInternationalizationFromJ
129
108
  if (!text)
130
109
  return '';
131
110
  if (_.isString(text)) {
132
- locTable = this.Locales.get(this.CurrentLocale);
111
+ locTable = this.Locales[this.CurrentLocale];
133
112
  toLocalize = text;
134
113
  }
135
114
  else {
136
- 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];
137
116
  toLocalize = text.phrase;
138
117
  }
139
118
  if (!locTable) {
@@ -158,15 +137,15 @@ let SpineJsInternationalizationFromJson = class SpineJsInternationalizationFromJ
158
137
  return '';
159
138
  if (_.isString(text)) {
160
139
  locale = this.CurrentLocale;
161
- locTable = this.Locales.get(this.CurrentLocale);
140
+ locTable = this.Locales[this.CurrentLocale];
162
141
  toLocalize = text;
163
142
  }
164
143
  else {
165
144
  locale = (_a = text.locale) !== null && _a !== void 0 ? _a : this.CurrentLocale;
166
- 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];
167
146
  toLocalize = text.phrase;
168
147
  }
169
- if (/%/.test(toLocalize) && this.Locales.has(locale)) {
148
+ if (/%/.test(toLocalize) && this.Locales[locale]) {
170
149
  const phrase = locTable[toLocalize];
171
150
  const pluralVerb = MakePlural[locale](count);
172
151
  if (phrase[pluralVerb]) {
@@ -224,7 +203,7 @@ let SpineJsInternationalizationFromJson = class SpineJsInternationalizationFromJ
224
203
  if (!text)
225
204
  return [];
226
205
  const extract = _.property(text);
227
- return Array.from(this.Locales.values()).map((v) => {
206
+ return Array.from(Object.values(this.Locales)).map((v) => {
228
207
  return extract(v);
229
208
  });
230
209
  }
@@ -237,7 +216,7 @@ let SpineJsInternationalizationFromJson = class SpineJsInternationalizationFromJ
237
216
  if (!text)
238
217
  return [];
239
218
  const extract = _.property(text);
240
- return Array.from(this.Locales.values()).map((v, locale) => {
219
+ return Array.from(Object.values(this.Locales)).map((v, locale) => {
241
220
  return { [locale]: extract(v) };
242
221
  });
243
222
  }
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAAqE;AACrE,0DAAuD;AACvD,sCAA2C;AAC3C,oDAAsD;AAEtD,uCAAyB;AACzB,2CAA6B;AAC7B,0CAA4B;AAC5B,+BAAoD;AACpD,2CAA6B;AAC7B,wDAA0C;AAC1C,qEAAuD;AAEvD,MAAM,SAAS,GAAQ,MAAM,CAAC;AAO9B,MAAsB,IAAK,SAAQ,eAAU;IAA7C;;QAqBE;;WAEG;QACI,YAAO,GAAG,IAAI,GAAG,EAAe,CAAC;IAmC1C,CAAC;IAxDC;;OAEG;IACH,IAAW,aAAa;QACtB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,IAAW,aAAa,CAAC,KAAa;QACpC,IAAI,CAAC,KAAK,EAAE;YACV,MAAM,IAAI,4BAAe,CAAC,+BAA+B,CAAC,CAAC;SAC5D;QAED,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC;IAC9B,CAAC;CAwCF;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B;IADC,IAAA,eAAU,GAAE;8BACY,6BAAa;0EAAC;AAb5B,mCAAmC;IAD/C,IAAA,eAAU,EAAC,IAAI,CAAC;GACJ,mCAAmC,CAyK/C;AAzKY,kFAAmC;AA2KhD;;;;;;;GAOG;AACH,SAAS,CAAC,EAAE,GAAG,CAAC,IAAiC,EAAE,GAAG,IAAW,EAAE,EAAE;IACnE,OAAO,OAAE,CAAC,GAAG,CAAO,IAAI,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;AAC9C,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,SAAS,CAAC,GAAG,GAAG,CAAC,IAAiC,EAAE,KAAa,EAAE,EAAE;IACnE,OAAO,OAAE,CAAC,GAAG,CAAO,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,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"}
@@ -1,4 +1,4 @@
1
- import { ILog } from './../../log-common/src/index';
1
+ import { ILog } from '@spinajs/log';
2
2
  import { Configuration } from '@spinajs/configuration';
3
3
  export declare abstract class TranslationSource {
4
4
  protected Configuration: Configuration;
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sources.js","sourceRoot":"","sources":["../src/sources.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,0DAAuD;AACvD,oCAAqD;AACrD,gDAAwB;AACxB,uCAAy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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,6 +1,6 @@
1
1
  {
2
2
  "name": "@spinajs/intl",
3
- "version": "1.2.103",
3
+ "version": "1.2.112",
4
4
  "description": "internationalization for spinajs framework",
5
5
  "main": "lib/index.js",
6
6
  "private": false,
@@ -48,5 +48,5 @@
48
48
  "make-plural": "^6.0.1",
49
49
  "math-interval-parser": "^2.0.1"
50
50
  },
51
- "gitHead": "18a08cf4cd3e4d2c728d2d372e3a42ddde071be8"
51
+ "gitHead": "a301403049bb83a6651a117ec5d6339390987a5b"
52
52
  }
@@ -1,12 +0,0 @@
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,17 +0,0 @@
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
- },
15
- };
16
- exports.default = config;
17
- //# sourceMappingURL=locales.js.map
@@ -1 +0,0 @@
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"}
@@ -1,99 +0,0 @@
1
- import { AsyncModule } from '@spinajs/di';
2
- import { Configuration } from '@spinajs/configuration';
3
- import { Log } from '@spinajs/log';
4
- export { TranslationSource } from './sources';
5
- export interface IPhraseWithOptions {
6
- phrase: string;
7
- locale: string;
8
- }
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
- */
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
- */
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
- */
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
- */
52
- abstract __h(text: string): any[];
53
- }
54
- /**
55
- * Basic internationalization support. Text phrases are read from json files specified
56
- * in system.dirs.locales
57
- */
58
- export declare class SpineJsInternationalizationFromJson extends Intl {
59
- /**
60
- * Map with avaible translations, keyed by locale name
61
- */
62
- Locales: {};
63
- /**
64
- * Logger for this module
65
- */
66
- protected Log: Log;
67
- protected Configuration: Configuration;
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
- */
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
- */
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
- */
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
- */
98
- __h(text: string): any[];
99
- }
@@ -1,272 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.SpineJsInternationalizationFromJson = exports.Intl = exports.TranslationSource = void 0;
36
- const di_1 = require("@spinajs/di");
37
- const configuration_1 = require("@spinajs/configuration");
38
- const log_1 = require("@spinajs/log");
39
- const exceptions_1 = require("@spinajs/exceptions");
40
- const _ = __importStar(require("lodash"));
41
- const util = __importStar(require("util"));
42
- const MakePlural = __importStar(require("make-plural"));
43
- const InvervalParser = __importStar(require("math-interval-parser"));
44
- const TranslatioSources = __importStar(require("./sources"));
45
- var sources_1 = require("./sources");
46
- Object.defineProperty(exports, "TranslationSource", { enumerable: true, get: function () { return sources_1.TranslationSource; } });
47
- const globalAny = global;
48
- class Intl extends di_1.AsyncModule {
49
- constructor() {
50
- super(...arguments);
51
- /**
52
- * Map with avaible translations, keyed by locale name
53
- */
54
- this.Locales = {};
55
- }
56
- /**
57
- * Currently selected locale
58
- */
59
- get CurrentLocale() {
60
- return this._currentLocale;
61
- }
62
- /**
63
- * Currently selected locale
64
- */
65
- set CurrentLocale(value) {
66
- if (!value) {
67
- throw new exceptions_1.InvalidArgument('value cannot be empty or null');
68
- }
69
- this._currentLocale = value;
70
- }
71
- }
72
- exports.Intl = Intl;
73
- /**
74
- * Basic internationalization support. Text phrases are read from json files specified
75
- * in system.dirs.locales
76
- */
77
- let SpineJsInternationalizationFromJson = class SpineJsInternationalizationFromJson extends Intl {
78
- constructor() {
79
- super(...arguments);
80
- /**
81
- * Map with avaible translations, keyed by locale name
82
- */
83
- this.Locales = {};
84
- }
85
- // tslint:disable-next-line: variable-name
86
- async resolveAsync() {
87
- this.CurrentLocale = this.Configuration.get('intl.defaultLocale', 'en');
88
- const sources = await di_1.DI.resolve(Array.ofType(TranslatioSources.TranslationSource));
89
- for (const s of sources) {
90
- const translations = await s.load();
91
- this.Locales = _.merge(translations, this.Locales);
92
- }
93
- }
94
- /**
95
- * I18n localization function. Returns localized string.
96
- * If no translation is avaible at current selected language, then fallback to
97
- * default language, if still no translation exists, original text is returned
98
- *
99
- * @param text - text to localize.
100
- * @param args - argument passed to formatted text
101
- */
102
- __(text, ...args) {
103
- var _a, _b;
104
- let locTable;
105
- let toLocalize;
106
- if (!text)
107
- return '';
108
- if (_.isString(text)) {
109
- locTable = this.Locales[this.CurrentLocale];
110
- toLocalize = text;
111
- }
112
- else {
113
- locTable = (_a = this.Locales[text.locale]) !== null && _a !== void 0 ? _a : this.Locales[this.CurrentLocale];
114
- toLocalize = text.phrase;
115
- }
116
- if (!locTable) {
117
- return util.format(toLocalize, ...args);
118
- }
119
- return util.format((_b = locTable[toLocalize]) !== null && _b !== void 0 ? _b : toLocalize, ...args);
120
- }
121
- /**
122
- * Plurals translation of a single phrase.
123
- * Returns translated, parsed and substituted string based on count parameter.
124
- *
125
- * @param text - text to localize
126
- * @param count - number of items/things
127
- * @example use like `__n("%s cats", 1) returns '1 cat'`
128
- */
129
- __n(text, count) {
130
- var _a, _b;
131
- let locTable;
132
- let toLocalize;
133
- let locale;
134
- if (!text)
135
- return '';
136
- if (_.isString(text)) {
137
- locale = this.CurrentLocale;
138
- locTable = this.Locales[this.CurrentLocale];
139
- toLocalize = text;
140
- }
141
- else {
142
- locale = (_a = text.locale) !== null && _a !== void 0 ? _a : this.CurrentLocale;
143
- locTable = (_b = this.Locales[text.locale]) !== null && _b !== void 0 ? _b : this.Locales[this.CurrentLocale];
144
- toLocalize = text.phrase;
145
- }
146
- if (/%/.test(toLocalize) && this.Locales[locale]) {
147
- const phrase = locTable[toLocalize];
148
- const pluralVerb = MakePlural[locale](count);
149
- if (phrase[pluralVerb]) {
150
- return util.format(phrase[pluralVerb], count);
151
- }
152
- else if (phrase.other) {
153
- return util.format(_getInterval(phrase.other, count), count);
154
- }
155
- return this.__(text, count);
156
- }
157
- return this.__(text, count);
158
- function _getInterval(text, count) {
159
- let toReturn = text;
160
- const phrases = text.split(/\|/);
161
- phrases.some((phrase) => {
162
- const matches = phrase.match(/^\s*([\(\)\[\]\d,]+)?\s*(.*)$/);
163
- if (matches[1] && _matchInterval(count, matches[1])) {
164
- toReturn = matches[2];
165
- return true;
166
- }
167
- else {
168
- toReturn = phrase;
169
- }
170
- });
171
- return toReturn;
172
- /**
173
- * test a number to match mathematical interval expressions
174
- * [0,2] - 0 to 2 (including, matches: 0, 1, 2)
175
- * ]0,3[ - 0 to 3 (excluding, matches: 1, 2)
176
- * [1] - 1 (matches: 1)
177
- * [20,] - all numbers ≥20 (matches: 20, 21, 22, ...)
178
- * [,20] - all numbers ≤20 (matches: 20, 21, 22, ...)
179
- */
180
- function _matchInterval(c, eq) {
181
- const interval = InvervalParser.default(eq);
182
- if (interval) {
183
- if (interval.from.value === c) {
184
- return interval.from.included;
185
- }
186
- if (interval.to.value === c) {
187
- return interval.from.included;
188
- }
189
- return Math.min(interval.from.value, c) === interval.from.value && Math.max(interval.to.value, c) === interval.to.value;
190
- }
191
- return false;
192
- }
193
- }
194
- }
195
- /**
196
- * Returns a list of translations for a given phrase in each language.
197
- *
198
- * @param text - text to translate
199
- */
200
- __l(text) {
201
- if (!text)
202
- return [];
203
- const extract = _.property(text);
204
- return Array.from(Object.values(this.Locales)).map((v) => {
205
- return extract(v);
206
- });
207
- }
208
- /**
209
- * Returns a hashed list of translations for a given phrase in each language.
210
- *
211
- * @param text - text to translate
212
- */
213
- __h(text) {
214
- if (!text)
215
- return [];
216
- const extract = _.property(text);
217
- return Array.from(Object.values(this.Locales)).map((v, locale) => {
218
- return { [locale]: extract(v) };
219
- });
220
- }
221
- };
222
- __decorate([
223
- (0, log_1.Logger)('Intl'),
224
- __metadata("design:type", log_1.Log)
225
- ], SpineJsInternationalizationFromJson.prototype, "Log", void 0);
226
- __decorate([
227
- (0, di_1.Autoinject)(),
228
- __metadata("design:type", configuration_1.Configuration)
229
- ], SpineJsInternationalizationFromJson.prototype, "Configuration", void 0);
230
- SpineJsInternationalizationFromJson = __decorate([
231
- (0, di_1.Injectable)(Intl)
232
- ], SpineJsInternationalizationFromJson);
233
- exports.SpineJsInternationalizationFromJson = SpineJsInternationalizationFromJson;
234
- /**
235
- * I18n localization function. Returns localized string.
236
- * If no translation is avaible at current selected language, then fallback to
237
- * default language, if still no translation exists, original text is returned
238
- *
239
- * @param text - text to localize.
240
- * @param locale - selected locale, if not specified - default locale is selected
241
- */
242
- globalAny.__ = (text, ...args) => {
243
- return di_1.DI.get(Intl).__(text, ...args);
244
- };
245
- /**
246
- * Plurals translation of a single phrase. Singular and plural forms will get added to locales if unknown.
247
- * Returns translated parsed and substituted string based on last count parameter.
248
- *
249
- * @param text - text to localize
250
- * @param count - number of items/things
251
- * @example use like `__n("%s cats", 1) returns `1 cat`
252
- */
253
- globalAny.__n = (text, count) => {
254
- return di_1.DI.get(Intl).__n(text, count);
255
- };
256
- /**
257
- * Returns a list of translations for a given phrase in each language.
258
- *
259
- * @param text - text to translate
260
- */
261
- globalAny.__l = (text) => {
262
- return di_1.DI.get(Intl).__l(text);
263
- };
264
- /**
265
- * Returns a hashed list of translations for a given phrase in each language.
266
- *
267
- * @param text - text to translate
268
- */
269
- globalAny.__h = (text) => {
270
- return di_1.DI.get(Intl).__h(text);
271
- };
272
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAAsE;AACtE,0DAAuD;AACvD,sCAA2C;AAC3C,oDAAsD;AACtD,0CAA4B;AAC5B,2CAA6B;AAC7B,wDAA0C;AAC1C,qEAAuD;AACvD,6DAA+C;AAE/C,qCAA8C;AAArC,4GAAA,iBAAiB,OAAA;AAE1B,MAAM,SAAS,GAAQ,MAAM,CAAC;AAO9B,MAAsB,IAAK,SAAQ,gBAAW;IAA9C;;QAqBE;;WAEG;QACI,YAAO,GAAG,EAAE,CAAC;IAmCtB,CAAC;IAxDC;;OAEG;IACH,IAAW,aAAa;QACtB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,IAAW,aAAa,CAAC,KAAa;QACpC,IAAI,CAAC,KAAK,EAAE;YACV,MAAM,IAAI,4BAAe,CAAC,+BAA+B,CAAC,CAAC;SAC5D;QAED,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC;IAC9B,CAAC;CAwCF;AA3DD,oBA2DC;AAED;;;GAGG;AAEH,IAAa,mCAAmC,GAAhD,MAAa,mCAAoC,SAAQ,IAAI;IAA7D;;QACE;;WAEG;QACI,YAAO,GAAG,EAAE,CA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T,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"}
@@ -1,179 +0,0 @@
1
- import { SyncModule } from "@spinajs/di";
2
- export declare enum LogLevel {
3
- Security = 999,
4
- Fatal = 6,
5
- Error = 5,
6
- Warn = 4,
7
- Success = 3,
8
- Info = 2,
9
- Debug = 1,
10
- Trace = 0
11
- }
12
- export declare const StrToLogLevel: {
13
- trace: LogLevel;
14
- debug: LogLevel;
15
- info: LogLevel;
16
- success: LogLevel;
17
- warn: LogLevel;
18
- error: LogLevel;
19
- fatal: LogLevel;
20
- security: LogLevel;
21
- };
22
- export declare const LogLevelStrings: {
23
- 1: string;
24
- 5: string;
25
- 6: string;
26
- 2: string;
27
- 999: string;
28
- 3: string;
29
- 0: string;
30
- 4: string;
31
- };
32
- export interface ILogRule {
33
- name: string;
34
- level: "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "security" | "success";
35
- target: string | string[];
36
- }
37
- export interface ITargetsOption {
38
- name: string;
39
- type: string;
40
- options?: ICommonTargetOptions;
41
- }
42
- export interface ILogOptions {
43
- targets: ITargetsOption[];
44
- rules: ILogRule[];
45
- variables?: Record<string, unknown>;
46
- }
47
- export interface ICommonTargetOptions {
48
- /**
49
- * Message layout. You can use variables
50
- *
51
- * Default message layout is: datetime level message (logger)
52
- */
53
- layout: string;
54
- /**
55
- * Target name
56
- */
57
- name: string;
58
- /**
59
- * Target type
60
- */
61
- type: string;
62
- /**
63
- * Is logger enabled
64
- */
65
- enabled: boolean;
66
- }
67
- export interface IColoredConsoleTargetOptions extends ICommonTargetOptions {
68
- /**
69
- * Color theme for console message. Best leave it for default.
70
- */
71
- theme: {
72
- security: string | string[];
73
- fatal: string | string[];
74
- error: string | string[];
75
- warn: string | string[];
76
- success: string | string[];
77
- info: string | string[];
78
- debug: string | string[];
79
- trace: string | string[];
80
- };
81
- }
82
- export interface IFileTargetOptions extends ICommonTargetOptions {
83
- options: {
84
- /**
85
- * path whre log is stored. It is allowed to use variables to create path eg. date / time etc.
86
- */
87
- path: string;
88
- /**
89
- * Archive path for logs eg. when size is exceeded. Is is allowed to use variables eg. date / time etc.
90
- *
91
- * Default is none. When not set archive files are stored in same folder as logs.
92
- */
93
- archivePath: string;
94
- /**
95
- * Maximum log file size, if exceeded it is moved to archive, and new log file is created
96
- *
97
- * Default is 1mb
98
- */
99
- maxSize: number;
100
- /**
101
- * Should compress log file when moved to archive
102
- *
103
- * Default is false
104
- */
105
- compress: boolean;
106
- /**
107
- * Should rotate log file eg. new file every new day.
108
- * You should use cron like definition eg. at 1am every day: 0 1 * * *
109
- * When rotate event occurs, old file is moved to archive, and new one is created
110
- *
111
- * Default is not set
112
- */
113
- rotate: string;
114
- /**
115
- * How mutch archive files should be preserved before deletion. Default is 0
116
- * Eg. to store max 5 archive files, set it to 5. Oldest by modification time are deleted.
117
- */
118
- maxArchiveFiles: number;
119
- };
120
- }
121
- export interface ILogStaticVariables {
122
- error: Error | undefined;
123
- level: string;
124
- logger: string;
125
- message: string;
126
- }
127
- export interface ILogVariable {
128
- [key: string]: unknown | (() => unknown);
129
- }
130
- export interface ILogEntry {
131
- Level: LogLevel;
132
- Variables: LogVariables;
133
- }
134
- export declare abstract class LogTarget<T extends ICommonTargetOptions> extends SyncModule {
135
- HasError: boolean;
136
- Error: Error | null | unknown;
137
- Options: T;
138
- constructor(options: T);
139
- abstract write(data: ILogEntry): void;
140
- }
141
- export interface ILogTargetDesc {
142
- instance: LogTarget<ICommonTargetOptions>;
143
- options?: ITargetsOption;
144
- rule: ILogRule;
145
- }
146
- export interface ILog {
147
- Targets: ILogTargetDesc[];
148
- trace(message: string, ...args: any[]): void;
149
- trace(err: Error, message: string, ...args: any[]): void;
150
- trace(err: Error | string, message: string | any[], ...args: any[]): void;
151
- debug(message: string, ...args: any[]): void;
152
- debug(err: Error, message: string, ...args: any[]): void;
153
- debug(err: Error | string, message: string | any[], ...args: any[]): void;
154
- info(message: string, ...args: any[]): void;
155
- info(err: Error, message: string, ...args: any[]): void;
156
- info(err: Error | string, message: string | any[], ...args: any[]): void;
157
- warn(message: string, ...args: any[]): void;
158
- warn(err: Error, message: string, ...args: any[]): void;
159
- warn(err: Error | string, message: string | any[], ...args: any[]): void;
160
- error(message: string, ...args: any[]): void;
161
- error(err: Error, message: string, ...args: any[]): void;
162
- error(err: Error | string, message: string | any[], ...args: any[]): void;
163
- fatal(message: string, ...args: any[]): void;
164
- fatal(err: Error, message: string, ...args: any[]): void;
165
- fatal(err: Error | string, message: string | any[], ...args: any[]): void;
166
- security(message: string, ...args: any[]): void;
167
- security(err: Error, message: string, ...args: any[]): void;
168
- security(err: Error | string, message: string | any[], ...args: any[]): void;
169
- success(message: string, ...args: any[]): void;
170
- success(err: Error, message: string, ...args: any[]): void;
171
- success(err: Error | string, message: string | any[], ...args: any[]): void;
172
- child(name: string, variables?: LogVariables): ILog;
173
- write(entry: ILogEntry): Promise<PromiseSettledResult<void>[]>;
174
- addVariable(name: string, value: unknown): void;
175
- timeStart(name: string): void;
176
- timeEnd(name: string): number;
177
- }
178
- export declare type LogVariables = ILogStaticVariables & ILogVariable;
179
- export declare function createLogMessageObject(err: Error | string, message: string | any[], level: LogLevel, logger: string, variables: any, ...args: any[]): ILogEntry;
@@ -1,88 +0,0 @@
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 __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.createLogMessageObject = exports.LogTarget = exports.LogLevelStrings = exports.StrToLogLevel = exports.LogLevel = void 0;
30
- const di_1 = require("@spinajs/di");
31
- const lodash_1 = __importDefault(require("lodash"));
32
- const util = __importStar(require("util"));
33
- var LogLevel;
34
- (function (LogLevel) {
35
- LogLevel[LogLevel["Security"] = 999] = "Security";
36
- LogLevel[LogLevel["Fatal"] = 6] = "Fatal";
37
- LogLevel[LogLevel["Error"] = 5] = "Error";
38
- LogLevel[LogLevel["Warn"] = 4] = "Warn";
39
- LogLevel[LogLevel["Success"] = 3] = "Success";
40
- LogLevel[LogLevel["Info"] = 2] = "Info";
41
- LogLevel[LogLevel["Debug"] = 1] = "Debug";
42
- LogLevel[LogLevel["Trace"] = 0] = "Trace";
43
- })(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
44
- exports.StrToLogLevel = {
45
- trace: LogLevel.Trace,
46
- debug: LogLevel.Debug,
47
- info: LogLevel.Info,
48
- success: LogLevel.Success,
49
- warn: LogLevel.Warn,
50
- error: LogLevel.Error,
51
- fatal: LogLevel.Fatal,
52
- security: LogLevel.Security,
53
- };
54
- exports.LogLevelStrings = {
55
- [LogLevel.Debug]: "debug",
56
- [LogLevel.Error]: "error",
57
- [LogLevel.Fatal]: "fatal",
58
- [LogLevel.Info]: "info",
59
- [LogLevel.Security]: "security",
60
- [LogLevel.Success]: "success",
61
- [LogLevel.Trace]: "trace",
62
- [LogLevel.Warn]: "warn",
63
- };
64
- class LogTarget extends di_1.SyncModule {
65
- constructor(options) {
66
- super();
67
- this.HasError = false;
68
- this.Error = null;
69
- if (options) {
70
- this.Options = lodash_1.default.merge(lodash_1.default.merge(this.Options, {
71
- enabled: true,
72
- layout: "${datetime} ${level} ${message} ${error} (${logger})",
73
- }), options);
74
- }
75
- }
76
- }
77
- exports.LogTarget = LogTarget;
78
- function createLogMessageObject(err, message, level, logger, variables, ...args) {
79
- const sMsg = err instanceof Error ? message : err;
80
- const tMsg = args.length !== 0 ? util.format(sMsg, ...args) : sMsg;
81
- const lName = logger !== null && logger !== void 0 ? logger : message;
82
- return {
83
- Level: level,
84
- Variables: Object.assign({ error: err instanceof Error ? err : undefined, level: exports.LogLevelStrings[`${level}`].toUpperCase(), logger: lName, message: tMsg }, variables),
85
- };
86
- }
87
- exports.createLogMessageObject = createLogMessageObject;
88
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../log-common/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAAyC;AACzC,oDAAuB;AACvB,2CAA6B;AAE7B,IAAY,QAgBX;AAhBD,WAAY,QAAQ;IAClB,iDAAc,CAAA;IAEd,yCAAS,CAAA;IAET,yCAAS,CAAA;IAET,uCAAQ,CAAA;IAER,6CAAW,CAAA;IAEX,uCAAQ,CAAA;IAER,yCAAS,CAAA;IAET,yCAAS,CAAA;AACX,CAAC,EAhBW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAgBnB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