vviinn-widgets 2.62.0 → 2.63.0
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/dist/cjs/{index-c33ee22e.js → index-906a587a.js} +2253 -92
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/{package-b1ec17b3.js → package-00199f27.js} +1 -1
- package/dist/cjs/resources-c5fbe419.js +97 -0
- package/dist/cjs/{search-filters_17.cjs.entry.js → search-filters_18.cjs.entry.js} +199 -9
- package/dist/cjs/{search.store-d6fff13b.js → search.store-ce0289aa.js} +68 -76
- package/dist/cjs/vviinn-carousel_6.cjs.entry.js +14 -14
- package/dist/cjs/vviinn-error.cjs.entry.js +1 -1
- package/dist/cjs/vviinn-preloader.cjs.entry.js +1 -1
- package/dist/cjs/vviinn-vpr-button.cjs.entry.js +1 -1
- package/dist/cjs/vviinn-vps-button.cjs.entry.js +2 -2
- package/dist/cjs/vviinn-vps-widget.cjs.entry.js +25 -134
- package/dist/cjs/vviinn-widgets.cjs.js +1 -1
- package/dist/collection/collection-manifest.json +1 -0
- package/dist/collection/components/vviinn-error/vviinn-error.css +3 -0
- package/dist/collection/components/vviinn-results/vviinn-results.css +94 -0
- package/dist/collection/components/vviinn-results/vviinn-results.js +647 -0
- package/dist/collection/components/vviinn-vps-button/vviinn-vps-button.js +11 -2
- package/dist/collection/components/vviinn-vps-widget/vviinn-vps-widget.css +4 -100
- package/dist/collection/components/vviinn-vps-widget/vviinn-vps-widget.js +38 -254
- package/dist/collection/geometry/Rectangle.js +0 -34
- package/dist/collection/network/ion/Link.js +4 -0
- package/dist/collection/store/search.store.js +8 -9
- package/dist/esm/{index-f797914c.js → index-f183e646.js} +2253 -92
- package/dist/esm/loader.js +1 -1
- package/dist/esm/{package-be836bde.js → package-ab3fee7e.js} +1 -1
- package/dist/esm/resources-5ad3b316.js +95 -0
- package/dist/esm/{search-filters_17.entry.js → search-filters_18.entry.js} +192 -3
- package/dist/esm/{search.store-4d95a8f8.js → search.store-5dda7985.js} +67 -77
- package/dist/esm/vviinn-carousel_6.entry.js +4 -4
- package/dist/esm/vviinn-error.entry.js +1 -1
- package/dist/esm/vviinn-preloader.entry.js +1 -1
- package/dist/esm/vviinn-vpr-button.entry.js +1 -1
- package/dist/esm/vviinn-vps-button.entry.js +2 -2
- package/dist/esm/vviinn-vps-widget.entry.js +20 -129
- package/dist/esm/vviinn-widgets.js +1 -1
- package/dist/types/components/vviinn-results/vviinn-results.d.ts +83 -0
- package/dist/types/components/vviinn-vps-button/vviinn-vps-button.d.ts +10 -1
- package/dist/types/components/vviinn-vps-widget/vviinn-vps-widget.d.ts +8 -27
- package/dist/types/components.d.ts +103 -20
- package/dist/types/geometry/Rectangle.d.ts +0 -7
- package/dist/types/network/ion/Link.d.ts +2 -0
- package/dist/types/store/search.store.d.ts +19 -3
- package/dist/vviinn-widgets/p-12f21b13.js +1 -0
- package/dist/vviinn-widgets/p-2261d4fc.entry.js +1 -0
- package/dist/vviinn-widgets/p-32f5cf0b.js +1 -0
- package/dist/vviinn-widgets/p-6b53f2a1.entry.js +11 -0
- package/dist/vviinn-widgets/p-7898794a.js +1 -0
- package/dist/vviinn-widgets/p-b1fabcfc.entry.js +1 -0
- package/dist/vviinn-widgets/{p-c09c2a29.entry.js → p-b5fcd710.entry.js} +1 -1
- package/{www/build/p-98f4c68e.js → dist/vviinn-widgets/p-bba30ade.js} +1 -1
- package/dist/vviinn-widgets/p-d22e2933.entry.js +1 -0
- package/dist/vviinn-widgets/{p-8d4d9e15.entry.js → p-dbd312bf.entry.js} +1 -1
- package/dist/vviinn-widgets/{p-e3e2c98a.entry.js → p-e5d8ae2b.entry.js} +1 -1
- package/dist/vviinn-widgets/vviinn-widgets.esm.js +1 -1
- package/package.json +1 -1
- package/www/build/p-12f21b13.js +1 -0
- package/www/build/p-2261d4fc.entry.js +1 -0
- package/www/build/p-32f5cf0b.js +1 -0
- package/www/build/p-6b53f2a1.entry.js +11 -0
- package/www/build/p-7898794a.js +1 -0
- package/www/build/p-b1fabcfc.entry.js +1 -0
- package/www/build/{p-c09c2a29.entry.js → p-b5fcd710.entry.js} +1 -1
- package/{dist/vviinn-widgets/p-98f4c68e.js → www/build/p-bba30ade.js} +1 -1
- package/www/build/p-d22e2933.entry.js +1 -0
- package/www/build/{p-8d4d9e15.entry.js → p-dbd312bf.entry.js} +1 -1
- package/www/build/{p-e3e2c98a.entry.js → p-e5d8ae2b.entry.js} +1 -1
- package/www/build/vviinn-widgets.esm.js +1 -1
- package/dist/cjs/i18next-74ff3413.js +0 -2258
- package/dist/collection/cropper/Cropper.js +0 -1
- package/dist/collection/cropper/Handler.js +0 -61
- package/dist/esm/i18next-387f2b0a.js +0 -2256
- package/dist/types/cropper/Cropper.d.ts +0 -2
- package/dist/types/cropper/Handler.d.ts +0 -18
- package/dist/vviinn-widgets/p-14df98d5.entry.js +0 -1
- package/dist/vviinn-widgets/p-2cead38f.entry.js +0 -1
- package/dist/vviinn-widgets/p-2d5b312d.entry.js +0 -1
- package/dist/vviinn-widgets/p-2e76a5c3.js +0 -1
- package/dist/vviinn-widgets/p-43a9167b.entry.js +0 -11
- package/dist/vviinn-widgets/p-c0e34407.js +0 -1
- package/dist/vviinn-widgets/p-cd71ef95.js +0 -1
- package/www/build/p-14df98d5.entry.js +0 -1
- package/www/build/p-2cead38f.entry.js +0 -1
- package/www/build/p-2d5b312d.entry.js +0 -1
- package/www/build/p-2e76a5c3.js +0 -1
- package/www/build/p-43a9167b.entry.js +0 -11
- package/www/build/p-c0e34407.js +0 -1
- package/www/build/p-cd71ef95.js +0 -1
|
@@ -1,100 +1,2261 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const search_store = require('./search.store-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
noResultText: "Keine Ergebnisse! Versuche es bitte später erneut.",
|
|
10
|
-
basketButtonText: "In den Warenkorb",
|
|
11
|
-
setMode: {
|
|
12
|
-
widgetTitle: "Kaufen Sie ein Set und erhalten Sie Rabatt",
|
|
13
|
-
widgetSubtitle: "Sparen Sie bis zu 15% beim Kauf von Produkten aus der Liste",
|
|
14
|
-
basketButtonText: "Als Set kaufen",
|
|
15
|
-
appliedDiscountText: "gespart",
|
|
16
|
-
updateButtonText: "Neues Set vorschlagen",
|
|
17
|
-
},
|
|
18
|
-
exampleImagesTitle: "Mit den Beispielbildern die Suche direkt ausprobieren",
|
|
19
|
-
imageUploadButtonText: "Bild hochladen",
|
|
20
|
-
cameraButtonTextStart: "Kamera starten",
|
|
21
|
-
cameraButtonTextStop: "Kamera stoppen",
|
|
22
|
-
privacyBadgeText: `Durch das Hochladen eines Bildes willigst Du in die Verarbeitung durch unseren Partner ${VVIINN_LINK} ein. Das Bild wird nach einer Stunde Inaktivität gelöscht.`,
|
|
23
|
-
teaserText: "Finde Produkte auf \n einem Foto",
|
|
24
|
-
imageSearchModalTitle: "AI Search",
|
|
25
|
-
textSearchPlaceholder: "mit Text suchen",
|
|
26
|
-
emptyResultsBlock: {
|
|
27
|
-
title: "Leider nichts gefunden",
|
|
28
|
-
button: "Neues Bild hochladen",
|
|
29
|
-
},
|
|
30
|
-
serverErrorBlock: {
|
|
31
|
-
title: "Keine Verbindung",
|
|
32
|
-
button: "Erneut versuchen",
|
|
33
|
-
},
|
|
34
|
-
wrongFormatBlock: {
|
|
35
|
-
title: "Dateityp wird nicht unterstützt",
|
|
36
|
-
text: "Bitte laden Sie eine .jpg, .png oder .webp Bilddatei hoch.",
|
|
37
|
-
button: "Neues Bild hochladen",
|
|
38
|
-
},
|
|
39
|
-
wrongAspectRatioBlock: {
|
|
40
|
-
title: "Das Bild ist zu schmal",
|
|
41
|
-
button: "Neues Bild hochladen",
|
|
42
|
-
},
|
|
43
|
-
filters: {
|
|
44
|
-
modal: {
|
|
45
|
-
title: "Filter",
|
|
46
|
-
apply: "Anwenden",
|
|
47
|
-
resetFilters: "Filter zurücksetzen",
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
},
|
|
3
|
+
const search_store = require('./search.store-ce0289aa.js');
|
|
4
|
+
|
|
5
|
+
const consoleLogger = {
|
|
6
|
+
type: 'logger',
|
|
7
|
+
log(args) {
|
|
8
|
+
this.output('log', args);
|
|
51
9
|
},
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
10
|
+
warn(args) {
|
|
11
|
+
this.output('warn', args);
|
|
12
|
+
},
|
|
13
|
+
error(args) {
|
|
14
|
+
this.output('error', args);
|
|
15
|
+
},
|
|
16
|
+
output(type, args) {
|
|
17
|
+
if (console && console[type]) console[type].apply(console, args);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
class Logger {
|
|
21
|
+
constructor(concreteLogger) {
|
|
22
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
23
|
+
this.init(concreteLogger, options);
|
|
24
|
+
}
|
|
25
|
+
init(concreteLogger) {
|
|
26
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
27
|
+
this.prefix = options.prefix || 'i18next:';
|
|
28
|
+
this.logger = concreteLogger || consoleLogger;
|
|
29
|
+
this.options = options;
|
|
30
|
+
this.debug = options.debug;
|
|
31
|
+
}
|
|
32
|
+
log() {
|
|
33
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
34
|
+
args[_key] = arguments[_key];
|
|
35
|
+
}
|
|
36
|
+
return this.forward(args, 'log', '', true);
|
|
37
|
+
}
|
|
38
|
+
warn() {
|
|
39
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
40
|
+
args[_key2] = arguments[_key2];
|
|
41
|
+
}
|
|
42
|
+
return this.forward(args, 'warn', '', true);
|
|
43
|
+
}
|
|
44
|
+
error() {
|
|
45
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
46
|
+
args[_key3] = arguments[_key3];
|
|
47
|
+
}
|
|
48
|
+
return this.forward(args, 'error', '');
|
|
49
|
+
}
|
|
50
|
+
deprecate() {
|
|
51
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
52
|
+
args[_key4] = arguments[_key4];
|
|
53
|
+
}
|
|
54
|
+
return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
|
|
55
|
+
}
|
|
56
|
+
forward(args, lvl, prefix, debugOnly) {
|
|
57
|
+
if (debugOnly && !this.debug) return null;
|
|
58
|
+
if (typeof args[0] === 'string') args[0] = `${prefix}${this.prefix} ${args[0]}`;
|
|
59
|
+
return this.logger[lvl](args);
|
|
60
|
+
}
|
|
61
|
+
create(moduleName) {
|
|
62
|
+
return new Logger(this.logger, {
|
|
63
|
+
...{
|
|
64
|
+
prefix: `${this.prefix}:${moduleName}:`
|
|
94
65
|
},
|
|
95
|
-
|
|
66
|
+
...this.options
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
clone(options) {
|
|
70
|
+
options = options || this.options;
|
|
71
|
+
options.prefix = options.prefix || this.prefix;
|
|
72
|
+
return new Logger(this.logger, options);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
var baseLogger = new Logger();
|
|
76
|
+
|
|
77
|
+
class EventEmitter {
|
|
78
|
+
constructor() {
|
|
79
|
+
this.observers = {};
|
|
80
|
+
}
|
|
81
|
+
on(events, listener) {
|
|
82
|
+
events.split(' ').forEach(event => {
|
|
83
|
+
this.observers[event] = this.observers[event] || [];
|
|
84
|
+
this.observers[event].push(listener);
|
|
85
|
+
});
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
off(event, listener) {
|
|
89
|
+
if (!this.observers[event]) return;
|
|
90
|
+
if (!listener) {
|
|
91
|
+
delete this.observers[event];
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
this.observers[event] = this.observers[event].filter(l => l !== listener);
|
|
95
|
+
}
|
|
96
|
+
emit(event) {
|
|
97
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
98
|
+
args[_key - 1] = arguments[_key];
|
|
99
|
+
}
|
|
100
|
+
if (this.observers[event]) {
|
|
101
|
+
const cloned = [].concat(this.observers[event]);
|
|
102
|
+
cloned.forEach(observer => {
|
|
103
|
+
observer(...args);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (this.observers['*']) {
|
|
107
|
+
const cloned = [].concat(this.observers['*']);
|
|
108
|
+
cloned.forEach(observer => {
|
|
109
|
+
observer.apply(observer, [event, ...args]);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function defer() {
|
|
116
|
+
let res;
|
|
117
|
+
let rej;
|
|
118
|
+
const promise = new Promise((resolve, reject) => {
|
|
119
|
+
res = resolve;
|
|
120
|
+
rej = reject;
|
|
121
|
+
});
|
|
122
|
+
promise.resolve = res;
|
|
123
|
+
promise.reject = rej;
|
|
124
|
+
return promise;
|
|
125
|
+
}
|
|
126
|
+
function makeString(object) {
|
|
127
|
+
if (object == null) return '';
|
|
128
|
+
return '' + object;
|
|
129
|
+
}
|
|
130
|
+
function copy(a, s, t) {
|
|
131
|
+
a.forEach(m => {
|
|
132
|
+
if (s[m]) t[m] = s[m];
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
function getLastOfPath(object, path, Empty) {
|
|
136
|
+
function cleanKey(key) {
|
|
137
|
+
return key && key.indexOf('###') > -1 ? key.replace(/###/g, '.') : key;
|
|
138
|
+
}
|
|
139
|
+
function canNotTraverseDeeper() {
|
|
140
|
+
return !object || typeof object === 'string';
|
|
141
|
+
}
|
|
142
|
+
const stack = typeof path !== 'string' ? [].concat(path) : path.split('.');
|
|
143
|
+
while (stack.length > 1) {
|
|
144
|
+
if (canNotTraverseDeeper()) return {};
|
|
145
|
+
const key = cleanKey(stack.shift());
|
|
146
|
+
if (!object[key] && Empty) object[key] = new Empty();
|
|
147
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
148
|
+
object = object[key];
|
|
149
|
+
} else {
|
|
150
|
+
object = {};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (canNotTraverseDeeper()) return {};
|
|
154
|
+
return {
|
|
155
|
+
obj: object,
|
|
156
|
+
k: cleanKey(stack.shift())
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function setPath(object, path, newValue) {
|
|
160
|
+
const {
|
|
161
|
+
obj,
|
|
162
|
+
k
|
|
163
|
+
} = getLastOfPath(object, path, Object);
|
|
164
|
+
obj[k] = newValue;
|
|
165
|
+
}
|
|
166
|
+
function pushPath(object, path, newValue, concat) {
|
|
167
|
+
const {
|
|
168
|
+
obj,
|
|
169
|
+
k
|
|
170
|
+
} = getLastOfPath(object, path, Object);
|
|
171
|
+
obj[k] = obj[k] || [];
|
|
172
|
+
if (concat) obj[k] = obj[k].concat(newValue);
|
|
173
|
+
if (!concat) obj[k].push(newValue);
|
|
174
|
+
}
|
|
175
|
+
function getPath(object, path) {
|
|
176
|
+
const {
|
|
177
|
+
obj,
|
|
178
|
+
k
|
|
179
|
+
} = getLastOfPath(object, path);
|
|
180
|
+
if (!obj) return undefined;
|
|
181
|
+
return obj[k];
|
|
182
|
+
}
|
|
183
|
+
function getPathWithDefaults(data, defaultData, key) {
|
|
184
|
+
const value = getPath(data, key);
|
|
185
|
+
if (value !== undefined) {
|
|
186
|
+
return value;
|
|
187
|
+
}
|
|
188
|
+
return getPath(defaultData, key);
|
|
189
|
+
}
|
|
190
|
+
function deepExtend(target, source, overwrite) {
|
|
191
|
+
for (const prop in source) {
|
|
192
|
+
if (prop !== '__proto__' && prop !== 'constructor') {
|
|
193
|
+
if (prop in target) {
|
|
194
|
+
if (typeof target[prop] === 'string' || target[prop] instanceof String || typeof source[prop] === 'string' || source[prop] instanceof String) {
|
|
195
|
+
if (overwrite) target[prop] = source[prop];
|
|
196
|
+
} else {
|
|
197
|
+
deepExtend(target[prop], source[prop], overwrite);
|
|
198
|
+
}
|
|
199
|
+
} else {
|
|
200
|
+
target[prop] = source[prop];
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return target;
|
|
205
|
+
}
|
|
206
|
+
function regexEscape(str) {
|
|
207
|
+
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
|
|
208
|
+
}
|
|
209
|
+
var _entityMap = {
|
|
210
|
+
'&': '&',
|
|
211
|
+
'<': '<',
|
|
212
|
+
'>': '>',
|
|
213
|
+
'"': '"',
|
|
214
|
+
"'": ''',
|
|
215
|
+
'/': '/'
|
|
216
|
+
};
|
|
217
|
+
function escape(data) {
|
|
218
|
+
if (typeof data === 'string') {
|
|
219
|
+
return data.replace(/[&<>"'\/]/g, s => _entityMap[s]);
|
|
220
|
+
}
|
|
221
|
+
return data;
|
|
222
|
+
}
|
|
223
|
+
const chars = [' ', ',', '?', '!', ';'];
|
|
224
|
+
function looksLikeObjectPath(key, nsSeparator, keySeparator) {
|
|
225
|
+
nsSeparator = nsSeparator || '';
|
|
226
|
+
keySeparator = keySeparator || '';
|
|
227
|
+
const possibleChars = chars.filter(c => nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0);
|
|
228
|
+
if (possibleChars.length === 0) return true;
|
|
229
|
+
const r = new RegExp(`(${possibleChars.map(c => c === '?' ? '\\?' : c).join('|')})`);
|
|
230
|
+
let matched = !r.test(key);
|
|
231
|
+
if (!matched) {
|
|
232
|
+
const ki = key.indexOf(keySeparator);
|
|
233
|
+
if (ki > 0 && !r.test(key.substring(0, ki))) {
|
|
234
|
+
matched = true;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return matched;
|
|
238
|
+
}
|
|
239
|
+
function deepFind(obj, path) {
|
|
240
|
+
let keySeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
|
|
241
|
+
if (!obj) return undefined;
|
|
242
|
+
if (obj[path]) return obj[path];
|
|
243
|
+
const paths = path.split(keySeparator);
|
|
244
|
+
let current = obj;
|
|
245
|
+
for (let i = 0; i < paths.length; ++i) {
|
|
246
|
+
if (!current) return undefined;
|
|
247
|
+
if (typeof current[paths[i]] === 'string' && i + 1 < paths.length) {
|
|
248
|
+
return undefined;
|
|
249
|
+
}
|
|
250
|
+
if (current[paths[i]] === undefined) {
|
|
251
|
+
let j = 2;
|
|
252
|
+
let p = paths.slice(i, i + j).join(keySeparator);
|
|
253
|
+
let mix = current[p];
|
|
254
|
+
while (mix === undefined && paths.length > i + j) {
|
|
255
|
+
j++;
|
|
256
|
+
p = paths.slice(i, i + j).join(keySeparator);
|
|
257
|
+
mix = current[p];
|
|
258
|
+
}
|
|
259
|
+
if (mix === undefined) return undefined;
|
|
260
|
+
if (mix === null) return null;
|
|
261
|
+
if (path.endsWith(p)) {
|
|
262
|
+
if (typeof mix === 'string') return mix;
|
|
263
|
+
if (p && typeof mix[p] === 'string') return mix[p];
|
|
264
|
+
}
|
|
265
|
+
const joinedPath = paths.slice(i + j).join(keySeparator);
|
|
266
|
+
if (joinedPath) return deepFind(mix, joinedPath, keySeparator);
|
|
267
|
+
return undefined;
|
|
268
|
+
}
|
|
269
|
+
current = current[paths[i]];
|
|
270
|
+
}
|
|
271
|
+
return current;
|
|
272
|
+
}
|
|
273
|
+
function getCleanedCode(code) {
|
|
274
|
+
if (code && code.indexOf('_') > 0) return code.replace('_', '-');
|
|
275
|
+
return code;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
class ResourceStore extends EventEmitter {
|
|
279
|
+
constructor(data) {
|
|
280
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
281
|
+
ns: ['translation'],
|
|
282
|
+
defaultNS: 'translation'
|
|
283
|
+
};
|
|
284
|
+
super();
|
|
285
|
+
this.data = data || {};
|
|
286
|
+
this.options = options;
|
|
287
|
+
if (this.options.keySeparator === undefined) {
|
|
288
|
+
this.options.keySeparator = '.';
|
|
289
|
+
}
|
|
290
|
+
if (this.options.ignoreJSONStructure === undefined) {
|
|
291
|
+
this.options.ignoreJSONStructure = true;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
addNamespaces(ns) {
|
|
295
|
+
if (this.options.ns.indexOf(ns) < 0) {
|
|
296
|
+
this.options.ns.push(ns);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
removeNamespaces(ns) {
|
|
300
|
+
const index = this.options.ns.indexOf(ns);
|
|
301
|
+
if (index > -1) {
|
|
302
|
+
this.options.ns.splice(index, 1);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
getResource(lng, ns, key) {
|
|
306
|
+
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
307
|
+
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
308
|
+
const ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
309
|
+
let path = [lng, ns];
|
|
310
|
+
if (key && typeof key !== 'string') path = path.concat(key);
|
|
311
|
+
if (key && typeof key === 'string') path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
312
|
+
if (lng.indexOf('.') > -1) {
|
|
313
|
+
path = lng.split('.');
|
|
314
|
+
}
|
|
315
|
+
const result = getPath(this.data, path);
|
|
316
|
+
if (result || !ignoreJSONStructure || typeof key !== 'string') return result;
|
|
317
|
+
return deepFind(this.data && this.data[lng] && this.data[lng][ns], key, keySeparator);
|
|
318
|
+
}
|
|
319
|
+
addResource(lng, ns, key, value) {
|
|
320
|
+
let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
|
321
|
+
silent: false
|
|
322
|
+
};
|
|
323
|
+
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
324
|
+
let path = [lng, ns];
|
|
325
|
+
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
326
|
+
if (lng.indexOf('.') > -1) {
|
|
327
|
+
path = lng.split('.');
|
|
328
|
+
value = ns;
|
|
329
|
+
ns = path[1];
|
|
330
|
+
}
|
|
331
|
+
this.addNamespaces(ns);
|
|
332
|
+
setPath(this.data, path, value);
|
|
333
|
+
if (!options.silent) this.emit('added', lng, ns, key, value);
|
|
334
|
+
}
|
|
335
|
+
addResources(lng, ns, resources) {
|
|
336
|
+
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
337
|
+
silent: false
|
|
338
|
+
};
|
|
339
|
+
for (const m in resources) {
|
|
340
|
+
if (typeof resources[m] === 'string' || Object.prototype.toString.apply(resources[m]) === '[object Array]') this.addResource(lng, ns, m, resources[m], {
|
|
341
|
+
silent: true
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
345
|
+
}
|
|
346
|
+
addResourceBundle(lng, ns, resources, deep, overwrite) {
|
|
347
|
+
let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {
|
|
348
|
+
silent: false
|
|
349
|
+
};
|
|
350
|
+
let path = [lng, ns];
|
|
351
|
+
if (lng.indexOf('.') > -1) {
|
|
352
|
+
path = lng.split('.');
|
|
353
|
+
deep = resources;
|
|
354
|
+
resources = ns;
|
|
355
|
+
ns = path[1];
|
|
356
|
+
}
|
|
357
|
+
this.addNamespaces(ns);
|
|
358
|
+
let pack = getPath(this.data, path) || {};
|
|
359
|
+
if (deep) {
|
|
360
|
+
deepExtend(pack, resources, overwrite);
|
|
361
|
+
} else {
|
|
362
|
+
pack = {
|
|
363
|
+
...pack,
|
|
364
|
+
...resources
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
setPath(this.data, path, pack);
|
|
368
|
+
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
369
|
+
}
|
|
370
|
+
removeResourceBundle(lng, ns) {
|
|
371
|
+
if (this.hasResourceBundle(lng, ns)) {
|
|
372
|
+
delete this.data[lng][ns];
|
|
373
|
+
}
|
|
374
|
+
this.removeNamespaces(ns);
|
|
375
|
+
this.emit('removed', lng, ns);
|
|
376
|
+
}
|
|
377
|
+
hasResourceBundle(lng, ns) {
|
|
378
|
+
return this.getResource(lng, ns) !== undefined;
|
|
379
|
+
}
|
|
380
|
+
getResourceBundle(lng, ns) {
|
|
381
|
+
if (!ns) ns = this.options.defaultNS;
|
|
382
|
+
if (this.options.compatibilityAPI === 'v1') return {
|
|
383
|
+
...{},
|
|
384
|
+
...this.getResource(lng, ns)
|
|
385
|
+
};
|
|
386
|
+
return this.getResource(lng, ns);
|
|
387
|
+
}
|
|
388
|
+
getDataByLanguage(lng) {
|
|
389
|
+
return this.data[lng];
|
|
390
|
+
}
|
|
391
|
+
hasLanguageSomeTranslations(lng) {
|
|
392
|
+
const data = this.getDataByLanguage(lng);
|
|
393
|
+
const n = data && Object.keys(data) || [];
|
|
394
|
+
return !!n.find(v => data[v] && Object.keys(data[v]).length > 0);
|
|
395
|
+
}
|
|
396
|
+
toJSON() {
|
|
397
|
+
return this.data;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
var postProcessor = {
|
|
402
|
+
processors: {},
|
|
403
|
+
addPostProcessor(module) {
|
|
404
|
+
this.processors[module.name] = module;
|
|
405
|
+
},
|
|
406
|
+
handle(processors, value, key, options, translator) {
|
|
407
|
+
processors.forEach(processor => {
|
|
408
|
+
if (this.processors[processor]) value = this.processors[processor].process(value, key, options, translator);
|
|
409
|
+
});
|
|
410
|
+
return value;
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
const checkedLoadedFor = {};
|
|
415
|
+
class Translator extends EventEmitter {
|
|
416
|
+
constructor(services) {
|
|
417
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
418
|
+
super();
|
|
419
|
+
copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector', 'i18nFormat', 'utils'], services, this);
|
|
420
|
+
this.options = options;
|
|
421
|
+
if (this.options.keySeparator === undefined) {
|
|
422
|
+
this.options.keySeparator = '.';
|
|
423
|
+
}
|
|
424
|
+
this.logger = baseLogger.create('translator');
|
|
425
|
+
}
|
|
426
|
+
changeLanguage(lng) {
|
|
427
|
+
if (lng) this.language = lng;
|
|
428
|
+
}
|
|
429
|
+
exists(key) {
|
|
430
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
431
|
+
interpolation: {}
|
|
432
|
+
};
|
|
433
|
+
if (key === undefined || key === null) {
|
|
434
|
+
return false;
|
|
435
|
+
}
|
|
436
|
+
const resolved = this.resolve(key, options);
|
|
437
|
+
return resolved && resolved.res !== undefined;
|
|
438
|
+
}
|
|
439
|
+
extractFromKey(key, options) {
|
|
440
|
+
let nsSeparator = options.nsSeparator !== undefined ? options.nsSeparator : this.options.nsSeparator;
|
|
441
|
+
if (nsSeparator === undefined) nsSeparator = ':';
|
|
442
|
+
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
443
|
+
let namespaces = options.ns || this.options.defaultNS || [];
|
|
444
|
+
const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
|
|
445
|
+
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
446
|
+
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
447
|
+
const m = key.match(this.interpolator.nestingRegexp);
|
|
448
|
+
if (m && m.length > 0) {
|
|
449
|
+
return {
|
|
450
|
+
key,
|
|
451
|
+
namespaces
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
const parts = key.split(nsSeparator);
|
|
455
|
+
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
|
|
456
|
+
key = parts.join(keySeparator);
|
|
457
|
+
}
|
|
458
|
+
if (typeof namespaces === 'string') namespaces = [namespaces];
|
|
459
|
+
return {
|
|
460
|
+
key,
|
|
461
|
+
namespaces
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
translate(keys, options, lastKey) {
|
|
465
|
+
if (typeof options !== 'object' && this.options.overloadTranslationOptionHandler) {
|
|
466
|
+
options = this.options.overloadTranslationOptionHandler(arguments);
|
|
467
|
+
}
|
|
468
|
+
if (typeof options === 'object') options = {
|
|
469
|
+
...options
|
|
470
|
+
};
|
|
471
|
+
if (!options) options = {};
|
|
472
|
+
if (keys === undefined || keys === null) return '';
|
|
473
|
+
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
474
|
+
const returnDetails = options.returnDetails !== undefined ? options.returnDetails : this.options.returnDetails;
|
|
475
|
+
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
476
|
+
const {
|
|
477
|
+
key,
|
|
478
|
+
namespaces
|
|
479
|
+
} = this.extractFromKey(keys[keys.length - 1], options);
|
|
480
|
+
const namespace = namespaces[namespaces.length - 1];
|
|
481
|
+
const lng = options.lng || this.language;
|
|
482
|
+
const appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
483
|
+
if (lng && lng.toLowerCase() === 'cimode') {
|
|
484
|
+
if (appendNamespaceToCIMode) {
|
|
485
|
+
const nsSeparator = options.nsSeparator || this.options.nsSeparator;
|
|
486
|
+
if (returnDetails) {
|
|
487
|
+
return {
|
|
488
|
+
res: `${namespace}${nsSeparator}${key}`,
|
|
489
|
+
usedKey: key,
|
|
490
|
+
exactUsedKey: key,
|
|
491
|
+
usedLng: lng,
|
|
492
|
+
usedNS: namespace
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
return `${namespace}${nsSeparator}${key}`;
|
|
496
|
+
}
|
|
497
|
+
if (returnDetails) {
|
|
498
|
+
return {
|
|
499
|
+
res: key,
|
|
500
|
+
usedKey: key,
|
|
501
|
+
exactUsedKey: key,
|
|
502
|
+
usedLng: lng,
|
|
503
|
+
usedNS: namespace
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
return key;
|
|
507
|
+
}
|
|
508
|
+
const resolved = this.resolve(keys, options);
|
|
509
|
+
let res = resolved && resolved.res;
|
|
510
|
+
const resUsedKey = resolved && resolved.usedKey || key;
|
|
511
|
+
const resExactUsedKey = resolved && resolved.exactUsedKey || key;
|
|
512
|
+
const resType = Object.prototype.toString.apply(res);
|
|
513
|
+
const noObject = ['[object Number]', '[object Function]', '[object RegExp]'];
|
|
514
|
+
const joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays;
|
|
515
|
+
const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
516
|
+
const handleAsObject = typeof res !== 'string' && typeof res !== 'boolean' && typeof res !== 'number';
|
|
517
|
+
if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(typeof joinArrays === 'string' && resType === '[object Array]')) {
|
|
518
|
+
if (!options.returnObjects && !this.options.returnObjects) {
|
|
519
|
+
if (!this.options.returnedObjectHandler) {
|
|
520
|
+
this.logger.warn('accessing an object - but returnObjects options is not enabled!');
|
|
521
|
+
}
|
|
522
|
+
const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, {
|
|
523
|
+
...options,
|
|
524
|
+
ns: namespaces
|
|
525
|
+
}) : `key '${key} (${this.language})' returned an object instead of string.`;
|
|
526
|
+
if (returnDetails) {
|
|
527
|
+
resolved.res = r;
|
|
528
|
+
return resolved;
|
|
529
|
+
}
|
|
530
|
+
return r;
|
|
531
|
+
}
|
|
532
|
+
if (keySeparator) {
|
|
533
|
+
const resTypeIsArray = resType === '[object Array]';
|
|
534
|
+
const copy = resTypeIsArray ? [] : {};
|
|
535
|
+
const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
536
|
+
for (const m in res) {
|
|
537
|
+
if (Object.prototype.hasOwnProperty.call(res, m)) {
|
|
538
|
+
const deepKey = `${newKeyToUse}${keySeparator}${m}`;
|
|
539
|
+
copy[m] = this.translate(deepKey, {
|
|
540
|
+
...options,
|
|
541
|
+
...{
|
|
542
|
+
joinArrays: false,
|
|
543
|
+
ns: namespaces
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
if (copy[m] === deepKey) copy[m] = res[m];
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
res = copy;
|
|
550
|
+
}
|
|
551
|
+
} else if (handleAsObjectInI18nFormat && typeof joinArrays === 'string' && resType === '[object Array]') {
|
|
552
|
+
res = res.join(joinArrays);
|
|
553
|
+
if (res) res = this.extendTranslation(res, keys, options, lastKey);
|
|
554
|
+
} else {
|
|
555
|
+
let usedDefault = false;
|
|
556
|
+
let usedKey = false;
|
|
557
|
+
const needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
|
|
558
|
+
const hasDefaultValue = Translator.hasDefaultValue(options);
|
|
559
|
+
const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : '';
|
|
560
|
+
const defaultValueSuffixOrdinalFallback = options.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, {
|
|
561
|
+
ordinal: false
|
|
562
|
+
}) : '';
|
|
563
|
+
const defaultValue = options[`defaultValue${defaultValueSuffix}`] || options[`defaultValue${defaultValueSuffixOrdinalFallback}`] || options.defaultValue;
|
|
564
|
+
if (!this.isValidLookup(res) && hasDefaultValue) {
|
|
565
|
+
usedDefault = true;
|
|
566
|
+
res = defaultValue;
|
|
567
|
+
}
|
|
568
|
+
if (!this.isValidLookup(res)) {
|
|
569
|
+
usedKey = true;
|
|
570
|
+
res = key;
|
|
571
|
+
}
|
|
572
|
+
const missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
|
|
573
|
+
const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? undefined : res;
|
|
574
|
+
const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
575
|
+
if (usedKey || usedDefault || updateMissing) {
|
|
576
|
+
this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? defaultValue : res);
|
|
577
|
+
if (keySeparator) {
|
|
578
|
+
const fk = this.resolve(key, {
|
|
579
|
+
...options,
|
|
580
|
+
keySeparator: false
|
|
581
|
+
});
|
|
582
|
+
if (fk && fk.res) this.logger.warn('Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.');
|
|
583
|
+
}
|
|
584
|
+
let lngs = [];
|
|
585
|
+
const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
|
|
586
|
+
if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) {
|
|
587
|
+
for (let i = 0; i < fallbackLngs.length; i++) {
|
|
588
|
+
lngs.push(fallbackLngs[i]);
|
|
589
|
+
}
|
|
590
|
+
} else if (this.options.saveMissingTo === 'all') {
|
|
591
|
+
lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
|
|
592
|
+
} else {
|
|
593
|
+
lngs.push(options.lng || this.language);
|
|
594
|
+
}
|
|
595
|
+
const send = (l, k, specificDefaultValue) => {
|
|
596
|
+
const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
597
|
+
if (this.options.missingKeyHandler) {
|
|
598
|
+
this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
599
|
+
} else if (this.backendConnector && this.backendConnector.saveMissing) {
|
|
600
|
+
this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
601
|
+
}
|
|
602
|
+
this.emit('missingKey', l, namespace, k, res);
|
|
603
|
+
};
|
|
604
|
+
if (this.options.saveMissing) {
|
|
605
|
+
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
606
|
+
lngs.forEach(language => {
|
|
607
|
+
this.pluralResolver.getSuffixes(language, options).forEach(suffix => {
|
|
608
|
+
send([language], key + suffix, options[`defaultValue${suffix}`] || defaultValue);
|
|
609
|
+
});
|
|
610
|
+
});
|
|
611
|
+
} else {
|
|
612
|
+
send(lngs, key, defaultValue);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
res = this.extendTranslation(res, keys, options, resolved, lastKey);
|
|
617
|
+
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
|
|
618
|
+
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
|
|
619
|
+
if (this.options.compatibilityAPI !== 'v1') {
|
|
620
|
+
res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : undefined);
|
|
621
|
+
} else {
|
|
622
|
+
res = this.options.parseMissingKeyHandler(res);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
if (returnDetails) {
|
|
627
|
+
resolved.res = res;
|
|
628
|
+
return resolved;
|
|
629
|
+
}
|
|
630
|
+
return res;
|
|
631
|
+
}
|
|
632
|
+
extendTranslation(res, key, options, resolved, lastKey) {
|
|
633
|
+
var _this = this;
|
|
634
|
+
if (this.i18nFormat && this.i18nFormat.parse) {
|
|
635
|
+
res = this.i18nFormat.parse(res, {
|
|
636
|
+
...this.options.interpolation.defaultVariables,
|
|
637
|
+
...options
|
|
638
|
+
}, resolved.usedLng, resolved.usedNS, resolved.usedKey, {
|
|
639
|
+
resolved
|
|
640
|
+
});
|
|
641
|
+
} else if (!options.skipInterpolation) {
|
|
642
|
+
if (options.interpolation) this.interpolator.init({
|
|
643
|
+
...options,
|
|
644
|
+
...{
|
|
645
|
+
interpolation: {
|
|
646
|
+
...this.options.interpolation,
|
|
647
|
+
...options.interpolation
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
});
|
|
651
|
+
const skipOnVariables = typeof res === 'string' && (options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
652
|
+
let nestBef;
|
|
653
|
+
if (skipOnVariables) {
|
|
654
|
+
const nb = res.match(this.interpolator.nestingRegexp);
|
|
655
|
+
nestBef = nb && nb.length;
|
|
656
|
+
}
|
|
657
|
+
let data = options.replace && typeof options.replace !== 'string' ? options.replace : options;
|
|
658
|
+
if (this.options.interpolation.defaultVariables) data = {
|
|
659
|
+
...this.options.interpolation.defaultVariables,
|
|
660
|
+
...data
|
|
661
|
+
};
|
|
662
|
+
res = this.interpolator.interpolate(res, data, options.lng || this.language, options);
|
|
663
|
+
if (skipOnVariables) {
|
|
664
|
+
const na = res.match(this.interpolator.nestingRegexp);
|
|
665
|
+
const nestAft = na && na.length;
|
|
666
|
+
if (nestBef < nestAft) options.nest = false;
|
|
667
|
+
}
|
|
668
|
+
if (!options.lng && this.options.compatibilityAPI !== 'v1' && resolved && resolved.res) options.lng = resolved.usedLng;
|
|
669
|
+
if (options.nest !== false) res = this.interpolator.nest(res, function () {
|
|
670
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
671
|
+
args[_key] = arguments[_key];
|
|
672
|
+
}
|
|
673
|
+
if (lastKey && lastKey[0] === args[0] && !options.context) {
|
|
674
|
+
_this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
|
|
675
|
+
return null;
|
|
676
|
+
}
|
|
677
|
+
return _this.translate(...args, key);
|
|
678
|
+
}, options);
|
|
679
|
+
if (options.interpolation) this.interpolator.reset();
|
|
680
|
+
}
|
|
681
|
+
const postProcess = options.postProcess || this.options.postProcess;
|
|
682
|
+
const postProcessorNames = typeof postProcess === 'string' ? [postProcess] : postProcess;
|
|
683
|
+
if (res !== undefined && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) {
|
|
684
|
+
res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
|
|
685
|
+
i18nResolved: resolved,
|
|
686
|
+
...options
|
|
687
|
+
} : options, this);
|
|
688
|
+
}
|
|
689
|
+
return res;
|
|
690
|
+
}
|
|
691
|
+
resolve(keys) {
|
|
692
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
693
|
+
let found;
|
|
694
|
+
let usedKey;
|
|
695
|
+
let exactUsedKey;
|
|
696
|
+
let usedLng;
|
|
697
|
+
let usedNS;
|
|
698
|
+
if (typeof keys === 'string') keys = [keys];
|
|
699
|
+
keys.forEach(k => {
|
|
700
|
+
if (this.isValidLookup(found)) return;
|
|
701
|
+
const extracted = this.extractFromKey(k, options);
|
|
702
|
+
const key = extracted.key;
|
|
703
|
+
usedKey = key;
|
|
704
|
+
let namespaces = extracted.namespaces;
|
|
705
|
+
if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
|
|
706
|
+
const needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
|
|
707
|
+
const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
|
|
708
|
+
const needsContextHandling = options.context !== undefined && (typeof options.context === 'string' || typeof options.context === 'number') && options.context !== '';
|
|
709
|
+
const codes = options.lngs ? options.lngs : this.languageUtils.toResolveHierarchy(options.lng || this.language, options.fallbackLng);
|
|
710
|
+
namespaces.forEach(ns => {
|
|
711
|
+
if (this.isValidLookup(found)) return;
|
|
712
|
+
usedNS = ns;
|
|
713
|
+
if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils && this.utils.hasLoadedNamespace && !this.utils.hasLoadedNamespace(usedNS)) {
|
|
714
|
+
checkedLoadedFor[`${codes[0]}-${ns}`] = true;
|
|
715
|
+
this.logger.warn(`key "${usedKey}" for languages "${codes.join(', ')}" won't get resolved as namespace "${usedNS}" was not yet loaded`, 'This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!');
|
|
716
|
+
}
|
|
717
|
+
codes.forEach(code => {
|
|
718
|
+
if (this.isValidLookup(found)) return;
|
|
719
|
+
usedLng = code;
|
|
720
|
+
const finalKeys = [key];
|
|
721
|
+
if (this.i18nFormat && this.i18nFormat.addLookupKeys) {
|
|
722
|
+
this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
|
|
723
|
+
} else {
|
|
724
|
+
let pluralSuffix;
|
|
725
|
+
if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, options.count, options);
|
|
726
|
+
const zeroSuffix = `${this.options.pluralSeparator}zero`;
|
|
727
|
+
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
|
|
728
|
+
if (needsPluralHandling) {
|
|
729
|
+
finalKeys.push(key + pluralSuffix);
|
|
730
|
+
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
731
|
+
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
732
|
+
}
|
|
733
|
+
if (needsZeroSuffixLookup) {
|
|
734
|
+
finalKeys.push(key + zeroSuffix);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
if (needsContextHandling) {
|
|
738
|
+
const contextKey = `${key}${this.options.contextSeparator}${options.context}`;
|
|
739
|
+
finalKeys.push(contextKey);
|
|
740
|
+
if (needsPluralHandling) {
|
|
741
|
+
finalKeys.push(contextKey + pluralSuffix);
|
|
742
|
+
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
743
|
+
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
744
|
+
}
|
|
745
|
+
if (needsZeroSuffixLookup) {
|
|
746
|
+
finalKeys.push(contextKey + zeroSuffix);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
let possibleKey;
|
|
752
|
+
while (possibleKey = finalKeys.pop()) {
|
|
753
|
+
if (!this.isValidLookup(found)) {
|
|
754
|
+
exactUsedKey = possibleKey;
|
|
755
|
+
found = this.getResource(code, ns, possibleKey, options);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
});
|
|
760
|
+
});
|
|
761
|
+
return {
|
|
762
|
+
res: found,
|
|
763
|
+
usedKey,
|
|
764
|
+
exactUsedKey,
|
|
765
|
+
usedLng,
|
|
766
|
+
usedNS
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
isValidLookup(res) {
|
|
770
|
+
return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === '');
|
|
771
|
+
}
|
|
772
|
+
getResource(code, ns, key) {
|
|
773
|
+
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
774
|
+
if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options);
|
|
775
|
+
return this.resourceStore.getResource(code, ns, key, options);
|
|
776
|
+
}
|
|
777
|
+
static hasDefaultValue(options) {
|
|
778
|
+
const prefix = 'defaultValue';
|
|
779
|
+
for (const option in options) {
|
|
780
|
+
if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && undefined !== options[option]) {
|
|
781
|
+
return true;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
return false;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
function capitalize(string) {
|
|
789
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
790
|
+
}
|
|
791
|
+
class LanguageUtil {
|
|
792
|
+
constructor(options) {
|
|
793
|
+
this.options = options;
|
|
794
|
+
this.supportedLngs = this.options.supportedLngs || false;
|
|
795
|
+
this.logger = baseLogger.create('languageUtils');
|
|
796
|
+
}
|
|
797
|
+
getScriptPartFromCode(code) {
|
|
798
|
+
code = getCleanedCode(code);
|
|
799
|
+
if (!code || code.indexOf('-') < 0) return null;
|
|
800
|
+
const p = code.split('-');
|
|
801
|
+
if (p.length === 2) return null;
|
|
802
|
+
p.pop();
|
|
803
|
+
if (p[p.length - 1].toLowerCase() === 'x') return null;
|
|
804
|
+
return this.formatLanguageCode(p.join('-'));
|
|
805
|
+
}
|
|
806
|
+
getLanguagePartFromCode(code) {
|
|
807
|
+
code = getCleanedCode(code);
|
|
808
|
+
if (!code || code.indexOf('-') < 0) return code;
|
|
809
|
+
const p = code.split('-');
|
|
810
|
+
return this.formatLanguageCode(p[0]);
|
|
811
|
+
}
|
|
812
|
+
formatLanguageCode(code) {
|
|
813
|
+
if (typeof code === 'string' && code.indexOf('-') > -1) {
|
|
814
|
+
const specialCases = ['hans', 'hant', 'latn', 'cyrl', 'cans', 'mong', 'arab'];
|
|
815
|
+
let p = code.split('-');
|
|
816
|
+
if (this.options.lowerCaseLng) {
|
|
817
|
+
p = p.map(part => part.toLowerCase());
|
|
818
|
+
} else if (p.length === 2) {
|
|
819
|
+
p[0] = p[0].toLowerCase();
|
|
820
|
+
p[1] = p[1].toUpperCase();
|
|
821
|
+
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
|
|
822
|
+
} else if (p.length === 3) {
|
|
823
|
+
p[0] = p[0].toLowerCase();
|
|
824
|
+
if (p[1].length === 2) p[1] = p[1].toUpperCase();
|
|
825
|
+
if (p[0] !== 'sgn' && p[2].length === 2) p[2] = p[2].toUpperCase();
|
|
826
|
+
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
|
|
827
|
+
if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize(p[2].toLowerCase());
|
|
828
|
+
}
|
|
829
|
+
return p.join('-');
|
|
830
|
+
}
|
|
831
|
+
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
|
|
832
|
+
}
|
|
833
|
+
isSupportedCode(code) {
|
|
834
|
+
if (this.options.load === 'languageOnly' || this.options.nonExplicitSupportedLngs) {
|
|
835
|
+
code = this.getLanguagePartFromCode(code);
|
|
836
|
+
}
|
|
837
|
+
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
|
|
838
|
+
}
|
|
839
|
+
getBestMatchFromCodes(codes) {
|
|
840
|
+
if (!codes) return null;
|
|
841
|
+
let found;
|
|
842
|
+
codes.forEach(code => {
|
|
843
|
+
if (found) return;
|
|
844
|
+
const cleanedLng = this.formatLanguageCode(code);
|
|
845
|
+
if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
|
|
846
|
+
});
|
|
847
|
+
if (!found && this.options.supportedLngs) {
|
|
848
|
+
codes.forEach(code => {
|
|
849
|
+
if (found) return;
|
|
850
|
+
const lngOnly = this.getLanguagePartFromCode(code);
|
|
851
|
+
if (this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
852
|
+
found = this.options.supportedLngs.find(supportedLng => {
|
|
853
|
+
if (supportedLng === lngOnly) return supportedLng;
|
|
854
|
+
if (supportedLng.indexOf('-') < 0 && lngOnly.indexOf('-') < 0) return;
|
|
855
|
+
if (supportedLng.indexOf(lngOnly) === 0) return supportedLng;
|
|
856
|
+
});
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
|
|
860
|
+
return found;
|
|
861
|
+
}
|
|
862
|
+
getFallbackCodes(fallbacks, code) {
|
|
863
|
+
if (!fallbacks) return [];
|
|
864
|
+
if (typeof fallbacks === 'function') fallbacks = fallbacks(code);
|
|
865
|
+
if (typeof fallbacks === 'string') fallbacks = [fallbacks];
|
|
866
|
+
if (Object.prototype.toString.apply(fallbacks) === '[object Array]') return fallbacks;
|
|
867
|
+
if (!code) return fallbacks.default || [];
|
|
868
|
+
let found = fallbacks[code];
|
|
869
|
+
if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
|
|
870
|
+
if (!found) found = fallbacks[this.formatLanguageCode(code)];
|
|
871
|
+
if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
872
|
+
if (!found) found = fallbacks.default;
|
|
873
|
+
return found || [];
|
|
874
|
+
}
|
|
875
|
+
toResolveHierarchy(code, fallbackCode) {
|
|
876
|
+
const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
|
|
877
|
+
const codes = [];
|
|
878
|
+
const addCode = c => {
|
|
879
|
+
if (!c) return;
|
|
880
|
+
if (this.isSupportedCode(c)) {
|
|
881
|
+
codes.push(c);
|
|
882
|
+
} else {
|
|
883
|
+
this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
|
|
884
|
+
}
|
|
885
|
+
};
|
|
886
|
+
if (typeof code === 'string' && (code.indexOf('-') > -1 || code.indexOf('_') > -1)) {
|
|
887
|
+
if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code));
|
|
888
|
+
if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code));
|
|
889
|
+
if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code));
|
|
890
|
+
} else if (typeof code === 'string') {
|
|
891
|
+
addCode(this.formatLanguageCode(code));
|
|
892
|
+
}
|
|
893
|
+
fallbackCodes.forEach(fc => {
|
|
894
|
+
if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
|
|
895
|
+
});
|
|
896
|
+
return codes;
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
let sets = [{
|
|
901
|
+
lngs: ['ach', 'ak', 'am', 'arn', 'br', 'fil', 'gun', 'ln', 'mfe', 'mg', 'mi', 'oc', 'pt', 'pt-BR', 'tg', 'tl', 'ti', 'tr', 'uz', 'wa'],
|
|
902
|
+
nr: [1, 2],
|
|
903
|
+
fc: 1
|
|
904
|
+
}, {
|
|
905
|
+
lngs: ['af', 'an', 'ast', 'az', 'bg', 'bn', 'ca', 'da', 'de', 'dev', 'el', 'en', 'eo', 'es', 'et', 'eu', 'fi', 'fo', 'fur', 'fy', 'gl', 'gu', 'ha', 'hi', 'hu', 'hy', 'ia', 'it', 'kk', 'kn', 'ku', 'lb', 'mai', 'ml', 'mn', 'mr', 'nah', 'nap', 'nb', 'ne', 'nl', 'nn', 'no', 'nso', 'pa', 'pap', 'pms', 'ps', 'pt-PT', 'rm', 'sco', 'se', 'si', 'so', 'son', 'sq', 'sv', 'sw', 'ta', 'te', 'tk', 'ur', 'yo'],
|
|
906
|
+
nr: [1, 2],
|
|
907
|
+
fc: 2
|
|
908
|
+
}, {
|
|
909
|
+
lngs: ['ay', 'bo', 'cgg', 'fa', 'ht', 'id', 'ja', 'jbo', 'ka', 'km', 'ko', 'ky', 'lo', 'ms', 'sah', 'su', 'th', 'tt', 'ug', 'vi', 'wo', 'zh'],
|
|
910
|
+
nr: [1],
|
|
911
|
+
fc: 3
|
|
912
|
+
}, {
|
|
913
|
+
lngs: ['be', 'bs', 'cnr', 'dz', 'hr', 'ru', 'sr', 'uk'],
|
|
914
|
+
nr: [1, 2, 5],
|
|
915
|
+
fc: 4
|
|
916
|
+
}, {
|
|
917
|
+
lngs: ['ar'],
|
|
918
|
+
nr: [0, 1, 2, 3, 11, 100],
|
|
919
|
+
fc: 5
|
|
920
|
+
}, {
|
|
921
|
+
lngs: ['cs', 'sk'],
|
|
922
|
+
nr: [1, 2, 5],
|
|
923
|
+
fc: 6
|
|
924
|
+
}, {
|
|
925
|
+
lngs: ['csb', 'pl'],
|
|
926
|
+
nr: [1, 2, 5],
|
|
927
|
+
fc: 7
|
|
928
|
+
}, {
|
|
929
|
+
lngs: ['cy'],
|
|
930
|
+
nr: [1, 2, 3, 8],
|
|
931
|
+
fc: 8
|
|
932
|
+
}, {
|
|
933
|
+
lngs: ['fr'],
|
|
934
|
+
nr: [1, 2],
|
|
935
|
+
fc: 9
|
|
936
|
+
}, {
|
|
937
|
+
lngs: ['ga'],
|
|
938
|
+
nr: [1, 2, 3, 7, 11],
|
|
939
|
+
fc: 10
|
|
940
|
+
}, {
|
|
941
|
+
lngs: ['gd'],
|
|
942
|
+
nr: [1, 2, 3, 20],
|
|
943
|
+
fc: 11
|
|
944
|
+
}, {
|
|
945
|
+
lngs: ['is'],
|
|
946
|
+
nr: [1, 2],
|
|
947
|
+
fc: 12
|
|
948
|
+
}, {
|
|
949
|
+
lngs: ['jv'],
|
|
950
|
+
nr: [0, 1],
|
|
951
|
+
fc: 13
|
|
952
|
+
}, {
|
|
953
|
+
lngs: ['kw'],
|
|
954
|
+
nr: [1, 2, 3, 4],
|
|
955
|
+
fc: 14
|
|
956
|
+
}, {
|
|
957
|
+
lngs: ['lt'],
|
|
958
|
+
nr: [1, 2, 10],
|
|
959
|
+
fc: 15
|
|
960
|
+
}, {
|
|
961
|
+
lngs: ['lv'],
|
|
962
|
+
nr: [1, 2, 0],
|
|
963
|
+
fc: 16
|
|
964
|
+
}, {
|
|
965
|
+
lngs: ['mk'],
|
|
966
|
+
nr: [1, 2],
|
|
967
|
+
fc: 17
|
|
968
|
+
}, {
|
|
969
|
+
lngs: ['mnk'],
|
|
970
|
+
nr: [0, 1, 2],
|
|
971
|
+
fc: 18
|
|
972
|
+
}, {
|
|
973
|
+
lngs: ['mt'],
|
|
974
|
+
nr: [1, 2, 11, 20],
|
|
975
|
+
fc: 19
|
|
976
|
+
}, {
|
|
977
|
+
lngs: ['or'],
|
|
978
|
+
nr: [2, 1],
|
|
979
|
+
fc: 2
|
|
980
|
+
}, {
|
|
981
|
+
lngs: ['ro'],
|
|
982
|
+
nr: [1, 2, 20],
|
|
983
|
+
fc: 20
|
|
984
|
+
}, {
|
|
985
|
+
lngs: ['sl'],
|
|
986
|
+
nr: [5, 1, 2, 3],
|
|
987
|
+
fc: 21
|
|
988
|
+
}, {
|
|
989
|
+
lngs: ['he', 'iw'],
|
|
990
|
+
nr: [1, 2, 20, 21],
|
|
991
|
+
fc: 22
|
|
992
|
+
}];
|
|
993
|
+
let _rulesPluralsTypes = {
|
|
994
|
+
1: function (n) {
|
|
995
|
+
return Number(n > 1);
|
|
996
|
+
},
|
|
997
|
+
2: function (n) {
|
|
998
|
+
return Number(n != 1);
|
|
96
999
|
},
|
|
1000
|
+
3: function (n) {
|
|
1001
|
+
return 0;
|
|
1002
|
+
},
|
|
1003
|
+
4: function (n) {
|
|
1004
|
+
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
1005
|
+
},
|
|
1006
|
+
5: function (n) {
|
|
1007
|
+
return Number(n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5);
|
|
1008
|
+
},
|
|
1009
|
+
6: function (n) {
|
|
1010
|
+
return Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2);
|
|
1011
|
+
},
|
|
1012
|
+
7: function (n) {
|
|
1013
|
+
return Number(n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
1014
|
+
},
|
|
1015
|
+
8: function (n) {
|
|
1016
|
+
return Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3);
|
|
1017
|
+
},
|
|
1018
|
+
9: function (n) {
|
|
1019
|
+
return Number(n >= 2);
|
|
1020
|
+
},
|
|
1021
|
+
10: function (n) {
|
|
1022
|
+
return Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4);
|
|
1023
|
+
},
|
|
1024
|
+
11: function (n) {
|
|
1025
|
+
return Number(n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3);
|
|
1026
|
+
},
|
|
1027
|
+
12: function (n) {
|
|
1028
|
+
return Number(n % 10 != 1 || n % 100 == 11);
|
|
1029
|
+
},
|
|
1030
|
+
13: function (n) {
|
|
1031
|
+
return Number(n !== 0);
|
|
1032
|
+
},
|
|
1033
|
+
14: function (n) {
|
|
1034
|
+
return Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3);
|
|
1035
|
+
},
|
|
1036
|
+
15: function (n) {
|
|
1037
|
+
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
1038
|
+
},
|
|
1039
|
+
16: function (n) {
|
|
1040
|
+
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2);
|
|
1041
|
+
},
|
|
1042
|
+
17: function (n) {
|
|
1043
|
+
return Number(n == 1 || n % 10 == 1 && n % 100 != 11 ? 0 : 1);
|
|
1044
|
+
},
|
|
1045
|
+
18: function (n) {
|
|
1046
|
+
return Number(n == 0 ? 0 : n == 1 ? 1 : 2);
|
|
1047
|
+
},
|
|
1048
|
+
19: function (n) {
|
|
1049
|
+
return Number(n == 1 ? 0 : n == 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3);
|
|
1050
|
+
},
|
|
1051
|
+
20: function (n) {
|
|
1052
|
+
return Number(n == 1 ? 0 : n == 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2);
|
|
1053
|
+
},
|
|
1054
|
+
21: function (n) {
|
|
1055
|
+
return Number(n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0);
|
|
1056
|
+
},
|
|
1057
|
+
22: function (n) {
|
|
1058
|
+
return Number(n == 1 ? 0 : n == 2 ? 1 : (n < 0 || n > 10) && n % 10 == 0 ? 2 : 3);
|
|
1059
|
+
}
|
|
97
1060
|
};
|
|
1061
|
+
const nonIntlVersions = ['v1', 'v2', 'v3'];
|
|
1062
|
+
const intlVersions = ['v4'];
|
|
1063
|
+
const suffixesOrder = {
|
|
1064
|
+
zero: 0,
|
|
1065
|
+
one: 1,
|
|
1066
|
+
two: 2,
|
|
1067
|
+
few: 3,
|
|
1068
|
+
many: 4,
|
|
1069
|
+
other: 5
|
|
1070
|
+
};
|
|
1071
|
+
function createRules() {
|
|
1072
|
+
const rules = {};
|
|
1073
|
+
sets.forEach(set => {
|
|
1074
|
+
set.lngs.forEach(l => {
|
|
1075
|
+
rules[l] = {
|
|
1076
|
+
numbers: set.nr,
|
|
1077
|
+
plurals: _rulesPluralsTypes[set.fc]
|
|
1078
|
+
};
|
|
1079
|
+
});
|
|
1080
|
+
});
|
|
1081
|
+
return rules;
|
|
1082
|
+
}
|
|
1083
|
+
class PluralResolver {
|
|
1084
|
+
constructor(languageUtils) {
|
|
1085
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1086
|
+
this.languageUtils = languageUtils;
|
|
1087
|
+
this.options = options;
|
|
1088
|
+
this.logger = baseLogger.create('pluralResolver');
|
|
1089
|
+
if ((!this.options.compatibilityJSON || intlVersions.includes(this.options.compatibilityJSON)) && (typeof Intl === 'undefined' || !Intl.PluralRules)) {
|
|
1090
|
+
this.options.compatibilityJSON = 'v3';
|
|
1091
|
+
this.logger.error('Your environment seems not to be Intl API compatible, use an Intl.PluralRules polyfill. Will fallback to the compatibilityJSON v3 format handling.');
|
|
1092
|
+
}
|
|
1093
|
+
this.rules = createRules();
|
|
1094
|
+
}
|
|
1095
|
+
addRule(lng, obj) {
|
|
1096
|
+
this.rules[lng] = obj;
|
|
1097
|
+
}
|
|
1098
|
+
getRule(code) {
|
|
1099
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1100
|
+
if (this.shouldUseIntlApi()) {
|
|
1101
|
+
try {
|
|
1102
|
+
return new Intl.PluralRules(getCleanedCode(code), {
|
|
1103
|
+
type: options.ordinal ? 'ordinal' : 'cardinal'
|
|
1104
|
+
});
|
|
1105
|
+
} catch {
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
|
|
1110
|
+
}
|
|
1111
|
+
needsPlural(code) {
|
|
1112
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1113
|
+
const rule = this.getRule(code, options);
|
|
1114
|
+
if (this.shouldUseIntlApi()) {
|
|
1115
|
+
return rule && rule.resolvedOptions().pluralCategories.length > 1;
|
|
1116
|
+
}
|
|
1117
|
+
return rule && rule.numbers.length > 1;
|
|
1118
|
+
}
|
|
1119
|
+
getPluralFormsOfKey(code, key) {
|
|
1120
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1121
|
+
return this.getSuffixes(code, options).map(suffix => `${key}${suffix}`);
|
|
1122
|
+
}
|
|
1123
|
+
getSuffixes(code) {
|
|
1124
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1125
|
+
const rule = this.getRule(code, options);
|
|
1126
|
+
if (!rule) {
|
|
1127
|
+
return [];
|
|
1128
|
+
}
|
|
1129
|
+
if (this.shouldUseIntlApi()) {
|
|
1130
|
+
return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map(pluralCategory => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${pluralCategory}`);
|
|
1131
|
+
}
|
|
1132
|
+
return rule.numbers.map(number => this.getSuffix(code, number, options));
|
|
1133
|
+
}
|
|
1134
|
+
getSuffix(code, count) {
|
|
1135
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1136
|
+
const rule = this.getRule(code, options);
|
|
1137
|
+
if (rule) {
|
|
1138
|
+
if (this.shouldUseIntlApi()) {
|
|
1139
|
+
return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${rule.select(count)}`;
|
|
1140
|
+
}
|
|
1141
|
+
return this.getSuffixRetroCompatible(rule, count);
|
|
1142
|
+
}
|
|
1143
|
+
this.logger.warn(`no plural rule found for: ${code}`);
|
|
1144
|
+
return '';
|
|
1145
|
+
}
|
|
1146
|
+
getSuffixRetroCompatible(rule, count) {
|
|
1147
|
+
const idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
|
|
1148
|
+
let suffix = rule.numbers[idx];
|
|
1149
|
+
if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
1150
|
+
if (suffix === 2) {
|
|
1151
|
+
suffix = 'plural';
|
|
1152
|
+
} else if (suffix === 1) {
|
|
1153
|
+
suffix = '';
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
const returnSuffix = () => this.options.prepend && suffix.toString() ? this.options.prepend + suffix.toString() : suffix.toString();
|
|
1157
|
+
if (this.options.compatibilityJSON === 'v1') {
|
|
1158
|
+
if (suffix === 1) return '';
|
|
1159
|
+
if (typeof suffix === 'number') return `_plural_${suffix.toString()}`;
|
|
1160
|
+
return returnSuffix();
|
|
1161
|
+
} else if (this.options.compatibilityJSON === 'v2') {
|
|
1162
|
+
return returnSuffix();
|
|
1163
|
+
} else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
1164
|
+
return returnSuffix();
|
|
1165
|
+
}
|
|
1166
|
+
return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
|
|
1167
|
+
}
|
|
1168
|
+
shouldUseIntlApi() {
|
|
1169
|
+
return !nonIntlVersions.includes(this.options.compatibilityJSON);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
function deepFindWithDefaults(data, defaultData, key) {
|
|
1174
|
+
let keySeparator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '.';
|
|
1175
|
+
let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
1176
|
+
let path = getPathWithDefaults(data, defaultData, key);
|
|
1177
|
+
if (!path && ignoreJSONStructure && typeof key === 'string') {
|
|
1178
|
+
path = deepFind(data, key, keySeparator);
|
|
1179
|
+
if (path === undefined) path = deepFind(defaultData, key, keySeparator);
|
|
1180
|
+
}
|
|
1181
|
+
return path;
|
|
1182
|
+
}
|
|
1183
|
+
class Interpolator {
|
|
1184
|
+
constructor() {
|
|
1185
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1186
|
+
this.logger = baseLogger.create('interpolator');
|
|
1187
|
+
this.options = options;
|
|
1188
|
+
this.format = options.interpolation && options.interpolation.format || (value => value);
|
|
1189
|
+
this.init(options);
|
|
1190
|
+
}
|
|
1191
|
+
init() {
|
|
1192
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1193
|
+
if (!options.interpolation) options.interpolation = {
|
|
1194
|
+
escapeValue: true
|
|
1195
|
+
};
|
|
1196
|
+
const iOpts = options.interpolation;
|
|
1197
|
+
this.escape = iOpts.escape !== undefined ? iOpts.escape : escape;
|
|
1198
|
+
this.escapeValue = iOpts.escapeValue !== undefined ? iOpts.escapeValue : true;
|
|
1199
|
+
this.useRawValueToEscape = iOpts.useRawValueToEscape !== undefined ? iOpts.useRawValueToEscape : false;
|
|
1200
|
+
this.prefix = iOpts.prefix ? regexEscape(iOpts.prefix) : iOpts.prefixEscaped || '{{';
|
|
1201
|
+
this.suffix = iOpts.suffix ? regexEscape(iOpts.suffix) : iOpts.suffixEscaped || '}}';
|
|
1202
|
+
this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
|
|
1203
|
+
this.unescapePrefix = iOpts.unescapeSuffix ? '' : iOpts.unescapePrefix || '-';
|
|
1204
|
+
this.unescapeSuffix = this.unescapePrefix ? '' : iOpts.unescapeSuffix || '';
|
|
1205
|
+
this.nestingPrefix = iOpts.nestingPrefix ? regexEscape(iOpts.nestingPrefix) : iOpts.nestingPrefixEscaped || regexEscape('$t(');
|
|
1206
|
+
this.nestingSuffix = iOpts.nestingSuffix ? regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || regexEscape(')');
|
|
1207
|
+
this.nestingOptionsSeparator = iOpts.nestingOptionsSeparator ? iOpts.nestingOptionsSeparator : iOpts.nestingOptionsSeparator || ',';
|
|
1208
|
+
this.maxReplaces = iOpts.maxReplaces ? iOpts.maxReplaces : 1000;
|
|
1209
|
+
this.alwaysFormat = iOpts.alwaysFormat !== undefined ? iOpts.alwaysFormat : false;
|
|
1210
|
+
this.resetRegExp();
|
|
1211
|
+
}
|
|
1212
|
+
reset() {
|
|
1213
|
+
if (this.options) this.init(this.options);
|
|
1214
|
+
}
|
|
1215
|
+
resetRegExp() {
|
|
1216
|
+
const regexpStr = `${this.prefix}(.+?)${this.suffix}`;
|
|
1217
|
+
this.regexp = new RegExp(regexpStr, 'g');
|
|
1218
|
+
const regexpUnescapeStr = `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`;
|
|
1219
|
+
this.regexpUnescape = new RegExp(regexpUnescapeStr, 'g');
|
|
1220
|
+
const nestingRegexpStr = `${this.nestingPrefix}(.+?)${this.nestingSuffix}`;
|
|
1221
|
+
this.nestingRegexp = new RegExp(nestingRegexpStr, 'g');
|
|
1222
|
+
}
|
|
1223
|
+
interpolate(str, data, lng, options) {
|
|
1224
|
+
let match;
|
|
1225
|
+
let value;
|
|
1226
|
+
let replaces;
|
|
1227
|
+
const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
1228
|
+
function regexSafe(val) {
|
|
1229
|
+
return val.replace(/\$/g, '$$$$');
|
|
1230
|
+
}
|
|
1231
|
+
const handleFormat = key => {
|
|
1232
|
+
if (key.indexOf(this.formatSeparator) < 0) {
|
|
1233
|
+
const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
|
|
1234
|
+
return this.alwaysFormat ? this.format(path, undefined, lng, {
|
|
1235
|
+
...options,
|
|
1236
|
+
...data,
|
|
1237
|
+
interpolationkey: key
|
|
1238
|
+
}) : path;
|
|
1239
|
+
}
|
|
1240
|
+
const p = key.split(this.formatSeparator);
|
|
1241
|
+
const k = p.shift().trim();
|
|
1242
|
+
const f = p.join(this.formatSeparator).trim();
|
|
1243
|
+
return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
|
|
1244
|
+
...options,
|
|
1245
|
+
...data,
|
|
1246
|
+
interpolationkey: k
|
|
1247
|
+
});
|
|
1248
|
+
};
|
|
1249
|
+
this.resetRegExp();
|
|
1250
|
+
const missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler;
|
|
1251
|
+
const skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
|
|
1252
|
+
const todos = [{
|
|
1253
|
+
regex: this.regexpUnescape,
|
|
1254
|
+
safeValue: val => regexSafe(val)
|
|
1255
|
+
}, {
|
|
1256
|
+
regex: this.regexp,
|
|
1257
|
+
safeValue: val => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
|
|
1258
|
+
}];
|
|
1259
|
+
todos.forEach(todo => {
|
|
1260
|
+
replaces = 0;
|
|
1261
|
+
while (match = todo.regex.exec(str)) {
|
|
1262
|
+
const matchedVar = match[1].trim();
|
|
1263
|
+
value = handleFormat(matchedVar);
|
|
1264
|
+
if (value === undefined) {
|
|
1265
|
+
if (typeof missingInterpolationHandler === 'function') {
|
|
1266
|
+
const temp = missingInterpolationHandler(str, match, options);
|
|
1267
|
+
value = typeof temp === 'string' ? temp : '';
|
|
1268
|
+
} else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
|
|
1269
|
+
value = '';
|
|
1270
|
+
} else if (skipOnVariables) {
|
|
1271
|
+
value = match[0];
|
|
1272
|
+
continue;
|
|
1273
|
+
} else {
|
|
1274
|
+
this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
|
|
1275
|
+
value = '';
|
|
1276
|
+
}
|
|
1277
|
+
} else if (typeof value !== 'string' && !this.useRawValueToEscape) {
|
|
1278
|
+
value = makeString(value);
|
|
1279
|
+
}
|
|
1280
|
+
const safeValue = todo.safeValue(value);
|
|
1281
|
+
str = str.replace(match[0], safeValue);
|
|
1282
|
+
if (skipOnVariables) {
|
|
1283
|
+
todo.regex.lastIndex += value.length;
|
|
1284
|
+
todo.regex.lastIndex -= match[0].length;
|
|
1285
|
+
} else {
|
|
1286
|
+
todo.regex.lastIndex = 0;
|
|
1287
|
+
}
|
|
1288
|
+
replaces++;
|
|
1289
|
+
if (replaces >= this.maxReplaces) {
|
|
1290
|
+
break;
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
});
|
|
1294
|
+
return str;
|
|
1295
|
+
}
|
|
1296
|
+
nest(str, fc) {
|
|
1297
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1298
|
+
let match;
|
|
1299
|
+
let value;
|
|
1300
|
+
let clonedOptions;
|
|
1301
|
+
function handleHasOptions(key, inheritedOptions) {
|
|
1302
|
+
const sep = this.nestingOptionsSeparator;
|
|
1303
|
+
if (key.indexOf(sep) < 0) return key;
|
|
1304
|
+
const c = key.split(new RegExp(`${sep}[ ]*{`));
|
|
1305
|
+
let optionsString = `{${c[1]}`;
|
|
1306
|
+
key = c[0];
|
|
1307
|
+
optionsString = this.interpolate(optionsString, clonedOptions);
|
|
1308
|
+
const matchedSingleQuotes = optionsString.match(/'/g);
|
|
1309
|
+
const matchedDoubleQuotes = optionsString.match(/"/g);
|
|
1310
|
+
if (matchedSingleQuotes && matchedSingleQuotes.length % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
|
|
1311
|
+
optionsString = optionsString.replace(/'/g, '"');
|
|
1312
|
+
}
|
|
1313
|
+
try {
|
|
1314
|
+
clonedOptions = JSON.parse(optionsString);
|
|
1315
|
+
if (inheritedOptions) clonedOptions = {
|
|
1316
|
+
...inheritedOptions,
|
|
1317
|
+
...clonedOptions
|
|
1318
|
+
};
|
|
1319
|
+
} catch (e) {
|
|
1320
|
+
this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
|
|
1321
|
+
return `${key}${sep}${optionsString}`;
|
|
1322
|
+
}
|
|
1323
|
+
delete clonedOptions.defaultValue;
|
|
1324
|
+
return key;
|
|
1325
|
+
}
|
|
1326
|
+
while (match = this.nestingRegexp.exec(str)) {
|
|
1327
|
+
let formatters = [];
|
|
1328
|
+
clonedOptions = {
|
|
1329
|
+
...options
|
|
1330
|
+
};
|
|
1331
|
+
clonedOptions = clonedOptions.replace && typeof clonedOptions.replace !== 'string' ? clonedOptions.replace : clonedOptions;
|
|
1332
|
+
clonedOptions.applyPostProcessor = false;
|
|
1333
|
+
delete clonedOptions.defaultValue;
|
|
1334
|
+
let doReduce = false;
|
|
1335
|
+
if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
|
|
1336
|
+
const r = match[1].split(this.formatSeparator).map(elem => elem.trim());
|
|
1337
|
+
match[1] = r.shift();
|
|
1338
|
+
formatters = r;
|
|
1339
|
+
doReduce = true;
|
|
1340
|
+
}
|
|
1341
|
+
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
1342
|
+
if (value && match[0] === str && typeof value !== 'string') return value;
|
|
1343
|
+
if (typeof value !== 'string') value = makeString(value);
|
|
1344
|
+
if (!value) {
|
|
1345
|
+
this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
|
|
1346
|
+
value = '';
|
|
1347
|
+
}
|
|
1348
|
+
if (doReduce) {
|
|
1349
|
+
value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
|
|
1350
|
+
...options,
|
|
1351
|
+
interpolationkey: match[1].trim()
|
|
1352
|
+
}), value.trim());
|
|
1353
|
+
}
|
|
1354
|
+
str = str.replace(match[0], value);
|
|
1355
|
+
this.regexp.lastIndex = 0;
|
|
1356
|
+
}
|
|
1357
|
+
return str;
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
function parseFormatStr(formatStr) {
|
|
1362
|
+
let formatName = formatStr.toLowerCase().trim();
|
|
1363
|
+
const formatOptions = {};
|
|
1364
|
+
if (formatStr.indexOf('(') > -1) {
|
|
1365
|
+
const p = formatStr.split('(');
|
|
1366
|
+
formatName = p[0].toLowerCase().trim();
|
|
1367
|
+
const optStr = p[1].substring(0, p[1].length - 1);
|
|
1368
|
+
if (formatName === 'currency' && optStr.indexOf(':') < 0) {
|
|
1369
|
+
if (!formatOptions.currency) formatOptions.currency = optStr.trim();
|
|
1370
|
+
} else if (formatName === 'relativetime' && optStr.indexOf(':') < 0) {
|
|
1371
|
+
if (!formatOptions.range) formatOptions.range = optStr.trim();
|
|
1372
|
+
} else {
|
|
1373
|
+
const opts = optStr.split(';');
|
|
1374
|
+
opts.forEach(opt => {
|
|
1375
|
+
if (!opt) return;
|
|
1376
|
+
const [key, ...rest] = opt.split(':');
|
|
1377
|
+
const val = rest.join(':').trim().replace(/^'+|'+$/g, '');
|
|
1378
|
+
if (!formatOptions[key.trim()]) formatOptions[key.trim()] = val;
|
|
1379
|
+
if (val === 'false') formatOptions[key.trim()] = false;
|
|
1380
|
+
if (val === 'true') formatOptions[key.trim()] = true;
|
|
1381
|
+
if (!isNaN(val)) formatOptions[key.trim()] = parseInt(val, 10);
|
|
1382
|
+
});
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
return {
|
|
1386
|
+
formatName,
|
|
1387
|
+
formatOptions
|
|
1388
|
+
};
|
|
1389
|
+
}
|
|
1390
|
+
function createCachedFormatter(fn) {
|
|
1391
|
+
const cache = {};
|
|
1392
|
+
return function invokeFormatter(val, lng, options) {
|
|
1393
|
+
const key = lng + JSON.stringify(options);
|
|
1394
|
+
let formatter = cache[key];
|
|
1395
|
+
if (!formatter) {
|
|
1396
|
+
formatter = fn(getCleanedCode(lng), options);
|
|
1397
|
+
cache[key] = formatter;
|
|
1398
|
+
}
|
|
1399
|
+
return formatter(val);
|
|
1400
|
+
};
|
|
1401
|
+
}
|
|
1402
|
+
class Formatter {
|
|
1403
|
+
constructor() {
|
|
1404
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1405
|
+
this.logger = baseLogger.create('formatter');
|
|
1406
|
+
this.options = options;
|
|
1407
|
+
this.formats = {
|
|
1408
|
+
number: createCachedFormatter((lng, opt) => {
|
|
1409
|
+
const formatter = new Intl.NumberFormat(lng, {
|
|
1410
|
+
...opt
|
|
1411
|
+
});
|
|
1412
|
+
return val => formatter.format(val);
|
|
1413
|
+
}),
|
|
1414
|
+
currency: createCachedFormatter((lng, opt) => {
|
|
1415
|
+
const formatter = new Intl.NumberFormat(lng, {
|
|
1416
|
+
...opt,
|
|
1417
|
+
style: 'currency'
|
|
1418
|
+
});
|
|
1419
|
+
return val => formatter.format(val);
|
|
1420
|
+
}),
|
|
1421
|
+
datetime: createCachedFormatter((lng, opt) => {
|
|
1422
|
+
const formatter = new Intl.DateTimeFormat(lng, {
|
|
1423
|
+
...opt
|
|
1424
|
+
});
|
|
1425
|
+
return val => formatter.format(val);
|
|
1426
|
+
}),
|
|
1427
|
+
relativetime: createCachedFormatter((lng, opt) => {
|
|
1428
|
+
const formatter = new Intl.RelativeTimeFormat(lng, {
|
|
1429
|
+
...opt
|
|
1430
|
+
});
|
|
1431
|
+
return val => formatter.format(val, opt.range || 'day');
|
|
1432
|
+
}),
|
|
1433
|
+
list: createCachedFormatter((lng, opt) => {
|
|
1434
|
+
const formatter = new Intl.ListFormat(lng, {
|
|
1435
|
+
...opt
|
|
1436
|
+
});
|
|
1437
|
+
return val => formatter.format(val);
|
|
1438
|
+
})
|
|
1439
|
+
};
|
|
1440
|
+
this.init(options);
|
|
1441
|
+
}
|
|
1442
|
+
init(services) {
|
|
1443
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
1444
|
+
interpolation: {}
|
|
1445
|
+
};
|
|
1446
|
+
const iOpts = options.interpolation;
|
|
1447
|
+
this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
|
|
1448
|
+
}
|
|
1449
|
+
add(name, fc) {
|
|
1450
|
+
this.formats[name.toLowerCase().trim()] = fc;
|
|
1451
|
+
}
|
|
1452
|
+
addCached(name, fc) {
|
|
1453
|
+
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
1454
|
+
}
|
|
1455
|
+
format(value, format, lng) {
|
|
1456
|
+
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1457
|
+
const formats = format.split(this.formatSeparator);
|
|
1458
|
+
const result = formats.reduce((mem, f) => {
|
|
1459
|
+
const {
|
|
1460
|
+
formatName,
|
|
1461
|
+
formatOptions
|
|
1462
|
+
} = parseFormatStr(f);
|
|
1463
|
+
if (this.formats[formatName]) {
|
|
1464
|
+
let formatted = mem;
|
|
1465
|
+
try {
|
|
1466
|
+
const valOptions = options && options.formatParams && options.formatParams[options.interpolationkey] || {};
|
|
1467
|
+
const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
|
|
1468
|
+
formatted = this.formats[formatName](mem, l, {
|
|
1469
|
+
...formatOptions,
|
|
1470
|
+
...options,
|
|
1471
|
+
...valOptions
|
|
1472
|
+
});
|
|
1473
|
+
} catch (error) {
|
|
1474
|
+
this.logger.warn(error);
|
|
1475
|
+
}
|
|
1476
|
+
return formatted;
|
|
1477
|
+
} else {
|
|
1478
|
+
this.logger.warn(`there was no format function for ${formatName}`);
|
|
1479
|
+
}
|
|
1480
|
+
return mem;
|
|
1481
|
+
}, value);
|
|
1482
|
+
return result;
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
function removePending(q, name) {
|
|
1487
|
+
if (q.pending[name] !== undefined) {
|
|
1488
|
+
delete q.pending[name];
|
|
1489
|
+
q.pendingCount--;
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
class Connector extends EventEmitter {
|
|
1493
|
+
constructor(backend, store, services) {
|
|
1494
|
+
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1495
|
+
super();
|
|
1496
|
+
this.backend = backend;
|
|
1497
|
+
this.store = store;
|
|
1498
|
+
this.services = services;
|
|
1499
|
+
this.languageUtils = services.languageUtils;
|
|
1500
|
+
this.options = options;
|
|
1501
|
+
this.logger = baseLogger.create('backendConnector');
|
|
1502
|
+
this.waitingReads = [];
|
|
1503
|
+
this.maxParallelReads = options.maxParallelReads || 10;
|
|
1504
|
+
this.readingCalls = 0;
|
|
1505
|
+
this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
|
|
1506
|
+
this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
|
|
1507
|
+
this.state = {};
|
|
1508
|
+
this.queue = [];
|
|
1509
|
+
if (this.backend && this.backend.init) {
|
|
1510
|
+
this.backend.init(services, options.backend, options);
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
queueLoad(languages, namespaces, options, callback) {
|
|
1514
|
+
const toLoad = {};
|
|
1515
|
+
const pending = {};
|
|
1516
|
+
const toLoadLanguages = {};
|
|
1517
|
+
const toLoadNamespaces = {};
|
|
1518
|
+
languages.forEach(lng => {
|
|
1519
|
+
let hasAllNamespaces = true;
|
|
1520
|
+
namespaces.forEach(ns => {
|
|
1521
|
+
const name = `${lng}|${ns}`;
|
|
1522
|
+
if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
|
|
1523
|
+
this.state[name] = 2;
|
|
1524
|
+
} else if (this.state[name] < 0) ; else if (this.state[name] === 1) {
|
|
1525
|
+
if (pending[name] === undefined) pending[name] = true;
|
|
1526
|
+
} else {
|
|
1527
|
+
this.state[name] = 1;
|
|
1528
|
+
hasAllNamespaces = false;
|
|
1529
|
+
if (pending[name] === undefined) pending[name] = true;
|
|
1530
|
+
if (toLoad[name] === undefined) toLoad[name] = true;
|
|
1531
|
+
if (toLoadNamespaces[ns] === undefined) toLoadNamespaces[ns] = true;
|
|
1532
|
+
}
|
|
1533
|
+
});
|
|
1534
|
+
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
1535
|
+
});
|
|
1536
|
+
if (Object.keys(toLoad).length || Object.keys(pending).length) {
|
|
1537
|
+
this.queue.push({
|
|
1538
|
+
pending,
|
|
1539
|
+
pendingCount: Object.keys(pending).length,
|
|
1540
|
+
loaded: {},
|
|
1541
|
+
errors: [],
|
|
1542
|
+
callback
|
|
1543
|
+
});
|
|
1544
|
+
}
|
|
1545
|
+
return {
|
|
1546
|
+
toLoad: Object.keys(toLoad),
|
|
1547
|
+
pending: Object.keys(pending),
|
|
1548
|
+
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
1549
|
+
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
1550
|
+
};
|
|
1551
|
+
}
|
|
1552
|
+
loaded(name, err, data) {
|
|
1553
|
+
const s = name.split('|');
|
|
1554
|
+
const lng = s[0];
|
|
1555
|
+
const ns = s[1];
|
|
1556
|
+
if (err) this.emit('failedLoading', lng, ns, err);
|
|
1557
|
+
if (data) {
|
|
1558
|
+
this.store.addResourceBundle(lng, ns, data);
|
|
1559
|
+
}
|
|
1560
|
+
this.state[name] = err ? -1 : 2;
|
|
1561
|
+
const loaded = {};
|
|
1562
|
+
this.queue.forEach(q => {
|
|
1563
|
+
pushPath(q.loaded, [lng], ns);
|
|
1564
|
+
removePending(q, name);
|
|
1565
|
+
if (err) q.errors.push(err);
|
|
1566
|
+
if (q.pendingCount === 0 && !q.done) {
|
|
1567
|
+
Object.keys(q.loaded).forEach(l => {
|
|
1568
|
+
if (!loaded[l]) loaded[l] = {};
|
|
1569
|
+
const loadedKeys = q.loaded[l];
|
|
1570
|
+
if (loadedKeys.length) {
|
|
1571
|
+
loadedKeys.forEach(n => {
|
|
1572
|
+
if (loaded[l][n] === undefined) loaded[l][n] = true;
|
|
1573
|
+
});
|
|
1574
|
+
}
|
|
1575
|
+
});
|
|
1576
|
+
q.done = true;
|
|
1577
|
+
if (q.errors.length) {
|
|
1578
|
+
q.callback(q.errors);
|
|
1579
|
+
} else {
|
|
1580
|
+
q.callback();
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
});
|
|
1584
|
+
this.emit('loaded', loaded);
|
|
1585
|
+
this.queue = this.queue.filter(q => !q.done);
|
|
1586
|
+
}
|
|
1587
|
+
read(lng, ns, fcName) {
|
|
1588
|
+
let tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
1589
|
+
let wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
|
|
1590
|
+
let callback = arguments.length > 5 ? arguments[5] : undefined;
|
|
1591
|
+
if (!lng.length) return callback(null, {});
|
|
1592
|
+
if (this.readingCalls >= this.maxParallelReads) {
|
|
1593
|
+
this.waitingReads.push({
|
|
1594
|
+
lng,
|
|
1595
|
+
ns,
|
|
1596
|
+
fcName,
|
|
1597
|
+
tried,
|
|
1598
|
+
wait,
|
|
1599
|
+
callback
|
|
1600
|
+
});
|
|
1601
|
+
return;
|
|
1602
|
+
}
|
|
1603
|
+
this.readingCalls++;
|
|
1604
|
+
const resolver = (err, data) => {
|
|
1605
|
+
this.readingCalls--;
|
|
1606
|
+
if (this.waitingReads.length > 0) {
|
|
1607
|
+
const next = this.waitingReads.shift();
|
|
1608
|
+
this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
1609
|
+
}
|
|
1610
|
+
if (err && data && tried < this.maxRetries) {
|
|
1611
|
+
setTimeout(() => {
|
|
1612
|
+
this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
1613
|
+
}, wait);
|
|
1614
|
+
return;
|
|
1615
|
+
}
|
|
1616
|
+
callback(err, data);
|
|
1617
|
+
};
|
|
1618
|
+
const fc = this.backend[fcName].bind(this.backend);
|
|
1619
|
+
if (fc.length === 2) {
|
|
1620
|
+
try {
|
|
1621
|
+
const r = fc(lng, ns);
|
|
1622
|
+
if (r && typeof r.then === 'function') {
|
|
1623
|
+
r.then(data => resolver(null, data)).catch(resolver);
|
|
1624
|
+
} else {
|
|
1625
|
+
resolver(null, r);
|
|
1626
|
+
}
|
|
1627
|
+
} catch (err) {
|
|
1628
|
+
resolver(err);
|
|
1629
|
+
}
|
|
1630
|
+
return;
|
|
1631
|
+
}
|
|
1632
|
+
return fc(lng, ns, resolver);
|
|
1633
|
+
}
|
|
1634
|
+
prepareLoading(languages, namespaces) {
|
|
1635
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1636
|
+
let callback = arguments.length > 3 ? arguments[3] : undefined;
|
|
1637
|
+
if (!this.backend) {
|
|
1638
|
+
this.logger.warn('No backend was added via i18next.use. Will not load resources.');
|
|
1639
|
+
return callback && callback();
|
|
1640
|
+
}
|
|
1641
|
+
if (typeof languages === 'string') languages = this.languageUtils.toResolveHierarchy(languages);
|
|
1642
|
+
if (typeof namespaces === 'string') namespaces = [namespaces];
|
|
1643
|
+
const toLoad = this.queueLoad(languages, namespaces, options, callback);
|
|
1644
|
+
if (!toLoad.toLoad.length) {
|
|
1645
|
+
if (!toLoad.pending.length) callback();
|
|
1646
|
+
return null;
|
|
1647
|
+
}
|
|
1648
|
+
toLoad.toLoad.forEach(name => {
|
|
1649
|
+
this.loadOne(name);
|
|
1650
|
+
});
|
|
1651
|
+
}
|
|
1652
|
+
load(languages, namespaces, callback) {
|
|
1653
|
+
this.prepareLoading(languages, namespaces, {}, callback);
|
|
1654
|
+
}
|
|
1655
|
+
reload(languages, namespaces, callback) {
|
|
1656
|
+
this.prepareLoading(languages, namespaces, {
|
|
1657
|
+
reload: true
|
|
1658
|
+
}, callback);
|
|
1659
|
+
}
|
|
1660
|
+
loadOne(name) {
|
|
1661
|
+
let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
1662
|
+
const s = name.split('|');
|
|
1663
|
+
const lng = s[0];
|
|
1664
|
+
const ns = s[1];
|
|
1665
|
+
this.read(lng, ns, 'read', undefined, undefined, (err, data) => {
|
|
1666
|
+
if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
|
|
1667
|
+
if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
|
|
1668
|
+
this.loaded(name, err, data);
|
|
1669
|
+
});
|
|
1670
|
+
}
|
|
1671
|
+
saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
|
|
1672
|
+
let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
1673
|
+
let clb = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : () => {};
|
|
1674
|
+
if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
|
|
1675
|
+
this.logger.warn(`did not save key "${key}" as the namespace "${namespace}" was not yet loaded`, 'This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!');
|
|
1676
|
+
return;
|
|
1677
|
+
}
|
|
1678
|
+
if (key === undefined || key === null || key === '') return;
|
|
1679
|
+
if (this.backend && this.backend.create) {
|
|
1680
|
+
const opts = {
|
|
1681
|
+
...options,
|
|
1682
|
+
isUpdate
|
|
1683
|
+
};
|
|
1684
|
+
const fc = this.backend.create.bind(this.backend);
|
|
1685
|
+
if (fc.length < 6) {
|
|
1686
|
+
try {
|
|
1687
|
+
let r;
|
|
1688
|
+
if (fc.length === 5) {
|
|
1689
|
+
r = fc(languages, namespace, key, fallbackValue, opts);
|
|
1690
|
+
} else {
|
|
1691
|
+
r = fc(languages, namespace, key, fallbackValue);
|
|
1692
|
+
}
|
|
1693
|
+
if (r && typeof r.then === 'function') {
|
|
1694
|
+
r.then(data => clb(null, data)).catch(clb);
|
|
1695
|
+
} else {
|
|
1696
|
+
clb(null, r);
|
|
1697
|
+
}
|
|
1698
|
+
} catch (err) {
|
|
1699
|
+
clb(err);
|
|
1700
|
+
}
|
|
1701
|
+
} else {
|
|
1702
|
+
fc(languages, namespace, key, fallbackValue, clb, opts);
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
if (!languages || !languages[0]) return;
|
|
1706
|
+
this.store.addResource(languages[0], namespace, key, fallbackValue);
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
function get() {
|
|
1711
|
+
return {
|
|
1712
|
+
debug: false,
|
|
1713
|
+
initImmediate: true,
|
|
1714
|
+
ns: ['translation'],
|
|
1715
|
+
defaultNS: ['translation'],
|
|
1716
|
+
fallbackLng: ['dev'],
|
|
1717
|
+
fallbackNS: false,
|
|
1718
|
+
supportedLngs: false,
|
|
1719
|
+
nonExplicitSupportedLngs: false,
|
|
1720
|
+
load: 'all',
|
|
1721
|
+
preload: false,
|
|
1722
|
+
simplifyPluralSuffix: true,
|
|
1723
|
+
keySeparator: '.',
|
|
1724
|
+
nsSeparator: ':',
|
|
1725
|
+
pluralSeparator: '_',
|
|
1726
|
+
contextSeparator: '_',
|
|
1727
|
+
partialBundledLanguages: false,
|
|
1728
|
+
saveMissing: false,
|
|
1729
|
+
updateMissing: false,
|
|
1730
|
+
saveMissingTo: 'fallback',
|
|
1731
|
+
saveMissingPlurals: true,
|
|
1732
|
+
missingKeyHandler: false,
|
|
1733
|
+
missingInterpolationHandler: false,
|
|
1734
|
+
postProcess: false,
|
|
1735
|
+
postProcessPassResolved: false,
|
|
1736
|
+
returnNull: false,
|
|
1737
|
+
returnEmptyString: true,
|
|
1738
|
+
returnObjects: false,
|
|
1739
|
+
joinArrays: false,
|
|
1740
|
+
returnedObjectHandler: false,
|
|
1741
|
+
parseMissingKeyHandler: false,
|
|
1742
|
+
appendNamespaceToMissingKey: false,
|
|
1743
|
+
appendNamespaceToCIMode: false,
|
|
1744
|
+
overloadTranslationOptionHandler: function handle(args) {
|
|
1745
|
+
let ret = {};
|
|
1746
|
+
if (typeof args[1] === 'object') ret = args[1];
|
|
1747
|
+
if (typeof args[1] === 'string') ret.defaultValue = args[1];
|
|
1748
|
+
if (typeof args[2] === 'string') ret.tDescription = args[2];
|
|
1749
|
+
if (typeof args[2] === 'object' || typeof args[3] === 'object') {
|
|
1750
|
+
const options = args[3] || args[2];
|
|
1751
|
+
Object.keys(options).forEach(key => {
|
|
1752
|
+
ret[key] = options[key];
|
|
1753
|
+
});
|
|
1754
|
+
}
|
|
1755
|
+
return ret;
|
|
1756
|
+
},
|
|
1757
|
+
interpolation: {
|
|
1758
|
+
escapeValue: true,
|
|
1759
|
+
format: (value, format, lng, options) => value,
|
|
1760
|
+
prefix: '{{',
|
|
1761
|
+
suffix: '}}',
|
|
1762
|
+
formatSeparator: ',',
|
|
1763
|
+
unescapePrefix: '-',
|
|
1764
|
+
nestingPrefix: '$t(',
|
|
1765
|
+
nestingSuffix: ')',
|
|
1766
|
+
nestingOptionsSeparator: ',',
|
|
1767
|
+
maxReplaces: 1000,
|
|
1768
|
+
skipOnVariables: true
|
|
1769
|
+
}
|
|
1770
|
+
};
|
|
1771
|
+
}
|
|
1772
|
+
function transformOptions(options) {
|
|
1773
|
+
if (typeof options.ns === 'string') options.ns = [options.ns];
|
|
1774
|
+
if (typeof options.fallbackLng === 'string') options.fallbackLng = [options.fallbackLng];
|
|
1775
|
+
if (typeof options.fallbackNS === 'string') options.fallbackNS = [options.fallbackNS];
|
|
1776
|
+
if (options.supportedLngs && options.supportedLngs.indexOf('cimode') < 0) {
|
|
1777
|
+
options.supportedLngs = options.supportedLngs.concat(['cimode']);
|
|
1778
|
+
}
|
|
1779
|
+
return options;
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
function noop() {}
|
|
1783
|
+
function bindMemberFunctions(inst) {
|
|
1784
|
+
const mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
|
|
1785
|
+
mems.forEach(mem => {
|
|
1786
|
+
if (typeof inst[mem] === 'function') {
|
|
1787
|
+
inst[mem] = inst[mem].bind(inst);
|
|
1788
|
+
}
|
|
1789
|
+
});
|
|
1790
|
+
}
|
|
1791
|
+
class I18n extends EventEmitter {
|
|
1792
|
+
constructor() {
|
|
1793
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1794
|
+
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
1795
|
+
super();
|
|
1796
|
+
this.options = transformOptions(options);
|
|
1797
|
+
this.services = {};
|
|
1798
|
+
this.logger = baseLogger;
|
|
1799
|
+
this.modules = {
|
|
1800
|
+
external: []
|
|
1801
|
+
};
|
|
1802
|
+
bindMemberFunctions(this);
|
|
1803
|
+
if (callback && !this.isInitialized && !options.isClone) {
|
|
1804
|
+
if (!this.options.initImmediate) {
|
|
1805
|
+
this.init(options, callback);
|
|
1806
|
+
return this;
|
|
1807
|
+
}
|
|
1808
|
+
setTimeout(() => {
|
|
1809
|
+
this.init(options, callback);
|
|
1810
|
+
}, 0);
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
init() {
|
|
1814
|
+
var _this = this;
|
|
1815
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1816
|
+
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
1817
|
+
if (typeof options === 'function') {
|
|
1818
|
+
callback = options;
|
|
1819
|
+
options = {};
|
|
1820
|
+
}
|
|
1821
|
+
if (!options.defaultNS && options.defaultNS !== false && options.ns) {
|
|
1822
|
+
if (typeof options.ns === 'string') {
|
|
1823
|
+
options.defaultNS = options.ns;
|
|
1824
|
+
} else if (options.ns.indexOf('translation') < 0) {
|
|
1825
|
+
options.defaultNS = options.ns[0];
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
const defOpts = get();
|
|
1829
|
+
this.options = {
|
|
1830
|
+
...defOpts,
|
|
1831
|
+
...this.options,
|
|
1832
|
+
...transformOptions(options)
|
|
1833
|
+
};
|
|
1834
|
+
if (this.options.compatibilityAPI !== 'v1') {
|
|
1835
|
+
this.options.interpolation = {
|
|
1836
|
+
...defOpts.interpolation,
|
|
1837
|
+
...this.options.interpolation
|
|
1838
|
+
};
|
|
1839
|
+
}
|
|
1840
|
+
if (options.keySeparator !== undefined) {
|
|
1841
|
+
this.options.userDefinedKeySeparator = options.keySeparator;
|
|
1842
|
+
}
|
|
1843
|
+
if (options.nsSeparator !== undefined) {
|
|
1844
|
+
this.options.userDefinedNsSeparator = options.nsSeparator;
|
|
1845
|
+
}
|
|
1846
|
+
function createClassOnDemand(ClassOrObject) {
|
|
1847
|
+
if (!ClassOrObject) return null;
|
|
1848
|
+
if (typeof ClassOrObject === 'function') return new ClassOrObject();
|
|
1849
|
+
return ClassOrObject;
|
|
1850
|
+
}
|
|
1851
|
+
if (!this.options.isClone) {
|
|
1852
|
+
if (this.modules.logger) {
|
|
1853
|
+
baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
|
|
1854
|
+
} else {
|
|
1855
|
+
baseLogger.init(null, this.options);
|
|
1856
|
+
}
|
|
1857
|
+
let formatter;
|
|
1858
|
+
if (this.modules.formatter) {
|
|
1859
|
+
formatter = this.modules.formatter;
|
|
1860
|
+
} else if (typeof Intl !== 'undefined') {
|
|
1861
|
+
formatter = Formatter;
|
|
1862
|
+
}
|
|
1863
|
+
const lu = new LanguageUtil(this.options);
|
|
1864
|
+
this.store = new ResourceStore(this.options.resources, this.options);
|
|
1865
|
+
const s = this.services;
|
|
1866
|
+
s.logger = baseLogger;
|
|
1867
|
+
s.resourceStore = this.store;
|
|
1868
|
+
s.languageUtils = lu;
|
|
1869
|
+
s.pluralResolver = new PluralResolver(lu, {
|
|
1870
|
+
prepend: this.options.pluralSeparator,
|
|
1871
|
+
compatibilityJSON: this.options.compatibilityJSON,
|
|
1872
|
+
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
1873
|
+
});
|
|
1874
|
+
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
|
|
1875
|
+
s.formatter = createClassOnDemand(formatter);
|
|
1876
|
+
s.formatter.init(s, this.options);
|
|
1877
|
+
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
1878
|
+
}
|
|
1879
|
+
s.interpolator = new Interpolator(this.options);
|
|
1880
|
+
s.utils = {
|
|
1881
|
+
hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
|
|
1882
|
+
};
|
|
1883
|
+
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
1884
|
+
s.backendConnector.on('*', function (event) {
|
|
1885
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1886
|
+
args[_key - 1] = arguments[_key];
|
|
1887
|
+
}
|
|
1888
|
+
_this.emit(event, ...args);
|
|
1889
|
+
});
|
|
1890
|
+
if (this.modules.languageDetector) {
|
|
1891
|
+
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
1892
|
+
if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
|
|
1893
|
+
}
|
|
1894
|
+
if (this.modules.i18nFormat) {
|
|
1895
|
+
s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
|
|
1896
|
+
if (s.i18nFormat.init) s.i18nFormat.init(this);
|
|
1897
|
+
}
|
|
1898
|
+
this.translator = new Translator(this.services, this.options);
|
|
1899
|
+
this.translator.on('*', function (event) {
|
|
1900
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
1901
|
+
args[_key2 - 1] = arguments[_key2];
|
|
1902
|
+
}
|
|
1903
|
+
_this.emit(event, ...args);
|
|
1904
|
+
});
|
|
1905
|
+
this.modules.external.forEach(m => {
|
|
1906
|
+
if (m.init) m.init(this);
|
|
1907
|
+
});
|
|
1908
|
+
}
|
|
1909
|
+
this.format = this.options.interpolation.format;
|
|
1910
|
+
if (!callback) callback = noop;
|
|
1911
|
+
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
1912
|
+
const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
1913
|
+
if (codes.length > 0 && codes[0] !== 'dev') this.options.lng = codes[0];
|
|
1914
|
+
}
|
|
1915
|
+
if (!this.services.languageDetector && !this.options.lng) {
|
|
1916
|
+
this.logger.warn('init: no languageDetector is used and no lng is defined');
|
|
1917
|
+
}
|
|
1918
|
+
const storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
|
|
1919
|
+
storeApi.forEach(fcName => {
|
|
1920
|
+
this[fcName] = function () {
|
|
1921
|
+
return _this.store[fcName](...arguments);
|
|
1922
|
+
};
|
|
1923
|
+
});
|
|
1924
|
+
const storeApiChained = ['addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle'];
|
|
1925
|
+
storeApiChained.forEach(fcName => {
|
|
1926
|
+
this[fcName] = function () {
|
|
1927
|
+
_this.store[fcName](...arguments);
|
|
1928
|
+
return _this;
|
|
1929
|
+
};
|
|
1930
|
+
});
|
|
1931
|
+
const deferred = defer();
|
|
1932
|
+
const load = () => {
|
|
1933
|
+
const finish = (err, t) => {
|
|
1934
|
+
if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn('init: i18next is already initialized. You should call init just once!');
|
|
1935
|
+
this.isInitialized = true;
|
|
1936
|
+
if (!this.options.isClone) this.logger.log('initialized', this.options);
|
|
1937
|
+
this.emit('initialized', this.options);
|
|
1938
|
+
deferred.resolve(t);
|
|
1939
|
+
callback(err, t);
|
|
1940
|
+
};
|
|
1941
|
+
if (this.languages && this.options.compatibilityAPI !== 'v1' && !this.isInitialized) return finish(null, this.t.bind(this));
|
|
1942
|
+
this.changeLanguage(this.options.lng, finish);
|
|
1943
|
+
};
|
|
1944
|
+
if (this.options.resources || !this.options.initImmediate) {
|
|
1945
|
+
load();
|
|
1946
|
+
} else {
|
|
1947
|
+
setTimeout(load, 0);
|
|
1948
|
+
}
|
|
1949
|
+
return deferred;
|
|
1950
|
+
}
|
|
1951
|
+
loadResources(language) {
|
|
1952
|
+
let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
|
|
1953
|
+
let usedCallback = callback;
|
|
1954
|
+
const usedLng = typeof language === 'string' ? language : this.language;
|
|
1955
|
+
if (typeof language === 'function') usedCallback = language;
|
|
1956
|
+
if (!this.options.resources || this.options.partialBundledLanguages) {
|
|
1957
|
+
if (usedLng && usedLng.toLowerCase() === 'cimode') return usedCallback();
|
|
1958
|
+
const toLoad = [];
|
|
1959
|
+
const append = lng => {
|
|
1960
|
+
if (!lng) return;
|
|
1961
|
+
const lngs = this.services.languageUtils.toResolveHierarchy(lng);
|
|
1962
|
+
lngs.forEach(l => {
|
|
1963
|
+
if (toLoad.indexOf(l) < 0) toLoad.push(l);
|
|
1964
|
+
});
|
|
1965
|
+
};
|
|
1966
|
+
if (!usedLng) {
|
|
1967
|
+
const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
1968
|
+
fallbacks.forEach(l => append(l));
|
|
1969
|
+
} else {
|
|
1970
|
+
append(usedLng);
|
|
1971
|
+
}
|
|
1972
|
+
if (this.options.preload) {
|
|
1973
|
+
this.options.preload.forEach(l => append(l));
|
|
1974
|
+
}
|
|
1975
|
+
this.services.backendConnector.load(toLoad, this.options.ns, e => {
|
|
1976
|
+
if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
|
|
1977
|
+
usedCallback(e);
|
|
1978
|
+
});
|
|
1979
|
+
} else {
|
|
1980
|
+
usedCallback(null);
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
reloadResources(lngs, ns, callback) {
|
|
1984
|
+
const deferred = defer();
|
|
1985
|
+
if (!lngs) lngs = this.languages;
|
|
1986
|
+
if (!ns) ns = this.options.ns;
|
|
1987
|
+
if (!callback) callback = noop;
|
|
1988
|
+
this.services.backendConnector.reload(lngs, ns, err => {
|
|
1989
|
+
deferred.resolve();
|
|
1990
|
+
callback(err);
|
|
1991
|
+
});
|
|
1992
|
+
return deferred;
|
|
1993
|
+
}
|
|
1994
|
+
use(module) {
|
|
1995
|
+
if (!module) throw new Error('You are passing an undefined module! Please check the object you are passing to i18next.use()');
|
|
1996
|
+
if (!module.type) throw new Error('You are passing a wrong module! Please check the object you are passing to i18next.use()');
|
|
1997
|
+
if (module.type === 'backend') {
|
|
1998
|
+
this.modules.backend = module;
|
|
1999
|
+
}
|
|
2000
|
+
if (module.type === 'logger' || module.log && module.warn && module.error) {
|
|
2001
|
+
this.modules.logger = module;
|
|
2002
|
+
}
|
|
2003
|
+
if (module.type === 'languageDetector') {
|
|
2004
|
+
this.modules.languageDetector = module;
|
|
2005
|
+
}
|
|
2006
|
+
if (module.type === 'i18nFormat') {
|
|
2007
|
+
this.modules.i18nFormat = module;
|
|
2008
|
+
}
|
|
2009
|
+
if (module.type === 'postProcessor') {
|
|
2010
|
+
postProcessor.addPostProcessor(module);
|
|
2011
|
+
}
|
|
2012
|
+
if (module.type === 'formatter') {
|
|
2013
|
+
this.modules.formatter = module;
|
|
2014
|
+
}
|
|
2015
|
+
if (module.type === '3rdParty') {
|
|
2016
|
+
this.modules.external.push(module);
|
|
2017
|
+
}
|
|
2018
|
+
return this;
|
|
2019
|
+
}
|
|
2020
|
+
setResolvedLanguage(l) {
|
|
2021
|
+
if (!l || !this.languages) return;
|
|
2022
|
+
if (['cimode', 'dev'].indexOf(l) > -1) return;
|
|
2023
|
+
for (let li = 0; li < this.languages.length; li++) {
|
|
2024
|
+
const lngInLngs = this.languages[li];
|
|
2025
|
+
if (['cimode', 'dev'].indexOf(lngInLngs) > -1) continue;
|
|
2026
|
+
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
2027
|
+
this.resolvedLanguage = lngInLngs;
|
|
2028
|
+
break;
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
changeLanguage(lng, callback) {
|
|
2033
|
+
var _this2 = this;
|
|
2034
|
+
this.isLanguageChangingTo = lng;
|
|
2035
|
+
const deferred = defer();
|
|
2036
|
+
this.emit('languageChanging', lng);
|
|
2037
|
+
const setLngProps = l => {
|
|
2038
|
+
this.language = l;
|
|
2039
|
+
this.languages = this.services.languageUtils.toResolveHierarchy(l);
|
|
2040
|
+
this.resolvedLanguage = undefined;
|
|
2041
|
+
this.setResolvedLanguage(l);
|
|
2042
|
+
};
|
|
2043
|
+
const done = (err, l) => {
|
|
2044
|
+
if (l) {
|
|
2045
|
+
setLngProps(l);
|
|
2046
|
+
this.translator.changeLanguage(l);
|
|
2047
|
+
this.isLanguageChangingTo = undefined;
|
|
2048
|
+
this.emit('languageChanged', l);
|
|
2049
|
+
this.logger.log('languageChanged', l);
|
|
2050
|
+
} else {
|
|
2051
|
+
this.isLanguageChangingTo = undefined;
|
|
2052
|
+
}
|
|
2053
|
+
deferred.resolve(function () {
|
|
2054
|
+
return _this2.t(...arguments);
|
|
2055
|
+
});
|
|
2056
|
+
if (callback) callback(err, function () {
|
|
2057
|
+
return _this2.t(...arguments);
|
|
2058
|
+
});
|
|
2059
|
+
};
|
|
2060
|
+
const setLng = lngs => {
|
|
2061
|
+
if (!lng && !lngs && this.services.languageDetector) lngs = [];
|
|
2062
|
+
const l = typeof lngs === 'string' ? lngs : this.services.languageUtils.getBestMatchFromCodes(lngs);
|
|
2063
|
+
if (l) {
|
|
2064
|
+
if (!this.language) {
|
|
2065
|
+
setLngProps(l);
|
|
2066
|
+
}
|
|
2067
|
+
if (!this.translator.language) this.translator.changeLanguage(l);
|
|
2068
|
+
if (this.services.languageDetector && this.services.languageDetector.cacheUserLanguage) this.services.languageDetector.cacheUserLanguage(l);
|
|
2069
|
+
}
|
|
2070
|
+
this.loadResources(l, err => {
|
|
2071
|
+
done(err, l);
|
|
2072
|
+
});
|
|
2073
|
+
};
|
|
2074
|
+
if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
|
|
2075
|
+
setLng(this.services.languageDetector.detect());
|
|
2076
|
+
} else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
|
|
2077
|
+
if (this.services.languageDetector.detect.length === 0) {
|
|
2078
|
+
this.services.languageDetector.detect().then(setLng);
|
|
2079
|
+
} else {
|
|
2080
|
+
this.services.languageDetector.detect(setLng);
|
|
2081
|
+
}
|
|
2082
|
+
} else {
|
|
2083
|
+
setLng(lng);
|
|
2084
|
+
}
|
|
2085
|
+
return deferred;
|
|
2086
|
+
}
|
|
2087
|
+
getFixedT(lng, ns, keyPrefix) {
|
|
2088
|
+
var _this3 = this;
|
|
2089
|
+
const fixedT = function (key, opts) {
|
|
2090
|
+
let options;
|
|
2091
|
+
if (typeof opts !== 'object') {
|
|
2092
|
+
for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
2093
|
+
rest[_key3 - 2] = arguments[_key3];
|
|
2094
|
+
}
|
|
2095
|
+
options = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
2096
|
+
} else {
|
|
2097
|
+
options = {
|
|
2098
|
+
...opts
|
|
2099
|
+
};
|
|
2100
|
+
}
|
|
2101
|
+
options.lng = options.lng || fixedT.lng;
|
|
2102
|
+
options.lngs = options.lngs || fixedT.lngs;
|
|
2103
|
+
options.ns = options.ns || fixedT.ns;
|
|
2104
|
+
options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
|
|
2105
|
+
const keySeparator = _this3.options.keySeparator || '.';
|
|
2106
|
+
let resultKey;
|
|
2107
|
+
if (options.keyPrefix && Array.isArray(key)) {
|
|
2108
|
+
resultKey = key.map(k => `${options.keyPrefix}${keySeparator}${k}`);
|
|
2109
|
+
} else {
|
|
2110
|
+
resultKey = options.keyPrefix ? `${options.keyPrefix}${keySeparator}${key}` : key;
|
|
2111
|
+
}
|
|
2112
|
+
return _this3.t(resultKey, options);
|
|
2113
|
+
};
|
|
2114
|
+
if (typeof lng === 'string') {
|
|
2115
|
+
fixedT.lng = lng;
|
|
2116
|
+
} else {
|
|
2117
|
+
fixedT.lngs = lng;
|
|
2118
|
+
}
|
|
2119
|
+
fixedT.ns = ns;
|
|
2120
|
+
fixedT.keyPrefix = keyPrefix;
|
|
2121
|
+
return fixedT;
|
|
2122
|
+
}
|
|
2123
|
+
t() {
|
|
2124
|
+
return this.translator && this.translator.translate(...arguments);
|
|
2125
|
+
}
|
|
2126
|
+
exists() {
|
|
2127
|
+
return this.translator && this.translator.exists(...arguments);
|
|
2128
|
+
}
|
|
2129
|
+
setDefaultNamespace(ns) {
|
|
2130
|
+
this.options.defaultNS = ns;
|
|
2131
|
+
}
|
|
2132
|
+
hasLoadedNamespace(ns) {
|
|
2133
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2134
|
+
if (!this.isInitialized) {
|
|
2135
|
+
this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
|
|
2136
|
+
return false;
|
|
2137
|
+
}
|
|
2138
|
+
if (!this.languages || !this.languages.length) {
|
|
2139
|
+
this.logger.warn('hasLoadedNamespace: i18n.languages were undefined or empty', this.languages);
|
|
2140
|
+
return false;
|
|
2141
|
+
}
|
|
2142
|
+
const lng = options.lng || this.resolvedLanguage || this.languages[0];
|
|
2143
|
+
const fallbackLng = this.options ? this.options.fallbackLng : false;
|
|
2144
|
+
const lastLng = this.languages[this.languages.length - 1];
|
|
2145
|
+
if (lng.toLowerCase() === 'cimode') return true;
|
|
2146
|
+
const loadNotPending = (l, n) => {
|
|
2147
|
+
const loadState = this.services.backendConnector.state[`${l}|${n}`];
|
|
2148
|
+
return loadState === -1 || loadState === 2;
|
|
2149
|
+
};
|
|
2150
|
+
if (options.precheck) {
|
|
2151
|
+
const preResult = options.precheck(this, loadNotPending);
|
|
2152
|
+
if (preResult !== undefined) return preResult;
|
|
2153
|
+
}
|
|
2154
|
+
if (this.hasResourceBundle(lng, ns)) return true;
|
|
2155
|
+
if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
|
|
2156
|
+
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
2157
|
+
return false;
|
|
2158
|
+
}
|
|
2159
|
+
loadNamespaces(ns, callback) {
|
|
2160
|
+
const deferred = defer();
|
|
2161
|
+
if (!this.options.ns) {
|
|
2162
|
+
if (callback) callback();
|
|
2163
|
+
return Promise.resolve();
|
|
2164
|
+
}
|
|
2165
|
+
if (typeof ns === 'string') ns = [ns];
|
|
2166
|
+
ns.forEach(n => {
|
|
2167
|
+
if (this.options.ns.indexOf(n) < 0) this.options.ns.push(n);
|
|
2168
|
+
});
|
|
2169
|
+
this.loadResources(err => {
|
|
2170
|
+
deferred.resolve();
|
|
2171
|
+
if (callback) callback(err);
|
|
2172
|
+
});
|
|
2173
|
+
return deferred;
|
|
2174
|
+
}
|
|
2175
|
+
loadLanguages(lngs, callback) {
|
|
2176
|
+
const deferred = defer();
|
|
2177
|
+
if (typeof lngs === 'string') lngs = [lngs];
|
|
2178
|
+
const preloaded = this.options.preload || [];
|
|
2179
|
+
const newLngs = lngs.filter(lng => preloaded.indexOf(lng) < 0);
|
|
2180
|
+
if (!newLngs.length) {
|
|
2181
|
+
if (callback) callback();
|
|
2182
|
+
return Promise.resolve();
|
|
2183
|
+
}
|
|
2184
|
+
this.options.preload = preloaded.concat(newLngs);
|
|
2185
|
+
this.loadResources(err => {
|
|
2186
|
+
deferred.resolve();
|
|
2187
|
+
if (callback) callback(err);
|
|
2188
|
+
});
|
|
2189
|
+
return deferred;
|
|
2190
|
+
}
|
|
2191
|
+
dir(lng) {
|
|
2192
|
+
if (!lng) lng = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language);
|
|
2193
|
+
if (!lng) return 'rtl';
|
|
2194
|
+
const rtlLngs = ['ar', 'shu', 'sqr', 'ssh', 'xaa', 'yhd', 'yud', 'aao', 'abh', 'abv', 'acm', 'acq', 'acw', 'acx', 'acy', 'adf', 'ads', 'aeb', 'aec', 'afb', 'ajp', 'apc', 'apd', 'arb', 'arq', 'ars', 'ary', 'arz', 'auz', 'avl', 'ayh', 'ayl', 'ayn', 'ayp', 'bbz', 'pga', 'he', 'iw', 'ps', 'pbt', 'pbu', 'pst', 'prp', 'prd', 'ug', 'ur', 'ydd', 'yds', 'yih', 'ji', 'yi', 'hbo', 'men', 'xmn', 'fa', 'jpr', 'peo', 'pes', 'prs', 'dv', 'sam', 'ckb'];
|
|
2195
|
+
const languageUtils = this.services && this.services.languageUtils || new LanguageUtil(get());
|
|
2196
|
+
return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
|
|
2197
|
+
}
|
|
2198
|
+
static createInstance() {
|
|
2199
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2200
|
+
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
2201
|
+
return new I18n(options, callback);
|
|
2202
|
+
}
|
|
2203
|
+
cloneInstance() {
|
|
2204
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2205
|
+
let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
|
|
2206
|
+
const forkResourceStore = options.forkResourceStore;
|
|
2207
|
+
if (forkResourceStore) delete options.forkResourceStore;
|
|
2208
|
+
const mergedOptions = {
|
|
2209
|
+
...this.options,
|
|
2210
|
+
...options,
|
|
2211
|
+
...{
|
|
2212
|
+
isClone: true
|
|
2213
|
+
}
|
|
2214
|
+
};
|
|
2215
|
+
const clone = new I18n(mergedOptions);
|
|
2216
|
+
if (options.debug !== undefined || options.prefix !== undefined) {
|
|
2217
|
+
clone.logger = clone.logger.clone(options);
|
|
2218
|
+
}
|
|
2219
|
+
const membersToCopy = ['store', 'services', 'language'];
|
|
2220
|
+
membersToCopy.forEach(m => {
|
|
2221
|
+
clone[m] = this[m];
|
|
2222
|
+
});
|
|
2223
|
+
clone.services = {
|
|
2224
|
+
...this.services
|
|
2225
|
+
};
|
|
2226
|
+
clone.services.utils = {
|
|
2227
|
+
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2228
|
+
};
|
|
2229
|
+
if (forkResourceStore) {
|
|
2230
|
+
clone.store = new ResourceStore(this.store.data, mergedOptions);
|
|
2231
|
+
clone.services.resourceStore = clone.store;
|
|
2232
|
+
}
|
|
2233
|
+
clone.translator = new Translator(clone.services, mergedOptions);
|
|
2234
|
+
clone.translator.on('*', function (event) {
|
|
2235
|
+
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
2236
|
+
args[_key4 - 1] = arguments[_key4];
|
|
2237
|
+
}
|
|
2238
|
+
clone.emit(event, ...args);
|
|
2239
|
+
});
|
|
2240
|
+
clone.init(mergedOptions, callback);
|
|
2241
|
+
clone.translator.options = mergedOptions;
|
|
2242
|
+
clone.translator.backendConnector.services.utils = {
|
|
2243
|
+
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2244
|
+
};
|
|
2245
|
+
return clone;
|
|
2246
|
+
}
|
|
2247
|
+
toJSON() {
|
|
2248
|
+
return {
|
|
2249
|
+
options: this.options,
|
|
2250
|
+
store: this.store,
|
|
2251
|
+
language: this.language,
|
|
2252
|
+
languages: this.languages,
|
|
2253
|
+
resolvedLanguage: this.resolvedLanguage
|
|
2254
|
+
};
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
const instance = I18n.createInstance();
|
|
2258
|
+
instance.createInstance = I18n.createInstance;
|
|
98
2259
|
|
|
99
2260
|
// Unique ID creation requires a high quality random # generator. In the browser we therefore
|
|
100
2261
|
// require the crypto API and do not support built-in fallback to lower quality random number
|
|
@@ -4081,5 +6242,5 @@ exports.createTrackingApi = createTrackingApi;
|
|
|
4081
6242
|
exports.createWidgetVpcEvent = createWidgetVpcEvent;
|
|
4082
6243
|
exports.createWidgetVprEvent = createWidgetVprEvent;
|
|
4083
6244
|
exports.createWidgetVpsEvent = createWidgetVpsEvent;
|
|
4084
|
-
exports.
|
|
6245
|
+
exports.instance = instance;
|
|
4085
6246
|
exports.v4 = v4;
|