@spinajs/intl 1.0.1 → 1.2.103
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 +11 -0
- package/lib/config/locales.d.ts +12 -0
- package/lib/config/locales.js +15 -4
- package/lib/config/locales.js.map +1 -1
- package/lib/index.d.ts +77 -7
- package/lib/index.js +116 -26
- package/lib/index.js.map +1 -1
- package/lib/intl/src/config/locales.d.ts +12 -0
- package/lib/intl/src/config/locales.js +17 -0
- package/lib/intl/src/config/locales.js.map +1 -0
- package/lib/intl/src/index.d.ts +99 -0
- package/lib/intl/src/index.js +272 -0
- package/lib/intl/src/index.js.map +1 -0
- package/lib/intl/src/sources.d.ts +13 -0
- package/lib/intl/src/sources.js +126 -0
- package/lib/intl/src/sources.js.map +1 -0
- package/lib/log-common/src/index.d.ts +179 -0
- package/lib/log-common/src/index.js +88 -0
- package/lib/log-common/src/index.js.map +1 -0
- package/package.json +20 -40
- package/lib/src/index.d.ts +0 -28
- package/lib/src/index.js +0 -179
- package/lib/src/index.js.map +0 -1
- package/lib/typings/global/index.d.ts +0 -18
- package/lib/typings/global/index.js +0 -1
- package/lib/typings/global/index.js.map +0 -1
- package/typings/global/index.d.ts +0 -81
- package/typings/make-plural/index.d.ts +0 -1
package/README.md
ADDED
package/lib/config/locales.d.ts
CHANGED
package/lib/config/locales.js
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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":"
|
|
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,98 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SyncModule } from '@spinajs/di';
|
|
2
2
|
import { Configuration } from '@spinajs/configuration';
|
|
3
|
-
import { Log } from
|
|
3
|
+
import { Log } from '@spinajs/log';
|
|
4
4
|
export interface IPhraseWithOptions {
|
|
5
5
|
phrase: string;
|
|
6
6
|
locale: string;
|
|
7
7
|
}
|
|
8
8
|
export declare abstract class Intl extends SyncModule {
|
|
9
|
-
|
|
9
|
+
private _currentLocale;
|
|
10
|
+
/**
|
|
11
|
+
* Currently selected locale
|
|
12
|
+
*/
|
|
13
|
+
get CurrentLocale(): string;
|
|
14
|
+
/**
|
|
15
|
+
* Currently selected locale
|
|
16
|
+
*/
|
|
17
|
+
set CurrentLocale(value: string);
|
|
18
|
+
/**
|
|
19
|
+
* Map with avaible translations, keyed by locale name
|
|
20
|
+
*/
|
|
10
21
|
Locales: Map<string, any>;
|
|
22
|
+
/**
|
|
23
|
+
* I18n localization function. Returns localized string.
|
|
24
|
+
* If no translation is avaible at current selected language, then fallback to
|
|
25
|
+
* default language, if still no translation exists, original text is returned
|
|
26
|
+
*
|
|
27
|
+
* @param text - text to localize.
|
|
28
|
+
* @param args - argument passed to formatted text
|
|
29
|
+
*/
|
|
11
30
|
abstract __(text: string | IPhraseWithOptions, ...args: any[]): string;
|
|
31
|
+
/**
|
|
32
|
+
* Plurals translation of a single phrase. Singular and plural forms will get added to locales if unknown.
|
|
33
|
+
* Returns translated parsed and substituted string based on last count parameter.
|
|
34
|
+
*
|
|
35
|
+
* @param text - text to localize
|
|
36
|
+
* @param count - number of items/things
|
|
37
|
+
* @example use like `__n("%s cats", 1) returns `1 cat`
|
|
38
|
+
*/
|
|
12
39
|
abstract __n(text: string | IPhraseWithOptions, count: number): string;
|
|
40
|
+
/**
|
|
41
|
+
* Returns a list of translations for a given phrase in each language.
|
|
42
|
+
*
|
|
43
|
+
* @param text - text to translate
|
|
44
|
+
*/
|
|
13
45
|
abstract __l(text: string): string[];
|
|
46
|
+
/**
|
|
47
|
+
* Returns a hashed list of translations for a given phrase in each language.
|
|
48
|
+
*
|
|
49
|
+
* @param text - text to translate
|
|
50
|
+
*/
|
|
14
51
|
abstract __h(text: string): any[];
|
|
15
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Basic internationalization support. Text phrases are read from json files specified
|
|
55
|
+
* in system.dirs.locales
|
|
56
|
+
*/
|
|
16
57
|
export declare class SpineJsInternationalizationFromJson extends Intl {
|
|
17
|
-
|
|
18
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Map with avaible translations, keyed by locale name
|
|
60
|
+
*/
|
|
19
61
|
Locales: Map<string, any>;
|
|
62
|
+
/**
|
|
63
|
+
* Logger for this module
|
|
64
|
+
*/
|
|
20
65
|
protected Log: Log;
|
|
21
66
|
protected Configuration: Configuration;
|
|
22
|
-
|
|
23
|
-
|
|
67
|
+
resolve(): void;
|
|
68
|
+
/**
|
|
69
|
+
* I18n localization function. Returns localized string.
|
|
70
|
+
* If no translation is avaible at current selected language, then fallback to
|
|
71
|
+
* default language, if still no translation exists, original text is returned
|
|
72
|
+
*
|
|
73
|
+
* @param text - text to localize.
|
|
74
|
+
* @param args - argument passed to formatted text
|
|
75
|
+
*/
|
|
24
76
|
__(text: string | IPhraseWithOptions, ...args: any[]): string;
|
|
77
|
+
/**
|
|
78
|
+
* Plurals translation of a single phrase.
|
|
79
|
+
* Returns translated, parsed and substituted string based on count parameter.
|
|
80
|
+
*
|
|
81
|
+
* @param text - text to localize
|
|
82
|
+
* @param count - number of items/things
|
|
83
|
+
* @example use like `__n("%s cats", 1) returns '1 cat'`
|
|
84
|
+
*/
|
|
25
85
|
__n(text: string | IPhraseWithOptions, count: number): string;
|
|
86
|
+
/**
|
|
87
|
+
* Returns a list of translations for a given phrase in each language.
|
|
88
|
+
*
|
|
89
|
+
* @param text - text to translate
|
|
90
|
+
*/
|
|
26
91
|
__l(text: string): string[];
|
|
92
|
+
/**
|
|
93
|
+
* Returns a hashed list of translations for a given phrase in each language.
|
|
94
|
+
*
|
|
95
|
+
* @param text - text to translate
|
|
96
|
+
*/
|
|
27
97
|
__h(text: string): any[];
|
|
28
98
|
}
|
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.
|
|
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,7 +24,7 @@ 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
|
};
|
|
@@ -44,42 +48,60 @@ const globalAny = global;
|
|
|
44
48
|
class Intl extends di_1.SyncModule {
|
|
45
49
|
constructor() {
|
|
46
50
|
super(...arguments);
|
|
51
|
+
/**
|
|
52
|
+
* Map with avaible translations, keyed by locale name
|
|
53
|
+
*/
|
|
47
54
|
this.Locales = new Map();
|
|
48
55
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
constructor() {
|
|
53
|
-
super(...arguments);
|
|
54
|
-
this.Locales = new Map();
|
|
55
|
-
}
|
|
56
|
+
/**
|
|
57
|
+
* Currently selected locale
|
|
58
|
+
*/
|
|
56
59
|
get CurrentLocale() {
|
|
57
60
|
return this._currentLocale;
|
|
58
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Currently selected locale
|
|
64
|
+
*/
|
|
59
65
|
set CurrentLocale(value) {
|
|
60
66
|
if (!value) {
|
|
61
|
-
throw new exceptions_1.InvalidArgument(
|
|
67
|
+
throw new exceptions_1.InvalidArgument('value cannot be empty or null');
|
|
62
68
|
}
|
|
63
69
|
this._currentLocale = value;
|
|
64
70
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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 = new Map();
|
|
84
|
+
}
|
|
85
|
+
// tslint:disable-next-line: variable-name
|
|
86
|
+
resolve() {
|
|
87
|
+
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`))
|
|
70
92
|
.reduce((prev, current) => {
|
|
71
93
|
return prev.concat(_.flattenDeep(current));
|
|
72
94
|
}, [])
|
|
73
|
-
.map(f => path_1.normalize(path_1.resolve(f)))
|
|
74
|
-
.map(f => {
|
|
95
|
+
.map((f) => (0, path_1.normalize)((0, path_1.resolve)(f)))
|
|
96
|
+
.map((f) => {
|
|
75
97
|
this.Log.trace(`Found localisation file at ${f}`);
|
|
76
98
|
return f;
|
|
77
99
|
})
|
|
78
|
-
.forEach(f => {
|
|
79
|
-
const lang = path_1.basename(f, '.json');
|
|
100
|
+
.forEach((f) => {
|
|
101
|
+
const lang = (0, path_1.basename)(f, '.json');
|
|
80
102
|
let data;
|
|
81
103
|
try {
|
|
82
|
-
data = JSON.parse(fs.readFileSync(f,
|
|
104
|
+
data = JSON.parse(fs.readFileSync(f, 'utf-8'));
|
|
83
105
|
}
|
|
84
106
|
catch (ex) {
|
|
85
107
|
this.Log.warn(ex, `Cannot load localisation data from file ${f} for lang ${lang}`);
|
|
@@ -92,10 +114,20 @@ let SpineJsInternationalizationFromJson = class SpineJsInternationalizationFromJ
|
|
|
92
114
|
this.Locales.set(lang, _.merge(data, this.Locales.get(lang) && {}));
|
|
93
115
|
});
|
|
94
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* I18n localization function. Returns localized string.
|
|
119
|
+
* If no translation is avaible at current selected language, then fallback to
|
|
120
|
+
* default language, if still no translation exists, original text is returned
|
|
121
|
+
*
|
|
122
|
+
* @param text - text to localize.
|
|
123
|
+
* @param args - argument passed to formatted text
|
|
124
|
+
*/
|
|
95
125
|
__(text, ...args) {
|
|
96
126
|
var _a, _b;
|
|
97
127
|
let locTable;
|
|
98
128
|
let toLocalize;
|
|
129
|
+
if (!text)
|
|
130
|
+
return '';
|
|
99
131
|
if (_.isString(text)) {
|
|
100
132
|
locTable = this.Locales.get(this.CurrentLocale);
|
|
101
133
|
toLocalize = text;
|
|
@@ -109,11 +141,21 @@ let SpineJsInternationalizationFromJson = class SpineJsInternationalizationFromJ
|
|
|
109
141
|
}
|
|
110
142
|
return util.format((_b = locTable[toLocalize]) !== null && _b !== void 0 ? _b : toLocalize, ...args);
|
|
111
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Plurals translation of a single phrase.
|
|
146
|
+
* Returns translated, parsed and substituted string based on count parameter.
|
|
147
|
+
*
|
|
148
|
+
* @param text - text to localize
|
|
149
|
+
* @param count - number of items/things
|
|
150
|
+
* @example use like `__n("%s cats", 1) returns '1 cat'`
|
|
151
|
+
*/
|
|
112
152
|
__n(text, count) {
|
|
113
153
|
var _a, _b;
|
|
114
154
|
let locTable;
|
|
115
155
|
let toLocalize;
|
|
116
156
|
let locale;
|
|
157
|
+
if (!text)
|
|
158
|
+
return '';
|
|
117
159
|
if (_.isString(text)) {
|
|
118
160
|
locale = this.CurrentLocale;
|
|
119
161
|
locTable = this.Locales.get(this.CurrentLocale);
|
|
@@ -139,7 +181,7 @@ let SpineJsInternationalizationFromJson = class SpineJsInternationalizationFromJ
|
|
|
139
181
|
function _getInterval(text, count) {
|
|
140
182
|
let toReturn = text;
|
|
141
183
|
const phrases = text.split(/\|/);
|
|
142
|
-
phrases.some(phrase => {
|
|
184
|
+
phrases.some((phrase) => {
|
|
143
185
|
const matches = phrase.match(/^\s*([\(\)\[\]\d,]+)?\s*(.*)$/);
|
|
144
186
|
if (matches[1] && _matchInterval(count, matches[1])) {
|
|
145
187
|
toReturn = matches[2];
|
|
@@ -150,6 +192,14 @@ let SpineJsInternationalizationFromJson = class SpineJsInternationalizationFromJ
|
|
|
150
192
|
}
|
|
151
193
|
});
|
|
152
194
|
return toReturn;
|
|
195
|
+
/**
|
|
196
|
+
* test a number to match mathematical interval expressions
|
|
197
|
+
* [0,2] - 0 to 2 (including, matches: 0, 1, 2)
|
|
198
|
+
* ]0,3[ - 0 to 3 (excluding, matches: 1, 2)
|
|
199
|
+
* [1] - 1 (matches: 1)
|
|
200
|
+
* [20,] - all numbers ≥20 (matches: 20, 21, 22, ...)
|
|
201
|
+
* [,20] - all numbers ≤20 (matches: 20, 21, 22, ...)
|
|
202
|
+
*/
|
|
153
203
|
function _matchInterval(c, eq) {
|
|
154
204
|
const interval = InvervalParser.default(eq);
|
|
155
205
|
if (interval) {
|
|
@@ -159,19 +209,33 @@ let SpineJsInternationalizationFromJson = class SpineJsInternationalizationFromJ
|
|
|
159
209
|
if (interval.to.value === c) {
|
|
160
210
|
return interval.from.included;
|
|
161
211
|
}
|
|
162
|
-
return
|
|
212
|
+
return Math.min(interval.from.value, c) === interval.from.value && Math.max(interval.to.value, c) === interval.to.value;
|
|
163
213
|
}
|
|
164
214
|
return false;
|
|
165
215
|
}
|
|
166
216
|
}
|
|
167
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Returns a list of translations for a given phrase in each language.
|
|
220
|
+
*
|
|
221
|
+
* @param text - text to translate
|
|
222
|
+
*/
|
|
168
223
|
__l(text) {
|
|
224
|
+
if (!text)
|
|
225
|
+
return [];
|
|
169
226
|
const extract = _.property(text);
|
|
170
227
|
return Array.from(this.Locales.values()).map((v) => {
|
|
171
228
|
return extract(v);
|
|
172
229
|
});
|
|
173
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* Returns a hashed list of translations for a given phrase in each language.
|
|
233
|
+
*
|
|
234
|
+
* @param text - text to translate
|
|
235
|
+
*/
|
|
174
236
|
__h(text) {
|
|
237
|
+
if (!text)
|
|
238
|
+
return [];
|
|
175
239
|
const extract = _.property(text);
|
|
176
240
|
return Array.from(this.Locales.values()).map((v, locale) => {
|
|
177
241
|
return { [locale]: extract(v) };
|
|
@@ -179,26 +243,52 @@ let SpineJsInternationalizationFromJson = class SpineJsInternationalizationFromJ
|
|
|
179
243
|
}
|
|
180
244
|
};
|
|
181
245
|
__decorate([
|
|
182
|
-
log_1.Logger(
|
|
183
|
-
__metadata("design:type",
|
|
246
|
+
(0, log_1.Logger)('Intl'),
|
|
247
|
+
__metadata("design:type", log_1.Log)
|
|
184
248
|
], SpineJsInternationalizationFromJson.prototype, "Log", void 0);
|
|
185
249
|
__decorate([
|
|
186
|
-
di_1.Autoinject(),
|
|
250
|
+
(0, di_1.Autoinject)(),
|
|
187
251
|
__metadata("design:type", configuration_1.Configuration)
|
|
188
252
|
], SpineJsInternationalizationFromJson.prototype, "Configuration", void 0);
|
|
189
253
|
SpineJsInternationalizationFromJson = __decorate([
|
|
190
|
-
di_1.Injectable(Intl)
|
|
254
|
+
(0, di_1.Injectable)(Intl)
|
|
191
255
|
], SpineJsInternationalizationFromJson);
|
|
192
256
|
exports.SpineJsInternationalizationFromJson = SpineJsInternationalizationFromJson;
|
|
257
|
+
/**
|
|
258
|
+
* I18n localization function. Returns localized string.
|
|
259
|
+
* If no translation is avaible at current selected language, then fallback to
|
|
260
|
+
* default language, if still no translation exists, original text is returned
|
|
261
|
+
*
|
|
262
|
+
* @param text - text to localize.
|
|
263
|
+
* @param locale - selected locale, if not specified - default locale is selected
|
|
264
|
+
*/
|
|
193
265
|
globalAny.__ = (text, ...args) => {
|
|
194
266
|
return di_1.DI.get(Intl).__(text, ...args);
|
|
195
267
|
};
|
|
268
|
+
/**
|
|
269
|
+
* Plurals translation of a single phrase. Singular and plural forms will get added to locales if unknown.
|
|
270
|
+
* Returns translated parsed and substituted string based on last count parameter.
|
|
271
|
+
*
|
|
272
|
+
* @param text - text to localize
|
|
273
|
+
* @param count - number of items/things
|
|
274
|
+
* @example use like `__n("%s cats", 1) returns `1 cat`
|
|
275
|
+
*/
|
|
196
276
|
globalAny.__n = (text, count) => {
|
|
197
277
|
return di_1.DI.get(Intl).__n(text, count);
|
|
198
278
|
};
|
|
279
|
+
/**
|
|
280
|
+
* Returns a list of translations for a given phrase in each language.
|
|
281
|
+
*
|
|
282
|
+
* @param text - text to translate
|
|
283
|
+
*/
|
|
199
284
|
globalAny.__l = (text) => {
|
|
200
285
|
return di_1.DI.get(Intl).__l(text);
|
|
201
286
|
};
|
|
287
|
+
/**
|
|
288
|
+
* Returns a hashed list of translations for a given phrase in each language.
|
|
289
|
+
*
|
|
290
|
+
* @param text - text to translate
|
|
291
|
+
*/
|
|
202
292
|
globalAny.__h = (text) => {
|
|
203
293
|
return di_1.DI.get(Intl).__h(text);
|
|
204
294
|
};
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
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;SA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lMY,kFAAmC;AAoMhD;;;;;;;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"}
|
|
@@ -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
|
+
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,99 @@
|
|
|
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
|
+
}
|