@spinajs/intl 2.0.86 → 2.0.88

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.
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locales.d.ts","sourceRoot":"","sources":["../../../src/config/locales.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,QAAA,MAAM,MAAM;;;;;;CAUX,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -0,0 +1,17 @@
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
+ intl: {
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locales.js","sourceRoot":"","sources":["../../../src/config/locales.ts"],"names":[],"mappings":";;AAAA;;;GAGG;AACH,MAAM,MAAM,GAAG;IACb,IAAI,EAAE;QACJ,aAAa,EAAE,IAAI;QAEnB,oBAAoB;QACpB,OAAO,EAAE,CAAC,IAAI,CAAC;QAEf,0EAA0E;QAC1E,cAAc,EAAE,MAAM;KACvB;CACF,CAAC;AAEF,kBAAe,MAAM,CAAC"}
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,YAAY,EAAkB,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,GAAG,EAAU,MAAM,cAAc,CAAC;AAO3C,cAAc,cAAc,CAAC;AAI7B,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM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CD;;GAEG;AAEH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,UACxB,MAAM,GAAG,kBAAkB,WAAW,GAAG,EAAE,YAc1D;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,UAC9B,MAAM,GAAG,kBAAkB,SAAS,MAAM,YAczD;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,YAGxC;AACD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,SAGxC;AAED,wBAAgB,aAAa,CAAC,IAAI,CAAC,EAAE,MAAM,UAiB1C;AAED,wBAAgB,eAAe,WAE9B"}
@@ -0,0 +1,339 @@
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 __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
+ };
34
+ var __metadata = (this && this.__metadata) || function (k, v) {
35
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
36
+ };
37
+ var __importDefault = (this && this.__importDefault) || function (mod) {
38
+ return (mod && mod.__esModule) ? mod : { "default": mod };
39
+ };
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.defaultLanguage = exports.guessLanguage = exports.__translateH = exports.__translateL = exports.__translateNumber = exports.__translate = exports.SpineJsInternationalizationFromJson = exports.Intl = void 0;
42
+ const node_async_hooks_1 = require("node:async_hooks");
43
+ const di_1 = require("@spinajs/di");
44
+ const configuration_1 = require("@spinajs/configuration");
45
+ const log_1 = require("@spinajs/log");
46
+ const exceptions_1 = require("@spinajs/exceptions");
47
+ const lodash_1 = __importDefault(require("lodash"));
48
+ const util = __importStar(require("util"));
49
+ const MakePlural = __importStar(require("make-plural"));
50
+ const math_interval_parser_1 = __importDefault(require("math-interval-parser"));
51
+ const TranslatioSources = __importStar(require("./sources.js"));
52
+ __exportStar(require("./sources.js"), exports);
53
+ const globalAny = global;
54
+ class Intl extends di_1.AsyncService {
55
+ constructor() {
56
+ super(...arguments);
57
+ /**
58
+ * Map with avaible translations, keyed by locale name
59
+ */
60
+ this.Locales = {};
61
+ }
62
+ /**
63
+ * Currently selected locale
64
+ */
65
+ get CurrentLocale() {
66
+ return this._currentLocale;
67
+ }
68
+ /**
69
+ * Currently selected locale
70
+ */
71
+ set CurrentLocale(value) {
72
+ if (!value) {
73
+ throw new exceptions_1.InvalidArgument('value cannot be empty or null');
74
+ }
75
+ this._currentLocale = value;
76
+ }
77
+ }
78
+ exports.Intl = Intl;
79
+ /**
80
+ * Basic internationalization support. Text phrases are read from json files specified
81
+ * in system.dirs.locales
82
+ */
83
+ let SpineJsInternationalizationFromJson = class SpineJsInternationalizationFromJson extends Intl {
84
+ constructor() {
85
+ super(...arguments);
86
+ /**
87
+ * Map with avaible translations, keyed by locale name
88
+ */
89
+ this.Locales = {};
90
+ }
91
+ // tslint:disable-next-line: variable-name
92
+ async resolve() {
93
+ this.CurrentLocale = this.Configuration.get('intl.defaultLocale', 'en');
94
+ const sources = await di_1.DI.resolve(Array.ofType(TranslatioSources.TranslationSource));
95
+ for (const s of sources) {
96
+ const translations = await s.load();
97
+ this.Locales = lodash_1.default.merge(translations, this.Locales);
98
+ }
99
+ }
100
+ /**
101
+ * I18n localization function. Returns localized string.
102
+ * If no translation is avaible at current selected language, then fallback to
103
+ * default language, if still no translation exists, original text is returned
104
+ *
105
+ * @param text - text to localize.
106
+ * @param args - argument passed to formatted text
107
+ */
108
+ __(text, ...args) {
109
+ let locTable;
110
+ let toLocalize;
111
+ if (!text)
112
+ return '';
113
+ if (lodash_1.default.isString(text)) {
114
+ locTable = this.Locales[this.CurrentLocale];
115
+ toLocalize = text;
116
+ }
117
+ else {
118
+ locTable = this.Locales[text.locale] ?? this.Locales[this.CurrentLocale];
119
+ toLocalize = text.phrase;
120
+ }
121
+ if (!locTable) {
122
+ return util.format(toLocalize, ...args);
123
+ }
124
+ return util.format(locTable[toLocalize] ?? toLocalize, ...args);
125
+ }
126
+ /**
127
+ * Plurals translation of a single phrase.
128
+ * Returns translated, parsed and substituted string based on count parameter.
129
+ *
130
+ * @param text - text to localize
131
+ * @param count - number of items/things
132
+ * @example use like `__n("%s cats", 1) returns '1 cat'`
133
+ */
134
+ __n(text, count) {
135
+ let locTable;
136
+ let toLocalize;
137
+ let locale;
138
+ if (!text)
139
+ return '';
140
+ if (lodash_1.default.isString(text)) {
141
+ locale = this.CurrentLocale;
142
+ locTable = this.Locales[this.CurrentLocale];
143
+ toLocalize = text;
144
+ }
145
+ else {
146
+ locale = text.locale ?? this.CurrentLocale;
147
+ locTable = this.Locales[text.locale] ?? this.Locales[this.CurrentLocale];
148
+ toLocalize = text.phrase;
149
+ }
150
+ if (/%/.test(toLocalize) && this.Locales[locale]) {
151
+ const phrase = locTable[toLocalize];
152
+ const pluralVerb = MakePlural[locale](count);
153
+ if (phrase[pluralVerb]) {
154
+ return util.format(phrase[pluralVerb], count);
155
+ }
156
+ else if (phrase.other) {
157
+ return util.format(_getInterval(phrase.other, count), count);
158
+ }
159
+ return this.__(text, count);
160
+ }
161
+ return this.__(text, count);
162
+ function _getInterval(text, count) {
163
+ let toReturn = text;
164
+ const phrases = text.split(/\|/);
165
+ phrases.some((phrase) => {
166
+ const matches = phrase.match(/^\s*([\(\)\[\]\d,]+)?\s*(.*)$/);
167
+ if (matches[1] && _matchInterval(count, matches[1])) {
168
+ toReturn = matches[2];
169
+ return true;
170
+ }
171
+ else {
172
+ toReturn = phrase;
173
+ }
174
+ });
175
+ return toReturn;
176
+ /**
177
+ * test a number to match mathematical interval expressions
178
+ * [0,2] - 0 to 2 (including, matches: 0, 1, 2)
179
+ * ]0,3[ - 0 to 3 (excluding, matches: 1, 2)
180
+ * [1] - 1 (matches: 1)
181
+ * [20,] - all numbers ≥20 (matches: 20, 21, 22, ...)
182
+ * [,20] - all numbers ≤20 (matches: 20, 21, 22, ...)
183
+ */
184
+ function _matchInterval(c, eq) {
185
+ const interval = math_interval_parser_1.default.default ? math_interval_parser_1.default.default(eq) : math_interval_parser_1.default(eq);
186
+ if (interval) {
187
+ if (interval.from.value === c) {
188
+ return interval.from.included;
189
+ }
190
+ if (interval.to.value === c) {
191
+ return interval.from.included;
192
+ }
193
+ return Math.min(interval.from.value, c) === interval.from.value && Math.max(interval.to.value, c) === interval.to.value;
194
+ }
195
+ return false;
196
+ }
197
+ }
198
+ }
199
+ /**
200
+ * Returns a list of translations for a given phrase in each language.
201
+ *
202
+ * @param text - text to translate
203
+ */
204
+ __l(text) {
205
+ if (!text)
206
+ return [];
207
+ const extract = lodash_1.default.property(text);
208
+ return Array.from(Object.values(this.Locales)).map((v) => {
209
+ return extract(v);
210
+ });
211
+ }
212
+ /**
213
+ * Returns a hashed list of translations for a given phrase in each language.
214
+ *
215
+ * @param text - text to translate
216
+ */
217
+ __h(text) {
218
+ if (!text)
219
+ return [];
220
+ const extract = lodash_1.default.property(text);
221
+ return Array.from(Object.values(this.Locales)).map((v, locale) => {
222
+ return { [locale]: extract(v) };
223
+ });
224
+ }
225
+ };
226
+ __decorate([
227
+ (0, log_1.Logger)('Intl'),
228
+ __metadata("design:type", log_1.Log)
229
+ ], SpineJsInternationalizationFromJson.prototype, "Log", void 0);
230
+ __decorate([
231
+ (0, di_1.Autoinject)(),
232
+ __metadata("design:type", configuration_1.Configuration)
233
+ ], SpineJsInternationalizationFromJson.prototype, "Configuration", void 0);
234
+ SpineJsInternationalizationFromJson = __decorate([
235
+ (0, di_1.Injectable)(Intl)
236
+ ], SpineJsInternationalizationFromJson);
237
+ exports.SpineJsInternationalizationFromJson = SpineJsInternationalizationFromJson;
238
+ /**
239
+ * I18n localization function. Returns localized string.
240
+ * If no translation is avaible at current selected language, then fallback to
241
+ * default language, if still no translation exists, original text is returned
242
+ *
243
+ * @param text - text to localize.
244
+ * @param locale - selected locale, if not specified - default locale is selected
245
+ */
246
+ globalAny.__ = (text, ...args) => {
247
+ return di_1.DI.get(Intl).__(text, ...args);
248
+ };
249
+ /**
250
+ * Plurals translation of a single phrase. Singular and plural forms will get added to locales if unknown.
251
+ * Returns translated parsed and substituted string based on last count parameter.
252
+ *
253
+ * @param text - text to localize
254
+ * @param count - number of items/things
255
+ * @example use like `__n("%s cats", 1) returns `1 cat`
256
+ */
257
+ globalAny.__n = (text, count) => {
258
+ return di_1.DI.get(Intl).__n(text, count);
259
+ };
260
+ /**
261
+ * Returns a list of translations for a given phrase in each language.
262
+ *
263
+ * @param text - text to translate
264
+ */
265
+ globalAny.__l = (text) => {
266
+ return di_1.DI.get(Intl).__l(text);
267
+ };
268
+ /**
269
+ * Returns a hashed list of translations for a given phrase in each language.
270
+ *
271
+ * @param text - text to translate
272
+ */
273
+ globalAny.__h = (text) => {
274
+ return di_1.DI.get(Intl).__h(text);
275
+ };
276
+ /**
277
+ * Helper function for translations ( eg. for use as in template rentering engines)
278
+ */
279
+ function __translate(lang) {
280
+ return (text, ...args) => {
281
+ const intl = di_1.DI.get(Intl);
282
+ if (typeof text === 'string') {
283
+ return intl.__({
284
+ phrase: text,
285
+ locale: lang,
286
+ }, ...args);
287
+ }
288
+ return intl.__(text, ...args);
289
+ };
290
+ }
291
+ exports.__translate = __translate;
292
+ function __translateNumber(lang) {
293
+ return (text, count) => {
294
+ const intl = di_1.DI.get(Intl);
295
+ if (typeof text === 'string') {
296
+ return intl.__n({
297
+ phrase: text,
298
+ locale: lang,
299
+ }, count);
300
+ }
301
+ return intl.__n(text, count);
302
+ };
303
+ }
304
+ exports.__translateNumber = __translateNumber;
305
+ function __translateL(text) {
306
+ const intl = di_1.DI.get(Intl);
307
+ return intl.__l(text);
308
+ }
309
+ exports.__translateL = __translateL;
310
+ function __translateH(text) {
311
+ const intl = di_1.DI.get(Intl);
312
+ return intl.__h(text);
313
+ }
314
+ exports.__translateH = __translateH;
315
+ function guessLanguage(lang) {
316
+ let selectedLang = lang;
317
+ if (!selectedLang) {
318
+ const store = di_1.DI.get(node_async_hooks_1.AsyncLocalStorage);
319
+ if (store) {
320
+ const storage = di_1.DI.get(node_async_hooks_1.AsyncLocalStorage).getStore();
321
+ if (!storage || !storage.language) {
322
+ selectedLang = di_1.DI.get(configuration_1.Configuration).get('intl.defaultLocale');
323
+ }
324
+ else {
325
+ selectedLang = storage.language;
326
+ }
327
+ }
328
+ else {
329
+ selectedLang = di_1.DI.get(configuration_1.Configuration).get('intl.defaultLocale');
330
+ }
331
+ }
332
+ return selectedLang;
333
+ }
334
+ exports.guessLanguage = guessLanguage;
335
+ function defaultLanguage() {
336
+ return di_1.DI.get(configuration_1.Configuration).get('intl.defaultLocale');
337
+ }
338
+ exports.defaultLanguage = defaultLanguage;
339
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAAqD;AACrD,oCAAuE;AACvE,0DAAuD;AACvD,sCAA2C;AAC3C,oDAAsD;AACtD,oDAAuB;AACvB,2CAA6B;AAC7B,wDAA0C;AAC1C,gFAAiD;AACjD,gEAAkD;AAClD,+CAA6B;AAE7B,MAAM,SAAS,GAAQ,MAAM,CAAC;AAW9B,MAAsB,IAAK,SAAQ,iBAAY;IAA/C;;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;AAEI,IAAM,mCAAmC,GAAzC,MAAM,mCAAoC,SAAQ,IAAI;IAAtD;;QACL;;WAEG;QACI,YAAO,GAAG,EAAE,CAAC;IAqKtB,CAAC;IA1JC,0CAA0C;IACnC,KAAK,CAAC,OAAO;QAClB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;QAExE,MAAM,OAAO,GAAG,MAAM,OAAE,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAAC,CAAC;QAEpF,K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ts","sourceRoot":"","sources":["../../src/sources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAQvD,8BAAsB,iBAAiB;IAErC,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC;IAGvC,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC;aAEJ,IAAI,IAAI,OAAO,CAAC,EAAE,CAAC;CACpC;AAED,qBACa,qBAAsB,SAAQ,iBAAiB;IAC7C,IAAI,IAAI,OAAO,CAAC,EAAE,CAAC;CAoCjC;AAED,qBACa,mBAAoB,SAAQ,iBAAiB;IAC3C,IAAI,IAAI,OAAO,CAAC,EAAE,CAAC;CA8BjC"}
@@ -0,0 +1,127 @@
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 lodash_1 = __importDefault(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`.replace(/\\/g, '/')))
64
+ .reduce((prev, current) => {
65
+ return prev.concat(lodash_1.default.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 = lodash_1.default.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
+ var _a;
98
+ const localeDirs = this.Configuration.get('system.dirs.locales', []);
99
+ let translations = {};
100
+ const files = localeDirs
101
+ .filter((d) => fs.existsSync(d))
102
+ .map((d) => glob_1.default.sync(`${d}/**/*.{js,cjs}`.replace(/\\/g, '/')))
103
+ .reduce((prev, current) => {
104
+ return prev.concat(lodash_1.default.flattenDeep(current));
105
+ }, [])
106
+ .map((f) => (0, path_1.normalize)((0, path_1.resolve)(f)))
107
+ .map((f) => {
108
+ this.Log.trace(`Found json localisation file at ${f}`);
109
+ return f;
110
+ });
111
+ for (const f of files) {
112
+ const lang = (0, path_1.basename)((0, path_1.basename)(f, '.js'), '.cjs');
113
+ let data = await (_a = `file://${f}`, Promise.resolve().then(() => __importStar(require(_a))));
114
+ if (!data || !data.default) {
115
+ this.Log.warn(`No localisation data at ${f} for lang ${lang}`);
116
+ return;
117
+ }
118
+ translations = lodash_1.default.merge({ [lang]: data.default }, translations);
119
+ }
120
+ return translations;
121
+ }
122
+ };
123
+ JsTranslationSource = __decorate([
124
+ (0, di_1.Injectable)(TranslationSource)
125
+ ], JsTranslationSource);
126
+ exports.JsTranslationSource = JsTranslationSource;
127
+ //# 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,oDAAuB;AACvB,+BAAoD;AACpD,sCAAsC;AAEtC,MAAsB,iBAAiB;CAQtC;AAPC;IAAC,IAAA,eAAU,GAAE;8BACY,6BAAa;wDAAC;AAEvC;IAAC,IAAA,YAAM,EAAC,MAAM,CAAC;;8CACK;AALtB,8CAQC;AAGM,IAAM,qBAAqB,GAA3B,MAAM,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,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;aAC3D,MAAM,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE;YACxB,OAAO,IAAI,CAAC,MAAM,CAAC,gBAAC,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,CA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/BY,kDAAmB"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Localisation configuration, structure like in
3
+ * https://github.com/mashpie/i18n-node
4
+ */
5
+ declare const config: {
6
+ intl: {
7
+ defaultLocale: string;
8
+ locales: string[];
9
+ queryParameter: string;
10
+ };
11
+ };
12
+ export default config;
13
+ //# sourceMappingURL=locales.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locales.d.ts","sourceRoot":"","sources":["../../../src/config/locales.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,QAAA,MAAM,MAAM;;;;;;CAUX,CAAC;AAEF,eAAe,MAAM,CAAC"}
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locales.js","sourceRoot":"","sources":["../../../src/config/locales.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,GAAG;IACb,IAAI,EAAE;QACJ,aAAa,EAAE,IAAI;QAEnB,oBAAoB;QACpB,OAAO,EAAE,CAAC,IAAI,CAAC;QAEf,0EAA0E;QAC1E,cAAc,EAAE,MAAM;KACvB;CACF,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -0,0 +1,112 @@
1
+ import { AsyncService } from '@spinajs/di';
2
+ import { Configuration } from '@spinajs/configuration';
3
+ import { Log } from '@spinajs/log';
4
+ export * from './sources.js';
5
+ export interface IPhraseWithOptions {
6
+ phrase: string;
7
+ locale: string;
8
+ }
9
+ export interface IIntlAsyncStorage {
10
+ language?: string;
11
+ }
12
+ export declare abstract class Intl extends AsyncService {
13
+ private _currentLocale;
14
+ /**
15
+ * Currently selected locale
16
+ */
17
+ get CurrentLocale(): string;
18
+ /**
19
+ * Currently selected locale
20
+ */
21
+ set CurrentLocale(value: string);
22
+ /**
23
+ * Map with avaible translations, keyed by locale name
24
+ */
25
+ Locales: {};
26
+ /**
27
+ * I18n localization function. Returns localized string.
28
+ * If no translation is avaible at current selected language, then fallback to
29
+ * default language, if still no translation exists, original text is returned
30
+ *
31
+ * @param text - text to localize.
32
+ * @param args - argument passed to formatted text
33
+ */
34
+ abstract __(text: string | IPhraseWithOptions, ...args: any[]): string;
35
+ /**
36
+ * Plurals translation of a single phrase. Singular and plural forms will get added to locales if unknown.
37
+ * Returns translated parsed and substituted string based on last count parameter.
38
+ *
39
+ * @param text - text to localize
40
+ * @param count - number of items/things
41
+ * @example use like `__n("%s cats", 1) returns `1 cat`
42
+ */
43
+ abstract __n(text: string | IPhraseWithOptions, count: number): string;
44
+ /**
45
+ * Returns a list of translations for a given phrase in each language.
46
+ *
47
+ * @param text - text to translate
48
+ */
49
+ abstract __l(text: string): string[];
50
+ /**
51
+ * Returns a hashed list of translations for a given phrase in each language.
52
+ *
53
+ * @param text - text to translate
54
+ */
55
+ abstract __h(text: string): any[];
56
+ }
57
+ /**
58
+ * Basic internationalization support. Text phrases are read from json files specified
59
+ * in system.dirs.locales
60
+ */
61
+ export declare class SpineJsInternationalizationFromJson extends Intl {
62
+ /**
63
+ * Map with avaible translations, keyed by locale name
64
+ */
65
+ Locales: {};
66
+ /**
67
+ * Logger for this module
68
+ */
69
+ protected Log: Log;
70
+ protected Configuration: Configuration;
71
+ resolve(): Promise<void>;
72
+ /**
73
+ * I18n localization function. Returns localized string.
74
+ * If no translation is avaible at current selected language, then fallback to
75
+ * default language, if still no translation exists, original text is returned
76
+ *
77
+ * @param text - text to localize.
78
+ * @param args - argument passed to formatted text
79
+ */
80
+ __(text: string | IPhraseWithOptions, ...args: any[]): string;
81
+ /**
82
+ * Plurals translation of a single phrase.
83
+ * Returns translated, parsed and substituted string based on count parameter.
84
+ *
85
+ * @param text - text to localize
86
+ * @param count - number of items/things
87
+ * @example use like `__n("%s cats", 1) returns '1 cat'`
88
+ */
89
+ __n(text: string | IPhraseWithOptions, count: number): string;
90
+ /**
91
+ * Returns a list of translations for a given phrase in each language.
92
+ *
93
+ * @param text - text to translate
94
+ */
95
+ __l(text: string): string[];
96
+ /**
97
+ * Returns a hashed list of translations for a given phrase in each language.
98
+ *
99
+ * @param text - text to translate
100
+ */
101
+ __h(text: string): any[];
102
+ }
103
+ /**
104
+ * Helper function for translations ( eg. for use as in template rentering engines)
105
+ */
106
+ export declare function __translate(lang: string): (text: string | IPhraseWithOptions, ...args: any[]) => string;
107
+ export declare function __translateNumber(lang: string): (text: string | IPhraseWithOptions, count: number) => string;
108
+ export declare function __translateL(text: string): string[];
109
+ export declare function __translateH(text: string): any[];
110
+ export declare function guessLanguage(lang?: string): string;
111
+ export declare function defaultLanguage(): string;
112
+ //# sourceMappingURL=index.d.ts.map