@spscommerce/i18n 5.10.2 → 5.10.5-ie
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/package.json +4 -4
- package/vite.config.js +1 -1
- package/lib/SpsLanguage.d.ts +0 -2
- package/lib/index.cjs.js +0 -2
- package/lib/index.d.ts +0 -3
- package/lib/index.es.js +0 -4214
- package/lib/localize.d.ts +0 -21
- package/lib/useSpsLanguage.d.ts +0 -1
package/lib/index.es.js
DELETED
|
@@ -1,4214 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __spreadValues = (a2, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a2, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a2, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a2;
|
|
16
|
-
};
|
|
17
|
-
var __objRest = (source, exclude) => {
|
|
18
|
-
var target = {};
|
|
19
|
-
for (var prop in source)
|
|
20
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
21
|
-
target[prop] = source[prop];
|
|
22
|
-
if (source != null && __getOwnPropSymbols)
|
|
23
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
24
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
25
|
-
target[prop] = source[prop];
|
|
26
|
-
}
|
|
27
|
-
return target;
|
|
28
|
-
};
|
|
29
|
-
import * as React from "react";
|
|
30
|
-
import React__default, { useContext, useState, useRef, useEffect } from "react";
|
|
31
|
-
function _mergeNamespaces(n2, m) {
|
|
32
|
-
m.forEach(function(e) {
|
|
33
|
-
Object.keys(e).forEach(function(k) {
|
|
34
|
-
if (k !== "default" && !(k in n2)) {
|
|
35
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
36
|
-
Object.defineProperty(n2, k, d.get ? d : {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
get: function() {
|
|
39
|
-
return e[k];
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
return Object.freeze(n2);
|
|
46
|
-
}
|
|
47
|
-
function _typeof$2(obj) {
|
|
48
|
-
"@babel/helpers - typeof";
|
|
49
|
-
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
|
50
|
-
_typeof$2 = function _typeof2(obj2) {
|
|
51
|
-
return typeof obj2;
|
|
52
|
-
};
|
|
53
|
-
} else {
|
|
54
|
-
_typeof$2 = function _typeof2(obj2) {
|
|
55
|
-
return obj2 && typeof Symbol === "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
return _typeof$2(obj);
|
|
59
|
-
}
|
|
60
|
-
function _defineProperty$1(obj, key, value) {
|
|
61
|
-
if (key in obj) {
|
|
62
|
-
Object.defineProperty(obj, key, {
|
|
63
|
-
value,
|
|
64
|
-
enumerable: true,
|
|
65
|
-
configurable: true,
|
|
66
|
-
writable: true
|
|
67
|
-
});
|
|
68
|
-
} else {
|
|
69
|
-
obj[key] = value;
|
|
70
|
-
}
|
|
71
|
-
return obj;
|
|
72
|
-
}
|
|
73
|
-
function _objectSpread$3(target) {
|
|
74
|
-
for (var i2 = 1; i2 < arguments.length; i2++) {
|
|
75
|
-
var source = arguments[i2] != null ? Object(arguments[i2]) : {};
|
|
76
|
-
var ownKeys2 = Object.keys(source);
|
|
77
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
78
|
-
ownKeys2.push.apply(ownKeys2, Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
79
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
80
|
-
}));
|
|
81
|
-
}
|
|
82
|
-
ownKeys2.forEach(function(key) {
|
|
83
|
-
_defineProperty$1(target, key, source[key]);
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
return target;
|
|
87
|
-
}
|
|
88
|
-
function _classCallCheck$1(instance, Constructor) {
|
|
89
|
-
if (!(instance instanceof Constructor)) {
|
|
90
|
-
throw new TypeError("Cannot call a class as a function");
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function _defineProperties$1(target, props) {
|
|
94
|
-
for (var i2 = 0; i2 < props.length; i2++) {
|
|
95
|
-
var descriptor = props[i2];
|
|
96
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
97
|
-
descriptor.configurable = true;
|
|
98
|
-
if ("value" in descriptor)
|
|
99
|
-
descriptor.writable = true;
|
|
100
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
function _createClass$1(Constructor, protoProps, staticProps) {
|
|
104
|
-
if (protoProps)
|
|
105
|
-
_defineProperties$1(Constructor.prototype, protoProps);
|
|
106
|
-
if (staticProps)
|
|
107
|
-
_defineProperties$1(Constructor, staticProps);
|
|
108
|
-
return Constructor;
|
|
109
|
-
}
|
|
110
|
-
function _assertThisInitialized(self2) {
|
|
111
|
-
if (self2 === void 0) {
|
|
112
|
-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
113
|
-
}
|
|
114
|
-
return self2;
|
|
115
|
-
}
|
|
116
|
-
function _possibleConstructorReturn(self2, call) {
|
|
117
|
-
if (call && (_typeof$2(call) === "object" || typeof call === "function")) {
|
|
118
|
-
return call;
|
|
119
|
-
} else if (call !== void 0) {
|
|
120
|
-
throw new TypeError("Derived constructors may only return object or undefined");
|
|
121
|
-
}
|
|
122
|
-
return _assertThisInitialized(self2);
|
|
123
|
-
}
|
|
124
|
-
function _getPrototypeOf(o) {
|
|
125
|
-
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf2(o2) {
|
|
126
|
-
return o2.__proto__ || Object.getPrototypeOf(o2);
|
|
127
|
-
};
|
|
128
|
-
return _getPrototypeOf(o);
|
|
129
|
-
}
|
|
130
|
-
function _setPrototypeOf(o, p) {
|
|
131
|
-
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf2(o2, p2) {
|
|
132
|
-
o2.__proto__ = p2;
|
|
133
|
-
return o2;
|
|
134
|
-
};
|
|
135
|
-
return _setPrototypeOf(o, p);
|
|
136
|
-
}
|
|
137
|
-
function _inherits(subClass, superClass) {
|
|
138
|
-
if (typeof superClass !== "function" && superClass !== null) {
|
|
139
|
-
throw new TypeError("Super expression must either be null or a function");
|
|
140
|
-
}
|
|
141
|
-
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
142
|
-
constructor: {
|
|
143
|
-
value: subClass,
|
|
144
|
-
writable: true,
|
|
145
|
-
configurable: true
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
if (superClass)
|
|
149
|
-
_setPrototypeOf(subClass, superClass);
|
|
150
|
-
}
|
|
151
|
-
var consoleLogger = {
|
|
152
|
-
type: "logger",
|
|
153
|
-
log: function log(args) {
|
|
154
|
-
this.output("log", args);
|
|
155
|
-
},
|
|
156
|
-
warn: function warn(args) {
|
|
157
|
-
this.output("warn", args);
|
|
158
|
-
},
|
|
159
|
-
error: function error(args) {
|
|
160
|
-
this.output("error", args);
|
|
161
|
-
},
|
|
162
|
-
output: function output(type, args) {
|
|
163
|
-
if (console && console[type])
|
|
164
|
-
console[type].apply(console, args);
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
var Logger = function() {
|
|
168
|
-
function Logger2(concreteLogger) {
|
|
169
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
170
|
-
_classCallCheck$1(this, Logger2);
|
|
171
|
-
this.init(concreteLogger, options);
|
|
172
|
-
}
|
|
173
|
-
_createClass$1(Logger2, [{
|
|
174
|
-
key: "init",
|
|
175
|
-
value: function init2(concreteLogger) {
|
|
176
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
177
|
-
this.prefix = options.prefix || "i18next:";
|
|
178
|
-
this.logger = concreteLogger || consoleLogger;
|
|
179
|
-
this.options = options;
|
|
180
|
-
this.debug = options.debug;
|
|
181
|
-
}
|
|
182
|
-
}, {
|
|
183
|
-
key: "setDebug",
|
|
184
|
-
value: function setDebug(bool) {
|
|
185
|
-
this.debug = bool;
|
|
186
|
-
}
|
|
187
|
-
}, {
|
|
188
|
-
key: "log",
|
|
189
|
-
value: function log2() {
|
|
190
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
191
|
-
args[_key] = arguments[_key];
|
|
192
|
-
}
|
|
193
|
-
return this.forward(args, "log", "", true);
|
|
194
|
-
}
|
|
195
|
-
}, {
|
|
196
|
-
key: "warn",
|
|
197
|
-
value: function warn3() {
|
|
198
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
199
|
-
args[_key2] = arguments[_key2];
|
|
200
|
-
}
|
|
201
|
-
return this.forward(args, "warn", "", true);
|
|
202
|
-
}
|
|
203
|
-
}, {
|
|
204
|
-
key: "error",
|
|
205
|
-
value: function error2() {
|
|
206
|
-
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
207
|
-
args[_key3] = arguments[_key3];
|
|
208
|
-
}
|
|
209
|
-
return this.forward(args, "error", "");
|
|
210
|
-
}
|
|
211
|
-
}, {
|
|
212
|
-
key: "deprecate",
|
|
213
|
-
value: function deprecate() {
|
|
214
|
-
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
215
|
-
args[_key4] = arguments[_key4];
|
|
216
|
-
}
|
|
217
|
-
return this.forward(args, "warn", "WARNING DEPRECATED: ", true);
|
|
218
|
-
}
|
|
219
|
-
}, {
|
|
220
|
-
key: "forward",
|
|
221
|
-
value: function forward(args, lvl, prefix, debugOnly) {
|
|
222
|
-
if (debugOnly && !this.debug)
|
|
223
|
-
return null;
|
|
224
|
-
if (typeof args[0] === "string")
|
|
225
|
-
args[0] = "".concat(prefix).concat(this.prefix, " ").concat(args[0]);
|
|
226
|
-
return this.logger[lvl](args);
|
|
227
|
-
}
|
|
228
|
-
}, {
|
|
229
|
-
key: "create",
|
|
230
|
-
value: function create2(moduleName) {
|
|
231
|
-
return new Logger2(this.logger, _objectSpread$3({}, {
|
|
232
|
-
prefix: "".concat(this.prefix, ":").concat(moduleName, ":")
|
|
233
|
-
}, this.options));
|
|
234
|
-
}
|
|
235
|
-
}]);
|
|
236
|
-
return Logger2;
|
|
237
|
-
}();
|
|
238
|
-
var baseLogger = new Logger();
|
|
239
|
-
var EventEmitter = function() {
|
|
240
|
-
function EventEmitter2() {
|
|
241
|
-
_classCallCheck$1(this, EventEmitter2);
|
|
242
|
-
this.observers = {};
|
|
243
|
-
}
|
|
244
|
-
_createClass$1(EventEmitter2, [{
|
|
245
|
-
key: "on",
|
|
246
|
-
value: function on(events, listener) {
|
|
247
|
-
var _this = this;
|
|
248
|
-
events.split(" ").forEach(function(event) {
|
|
249
|
-
_this.observers[event] = _this.observers[event] || [];
|
|
250
|
-
_this.observers[event].push(listener);
|
|
251
|
-
});
|
|
252
|
-
return this;
|
|
253
|
-
}
|
|
254
|
-
}, {
|
|
255
|
-
key: "off",
|
|
256
|
-
value: function off(event, listener) {
|
|
257
|
-
if (!this.observers[event])
|
|
258
|
-
return;
|
|
259
|
-
if (!listener) {
|
|
260
|
-
delete this.observers[event];
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
this.observers[event] = this.observers[event].filter(function(l) {
|
|
264
|
-
return l !== listener;
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
}, {
|
|
268
|
-
key: "emit",
|
|
269
|
-
value: function emit(event) {
|
|
270
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
271
|
-
args[_key - 1] = arguments[_key];
|
|
272
|
-
}
|
|
273
|
-
if (this.observers[event]) {
|
|
274
|
-
var cloned = [].concat(this.observers[event]);
|
|
275
|
-
cloned.forEach(function(observer) {
|
|
276
|
-
observer.apply(void 0, args);
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
if (this.observers["*"]) {
|
|
280
|
-
var _cloned = [].concat(this.observers["*"]);
|
|
281
|
-
_cloned.forEach(function(observer) {
|
|
282
|
-
observer.apply(observer, [event].concat(args));
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}]);
|
|
287
|
-
return EventEmitter2;
|
|
288
|
-
}();
|
|
289
|
-
function defer() {
|
|
290
|
-
var res;
|
|
291
|
-
var rej;
|
|
292
|
-
var promise = new Promise(function(resolve, reject) {
|
|
293
|
-
res = resolve;
|
|
294
|
-
rej = reject;
|
|
295
|
-
});
|
|
296
|
-
promise.resolve = res;
|
|
297
|
-
promise.reject = rej;
|
|
298
|
-
return promise;
|
|
299
|
-
}
|
|
300
|
-
function makeString(object) {
|
|
301
|
-
if (object == null)
|
|
302
|
-
return "";
|
|
303
|
-
return "" + object;
|
|
304
|
-
}
|
|
305
|
-
function copy(a2, s2, t2) {
|
|
306
|
-
a2.forEach(function(m) {
|
|
307
|
-
if (s2[m])
|
|
308
|
-
t2[m] = s2[m];
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
function getLastOfPath(object, path2, Empty) {
|
|
312
|
-
function cleanKey(key2) {
|
|
313
|
-
return key2 && key2.indexOf("###") > -1 ? key2.replace(/###/g, ".") : key2;
|
|
314
|
-
}
|
|
315
|
-
function canNotTraverseDeeper() {
|
|
316
|
-
return !object || typeof object === "string";
|
|
317
|
-
}
|
|
318
|
-
var stack = typeof path2 !== "string" ? [].concat(path2) : path2.split(".");
|
|
319
|
-
while (stack.length > 1) {
|
|
320
|
-
if (canNotTraverseDeeper())
|
|
321
|
-
return {};
|
|
322
|
-
var key = cleanKey(stack.shift());
|
|
323
|
-
if (!object[key] && Empty)
|
|
324
|
-
object[key] = new Empty();
|
|
325
|
-
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
326
|
-
object = object[key];
|
|
327
|
-
} else {
|
|
328
|
-
object = {};
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
if (canNotTraverseDeeper())
|
|
332
|
-
return {};
|
|
333
|
-
return {
|
|
334
|
-
obj: object,
|
|
335
|
-
k: cleanKey(stack.shift())
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
function setPath(object, path2, newValue) {
|
|
339
|
-
var _getLastOfPath = getLastOfPath(object, path2, Object), obj = _getLastOfPath.obj, k = _getLastOfPath.k;
|
|
340
|
-
obj[k] = newValue;
|
|
341
|
-
}
|
|
342
|
-
function pushPath(object, path2, newValue, concat) {
|
|
343
|
-
var _getLastOfPath2 = getLastOfPath(object, path2, Object), obj = _getLastOfPath2.obj, k = _getLastOfPath2.k;
|
|
344
|
-
obj[k] = obj[k] || [];
|
|
345
|
-
if (concat)
|
|
346
|
-
obj[k] = obj[k].concat(newValue);
|
|
347
|
-
if (!concat)
|
|
348
|
-
obj[k].push(newValue);
|
|
349
|
-
}
|
|
350
|
-
function getPath(object, path2) {
|
|
351
|
-
var _getLastOfPath3 = getLastOfPath(object, path2), obj = _getLastOfPath3.obj, k = _getLastOfPath3.k;
|
|
352
|
-
if (!obj)
|
|
353
|
-
return void 0;
|
|
354
|
-
return obj[k];
|
|
355
|
-
}
|
|
356
|
-
function getPathWithDefaults(data, defaultData, key) {
|
|
357
|
-
var value = getPath(data, key);
|
|
358
|
-
if (value !== void 0) {
|
|
359
|
-
return value;
|
|
360
|
-
}
|
|
361
|
-
return getPath(defaultData, key);
|
|
362
|
-
}
|
|
363
|
-
function deepExtend(target, source, overwrite) {
|
|
364
|
-
for (var prop in source) {
|
|
365
|
-
if (prop !== "__proto__" && prop !== "constructor") {
|
|
366
|
-
if (prop in target) {
|
|
367
|
-
if (typeof target[prop] === "string" || target[prop] instanceof String || typeof source[prop] === "string" || source[prop] instanceof String) {
|
|
368
|
-
if (overwrite)
|
|
369
|
-
target[prop] = source[prop];
|
|
370
|
-
} else {
|
|
371
|
-
deepExtend(target[prop], source[prop], overwrite);
|
|
372
|
-
}
|
|
373
|
-
} else {
|
|
374
|
-
target[prop] = source[prop];
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
return target;
|
|
379
|
-
}
|
|
380
|
-
function regexEscape(str) {
|
|
381
|
-
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
|
382
|
-
}
|
|
383
|
-
var _entityMap = {
|
|
384
|
-
"&": "&",
|
|
385
|
-
"<": "<",
|
|
386
|
-
">": ">",
|
|
387
|
-
'"': """,
|
|
388
|
-
"'": "'",
|
|
389
|
-
"/": "/"
|
|
390
|
-
};
|
|
391
|
-
function escape(data) {
|
|
392
|
-
if (typeof data === "string") {
|
|
393
|
-
return data.replace(/[&<>"'\/]/g, function(s2) {
|
|
394
|
-
return _entityMap[s2];
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
return data;
|
|
398
|
-
}
|
|
399
|
-
var isIE10 = typeof window !== "undefined" && window.navigator && window.navigator.userAgent && window.navigator.userAgent.indexOf("MSIE") > -1;
|
|
400
|
-
var ResourceStore = function(_EventEmitter) {
|
|
401
|
-
_inherits(ResourceStore2, _EventEmitter);
|
|
402
|
-
function ResourceStore2(data) {
|
|
403
|
-
var _this;
|
|
404
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
|
|
405
|
-
ns: ["translation"],
|
|
406
|
-
defaultNS: "translation"
|
|
407
|
-
};
|
|
408
|
-
_classCallCheck$1(this, ResourceStore2);
|
|
409
|
-
_this = _possibleConstructorReturn(this, _getPrototypeOf(ResourceStore2).call(this));
|
|
410
|
-
if (isIE10) {
|
|
411
|
-
EventEmitter.call(_assertThisInitialized(_this));
|
|
412
|
-
}
|
|
413
|
-
_this.data = data || {};
|
|
414
|
-
_this.options = options;
|
|
415
|
-
if (_this.options.keySeparator === void 0) {
|
|
416
|
-
_this.options.keySeparator = ".";
|
|
417
|
-
}
|
|
418
|
-
return _this;
|
|
419
|
-
}
|
|
420
|
-
_createClass$1(ResourceStore2, [{
|
|
421
|
-
key: "addNamespaces",
|
|
422
|
-
value: function addNamespaces(ns) {
|
|
423
|
-
if (this.options.ns.indexOf(ns) < 0) {
|
|
424
|
-
this.options.ns.push(ns);
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
}, {
|
|
428
|
-
key: "removeNamespaces",
|
|
429
|
-
value: function removeNamespaces(ns) {
|
|
430
|
-
var index = this.options.ns.indexOf(ns);
|
|
431
|
-
if (index > -1) {
|
|
432
|
-
this.options.ns.splice(index, 1);
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
}, {
|
|
436
|
-
key: "getResource",
|
|
437
|
-
value: function getResource(lng, ns, key) {
|
|
438
|
-
var options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
439
|
-
var keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
440
|
-
var path2 = [lng, ns];
|
|
441
|
-
if (key && typeof key !== "string")
|
|
442
|
-
path2 = path2.concat(key);
|
|
443
|
-
if (key && typeof key === "string")
|
|
444
|
-
path2 = path2.concat(keySeparator ? key.split(keySeparator) : key);
|
|
445
|
-
if (lng.indexOf(".") > -1) {
|
|
446
|
-
path2 = lng.split(".");
|
|
447
|
-
}
|
|
448
|
-
return getPath(this.data, path2);
|
|
449
|
-
}
|
|
450
|
-
}, {
|
|
451
|
-
key: "addResource",
|
|
452
|
-
value: function addResource(lng, ns, key, value) {
|
|
453
|
-
var options = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : {
|
|
454
|
-
silent: false
|
|
455
|
-
};
|
|
456
|
-
var keySeparator = this.options.keySeparator;
|
|
457
|
-
if (keySeparator === void 0)
|
|
458
|
-
keySeparator = ".";
|
|
459
|
-
var path2 = [lng, ns];
|
|
460
|
-
if (key)
|
|
461
|
-
path2 = path2.concat(keySeparator ? key.split(keySeparator) : key);
|
|
462
|
-
if (lng.indexOf(".") > -1) {
|
|
463
|
-
path2 = lng.split(".");
|
|
464
|
-
value = ns;
|
|
465
|
-
ns = path2[1];
|
|
466
|
-
}
|
|
467
|
-
this.addNamespaces(ns);
|
|
468
|
-
setPath(this.data, path2, value);
|
|
469
|
-
if (!options.silent)
|
|
470
|
-
this.emit("added", lng, ns, key, value);
|
|
471
|
-
}
|
|
472
|
-
}, {
|
|
473
|
-
key: "addResources",
|
|
474
|
-
value: function addResources(lng, ns, resources) {
|
|
475
|
-
var options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {
|
|
476
|
-
silent: false
|
|
477
|
-
};
|
|
478
|
-
for (var m in resources) {
|
|
479
|
-
if (typeof resources[m] === "string" || Object.prototype.toString.apply(resources[m]) === "[object Array]")
|
|
480
|
-
this.addResource(lng, ns, m, resources[m], {
|
|
481
|
-
silent: true
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
if (!options.silent)
|
|
485
|
-
this.emit("added", lng, ns, resources);
|
|
486
|
-
}
|
|
487
|
-
}, {
|
|
488
|
-
key: "addResourceBundle",
|
|
489
|
-
value: function addResourceBundle(lng, ns, resources, deep, overwrite) {
|
|
490
|
-
var options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {
|
|
491
|
-
silent: false
|
|
492
|
-
};
|
|
493
|
-
var path2 = [lng, ns];
|
|
494
|
-
if (lng.indexOf(".") > -1) {
|
|
495
|
-
path2 = lng.split(".");
|
|
496
|
-
deep = resources;
|
|
497
|
-
resources = ns;
|
|
498
|
-
ns = path2[1];
|
|
499
|
-
}
|
|
500
|
-
this.addNamespaces(ns);
|
|
501
|
-
var pack = getPath(this.data, path2) || {};
|
|
502
|
-
if (deep) {
|
|
503
|
-
deepExtend(pack, resources, overwrite);
|
|
504
|
-
} else {
|
|
505
|
-
pack = _objectSpread$3({}, pack, resources);
|
|
506
|
-
}
|
|
507
|
-
setPath(this.data, path2, pack);
|
|
508
|
-
if (!options.silent)
|
|
509
|
-
this.emit("added", lng, ns, resources);
|
|
510
|
-
}
|
|
511
|
-
}, {
|
|
512
|
-
key: "removeResourceBundle",
|
|
513
|
-
value: function removeResourceBundle(lng, ns) {
|
|
514
|
-
if (this.hasResourceBundle(lng, ns)) {
|
|
515
|
-
delete this.data[lng][ns];
|
|
516
|
-
}
|
|
517
|
-
this.removeNamespaces(ns);
|
|
518
|
-
this.emit("removed", lng, ns);
|
|
519
|
-
}
|
|
520
|
-
}, {
|
|
521
|
-
key: "hasResourceBundle",
|
|
522
|
-
value: function hasResourceBundle(lng, ns) {
|
|
523
|
-
return this.getResource(lng, ns) !== void 0;
|
|
524
|
-
}
|
|
525
|
-
}, {
|
|
526
|
-
key: "getResourceBundle",
|
|
527
|
-
value: function getResourceBundle(lng, ns) {
|
|
528
|
-
if (!ns)
|
|
529
|
-
ns = this.options.defaultNS;
|
|
530
|
-
if (this.options.compatibilityAPI === "v1")
|
|
531
|
-
return _objectSpread$3({}, {}, this.getResource(lng, ns));
|
|
532
|
-
return this.getResource(lng, ns);
|
|
533
|
-
}
|
|
534
|
-
}, {
|
|
535
|
-
key: "getDataByLanguage",
|
|
536
|
-
value: function getDataByLanguage(lng) {
|
|
537
|
-
return this.data[lng];
|
|
538
|
-
}
|
|
539
|
-
}, {
|
|
540
|
-
key: "toJSON",
|
|
541
|
-
value: function toJSON() {
|
|
542
|
-
return this.data;
|
|
543
|
-
}
|
|
544
|
-
}]);
|
|
545
|
-
return ResourceStore2;
|
|
546
|
-
}(EventEmitter);
|
|
547
|
-
var postProcessor = {
|
|
548
|
-
processors: {},
|
|
549
|
-
addPostProcessor: function addPostProcessor(module) {
|
|
550
|
-
this.processors[module.name] = module;
|
|
551
|
-
},
|
|
552
|
-
handle: function handle(processors, value, key, options, translator) {
|
|
553
|
-
var _this = this;
|
|
554
|
-
processors.forEach(function(processor) {
|
|
555
|
-
if (_this.processors[processor])
|
|
556
|
-
value = _this.processors[processor].process(value, key, options, translator);
|
|
557
|
-
});
|
|
558
|
-
return value;
|
|
559
|
-
}
|
|
560
|
-
};
|
|
561
|
-
var checkedLoadedFor = {};
|
|
562
|
-
var Translator = function(_EventEmitter) {
|
|
563
|
-
_inherits(Translator2, _EventEmitter);
|
|
564
|
-
function Translator2(services) {
|
|
565
|
-
var _this;
|
|
566
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
567
|
-
_classCallCheck$1(this, Translator2);
|
|
568
|
-
_this = _possibleConstructorReturn(this, _getPrototypeOf(Translator2).call(this));
|
|
569
|
-
if (isIE10) {
|
|
570
|
-
EventEmitter.call(_assertThisInitialized(_this));
|
|
571
|
-
}
|
|
572
|
-
copy(["resourceStore", "languageUtils", "pluralResolver", "interpolator", "backendConnector", "i18nFormat", "utils"], services, _assertThisInitialized(_this));
|
|
573
|
-
_this.options = options;
|
|
574
|
-
if (_this.options.keySeparator === void 0) {
|
|
575
|
-
_this.options.keySeparator = ".";
|
|
576
|
-
}
|
|
577
|
-
_this.logger = baseLogger.create("translator");
|
|
578
|
-
return _this;
|
|
579
|
-
}
|
|
580
|
-
_createClass$1(Translator2, [{
|
|
581
|
-
key: "changeLanguage",
|
|
582
|
-
value: function changeLanguage(lng) {
|
|
583
|
-
if (lng)
|
|
584
|
-
this.language = lng;
|
|
585
|
-
}
|
|
586
|
-
}, {
|
|
587
|
-
key: "exists",
|
|
588
|
-
value: function exists(key) {
|
|
589
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
|
|
590
|
-
interpolation: {}
|
|
591
|
-
};
|
|
592
|
-
var resolved = this.resolve(key, options);
|
|
593
|
-
return resolved && resolved.res !== void 0;
|
|
594
|
-
}
|
|
595
|
-
}, {
|
|
596
|
-
key: "extractFromKey",
|
|
597
|
-
value: function extractFromKey(key, options) {
|
|
598
|
-
var nsSeparator = options.nsSeparator !== void 0 ? options.nsSeparator : this.options.nsSeparator;
|
|
599
|
-
if (nsSeparator === void 0)
|
|
600
|
-
nsSeparator = ":";
|
|
601
|
-
var keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
602
|
-
var namespaces = options.ns || this.options.defaultNS;
|
|
603
|
-
if (nsSeparator && key.indexOf(nsSeparator) > -1) {
|
|
604
|
-
var m = key.match(this.interpolator.nestingRegexp);
|
|
605
|
-
if (m && m.length > 0) {
|
|
606
|
-
return {
|
|
607
|
-
key,
|
|
608
|
-
namespaces
|
|
609
|
-
};
|
|
610
|
-
}
|
|
611
|
-
var parts = key.split(nsSeparator);
|
|
612
|
-
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1)
|
|
613
|
-
namespaces = parts.shift();
|
|
614
|
-
key = parts.join(keySeparator);
|
|
615
|
-
}
|
|
616
|
-
if (typeof namespaces === "string")
|
|
617
|
-
namespaces = [namespaces];
|
|
618
|
-
return {
|
|
619
|
-
key,
|
|
620
|
-
namespaces
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
}, {
|
|
624
|
-
key: "translate",
|
|
625
|
-
value: function translate(keys, options, lastKey) {
|
|
626
|
-
var _this2 = this;
|
|
627
|
-
if (_typeof$2(options) !== "object" && this.options.overloadTranslationOptionHandler) {
|
|
628
|
-
options = this.options.overloadTranslationOptionHandler(arguments);
|
|
629
|
-
}
|
|
630
|
-
if (!options)
|
|
631
|
-
options = {};
|
|
632
|
-
if (keys === void 0 || keys === null)
|
|
633
|
-
return "";
|
|
634
|
-
if (!Array.isArray(keys))
|
|
635
|
-
keys = [String(keys)];
|
|
636
|
-
var keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
637
|
-
var _this$extractFromKey = this.extractFromKey(keys[keys.length - 1], options), key = _this$extractFromKey.key, namespaces = _this$extractFromKey.namespaces;
|
|
638
|
-
var namespace = namespaces[namespaces.length - 1];
|
|
639
|
-
var lng = options.lng || this.language;
|
|
640
|
-
var appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
641
|
-
if (lng && lng.toLowerCase() === "cimode") {
|
|
642
|
-
if (appendNamespaceToCIMode) {
|
|
643
|
-
var nsSeparator = options.nsSeparator || this.options.nsSeparator;
|
|
644
|
-
return namespace + nsSeparator + key;
|
|
645
|
-
}
|
|
646
|
-
return key;
|
|
647
|
-
}
|
|
648
|
-
var resolved = this.resolve(keys, options);
|
|
649
|
-
var res = resolved && resolved.res;
|
|
650
|
-
var resUsedKey = resolved && resolved.usedKey || key;
|
|
651
|
-
var resExactUsedKey = resolved && resolved.exactUsedKey || key;
|
|
652
|
-
var resType = Object.prototype.toString.apply(res);
|
|
653
|
-
var noObject = ["[object Number]", "[object Function]", "[object RegExp]"];
|
|
654
|
-
var joinArrays = options.joinArrays !== void 0 ? options.joinArrays : this.options.joinArrays;
|
|
655
|
-
var handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
656
|
-
var handleAsObject = typeof res !== "string" && typeof res !== "boolean" && typeof res !== "number";
|
|
657
|
-
if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(typeof joinArrays === "string" && resType === "[object Array]")) {
|
|
658
|
-
if (!options.returnObjects && !this.options.returnObjects) {
|
|
659
|
-
this.logger.warn("accessing an object - but returnObjects options is not enabled!");
|
|
660
|
-
return this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, options) : "key '".concat(key, " (").concat(this.language, ")' returned an object instead of string.");
|
|
661
|
-
}
|
|
662
|
-
if (keySeparator) {
|
|
663
|
-
var resTypeIsArray = resType === "[object Array]";
|
|
664
|
-
var copy2 = resTypeIsArray ? [] : {};
|
|
665
|
-
var newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
666
|
-
for (var m in res) {
|
|
667
|
-
if (Object.prototype.hasOwnProperty.call(res, m)) {
|
|
668
|
-
var deepKey = "".concat(newKeyToUse).concat(keySeparator).concat(m);
|
|
669
|
-
copy2[m] = this.translate(deepKey, _objectSpread$3({}, options, {
|
|
670
|
-
joinArrays: false,
|
|
671
|
-
ns: namespaces
|
|
672
|
-
}));
|
|
673
|
-
if (copy2[m] === deepKey)
|
|
674
|
-
copy2[m] = res[m];
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
res = copy2;
|
|
678
|
-
}
|
|
679
|
-
} else if (handleAsObjectInI18nFormat && typeof joinArrays === "string" && resType === "[object Array]") {
|
|
680
|
-
res = res.join(joinArrays);
|
|
681
|
-
if (res)
|
|
682
|
-
res = this.extendTranslation(res, keys, options, lastKey);
|
|
683
|
-
} else {
|
|
684
|
-
var usedDefault = false;
|
|
685
|
-
var usedKey = false;
|
|
686
|
-
var needsPluralHandling = options.count !== void 0 && typeof options.count !== "string";
|
|
687
|
-
var hasDefaultValue = Translator2.hasDefaultValue(options);
|
|
688
|
-
var defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count) : "";
|
|
689
|
-
var defaultValue = options["defaultValue".concat(defaultValueSuffix)] || options.defaultValue;
|
|
690
|
-
if (!this.isValidLookup(res) && hasDefaultValue) {
|
|
691
|
-
usedDefault = true;
|
|
692
|
-
res = defaultValue;
|
|
693
|
-
}
|
|
694
|
-
if (!this.isValidLookup(res)) {
|
|
695
|
-
usedKey = true;
|
|
696
|
-
res = key;
|
|
697
|
-
}
|
|
698
|
-
var updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
699
|
-
if (usedKey || usedDefault || updateMissing) {
|
|
700
|
-
this.logger.log(updateMissing ? "updateKey" : "missingKey", lng, namespace, key, updateMissing ? defaultValue : res);
|
|
701
|
-
if (keySeparator) {
|
|
702
|
-
var fk = this.resolve(key, _objectSpread$3({}, options, {
|
|
703
|
-
keySeparator: false
|
|
704
|
-
}));
|
|
705
|
-
if (fk && fk.res)
|
|
706
|
-
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.");
|
|
707
|
-
}
|
|
708
|
-
var lngs = [];
|
|
709
|
-
var fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
|
|
710
|
-
if (this.options.saveMissingTo === "fallback" && fallbackLngs && fallbackLngs[0]) {
|
|
711
|
-
for (var i2 = 0; i2 < fallbackLngs.length; i2++) {
|
|
712
|
-
lngs.push(fallbackLngs[i2]);
|
|
713
|
-
}
|
|
714
|
-
} else if (this.options.saveMissingTo === "all") {
|
|
715
|
-
lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
|
|
716
|
-
} else {
|
|
717
|
-
lngs.push(options.lng || this.language);
|
|
718
|
-
}
|
|
719
|
-
var send = function send2(l, k, fallbackValue) {
|
|
720
|
-
if (_this2.options.missingKeyHandler) {
|
|
721
|
-
_this2.options.missingKeyHandler(l, namespace, k, updateMissing ? fallbackValue : res, updateMissing, options);
|
|
722
|
-
} else if (_this2.backendConnector && _this2.backendConnector.saveMissing) {
|
|
723
|
-
_this2.backendConnector.saveMissing(l, namespace, k, updateMissing ? fallbackValue : res, updateMissing, options);
|
|
724
|
-
}
|
|
725
|
-
_this2.emit("missingKey", l, namespace, k, res);
|
|
726
|
-
};
|
|
727
|
-
if (this.options.saveMissing) {
|
|
728
|
-
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
729
|
-
lngs.forEach(function(language) {
|
|
730
|
-
_this2.pluralResolver.getSuffixes(language).forEach(function(suffix) {
|
|
731
|
-
send([language], key + suffix, options["defaultValue".concat(suffix)] || defaultValue);
|
|
732
|
-
});
|
|
733
|
-
});
|
|
734
|
-
} else {
|
|
735
|
-
send(lngs, key, defaultValue);
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
res = this.extendTranslation(res, keys, options, resolved, lastKey);
|
|
740
|
-
if (usedKey && res === key && this.options.appendNamespaceToMissingKey)
|
|
741
|
-
res = "".concat(namespace, ":").concat(key);
|
|
742
|
-
if (usedKey && this.options.parseMissingKeyHandler)
|
|
743
|
-
res = this.options.parseMissingKeyHandler(res);
|
|
744
|
-
}
|
|
745
|
-
return res;
|
|
746
|
-
}
|
|
747
|
-
}, {
|
|
748
|
-
key: "extendTranslation",
|
|
749
|
-
value: function extendTranslation(res, key, options, resolved, lastKey) {
|
|
750
|
-
var _this3 = this;
|
|
751
|
-
if (this.i18nFormat && this.i18nFormat.parse) {
|
|
752
|
-
res = this.i18nFormat.parse(res, options, resolved.usedLng, resolved.usedNS, resolved.usedKey, {
|
|
753
|
-
resolved
|
|
754
|
-
});
|
|
755
|
-
} else if (!options.skipInterpolation) {
|
|
756
|
-
if (options.interpolation)
|
|
757
|
-
this.interpolator.init(_objectSpread$3({}, options, {
|
|
758
|
-
interpolation: _objectSpread$3({}, this.options.interpolation, options.interpolation)
|
|
759
|
-
}));
|
|
760
|
-
var skipOnVariables = options.interpolation && options.interpolation.skipOnVariables || this.options.interpolation.skipOnVariables;
|
|
761
|
-
var nestBef;
|
|
762
|
-
if (skipOnVariables) {
|
|
763
|
-
var nb = res.match(this.interpolator.nestingRegexp);
|
|
764
|
-
nestBef = nb && nb.length;
|
|
765
|
-
}
|
|
766
|
-
var data = options.replace && typeof options.replace !== "string" ? options.replace : options;
|
|
767
|
-
if (this.options.interpolation.defaultVariables)
|
|
768
|
-
data = _objectSpread$3({}, this.options.interpolation.defaultVariables, data);
|
|
769
|
-
res = this.interpolator.interpolate(res, data, options.lng || this.language, options);
|
|
770
|
-
if (skipOnVariables) {
|
|
771
|
-
var na = res.match(this.interpolator.nestingRegexp);
|
|
772
|
-
var nestAft = na && na.length;
|
|
773
|
-
if (nestBef < nestAft)
|
|
774
|
-
options.nest = false;
|
|
775
|
-
}
|
|
776
|
-
if (options.nest !== false)
|
|
777
|
-
res = this.interpolator.nest(res, function() {
|
|
778
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
779
|
-
args[_key] = arguments[_key];
|
|
780
|
-
}
|
|
781
|
-
if (lastKey && lastKey[0] === args[0] && !options.context) {
|
|
782
|
-
_this3.logger.warn("It seems you are nesting recursively key: ".concat(args[0], " in key: ").concat(key[0]));
|
|
783
|
-
return null;
|
|
784
|
-
}
|
|
785
|
-
return _this3.translate.apply(_this3, args.concat([key]));
|
|
786
|
-
}, options);
|
|
787
|
-
if (options.interpolation)
|
|
788
|
-
this.interpolator.reset();
|
|
789
|
-
}
|
|
790
|
-
var postProcess = options.postProcess || this.options.postProcess;
|
|
791
|
-
var postProcessorNames = typeof postProcess === "string" ? [postProcess] : postProcess;
|
|
792
|
-
if (res !== void 0 && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) {
|
|
793
|
-
res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? _objectSpread$3({
|
|
794
|
-
i18nResolved: resolved
|
|
795
|
-
}, options) : options, this);
|
|
796
|
-
}
|
|
797
|
-
return res;
|
|
798
|
-
}
|
|
799
|
-
}, {
|
|
800
|
-
key: "resolve",
|
|
801
|
-
value: function resolve(keys) {
|
|
802
|
-
var _this4 = this;
|
|
803
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
804
|
-
var found;
|
|
805
|
-
var usedKey;
|
|
806
|
-
var exactUsedKey;
|
|
807
|
-
var usedLng;
|
|
808
|
-
var usedNS;
|
|
809
|
-
if (typeof keys === "string")
|
|
810
|
-
keys = [keys];
|
|
811
|
-
keys.forEach(function(k) {
|
|
812
|
-
if (_this4.isValidLookup(found))
|
|
813
|
-
return;
|
|
814
|
-
var extracted = _this4.extractFromKey(k, options);
|
|
815
|
-
var key = extracted.key;
|
|
816
|
-
usedKey = key;
|
|
817
|
-
var namespaces = extracted.namespaces;
|
|
818
|
-
if (_this4.options.fallbackNS)
|
|
819
|
-
namespaces = namespaces.concat(_this4.options.fallbackNS);
|
|
820
|
-
var needsPluralHandling = options.count !== void 0 && typeof options.count !== "string";
|
|
821
|
-
var needsContextHandling = options.context !== void 0 && typeof options.context === "string" && options.context !== "";
|
|
822
|
-
var codes = options.lngs ? options.lngs : _this4.languageUtils.toResolveHierarchy(options.lng || _this4.language, options.fallbackLng);
|
|
823
|
-
namespaces.forEach(function(ns) {
|
|
824
|
-
if (_this4.isValidLookup(found))
|
|
825
|
-
return;
|
|
826
|
-
usedNS = ns;
|
|
827
|
-
if (!checkedLoadedFor["".concat(codes[0], "-").concat(ns)] && _this4.utils && _this4.utils.hasLoadedNamespace && !_this4.utils.hasLoadedNamespace(usedNS)) {
|
|
828
|
-
checkedLoadedFor["".concat(codes[0], "-").concat(ns)] = true;
|
|
829
|
-
_this4.logger.warn('key "'.concat(usedKey, '" for languages "').concat(codes.join(", "), `" won't get resolved as namespace "`).concat(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!!!");
|
|
830
|
-
}
|
|
831
|
-
codes.forEach(function(code) {
|
|
832
|
-
if (_this4.isValidLookup(found))
|
|
833
|
-
return;
|
|
834
|
-
usedLng = code;
|
|
835
|
-
var finalKey = key;
|
|
836
|
-
var finalKeys = [finalKey];
|
|
837
|
-
if (_this4.i18nFormat && _this4.i18nFormat.addLookupKeys) {
|
|
838
|
-
_this4.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
|
|
839
|
-
} else {
|
|
840
|
-
var pluralSuffix;
|
|
841
|
-
if (needsPluralHandling)
|
|
842
|
-
pluralSuffix = _this4.pluralResolver.getSuffix(code, options.count);
|
|
843
|
-
if (needsPluralHandling && needsContextHandling)
|
|
844
|
-
finalKeys.push(finalKey + pluralSuffix);
|
|
845
|
-
if (needsContextHandling)
|
|
846
|
-
finalKeys.push(finalKey += "".concat(_this4.options.contextSeparator).concat(options.context));
|
|
847
|
-
if (needsPluralHandling)
|
|
848
|
-
finalKeys.push(finalKey += pluralSuffix);
|
|
849
|
-
}
|
|
850
|
-
var possibleKey;
|
|
851
|
-
while (possibleKey = finalKeys.pop()) {
|
|
852
|
-
if (!_this4.isValidLookup(found)) {
|
|
853
|
-
exactUsedKey = possibleKey;
|
|
854
|
-
found = _this4.getResource(code, ns, possibleKey, options);
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
});
|
|
858
|
-
});
|
|
859
|
-
});
|
|
860
|
-
return {
|
|
861
|
-
res: found,
|
|
862
|
-
usedKey,
|
|
863
|
-
exactUsedKey,
|
|
864
|
-
usedLng,
|
|
865
|
-
usedNS
|
|
866
|
-
};
|
|
867
|
-
}
|
|
868
|
-
}, {
|
|
869
|
-
key: "isValidLookup",
|
|
870
|
-
value: function isValidLookup(res) {
|
|
871
|
-
return res !== void 0 && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === "");
|
|
872
|
-
}
|
|
873
|
-
}, {
|
|
874
|
-
key: "getResource",
|
|
875
|
-
value: function getResource(code, ns, key) {
|
|
876
|
-
var options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
877
|
-
if (this.i18nFormat && this.i18nFormat.getResource)
|
|
878
|
-
return this.i18nFormat.getResource(code, ns, key, options);
|
|
879
|
-
return this.resourceStore.getResource(code, ns, key, options);
|
|
880
|
-
}
|
|
881
|
-
}], [{
|
|
882
|
-
key: "hasDefaultValue",
|
|
883
|
-
value: function hasDefaultValue(options) {
|
|
884
|
-
var prefix = "defaultValue";
|
|
885
|
-
for (var option in options) {
|
|
886
|
-
if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && options[option] !== void 0) {
|
|
887
|
-
return true;
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
return false;
|
|
891
|
-
}
|
|
892
|
-
}]);
|
|
893
|
-
return Translator2;
|
|
894
|
-
}(EventEmitter);
|
|
895
|
-
function capitalize(string) {
|
|
896
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
897
|
-
}
|
|
898
|
-
var LanguageUtil = function() {
|
|
899
|
-
function LanguageUtil2(options) {
|
|
900
|
-
_classCallCheck$1(this, LanguageUtil2);
|
|
901
|
-
this.options = options;
|
|
902
|
-
this.whitelist = this.options.supportedLngs || false;
|
|
903
|
-
this.supportedLngs = this.options.supportedLngs || false;
|
|
904
|
-
this.logger = baseLogger.create("languageUtils");
|
|
905
|
-
}
|
|
906
|
-
_createClass$1(LanguageUtil2, [{
|
|
907
|
-
key: "getScriptPartFromCode",
|
|
908
|
-
value: function getScriptPartFromCode(code) {
|
|
909
|
-
if (!code || code.indexOf("-") < 0)
|
|
910
|
-
return null;
|
|
911
|
-
var p = code.split("-");
|
|
912
|
-
if (p.length === 2)
|
|
913
|
-
return null;
|
|
914
|
-
p.pop();
|
|
915
|
-
if (p[p.length - 1].toLowerCase() === "x")
|
|
916
|
-
return null;
|
|
917
|
-
return this.formatLanguageCode(p.join("-"));
|
|
918
|
-
}
|
|
919
|
-
}, {
|
|
920
|
-
key: "getLanguagePartFromCode",
|
|
921
|
-
value: function getLanguagePartFromCode(code) {
|
|
922
|
-
if (!code || code.indexOf("-") < 0)
|
|
923
|
-
return code;
|
|
924
|
-
var p = code.split("-");
|
|
925
|
-
return this.formatLanguageCode(p[0]);
|
|
926
|
-
}
|
|
927
|
-
}, {
|
|
928
|
-
key: "formatLanguageCode",
|
|
929
|
-
value: function formatLanguageCode(code) {
|
|
930
|
-
if (typeof code === "string" && code.indexOf("-") > -1) {
|
|
931
|
-
var specialCases = ["hans", "hant", "latn", "cyrl", "cans", "mong", "arab"];
|
|
932
|
-
var p = code.split("-");
|
|
933
|
-
if (this.options.lowerCaseLng) {
|
|
934
|
-
p = p.map(function(part) {
|
|
935
|
-
return part.toLowerCase();
|
|
936
|
-
});
|
|
937
|
-
} else if (p.length === 2) {
|
|
938
|
-
p[0] = p[0].toLowerCase();
|
|
939
|
-
p[1] = p[1].toUpperCase();
|
|
940
|
-
if (specialCases.indexOf(p[1].toLowerCase()) > -1)
|
|
941
|
-
p[1] = capitalize(p[1].toLowerCase());
|
|
942
|
-
} else if (p.length === 3) {
|
|
943
|
-
p[0] = p[0].toLowerCase();
|
|
944
|
-
if (p[1].length === 2)
|
|
945
|
-
p[1] = p[1].toUpperCase();
|
|
946
|
-
if (p[0] !== "sgn" && p[2].length === 2)
|
|
947
|
-
p[2] = p[2].toUpperCase();
|
|
948
|
-
if (specialCases.indexOf(p[1].toLowerCase()) > -1)
|
|
949
|
-
p[1] = capitalize(p[1].toLowerCase());
|
|
950
|
-
if (specialCases.indexOf(p[2].toLowerCase()) > -1)
|
|
951
|
-
p[2] = capitalize(p[2].toLowerCase());
|
|
952
|
-
}
|
|
953
|
-
return p.join("-");
|
|
954
|
-
}
|
|
955
|
-
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
|
|
956
|
-
}
|
|
957
|
-
}, {
|
|
958
|
-
key: "isWhitelisted",
|
|
959
|
-
value: function isWhitelisted(code) {
|
|
960
|
-
this.logger.deprecate("languageUtils.isWhitelisted", `function "isWhitelisted" will be renamed to "isSupportedCode" in the next major - please make sure to rename it's usage asap.`);
|
|
961
|
-
return this.isSupportedCode(code);
|
|
962
|
-
}
|
|
963
|
-
}, {
|
|
964
|
-
key: "isSupportedCode",
|
|
965
|
-
value: function isSupportedCode(code) {
|
|
966
|
-
if (this.options.load === "languageOnly" || this.options.nonExplicitSupportedLngs) {
|
|
967
|
-
code = this.getLanguagePartFromCode(code);
|
|
968
|
-
}
|
|
969
|
-
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
|
|
970
|
-
}
|
|
971
|
-
}, {
|
|
972
|
-
key: "getBestMatchFromCodes",
|
|
973
|
-
value: function getBestMatchFromCodes(codes) {
|
|
974
|
-
var _this = this;
|
|
975
|
-
if (!codes)
|
|
976
|
-
return null;
|
|
977
|
-
var found;
|
|
978
|
-
codes.forEach(function(code) {
|
|
979
|
-
if (found)
|
|
980
|
-
return;
|
|
981
|
-
var cleanedLng = _this.formatLanguageCode(code);
|
|
982
|
-
if (!_this.options.supportedLngs || _this.isSupportedCode(cleanedLng))
|
|
983
|
-
found = cleanedLng;
|
|
984
|
-
});
|
|
985
|
-
if (!found && this.options.supportedLngs) {
|
|
986
|
-
codes.forEach(function(code) {
|
|
987
|
-
if (found)
|
|
988
|
-
return;
|
|
989
|
-
var lngOnly = _this.getLanguagePartFromCode(code);
|
|
990
|
-
if (_this.isSupportedCode(lngOnly))
|
|
991
|
-
return found = lngOnly;
|
|
992
|
-
found = _this.options.supportedLngs.find(function(supportedLng) {
|
|
993
|
-
if (supportedLng.indexOf(lngOnly) === 0)
|
|
994
|
-
return supportedLng;
|
|
995
|
-
});
|
|
996
|
-
});
|
|
997
|
-
}
|
|
998
|
-
if (!found)
|
|
999
|
-
found = this.getFallbackCodes(this.options.fallbackLng)[0];
|
|
1000
|
-
return found;
|
|
1001
|
-
}
|
|
1002
|
-
}, {
|
|
1003
|
-
key: "getFallbackCodes",
|
|
1004
|
-
value: function getFallbackCodes(fallbacks, code) {
|
|
1005
|
-
if (!fallbacks)
|
|
1006
|
-
return [];
|
|
1007
|
-
if (typeof fallbacks === "function")
|
|
1008
|
-
fallbacks = fallbacks(code);
|
|
1009
|
-
if (typeof fallbacks === "string")
|
|
1010
|
-
fallbacks = [fallbacks];
|
|
1011
|
-
if (Object.prototype.toString.apply(fallbacks) === "[object Array]")
|
|
1012
|
-
return fallbacks;
|
|
1013
|
-
if (!code)
|
|
1014
|
-
return fallbacks["default"] || [];
|
|
1015
|
-
var found = fallbacks[code];
|
|
1016
|
-
if (!found)
|
|
1017
|
-
found = fallbacks[this.getScriptPartFromCode(code)];
|
|
1018
|
-
if (!found)
|
|
1019
|
-
found = fallbacks[this.formatLanguageCode(code)];
|
|
1020
|
-
if (!found)
|
|
1021
|
-
found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
1022
|
-
if (!found)
|
|
1023
|
-
found = fallbacks["default"];
|
|
1024
|
-
return found || [];
|
|
1025
|
-
}
|
|
1026
|
-
}, {
|
|
1027
|
-
key: "toResolveHierarchy",
|
|
1028
|
-
value: function toResolveHierarchy(code, fallbackCode) {
|
|
1029
|
-
var _this2 = this;
|
|
1030
|
-
var fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
|
|
1031
|
-
var codes = [];
|
|
1032
|
-
var addCode = function addCode2(c2) {
|
|
1033
|
-
if (!c2)
|
|
1034
|
-
return;
|
|
1035
|
-
if (_this2.isSupportedCode(c2)) {
|
|
1036
|
-
codes.push(c2);
|
|
1037
|
-
} else {
|
|
1038
|
-
_this2.logger.warn("rejecting language code not found in supportedLngs: ".concat(c2));
|
|
1039
|
-
}
|
|
1040
|
-
};
|
|
1041
|
-
if (typeof code === "string" && code.indexOf("-") > -1) {
|
|
1042
|
-
if (this.options.load !== "languageOnly")
|
|
1043
|
-
addCode(this.formatLanguageCode(code));
|
|
1044
|
-
if (this.options.load !== "languageOnly" && this.options.load !== "currentOnly")
|
|
1045
|
-
addCode(this.getScriptPartFromCode(code));
|
|
1046
|
-
if (this.options.load !== "currentOnly")
|
|
1047
|
-
addCode(this.getLanguagePartFromCode(code));
|
|
1048
|
-
} else if (typeof code === "string") {
|
|
1049
|
-
addCode(this.formatLanguageCode(code));
|
|
1050
|
-
}
|
|
1051
|
-
fallbackCodes.forEach(function(fc) {
|
|
1052
|
-
if (codes.indexOf(fc) < 0)
|
|
1053
|
-
addCode(_this2.formatLanguageCode(fc));
|
|
1054
|
-
});
|
|
1055
|
-
return codes;
|
|
1056
|
-
}
|
|
1057
|
-
}]);
|
|
1058
|
-
return LanguageUtil2;
|
|
1059
|
-
}();
|
|
1060
|
-
var sets = [{
|
|
1061
|
-
lngs: ["ach", "ak", "am", "arn", "br", "fil", "gun", "ln", "mfe", "mg", "mi", "oc", "pt", "pt-BR", "tg", "tl", "ti", "tr", "uz", "wa"],
|
|
1062
|
-
nr: [1, 2],
|
|
1063
|
-
fc: 1
|
|
1064
|
-
}, {
|
|
1065
|
-
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", "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"],
|
|
1066
|
-
nr: [1, 2],
|
|
1067
|
-
fc: 2
|
|
1068
|
-
}, {
|
|
1069
|
-
lngs: ["ay", "bo", "cgg", "fa", "ht", "id", "ja", "jbo", "ka", "kk", "km", "ko", "ky", "lo", "ms", "sah", "su", "th", "tt", "ug", "vi", "wo", "zh"],
|
|
1070
|
-
nr: [1],
|
|
1071
|
-
fc: 3
|
|
1072
|
-
}, {
|
|
1073
|
-
lngs: ["be", "bs", "cnr", "dz", "hr", "ru", "sr", "uk"],
|
|
1074
|
-
nr: [1, 2, 5],
|
|
1075
|
-
fc: 4
|
|
1076
|
-
}, {
|
|
1077
|
-
lngs: ["ar"],
|
|
1078
|
-
nr: [0, 1, 2, 3, 11, 100],
|
|
1079
|
-
fc: 5
|
|
1080
|
-
}, {
|
|
1081
|
-
lngs: ["cs", "sk"],
|
|
1082
|
-
nr: [1, 2, 5],
|
|
1083
|
-
fc: 6
|
|
1084
|
-
}, {
|
|
1085
|
-
lngs: ["csb", "pl"],
|
|
1086
|
-
nr: [1, 2, 5],
|
|
1087
|
-
fc: 7
|
|
1088
|
-
}, {
|
|
1089
|
-
lngs: ["cy"],
|
|
1090
|
-
nr: [1, 2, 3, 8],
|
|
1091
|
-
fc: 8
|
|
1092
|
-
}, {
|
|
1093
|
-
lngs: ["fr"],
|
|
1094
|
-
nr: [1, 2],
|
|
1095
|
-
fc: 9
|
|
1096
|
-
}, {
|
|
1097
|
-
lngs: ["ga"],
|
|
1098
|
-
nr: [1, 2, 3, 7, 11],
|
|
1099
|
-
fc: 10
|
|
1100
|
-
}, {
|
|
1101
|
-
lngs: ["gd"],
|
|
1102
|
-
nr: [1, 2, 3, 20],
|
|
1103
|
-
fc: 11
|
|
1104
|
-
}, {
|
|
1105
|
-
lngs: ["is"],
|
|
1106
|
-
nr: [1, 2],
|
|
1107
|
-
fc: 12
|
|
1108
|
-
}, {
|
|
1109
|
-
lngs: ["jv"],
|
|
1110
|
-
nr: [0, 1],
|
|
1111
|
-
fc: 13
|
|
1112
|
-
}, {
|
|
1113
|
-
lngs: ["kw"],
|
|
1114
|
-
nr: [1, 2, 3, 4],
|
|
1115
|
-
fc: 14
|
|
1116
|
-
}, {
|
|
1117
|
-
lngs: ["lt"],
|
|
1118
|
-
nr: [1, 2, 10],
|
|
1119
|
-
fc: 15
|
|
1120
|
-
}, {
|
|
1121
|
-
lngs: ["lv"],
|
|
1122
|
-
nr: [1, 2, 0],
|
|
1123
|
-
fc: 16
|
|
1124
|
-
}, {
|
|
1125
|
-
lngs: ["mk"],
|
|
1126
|
-
nr: [1, 2],
|
|
1127
|
-
fc: 17
|
|
1128
|
-
}, {
|
|
1129
|
-
lngs: ["mnk"],
|
|
1130
|
-
nr: [0, 1, 2],
|
|
1131
|
-
fc: 18
|
|
1132
|
-
}, {
|
|
1133
|
-
lngs: ["mt"],
|
|
1134
|
-
nr: [1, 2, 11, 20],
|
|
1135
|
-
fc: 19
|
|
1136
|
-
}, {
|
|
1137
|
-
lngs: ["or"],
|
|
1138
|
-
nr: [2, 1],
|
|
1139
|
-
fc: 2
|
|
1140
|
-
}, {
|
|
1141
|
-
lngs: ["ro"],
|
|
1142
|
-
nr: [1, 2, 20],
|
|
1143
|
-
fc: 20
|
|
1144
|
-
}, {
|
|
1145
|
-
lngs: ["sl"],
|
|
1146
|
-
nr: [5, 1, 2, 3],
|
|
1147
|
-
fc: 21
|
|
1148
|
-
}, {
|
|
1149
|
-
lngs: ["he", "iw"],
|
|
1150
|
-
nr: [1, 2, 20, 21],
|
|
1151
|
-
fc: 22
|
|
1152
|
-
}];
|
|
1153
|
-
var _rulesPluralsTypes = {
|
|
1154
|
-
1: function _(n2) {
|
|
1155
|
-
return Number(n2 > 1);
|
|
1156
|
-
},
|
|
1157
|
-
2: function _2(n2) {
|
|
1158
|
-
return Number(n2 != 1);
|
|
1159
|
-
},
|
|
1160
|
-
3: function _3(n2) {
|
|
1161
|
-
return 0;
|
|
1162
|
-
},
|
|
1163
|
-
4: function _4(n2) {
|
|
1164
|
-
return Number(n2 % 10 == 1 && n2 % 100 != 11 ? 0 : n2 % 10 >= 2 && n2 % 10 <= 4 && (n2 % 100 < 10 || n2 % 100 >= 20) ? 1 : 2);
|
|
1165
|
-
},
|
|
1166
|
-
5: function _5(n2) {
|
|
1167
|
-
return Number(n2 == 0 ? 0 : n2 == 1 ? 1 : n2 == 2 ? 2 : n2 % 100 >= 3 && n2 % 100 <= 10 ? 3 : n2 % 100 >= 11 ? 4 : 5);
|
|
1168
|
-
},
|
|
1169
|
-
6: function _6(n2) {
|
|
1170
|
-
return Number(n2 == 1 ? 0 : n2 >= 2 && n2 <= 4 ? 1 : 2);
|
|
1171
|
-
},
|
|
1172
|
-
7: function _7(n2) {
|
|
1173
|
-
return Number(n2 == 1 ? 0 : n2 % 10 >= 2 && n2 % 10 <= 4 && (n2 % 100 < 10 || n2 % 100 >= 20) ? 1 : 2);
|
|
1174
|
-
},
|
|
1175
|
-
8: function _8(n2) {
|
|
1176
|
-
return Number(n2 == 1 ? 0 : n2 == 2 ? 1 : n2 != 8 && n2 != 11 ? 2 : 3);
|
|
1177
|
-
},
|
|
1178
|
-
9: function _9(n2) {
|
|
1179
|
-
return Number(n2 >= 2);
|
|
1180
|
-
},
|
|
1181
|
-
10: function _10(n2) {
|
|
1182
|
-
return Number(n2 == 1 ? 0 : n2 == 2 ? 1 : n2 < 7 ? 2 : n2 < 11 ? 3 : 4);
|
|
1183
|
-
},
|
|
1184
|
-
11: function _11(n2) {
|
|
1185
|
-
return Number(n2 == 1 || n2 == 11 ? 0 : n2 == 2 || n2 == 12 ? 1 : n2 > 2 && n2 < 20 ? 2 : 3);
|
|
1186
|
-
},
|
|
1187
|
-
12: function _12(n2) {
|
|
1188
|
-
return Number(n2 % 10 != 1 || n2 % 100 == 11);
|
|
1189
|
-
},
|
|
1190
|
-
13: function _13(n2) {
|
|
1191
|
-
return Number(n2 !== 0);
|
|
1192
|
-
},
|
|
1193
|
-
14: function _14(n2) {
|
|
1194
|
-
return Number(n2 == 1 ? 0 : n2 == 2 ? 1 : n2 == 3 ? 2 : 3);
|
|
1195
|
-
},
|
|
1196
|
-
15: function _15(n2) {
|
|
1197
|
-
return Number(n2 % 10 == 1 && n2 % 100 != 11 ? 0 : n2 % 10 >= 2 && (n2 % 100 < 10 || n2 % 100 >= 20) ? 1 : 2);
|
|
1198
|
-
},
|
|
1199
|
-
16: function _16(n2) {
|
|
1200
|
-
return Number(n2 % 10 == 1 && n2 % 100 != 11 ? 0 : n2 !== 0 ? 1 : 2);
|
|
1201
|
-
},
|
|
1202
|
-
17: function _17(n2) {
|
|
1203
|
-
return Number(n2 == 1 || n2 % 10 == 1 && n2 % 100 != 11 ? 0 : 1);
|
|
1204
|
-
},
|
|
1205
|
-
18: function _18(n2) {
|
|
1206
|
-
return Number(n2 == 0 ? 0 : n2 == 1 ? 1 : 2);
|
|
1207
|
-
},
|
|
1208
|
-
19: function _19(n2) {
|
|
1209
|
-
return Number(n2 == 1 ? 0 : n2 == 0 || n2 % 100 > 1 && n2 % 100 < 11 ? 1 : n2 % 100 > 10 && n2 % 100 < 20 ? 2 : 3);
|
|
1210
|
-
},
|
|
1211
|
-
20: function _20(n2) {
|
|
1212
|
-
return Number(n2 == 1 ? 0 : n2 == 0 || n2 % 100 > 0 && n2 % 100 < 20 ? 1 : 2);
|
|
1213
|
-
},
|
|
1214
|
-
21: function _21(n2) {
|
|
1215
|
-
return Number(n2 % 100 == 1 ? 1 : n2 % 100 == 2 ? 2 : n2 % 100 == 3 || n2 % 100 == 4 ? 3 : 0);
|
|
1216
|
-
},
|
|
1217
|
-
22: function _22(n2) {
|
|
1218
|
-
return Number(n2 == 1 ? 0 : n2 == 2 ? 1 : (n2 < 0 || n2 > 10) && n2 % 10 == 0 ? 2 : 3);
|
|
1219
|
-
}
|
|
1220
|
-
};
|
|
1221
|
-
function createRules() {
|
|
1222
|
-
var rules = {};
|
|
1223
|
-
sets.forEach(function(set) {
|
|
1224
|
-
set.lngs.forEach(function(l) {
|
|
1225
|
-
rules[l] = {
|
|
1226
|
-
numbers: set.nr,
|
|
1227
|
-
plurals: _rulesPluralsTypes[set.fc]
|
|
1228
|
-
};
|
|
1229
|
-
});
|
|
1230
|
-
});
|
|
1231
|
-
return rules;
|
|
1232
|
-
}
|
|
1233
|
-
var PluralResolver = function() {
|
|
1234
|
-
function PluralResolver2(languageUtils) {
|
|
1235
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1236
|
-
_classCallCheck$1(this, PluralResolver2);
|
|
1237
|
-
this.languageUtils = languageUtils;
|
|
1238
|
-
this.options = options;
|
|
1239
|
-
this.logger = baseLogger.create("pluralResolver");
|
|
1240
|
-
this.rules = createRules();
|
|
1241
|
-
}
|
|
1242
|
-
_createClass$1(PluralResolver2, [{
|
|
1243
|
-
key: "addRule",
|
|
1244
|
-
value: function addRule(lng, obj) {
|
|
1245
|
-
this.rules[lng] = obj;
|
|
1246
|
-
}
|
|
1247
|
-
}, {
|
|
1248
|
-
key: "getRule",
|
|
1249
|
-
value: function getRule(code) {
|
|
1250
|
-
return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
|
|
1251
|
-
}
|
|
1252
|
-
}, {
|
|
1253
|
-
key: "needsPlural",
|
|
1254
|
-
value: function needsPlural(code) {
|
|
1255
|
-
var rule = this.getRule(code);
|
|
1256
|
-
return rule && rule.numbers.length > 1;
|
|
1257
|
-
}
|
|
1258
|
-
}, {
|
|
1259
|
-
key: "getPluralFormsOfKey",
|
|
1260
|
-
value: function getPluralFormsOfKey(code, key) {
|
|
1261
|
-
return this.getSuffixes(code).map(function(suffix) {
|
|
1262
|
-
return key + suffix;
|
|
1263
|
-
});
|
|
1264
|
-
}
|
|
1265
|
-
}, {
|
|
1266
|
-
key: "getSuffixes",
|
|
1267
|
-
value: function getSuffixes(code) {
|
|
1268
|
-
var _this = this;
|
|
1269
|
-
var rule = this.getRule(code);
|
|
1270
|
-
if (!rule) {
|
|
1271
|
-
return [];
|
|
1272
|
-
}
|
|
1273
|
-
return rule.numbers.map(function(number) {
|
|
1274
|
-
return _this.getSuffix(code, number);
|
|
1275
|
-
});
|
|
1276
|
-
}
|
|
1277
|
-
}, {
|
|
1278
|
-
key: "getSuffix",
|
|
1279
|
-
value: function getSuffix(code, count) {
|
|
1280
|
-
var _this2 = this;
|
|
1281
|
-
var rule = this.getRule(code);
|
|
1282
|
-
if (rule) {
|
|
1283
|
-
var idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
|
|
1284
|
-
var suffix = rule.numbers[idx];
|
|
1285
|
-
if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
1286
|
-
if (suffix === 2) {
|
|
1287
|
-
suffix = "plural";
|
|
1288
|
-
} else if (suffix === 1) {
|
|
1289
|
-
suffix = "";
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
var returnSuffix = function returnSuffix2() {
|
|
1293
|
-
return _this2.options.prepend && suffix.toString() ? _this2.options.prepend + suffix.toString() : suffix.toString();
|
|
1294
|
-
};
|
|
1295
|
-
if (this.options.compatibilityJSON === "v1") {
|
|
1296
|
-
if (suffix === 1)
|
|
1297
|
-
return "";
|
|
1298
|
-
if (typeof suffix === "number")
|
|
1299
|
-
return "_plural_".concat(suffix.toString());
|
|
1300
|
-
return returnSuffix();
|
|
1301
|
-
} else if (this.options.compatibilityJSON === "v2") {
|
|
1302
|
-
return returnSuffix();
|
|
1303
|
-
} else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
1304
|
-
return returnSuffix();
|
|
1305
|
-
}
|
|
1306
|
-
return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
|
|
1307
|
-
}
|
|
1308
|
-
this.logger.warn("no plural rule found for: ".concat(code));
|
|
1309
|
-
return "";
|
|
1310
|
-
}
|
|
1311
|
-
}]);
|
|
1312
|
-
return PluralResolver2;
|
|
1313
|
-
}();
|
|
1314
|
-
var Interpolator = function() {
|
|
1315
|
-
function Interpolator2() {
|
|
1316
|
-
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1317
|
-
_classCallCheck$1(this, Interpolator2);
|
|
1318
|
-
this.logger = baseLogger.create("interpolator");
|
|
1319
|
-
this.options = options;
|
|
1320
|
-
this.format = options.interpolation && options.interpolation.format || function(value) {
|
|
1321
|
-
return value;
|
|
1322
|
-
};
|
|
1323
|
-
this.init(options);
|
|
1324
|
-
}
|
|
1325
|
-
_createClass$1(Interpolator2, [{
|
|
1326
|
-
key: "init",
|
|
1327
|
-
value: function init2() {
|
|
1328
|
-
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1329
|
-
if (!options.interpolation)
|
|
1330
|
-
options.interpolation = {
|
|
1331
|
-
escapeValue: true
|
|
1332
|
-
};
|
|
1333
|
-
var iOpts = options.interpolation;
|
|
1334
|
-
this.escape = iOpts.escape !== void 0 ? iOpts.escape : escape;
|
|
1335
|
-
this.escapeValue = iOpts.escapeValue !== void 0 ? iOpts.escapeValue : true;
|
|
1336
|
-
this.useRawValueToEscape = iOpts.useRawValueToEscape !== void 0 ? iOpts.useRawValueToEscape : false;
|
|
1337
|
-
this.prefix = iOpts.prefix ? regexEscape(iOpts.prefix) : iOpts.prefixEscaped || "{{";
|
|
1338
|
-
this.suffix = iOpts.suffix ? regexEscape(iOpts.suffix) : iOpts.suffixEscaped || "}}";
|
|
1339
|
-
this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ",";
|
|
1340
|
-
this.unescapePrefix = iOpts.unescapeSuffix ? "" : iOpts.unescapePrefix || "-";
|
|
1341
|
-
this.unescapeSuffix = this.unescapePrefix ? "" : iOpts.unescapeSuffix || "";
|
|
1342
|
-
this.nestingPrefix = iOpts.nestingPrefix ? regexEscape(iOpts.nestingPrefix) : iOpts.nestingPrefixEscaped || regexEscape("$t(");
|
|
1343
|
-
this.nestingSuffix = iOpts.nestingSuffix ? regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || regexEscape(")");
|
|
1344
|
-
this.nestingOptionsSeparator = iOpts.nestingOptionsSeparator ? iOpts.nestingOptionsSeparator : iOpts.nestingOptionsSeparator || ",";
|
|
1345
|
-
this.maxReplaces = iOpts.maxReplaces ? iOpts.maxReplaces : 1e3;
|
|
1346
|
-
this.alwaysFormat = iOpts.alwaysFormat !== void 0 ? iOpts.alwaysFormat : false;
|
|
1347
|
-
this.resetRegExp();
|
|
1348
|
-
}
|
|
1349
|
-
}, {
|
|
1350
|
-
key: "reset",
|
|
1351
|
-
value: function reset() {
|
|
1352
|
-
if (this.options)
|
|
1353
|
-
this.init(this.options);
|
|
1354
|
-
}
|
|
1355
|
-
}, {
|
|
1356
|
-
key: "resetRegExp",
|
|
1357
|
-
value: function resetRegExp() {
|
|
1358
|
-
var regexpStr = "".concat(this.prefix, "(.+?)").concat(this.suffix);
|
|
1359
|
-
this.regexp = new RegExp(regexpStr, "g");
|
|
1360
|
-
var regexpUnescapeStr = "".concat(this.prefix).concat(this.unescapePrefix, "(.+?)").concat(this.unescapeSuffix).concat(this.suffix);
|
|
1361
|
-
this.regexpUnescape = new RegExp(regexpUnescapeStr, "g");
|
|
1362
|
-
var nestingRegexpStr = "".concat(this.nestingPrefix, "(.+?)").concat(this.nestingSuffix);
|
|
1363
|
-
this.nestingRegexp = new RegExp(nestingRegexpStr, "g");
|
|
1364
|
-
}
|
|
1365
|
-
}, {
|
|
1366
|
-
key: "interpolate",
|
|
1367
|
-
value: function interpolate(str, data, lng, options) {
|
|
1368
|
-
var _this = this;
|
|
1369
|
-
var match;
|
|
1370
|
-
var value;
|
|
1371
|
-
var replaces;
|
|
1372
|
-
var defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
1373
|
-
function regexSafe(val) {
|
|
1374
|
-
return val.replace(/\$/g, "$$$$");
|
|
1375
|
-
}
|
|
1376
|
-
var handleFormat = function handleFormat2(key) {
|
|
1377
|
-
if (key.indexOf(_this.formatSeparator) < 0) {
|
|
1378
|
-
var path2 = getPathWithDefaults(data, defaultData, key);
|
|
1379
|
-
return _this.alwaysFormat ? _this.format(path2, void 0, lng) : path2;
|
|
1380
|
-
}
|
|
1381
|
-
var p = key.split(_this.formatSeparator);
|
|
1382
|
-
var k = p.shift().trim();
|
|
1383
|
-
var f = p.join(_this.formatSeparator).trim();
|
|
1384
|
-
return _this.format(getPathWithDefaults(data, defaultData, k), f, lng, options);
|
|
1385
|
-
};
|
|
1386
|
-
this.resetRegExp();
|
|
1387
|
-
var missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler;
|
|
1388
|
-
var skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables || this.options.interpolation.skipOnVariables;
|
|
1389
|
-
var todos = [{
|
|
1390
|
-
regex: this.regexpUnescape,
|
|
1391
|
-
safeValue: function safeValue(val) {
|
|
1392
|
-
return regexSafe(val);
|
|
1393
|
-
}
|
|
1394
|
-
}, {
|
|
1395
|
-
regex: this.regexp,
|
|
1396
|
-
safeValue: function safeValue(val) {
|
|
1397
|
-
return _this.escapeValue ? regexSafe(_this.escape(val)) : regexSafe(val);
|
|
1398
|
-
}
|
|
1399
|
-
}];
|
|
1400
|
-
todos.forEach(function(todo) {
|
|
1401
|
-
replaces = 0;
|
|
1402
|
-
while (match = todo.regex.exec(str)) {
|
|
1403
|
-
value = handleFormat(match[1].trim());
|
|
1404
|
-
if (value === void 0) {
|
|
1405
|
-
if (typeof missingInterpolationHandler === "function") {
|
|
1406
|
-
var temp = missingInterpolationHandler(str, match, options);
|
|
1407
|
-
value = typeof temp === "string" ? temp : "";
|
|
1408
|
-
} else if (skipOnVariables) {
|
|
1409
|
-
value = match[0];
|
|
1410
|
-
continue;
|
|
1411
|
-
} else {
|
|
1412
|
-
_this.logger.warn("missed to pass in variable ".concat(match[1], " for interpolating ").concat(str));
|
|
1413
|
-
value = "";
|
|
1414
|
-
}
|
|
1415
|
-
} else if (typeof value !== "string" && !_this.useRawValueToEscape) {
|
|
1416
|
-
value = makeString(value);
|
|
1417
|
-
}
|
|
1418
|
-
str = str.replace(match[0], todo.safeValue(value));
|
|
1419
|
-
todo.regex.lastIndex = 0;
|
|
1420
|
-
replaces++;
|
|
1421
|
-
if (replaces >= _this.maxReplaces) {
|
|
1422
|
-
break;
|
|
1423
|
-
}
|
|
1424
|
-
}
|
|
1425
|
-
});
|
|
1426
|
-
return str;
|
|
1427
|
-
}
|
|
1428
|
-
}, {
|
|
1429
|
-
key: "nest",
|
|
1430
|
-
value: function nest(str, fc) {
|
|
1431
|
-
var _this2 = this;
|
|
1432
|
-
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1433
|
-
var match;
|
|
1434
|
-
var value;
|
|
1435
|
-
var clonedOptions = _objectSpread$3({}, options);
|
|
1436
|
-
clonedOptions.applyPostProcessor = false;
|
|
1437
|
-
delete clonedOptions.defaultValue;
|
|
1438
|
-
function handleHasOptions(key, inheritedOptions) {
|
|
1439
|
-
var sep = this.nestingOptionsSeparator;
|
|
1440
|
-
if (key.indexOf(sep) < 0)
|
|
1441
|
-
return key;
|
|
1442
|
-
var c2 = key.split(new RegExp("".concat(sep, "[ ]*{")));
|
|
1443
|
-
var optionsString = "{".concat(c2[1]);
|
|
1444
|
-
key = c2[0];
|
|
1445
|
-
optionsString = this.interpolate(optionsString, clonedOptions);
|
|
1446
|
-
optionsString = optionsString.replace(/'/g, '"');
|
|
1447
|
-
try {
|
|
1448
|
-
clonedOptions = JSON.parse(optionsString);
|
|
1449
|
-
if (inheritedOptions)
|
|
1450
|
-
clonedOptions = _objectSpread$3({}, inheritedOptions, clonedOptions);
|
|
1451
|
-
} catch (e) {
|
|
1452
|
-
this.logger.warn("failed parsing options string in nesting for key ".concat(key), e);
|
|
1453
|
-
return "".concat(key).concat(sep).concat(optionsString);
|
|
1454
|
-
}
|
|
1455
|
-
delete clonedOptions.defaultValue;
|
|
1456
|
-
return key;
|
|
1457
|
-
}
|
|
1458
|
-
while (match = this.nestingRegexp.exec(str)) {
|
|
1459
|
-
var formatters = [];
|
|
1460
|
-
var doReduce = false;
|
|
1461
|
-
if (match[0].includes(this.formatSeparator) && !/{.*}/.test(match[1])) {
|
|
1462
|
-
var r2 = match[1].split(this.formatSeparator).map(function(elem) {
|
|
1463
|
-
return elem.trim();
|
|
1464
|
-
});
|
|
1465
|
-
match[1] = r2.shift();
|
|
1466
|
-
formatters = r2;
|
|
1467
|
-
doReduce = true;
|
|
1468
|
-
}
|
|
1469
|
-
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
1470
|
-
if (value && match[0] === str && typeof value !== "string")
|
|
1471
|
-
return value;
|
|
1472
|
-
if (typeof value !== "string")
|
|
1473
|
-
value = makeString(value);
|
|
1474
|
-
if (!value) {
|
|
1475
|
-
this.logger.warn("missed to resolve ".concat(match[1], " for nesting ").concat(str));
|
|
1476
|
-
value = "";
|
|
1477
|
-
}
|
|
1478
|
-
if (doReduce) {
|
|
1479
|
-
value = formatters.reduce(function(v, f) {
|
|
1480
|
-
return _this2.format(v, f, options.lng, options);
|
|
1481
|
-
}, value.trim());
|
|
1482
|
-
}
|
|
1483
|
-
str = str.replace(match[0], value);
|
|
1484
|
-
this.regexp.lastIndex = 0;
|
|
1485
|
-
}
|
|
1486
|
-
return str;
|
|
1487
|
-
}
|
|
1488
|
-
}]);
|
|
1489
|
-
return Interpolator2;
|
|
1490
|
-
}();
|
|
1491
|
-
function remove(arr2, what) {
|
|
1492
|
-
var found = arr2.indexOf(what);
|
|
1493
|
-
while (found !== -1) {
|
|
1494
|
-
arr2.splice(found, 1);
|
|
1495
|
-
found = arr2.indexOf(what);
|
|
1496
|
-
}
|
|
1497
|
-
}
|
|
1498
|
-
var Connector = function(_EventEmitter) {
|
|
1499
|
-
_inherits(Connector2, _EventEmitter);
|
|
1500
|
-
function Connector2(backend, store, services) {
|
|
1501
|
-
var _this;
|
|
1502
|
-
var options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
1503
|
-
_classCallCheck$1(this, Connector2);
|
|
1504
|
-
_this = _possibleConstructorReturn(this, _getPrototypeOf(Connector2).call(this));
|
|
1505
|
-
if (isIE10) {
|
|
1506
|
-
EventEmitter.call(_assertThisInitialized(_this));
|
|
1507
|
-
}
|
|
1508
|
-
_this.backend = backend;
|
|
1509
|
-
_this.store = store;
|
|
1510
|
-
_this.services = services;
|
|
1511
|
-
_this.languageUtils = services.languageUtils;
|
|
1512
|
-
_this.options = options;
|
|
1513
|
-
_this.logger = baseLogger.create("backendConnector");
|
|
1514
|
-
_this.state = {};
|
|
1515
|
-
_this.queue = [];
|
|
1516
|
-
if (_this.backend && _this.backend.init) {
|
|
1517
|
-
_this.backend.init(services, options.backend, options);
|
|
1518
|
-
}
|
|
1519
|
-
return _this;
|
|
1520
|
-
}
|
|
1521
|
-
_createClass$1(Connector2, [{
|
|
1522
|
-
key: "queueLoad",
|
|
1523
|
-
value: function queueLoad(languages, namespaces, options, callback) {
|
|
1524
|
-
var _this2 = this;
|
|
1525
|
-
var toLoad = [];
|
|
1526
|
-
var pending = [];
|
|
1527
|
-
var toLoadLanguages = [];
|
|
1528
|
-
var toLoadNamespaces = [];
|
|
1529
|
-
languages.forEach(function(lng) {
|
|
1530
|
-
var hasAllNamespaces = true;
|
|
1531
|
-
namespaces.forEach(function(ns) {
|
|
1532
|
-
var name = "".concat(lng, "|").concat(ns);
|
|
1533
|
-
if (!options.reload && _this2.store.hasResourceBundle(lng, ns)) {
|
|
1534
|
-
_this2.state[name] = 2;
|
|
1535
|
-
} else if (_this2.state[name] < 0)
|
|
1536
|
-
;
|
|
1537
|
-
else if (_this2.state[name] === 1) {
|
|
1538
|
-
if (pending.indexOf(name) < 0)
|
|
1539
|
-
pending.push(name);
|
|
1540
|
-
} else {
|
|
1541
|
-
_this2.state[name] = 1;
|
|
1542
|
-
hasAllNamespaces = false;
|
|
1543
|
-
if (pending.indexOf(name) < 0)
|
|
1544
|
-
pending.push(name);
|
|
1545
|
-
if (toLoad.indexOf(name) < 0)
|
|
1546
|
-
toLoad.push(name);
|
|
1547
|
-
if (toLoadNamespaces.indexOf(ns) < 0)
|
|
1548
|
-
toLoadNamespaces.push(ns);
|
|
1549
|
-
}
|
|
1550
|
-
});
|
|
1551
|
-
if (!hasAllNamespaces)
|
|
1552
|
-
toLoadLanguages.push(lng);
|
|
1553
|
-
});
|
|
1554
|
-
if (toLoad.length || pending.length) {
|
|
1555
|
-
this.queue.push({
|
|
1556
|
-
pending,
|
|
1557
|
-
loaded: {},
|
|
1558
|
-
errors: [],
|
|
1559
|
-
callback
|
|
1560
|
-
});
|
|
1561
|
-
}
|
|
1562
|
-
return {
|
|
1563
|
-
toLoad,
|
|
1564
|
-
pending,
|
|
1565
|
-
toLoadLanguages,
|
|
1566
|
-
toLoadNamespaces
|
|
1567
|
-
};
|
|
1568
|
-
}
|
|
1569
|
-
}, {
|
|
1570
|
-
key: "loaded",
|
|
1571
|
-
value: function loaded(name, err, data) {
|
|
1572
|
-
var s2 = name.split("|");
|
|
1573
|
-
var lng = s2[0];
|
|
1574
|
-
var ns = s2[1];
|
|
1575
|
-
if (err)
|
|
1576
|
-
this.emit("failedLoading", lng, ns, err);
|
|
1577
|
-
if (data) {
|
|
1578
|
-
this.store.addResourceBundle(lng, ns, data);
|
|
1579
|
-
}
|
|
1580
|
-
this.state[name] = err ? -1 : 2;
|
|
1581
|
-
var loaded2 = {};
|
|
1582
|
-
this.queue.forEach(function(q) {
|
|
1583
|
-
pushPath(q.loaded, [lng], ns);
|
|
1584
|
-
remove(q.pending, name);
|
|
1585
|
-
if (err)
|
|
1586
|
-
q.errors.push(err);
|
|
1587
|
-
if (q.pending.length === 0 && !q.done) {
|
|
1588
|
-
Object.keys(q.loaded).forEach(function(l) {
|
|
1589
|
-
if (!loaded2[l])
|
|
1590
|
-
loaded2[l] = [];
|
|
1591
|
-
if (q.loaded[l].length) {
|
|
1592
|
-
q.loaded[l].forEach(function(ns2) {
|
|
1593
|
-
if (loaded2[l].indexOf(ns2) < 0)
|
|
1594
|
-
loaded2[l].push(ns2);
|
|
1595
|
-
});
|
|
1596
|
-
}
|
|
1597
|
-
});
|
|
1598
|
-
q.done = true;
|
|
1599
|
-
if (q.errors.length) {
|
|
1600
|
-
q.callback(q.errors);
|
|
1601
|
-
} else {
|
|
1602
|
-
q.callback();
|
|
1603
|
-
}
|
|
1604
|
-
}
|
|
1605
|
-
});
|
|
1606
|
-
this.emit("loaded", loaded2);
|
|
1607
|
-
this.queue = this.queue.filter(function(q) {
|
|
1608
|
-
return !q.done;
|
|
1609
|
-
});
|
|
1610
|
-
}
|
|
1611
|
-
}, {
|
|
1612
|
-
key: "read",
|
|
1613
|
-
value: function read2(lng, ns, fcName) {
|
|
1614
|
-
var _this3 = this;
|
|
1615
|
-
var tried = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0;
|
|
1616
|
-
var wait = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : 350;
|
|
1617
|
-
var callback = arguments.length > 5 ? arguments[5] : void 0;
|
|
1618
|
-
if (!lng.length)
|
|
1619
|
-
return callback(null, {});
|
|
1620
|
-
return this.backend[fcName](lng, ns, function(err, data) {
|
|
1621
|
-
if (err && data && tried < 5) {
|
|
1622
|
-
setTimeout(function() {
|
|
1623
|
-
_this3.read.call(_this3, lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
1624
|
-
}, wait);
|
|
1625
|
-
return;
|
|
1626
|
-
}
|
|
1627
|
-
callback(err, data);
|
|
1628
|
-
});
|
|
1629
|
-
}
|
|
1630
|
-
}, {
|
|
1631
|
-
key: "prepareLoading",
|
|
1632
|
-
value: function prepareLoading(languages, namespaces) {
|
|
1633
|
-
var _this4 = this;
|
|
1634
|
-
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1635
|
-
var callback = arguments.length > 3 ? arguments[3] : void 0;
|
|
1636
|
-
if (!this.backend) {
|
|
1637
|
-
this.logger.warn("No backend was added via i18next.use. Will not load resources.");
|
|
1638
|
-
return callback && callback();
|
|
1639
|
-
}
|
|
1640
|
-
if (typeof languages === "string")
|
|
1641
|
-
languages = this.languageUtils.toResolveHierarchy(languages);
|
|
1642
|
-
if (typeof namespaces === "string")
|
|
1643
|
-
namespaces = [namespaces];
|
|
1644
|
-
var toLoad = this.queueLoad(languages, namespaces, options, callback);
|
|
1645
|
-
if (!toLoad.toLoad.length) {
|
|
1646
|
-
if (!toLoad.pending.length)
|
|
1647
|
-
callback();
|
|
1648
|
-
return null;
|
|
1649
|
-
}
|
|
1650
|
-
toLoad.toLoad.forEach(function(name) {
|
|
1651
|
-
_this4.loadOne(name);
|
|
1652
|
-
});
|
|
1653
|
-
}
|
|
1654
|
-
}, {
|
|
1655
|
-
key: "load",
|
|
1656
|
-
value: function load(languages, namespaces, callback) {
|
|
1657
|
-
this.prepareLoading(languages, namespaces, {}, callback);
|
|
1658
|
-
}
|
|
1659
|
-
}, {
|
|
1660
|
-
key: "reload",
|
|
1661
|
-
value: function reload(languages, namespaces, callback) {
|
|
1662
|
-
this.prepareLoading(languages, namespaces, {
|
|
1663
|
-
reload: true
|
|
1664
|
-
}, callback);
|
|
1665
|
-
}
|
|
1666
|
-
}, {
|
|
1667
|
-
key: "loadOne",
|
|
1668
|
-
value: function loadOne(name) {
|
|
1669
|
-
var _this5 = this;
|
|
1670
|
-
var prefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
|
|
1671
|
-
var s2 = name.split("|");
|
|
1672
|
-
var lng = s2[0];
|
|
1673
|
-
var ns = s2[1];
|
|
1674
|
-
this.read(lng, ns, "read", void 0, void 0, function(err, data) {
|
|
1675
|
-
if (err)
|
|
1676
|
-
_this5.logger.warn("".concat(prefix, "loading namespace ").concat(ns, " for language ").concat(lng, " failed"), err);
|
|
1677
|
-
if (!err && data)
|
|
1678
|
-
_this5.logger.log("".concat(prefix, "loaded namespace ").concat(ns, " for language ").concat(lng), data);
|
|
1679
|
-
_this5.loaded(name, err, data);
|
|
1680
|
-
});
|
|
1681
|
-
}
|
|
1682
|
-
}, {
|
|
1683
|
-
key: "saveMissing",
|
|
1684
|
-
value: function saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
|
|
1685
|
-
var options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {};
|
|
1686
|
-
if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
|
|
1687
|
-
this.logger.warn('did not save key "'.concat(key, '" as the namespace "').concat(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!!!");
|
|
1688
|
-
return;
|
|
1689
|
-
}
|
|
1690
|
-
if (key === void 0 || key === null || key === "")
|
|
1691
|
-
return;
|
|
1692
|
-
if (this.backend && this.backend.create) {
|
|
1693
|
-
this.backend.create(languages, namespace, key, fallbackValue, null, _objectSpread$3({}, options, {
|
|
1694
|
-
isUpdate
|
|
1695
|
-
}));
|
|
1696
|
-
}
|
|
1697
|
-
if (!languages || !languages[0])
|
|
1698
|
-
return;
|
|
1699
|
-
this.store.addResource(languages[0], namespace, key, fallbackValue);
|
|
1700
|
-
}
|
|
1701
|
-
}]);
|
|
1702
|
-
return Connector2;
|
|
1703
|
-
}(EventEmitter);
|
|
1704
|
-
function get() {
|
|
1705
|
-
return {
|
|
1706
|
-
debug: false,
|
|
1707
|
-
initImmediate: true,
|
|
1708
|
-
ns: ["translation"],
|
|
1709
|
-
defaultNS: ["translation"],
|
|
1710
|
-
fallbackLng: ["dev"],
|
|
1711
|
-
fallbackNS: false,
|
|
1712
|
-
whitelist: false,
|
|
1713
|
-
nonExplicitWhitelist: false,
|
|
1714
|
-
supportedLngs: false,
|
|
1715
|
-
nonExplicitSupportedLngs: false,
|
|
1716
|
-
load: "all",
|
|
1717
|
-
preload: false,
|
|
1718
|
-
simplifyPluralSuffix: true,
|
|
1719
|
-
keySeparator: ".",
|
|
1720
|
-
nsSeparator: ":",
|
|
1721
|
-
pluralSeparator: "_",
|
|
1722
|
-
contextSeparator: "_",
|
|
1723
|
-
partialBundledLanguages: false,
|
|
1724
|
-
saveMissing: false,
|
|
1725
|
-
updateMissing: false,
|
|
1726
|
-
saveMissingTo: "fallback",
|
|
1727
|
-
saveMissingPlurals: true,
|
|
1728
|
-
missingKeyHandler: false,
|
|
1729
|
-
missingInterpolationHandler: false,
|
|
1730
|
-
postProcess: false,
|
|
1731
|
-
postProcessPassResolved: false,
|
|
1732
|
-
returnNull: true,
|
|
1733
|
-
returnEmptyString: true,
|
|
1734
|
-
returnObjects: false,
|
|
1735
|
-
joinArrays: false,
|
|
1736
|
-
returnedObjectHandler: false,
|
|
1737
|
-
parseMissingKeyHandler: false,
|
|
1738
|
-
appendNamespaceToMissingKey: false,
|
|
1739
|
-
appendNamespaceToCIMode: false,
|
|
1740
|
-
overloadTranslationOptionHandler: function handle2(args) {
|
|
1741
|
-
var ret = {};
|
|
1742
|
-
if (_typeof$2(args[1]) === "object")
|
|
1743
|
-
ret = args[1];
|
|
1744
|
-
if (typeof args[1] === "string")
|
|
1745
|
-
ret.defaultValue = args[1];
|
|
1746
|
-
if (typeof args[2] === "string")
|
|
1747
|
-
ret.tDescription = args[2];
|
|
1748
|
-
if (_typeof$2(args[2]) === "object" || _typeof$2(args[3]) === "object") {
|
|
1749
|
-
var options = args[3] || args[2];
|
|
1750
|
-
Object.keys(options).forEach(function(key) {
|
|
1751
|
-
ret[key] = options[key];
|
|
1752
|
-
});
|
|
1753
|
-
}
|
|
1754
|
-
return ret;
|
|
1755
|
-
},
|
|
1756
|
-
interpolation: {
|
|
1757
|
-
escapeValue: true,
|
|
1758
|
-
format: function format(value, _format, lng, options) {
|
|
1759
|
-
return value;
|
|
1760
|
-
},
|
|
1761
|
-
prefix: "{{",
|
|
1762
|
-
suffix: "}}",
|
|
1763
|
-
formatSeparator: ",",
|
|
1764
|
-
unescapePrefix: "-",
|
|
1765
|
-
nestingPrefix: "$t(",
|
|
1766
|
-
nestingSuffix: ")",
|
|
1767
|
-
nestingOptionsSeparator: ",",
|
|
1768
|
-
maxReplaces: 1e3,
|
|
1769
|
-
skipOnVariables: false
|
|
1770
|
-
}
|
|
1771
|
-
};
|
|
1772
|
-
}
|
|
1773
|
-
function transformOptions(options) {
|
|
1774
|
-
if (typeof options.ns === "string")
|
|
1775
|
-
options.ns = [options.ns];
|
|
1776
|
-
if (typeof options.fallbackLng === "string")
|
|
1777
|
-
options.fallbackLng = [options.fallbackLng];
|
|
1778
|
-
if (typeof options.fallbackNS === "string")
|
|
1779
|
-
options.fallbackNS = [options.fallbackNS];
|
|
1780
|
-
if (options.whitelist) {
|
|
1781
|
-
if (options.whitelist && options.whitelist.indexOf("cimode") < 0) {
|
|
1782
|
-
options.whitelist = options.whitelist.concat(["cimode"]);
|
|
1783
|
-
}
|
|
1784
|
-
options.supportedLngs = options.whitelist;
|
|
1785
|
-
}
|
|
1786
|
-
if (options.nonExplicitWhitelist) {
|
|
1787
|
-
options.nonExplicitSupportedLngs = options.nonExplicitWhitelist;
|
|
1788
|
-
}
|
|
1789
|
-
if (options.supportedLngs && options.supportedLngs.indexOf("cimode") < 0) {
|
|
1790
|
-
options.supportedLngs = options.supportedLngs.concat(["cimode"]);
|
|
1791
|
-
}
|
|
1792
|
-
return options;
|
|
1793
|
-
}
|
|
1794
|
-
function noop() {
|
|
1795
|
-
}
|
|
1796
|
-
var I18n = function(_EventEmitter) {
|
|
1797
|
-
_inherits(I18n2, _EventEmitter);
|
|
1798
|
-
function I18n2() {
|
|
1799
|
-
var _this;
|
|
1800
|
-
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1801
|
-
var callback = arguments.length > 1 ? arguments[1] : void 0;
|
|
1802
|
-
_classCallCheck$1(this, I18n2);
|
|
1803
|
-
_this = _possibleConstructorReturn(this, _getPrototypeOf(I18n2).call(this));
|
|
1804
|
-
if (isIE10) {
|
|
1805
|
-
EventEmitter.call(_assertThisInitialized(_this));
|
|
1806
|
-
}
|
|
1807
|
-
_this.options = transformOptions(options);
|
|
1808
|
-
_this.services = {};
|
|
1809
|
-
_this.logger = baseLogger;
|
|
1810
|
-
_this.modules = {
|
|
1811
|
-
external: []
|
|
1812
|
-
};
|
|
1813
|
-
if (callback && !_this.isInitialized && !options.isClone) {
|
|
1814
|
-
if (!_this.options.initImmediate) {
|
|
1815
|
-
_this.init(options, callback);
|
|
1816
|
-
return _possibleConstructorReturn(_this, _assertThisInitialized(_this));
|
|
1817
|
-
}
|
|
1818
|
-
setTimeout(function() {
|
|
1819
|
-
_this.init(options, callback);
|
|
1820
|
-
}, 0);
|
|
1821
|
-
}
|
|
1822
|
-
return _this;
|
|
1823
|
-
}
|
|
1824
|
-
_createClass$1(I18n2, [{
|
|
1825
|
-
key: "init",
|
|
1826
|
-
value: function init2() {
|
|
1827
|
-
var _this2 = this;
|
|
1828
|
-
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1829
|
-
var callback = arguments.length > 1 ? arguments[1] : void 0;
|
|
1830
|
-
if (typeof options === "function") {
|
|
1831
|
-
callback = options;
|
|
1832
|
-
options = {};
|
|
1833
|
-
}
|
|
1834
|
-
if (options.whitelist && !options.supportedLngs) {
|
|
1835
|
-
this.logger.deprecate("whitelist", 'option "whitelist" will be renamed to "supportedLngs" in the next major - please make sure to rename this option asap.');
|
|
1836
|
-
}
|
|
1837
|
-
if (options.nonExplicitWhitelist && !options.nonExplicitSupportedLngs) {
|
|
1838
|
-
this.logger.deprecate("whitelist", 'options "nonExplicitWhitelist" will be renamed to "nonExplicitSupportedLngs" in the next major - please make sure to rename this option asap.');
|
|
1839
|
-
}
|
|
1840
|
-
this.options = _objectSpread$3({}, get(), this.options, transformOptions(options));
|
|
1841
|
-
this.format = this.options.interpolation.format;
|
|
1842
|
-
if (!callback)
|
|
1843
|
-
callback = noop;
|
|
1844
|
-
function createClassOnDemand(ClassOrObject) {
|
|
1845
|
-
if (!ClassOrObject)
|
|
1846
|
-
return null;
|
|
1847
|
-
if (typeof ClassOrObject === "function")
|
|
1848
|
-
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
|
-
var lu = new LanguageUtil(this.options);
|
|
1858
|
-
this.store = new ResourceStore(this.options.resources, this.options);
|
|
1859
|
-
var s2 = this.services;
|
|
1860
|
-
s2.logger = baseLogger;
|
|
1861
|
-
s2.resourceStore = this.store;
|
|
1862
|
-
s2.languageUtils = lu;
|
|
1863
|
-
s2.pluralResolver = new PluralResolver(lu, {
|
|
1864
|
-
prepend: this.options.pluralSeparator,
|
|
1865
|
-
compatibilityJSON: this.options.compatibilityJSON,
|
|
1866
|
-
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
1867
|
-
});
|
|
1868
|
-
s2.interpolator = new Interpolator(this.options);
|
|
1869
|
-
s2.utils = {
|
|
1870
|
-
hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
|
|
1871
|
-
};
|
|
1872
|
-
s2.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s2.resourceStore, s2, this.options);
|
|
1873
|
-
s2.backendConnector.on("*", function(event) {
|
|
1874
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1875
|
-
args[_key - 1] = arguments[_key];
|
|
1876
|
-
}
|
|
1877
|
-
_this2.emit.apply(_this2, [event].concat(args));
|
|
1878
|
-
});
|
|
1879
|
-
if (this.modules.languageDetector) {
|
|
1880
|
-
s2.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
1881
|
-
s2.languageDetector.init(s2, this.options.detection, this.options);
|
|
1882
|
-
}
|
|
1883
|
-
if (this.modules.i18nFormat) {
|
|
1884
|
-
s2.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
|
|
1885
|
-
if (s2.i18nFormat.init)
|
|
1886
|
-
s2.i18nFormat.init(this);
|
|
1887
|
-
}
|
|
1888
|
-
this.translator = new Translator(this.services, this.options);
|
|
1889
|
-
this.translator.on("*", function(event) {
|
|
1890
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
1891
|
-
args[_key2 - 1] = arguments[_key2];
|
|
1892
|
-
}
|
|
1893
|
-
_this2.emit.apply(_this2, [event].concat(args));
|
|
1894
|
-
});
|
|
1895
|
-
this.modules.external.forEach(function(m) {
|
|
1896
|
-
if (m.init)
|
|
1897
|
-
m.init(_this2);
|
|
1898
|
-
});
|
|
1899
|
-
}
|
|
1900
|
-
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
1901
|
-
var codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
1902
|
-
if (codes.length > 0 && codes[0] !== "dev")
|
|
1903
|
-
this.options.lng = codes[0];
|
|
1904
|
-
}
|
|
1905
|
-
if (!this.services.languageDetector && !this.options.lng) {
|
|
1906
|
-
this.logger.warn("init: no languageDetector is used and no lng is defined");
|
|
1907
|
-
}
|
|
1908
|
-
var storeApi = ["getResource", "hasResourceBundle", "getResourceBundle", "getDataByLanguage"];
|
|
1909
|
-
storeApi.forEach(function(fcName) {
|
|
1910
|
-
_this2[fcName] = function() {
|
|
1911
|
-
var _this2$store;
|
|
1912
|
-
return (_this2$store = _this2.store)[fcName].apply(_this2$store, arguments);
|
|
1913
|
-
};
|
|
1914
|
-
});
|
|
1915
|
-
var storeApiChained = ["addResource", "addResources", "addResourceBundle", "removeResourceBundle"];
|
|
1916
|
-
storeApiChained.forEach(function(fcName) {
|
|
1917
|
-
_this2[fcName] = function() {
|
|
1918
|
-
var _this2$store2;
|
|
1919
|
-
(_this2$store2 = _this2.store)[fcName].apply(_this2$store2, arguments);
|
|
1920
|
-
return _this2;
|
|
1921
|
-
};
|
|
1922
|
-
});
|
|
1923
|
-
var deferred = defer();
|
|
1924
|
-
var load = function load2() {
|
|
1925
|
-
var finish = function finish2(err, t2) {
|
|
1926
|
-
if (_this2.isInitialized)
|
|
1927
|
-
_this2.logger.warn("init: i18next is already initialized. You should call init just once!");
|
|
1928
|
-
_this2.isInitialized = true;
|
|
1929
|
-
if (!_this2.options.isClone)
|
|
1930
|
-
_this2.logger.log("initialized", _this2.options);
|
|
1931
|
-
_this2.emit("initialized", _this2.options);
|
|
1932
|
-
deferred.resolve(t2);
|
|
1933
|
-
callback(err, t2);
|
|
1934
|
-
};
|
|
1935
|
-
if (_this2.languages && _this2.options.compatibilityAPI !== "v1" && !_this2.isInitialized)
|
|
1936
|
-
return finish(null, _this2.t.bind(_this2));
|
|
1937
|
-
_this2.changeLanguage(_this2.options.lng, finish);
|
|
1938
|
-
};
|
|
1939
|
-
if (this.options.resources || !this.options.initImmediate) {
|
|
1940
|
-
load();
|
|
1941
|
-
} else {
|
|
1942
|
-
setTimeout(load, 0);
|
|
1943
|
-
}
|
|
1944
|
-
return deferred;
|
|
1945
|
-
}
|
|
1946
|
-
}, {
|
|
1947
|
-
key: "loadResources",
|
|
1948
|
-
value: function loadResources(language) {
|
|
1949
|
-
var _this3 = this;
|
|
1950
|
-
var callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
1951
|
-
var usedCallback = callback;
|
|
1952
|
-
var usedLng = typeof language === "string" ? language : this.language;
|
|
1953
|
-
if (typeof language === "function")
|
|
1954
|
-
usedCallback = language;
|
|
1955
|
-
if (!this.options.resources || this.options.partialBundledLanguages) {
|
|
1956
|
-
if (usedLng && usedLng.toLowerCase() === "cimode")
|
|
1957
|
-
return usedCallback();
|
|
1958
|
-
var toLoad = [];
|
|
1959
|
-
var append = function append2(lng) {
|
|
1960
|
-
if (!lng)
|
|
1961
|
-
return;
|
|
1962
|
-
var lngs = _this3.services.languageUtils.toResolveHierarchy(lng);
|
|
1963
|
-
lngs.forEach(function(l) {
|
|
1964
|
-
if (toLoad.indexOf(l) < 0)
|
|
1965
|
-
toLoad.push(l);
|
|
1966
|
-
});
|
|
1967
|
-
};
|
|
1968
|
-
if (!usedLng) {
|
|
1969
|
-
var fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
1970
|
-
fallbacks.forEach(function(l) {
|
|
1971
|
-
return append(l);
|
|
1972
|
-
});
|
|
1973
|
-
} else {
|
|
1974
|
-
append(usedLng);
|
|
1975
|
-
}
|
|
1976
|
-
if (this.options.preload) {
|
|
1977
|
-
this.options.preload.forEach(function(l) {
|
|
1978
|
-
return append(l);
|
|
1979
|
-
});
|
|
1980
|
-
}
|
|
1981
|
-
this.services.backendConnector.load(toLoad, this.options.ns, usedCallback);
|
|
1982
|
-
} else {
|
|
1983
|
-
usedCallback(null);
|
|
1984
|
-
}
|
|
1985
|
-
}
|
|
1986
|
-
}, {
|
|
1987
|
-
key: "reloadResources",
|
|
1988
|
-
value: function reloadResources(lngs, ns, callback) {
|
|
1989
|
-
var deferred = defer();
|
|
1990
|
-
if (!lngs)
|
|
1991
|
-
lngs = this.languages;
|
|
1992
|
-
if (!ns)
|
|
1993
|
-
ns = this.options.ns;
|
|
1994
|
-
if (!callback)
|
|
1995
|
-
callback = noop;
|
|
1996
|
-
this.services.backendConnector.reload(lngs, ns, function(err) {
|
|
1997
|
-
deferred.resolve();
|
|
1998
|
-
callback(err);
|
|
1999
|
-
});
|
|
2000
|
-
return deferred;
|
|
2001
|
-
}
|
|
2002
|
-
}, {
|
|
2003
|
-
key: "use",
|
|
2004
|
-
value: function use(module) {
|
|
2005
|
-
if (!module)
|
|
2006
|
-
throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");
|
|
2007
|
-
if (!module.type)
|
|
2008
|
-
throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");
|
|
2009
|
-
if (module.type === "backend") {
|
|
2010
|
-
this.modules.backend = module;
|
|
2011
|
-
}
|
|
2012
|
-
if (module.type === "logger" || module.log && module.warn && module.error) {
|
|
2013
|
-
this.modules.logger = module;
|
|
2014
|
-
}
|
|
2015
|
-
if (module.type === "languageDetector") {
|
|
2016
|
-
this.modules.languageDetector = module;
|
|
2017
|
-
}
|
|
2018
|
-
if (module.type === "i18nFormat") {
|
|
2019
|
-
this.modules.i18nFormat = module;
|
|
2020
|
-
}
|
|
2021
|
-
if (module.type === "postProcessor") {
|
|
2022
|
-
postProcessor.addPostProcessor(module);
|
|
2023
|
-
}
|
|
2024
|
-
if (module.type === "3rdParty") {
|
|
2025
|
-
this.modules.external.push(module);
|
|
2026
|
-
}
|
|
2027
|
-
return this;
|
|
2028
|
-
}
|
|
2029
|
-
}, {
|
|
2030
|
-
key: "changeLanguage",
|
|
2031
|
-
value: function changeLanguage(lng, callback) {
|
|
2032
|
-
var _this4 = this;
|
|
2033
|
-
this.isLanguageChangingTo = lng;
|
|
2034
|
-
var deferred = defer();
|
|
2035
|
-
this.emit("languageChanging", lng);
|
|
2036
|
-
var done = function done2(err, l) {
|
|
2037
|
-
if (l) {
|
|
2038
|
-
_this4.language = l;
|
|
2039
|
-
_this4.languages = _this4.services.languageUtils.toResolveHierarchy(l);
|
|
2040
|
-
_this4.translator.changeLanguage(l);
|
|
2041
|
-
_this4.isLanguageChangingTo = void 0;
|
|
2042
|
-
_this4.emit("languageChanged", l);
|
|
2043
|
-
_this4.logger.log("languageChanged", l);
|
|
2044
|
-
} else {
|
|
2045
|
-
_this4.isLanguageChangingTo = void 0;
|
|
2046
|
-
}
|
|
2047
|
-
deferred.resolve(function() {
|
|
2048
|
-
return _this4.t.apply(_this4, arguments);
|
|
2049
|
-
});
|
|
2050
|
-
if (callback)
|
|
2051
|
-
callback(err, function() {
|
|
2052
|
-
return _this4.t.apply(_this4, arguments);
|
|
2053
|
-
});
|
|
2054
|
-
};
|
|
2055
|
-
var setLng = function setLng2(lngs) {
|
|
2056
|
-
var l = typeof lngs === "string" ? lngs : _this4.services.languageUtils.getBestMatchFromCodes(lngs);
|
|
2057
|
-
if (l) {
|
|
2058
|
-
if (!_this4.language) {
|
|
2059
|
-
_this4.language = l;
|
|
2060
|
-
_this4.languages = _this4.services.languageUtils.toResolveHierarchy(l);
|
|
2061
|
-
}
|
|
2062
|
-
if (!_this4.translator.language)
|
|
2063
|
-
_this4.translator.changeLanguage(l);
|
|
2064
|
-
if (_this4.services.languageDetector)
|
|
2065
|
-
_this4.services.languageDetector.cacheUserLanguage(l);
|
|
2066
|
-
}
|
|
2067
|
-
_this4.loadResources(l, function(err) {
|
|
2068
|
-
done(err, l);
|
|
2069
|
-
});
|
|
2070
|
-
};
|
|
2071
|
-
if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
|
|
2072
|
-
setLng(this.services.languageDetector.detect());
|
|
2073
|
-
} else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
|
|
2074
|
-
this.services.languageDetector.detect(setLng);
|
|
2075
|
-
} else {
|
|
2076
|
-
setLng(lng);
|
|
2077
|
-
}
|
|
2078
|
-
return deferred;
|
|
2079
|
-
}
|
|
2080
|
-
}, {
|
|
2081
|
-
key: "getFixedT",
|
|
2082
|
-
value: function getFixedT(lng, ns) {
|
|
2083
|
-
var _this5 = this;
|
|
2084
|
-
var fixedT = function fixedT2(key, opts) {
|
|
2085
|
-
var options;
|
|
2086
|
-
if (_typeof$2(opts) !== "object") {
|
|
2087
|
-
for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
2088
|
-
rest[_key3 - 2] = arguments[_key3];
|
|
2089
|
-
}
|
|
2090
|
-
options = _this5.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
2091
|
-
} else {
|
|
2092
|
-
options = _objectSpread$3({}, opts);
|
|
2093
|
-
}
|
|
2094
|
-
options.lng = options.lng || fixedT2.lng;
|
|
2095
|
-
options.lngs = options.lngs || fixedT2.lngs;
|
|
2096
|
-
options.ns = options.ns || fixedT2.ns;
|
|
2097
|
-
return _this5.t(key, options);
|
|
2098
|
-
};
|
|
2099
|
-
if (typeof lng === "string") {
|
|
2100
|
-
fixedT.lng = lng;
|
|
2101
|
-
} else {
|
|
2102
|
-
fixedT.lngs = lng;
|
|
2103
|
-
}
|
|
2104
|
-
fixedT.ns = ns;
|
|
2105
|
-
return fixedT;
|
|
2106
|
-
}
|
|
2107
|
-
}, {
|
|
2108
|
-
key: "t",
|
|
2109
|
-
value: function t2() {
|
|
2110
|
-
var _this$translator;
|
|
2111
|
-
return this.translator && (_this$translator = this.translator).translate.apply(_this$translator, arguments);
|
|
2112
|
-
}
|
|
2113
|
-
}, {
|
|
2114
|
-
key: "exists",
|
|
2115
|
-
value: function exists() {
|
|
2116
|
-
var _this$translator2;
|
|
2117
|
-
return this.translator && (_this$translator2 = this.translator).exists.apply(_this$translator2, arguments);
|
|
2118
|
-
}
|
|
2119
|
-
}, {
|
|
2120
|
-
key: "setDefaultNamespace",
|
|
2121
|
-
value: function setDefaultNamespace(ns) {
|
|
2122
|
-
this.options.defaultNS = ns;
|
|
2123
|
-
}
|
|
2124
|
-
}, {
|
|
2125
|
-
key: "hasLoadedNamespace",
|
|
2126
|
-
value: function hasLoadedNamespace2(ns) {
|
|
2127
|
-
var _this6 = this;
|
|
2128
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
2129
|
-
if (!this.isInitialized) {
|
|
2130
|
-
this.logger.warn("hasLoadedNamespace: i18next was not initialized", this.languages);
|
|
2131
|
-
return false;
|
|
2132
|
-
}
|
|
2133
|
-
if (!this.languages || !this.languages.length) {
|
|
2134
|
-
this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty", this.languages);
|
|
2135
|
-
return false;
|
|
2136
|
-
}
|
|
2137
|
-
var lng = this.languages[0];
|
|
2138
|
-
var fallbackLng = this.options ? this.options.fallbackLng : false;
|
|
2139
|
-
var lastLng = this.languages[this.languages.length - 1];
|
|
2140
|
-
if (lng.toLowerCase() === "cimode")
|
|
2141
|
-
return true;
|
|
2142
|
-
var loadNotPending = function loadNotPending2(l, n2) {
|
|
2143
|
-
var loadState = _this6.services.backendConnector.state["".concat(l, "|").concat(n2)];
|
|
2144
|
-
return loadState === -1 || loadState === 2;
|
|
2145
|
-
};
|
|
2146
|
-
if (options.precheck) {
|
|
2147
|
-
var preResult = options.precheck(this, loadNotPending);
|
|
2148
|
-
if (preResult !== void 0)
|
|
2149
|
-
return preResult;
|
|
2150
|
-
}
|
|
2151
|
-
if (this.hasResourceBundle(lng, ns))
|
|
2152
|
-
return true;
|
|
2153
|
-
if (!this.services.backendConnector.backend)
|
|
2154
|
-
return true;
|
|
2155
|
-
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns)))
|
|
2156
|
-
return true;
|
|
2157
|
-
return false;
|
|
2158
|
-
}
|
|
2159
|
-
}, {
|
|
2160
|
-
key: "loadNamespaces",
|
|
2161
|
-
value: function loadNamespaces2(ns, callback) {
|
|
2162
|
-
var _this7 = this;
|
|
2163
|
-
var deferred = defer();
|
|
2164
|
-
if (!this.options.ns) {
|
|
2165
|
-
callback && callback();
|
|
2166
|
-
return Promise.resolve();
|
|
2167
|
-
}
|
|
2168
|
-
if (typeof ns === "string")
|
|
2169
|
-
ns = [ns];
|
|
2170
|
-
ns.forEach(function(n2) {
|
|
2171
|
-
if (_this7.options.ns.indexOf(n2) < 0)
|
|
2172
|
-
_this7.options.ns.push(n2);
|
|
2173
|
-
});
|
|
2174
|
-
this.loadResources(function(err) {
|
|
2175
|
-
deferred.resolve();
|
|
2176
|
-
if (callback)
|
|
2177
|
-
callback(err);
|
|
2178
|
-
});
|
|
2179
|
-
return deferred;
|
|
2180
|
-
}
|
|
2181
|
-
}, {
|
|
2182
|
-
key: "loadLanguages",
|
|
2183
|
-
value: function loadLanguages(lngs, callback) {
|
|
2184
|
-
var deferred = defer();
|
|
2185
|
-
if (typeof lngs === "string")
|
|
2186
|
-
lngs = [lngs];
|
|
2187
|
-
var preloaded = this.options.preload || [];
|
|
2188
|
-
var newLngs = lngs.filter(function(lng) {
|
|
2189
|
-
return preloaded.indexOf(lng) < 0;
|
|
2190
|
-
});
|
|
2191
|
-
if (!newLngs.length) {
|
|
2192
|
-
if (callback)
|
|
2193
|
-
callback();
|
|
2194
|
-
return Promise.resolve();
|
|
2195
|
-
}
|
|
2196
|
-
this.options.preload = preloaded.concat(newLngs);
|
|
2197
|
-
this.loadResources(function(err) {
|
|
2198
|
-
deferred.resolve();
|
|
2199
|
-
if (callback)
|
|
2200
|
-
callback(err);
|
|
2201
|
-
});
|
|
2202
|
-
return deferred;
|
|
2203
|
-
}
|
|
2204
|
-
}, {
|
|
2205
|
-
key: "dir",
|
|
2206
|
-
value: function dir(lng) {
|
|
2207
|
-
if (!lng)
|
|
2208
|
-
lng = this.languages && this.languages.length > 0 ? this.languages[0] : this.language;
|
|
2209
|
-
if (!lng)
|
|
2210
|
-
return "rtl";
|
|
2211
|
-
var 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"];
|
|
2212
|
-
return rtlLngs.indexOf(this.services.languageUtils.getLanguagePartFromCode(lng)) >= 0 ? "rtl" : "ltr";
|
|
2213
|
-
}
|
|
2214
|
-
}, {
|
|
2215
|
-
key: "createInstance",
|
|
2216
|
-
value: function createInstance() {
|
|
2217
|
-
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
2218
|
-
var callback = arguments.length > 1 ? arguments[1] : void 0;
|
|
2219
|
-
return new I18n2(options, callback);
|
|
2220
|
-
}
|
|
2221
|
-
}, {
|
|
2222
|
-
key: "cloneInstance",
|
|
2223
|
-
value: function cloneInstance() {
|
|
2224
|
-
var _this8 = this;
|
|
2225
|
-
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
2226
|
-
var callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
2227
|
-
var mergedOptions = _objectSpread$3({}, this.options, options, {
|
|
2228
|
-
isClone: true
|
|
2229
|
-
});
|
|
2230
|
-
var clone = new I18n2(mergedOptions);
|
|
2231
|
-
var membersToCopy = ["store", "services", "language"];
|
|
2232
|
-
membersToCopy.forEach(function(m) {
|
|
2233
|
-
clone[m] = _this8[m];
|
|
2234
|
-
});
|
|
2235
|
-
clone.services = _objectSpread$3({}, this.services);
|
|
2236
|
-
clone.services.utils = {
|
|
2237
|
-
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2238
|
-
};
|
|
2239
|
-
clone.translator = new Translator(clone.services, clone.options);
|
|
2240
|
-
clone.translator.on("*", function(event) {
|
|
2241
|
-
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
2242
|
-
args[_key4 - 1] = arguments[_key4];
|
|
2243
|
-
}
|
|
2244
|
-
clone.emit.apply(clone, [event].concat(args));
|
|
2245
|
-
});
|
|
2246
|
-
clone.init(mergedOptions, callback);
|
|
2247
|
-
clone.translator.options = clone.options;
|
|
2248
|
-
clone.translator.backendConnector.services.utils = {
|
|
2249
|
-
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2250
|
-
};
|
|
2251
|
-
return clone;
|
|
2252
|
-
}
|
|
2253
|
-
}]);
|
|
2254
|
-
return I18n2;
|
|
2255
|
-
}(EventEmitter);
|
|
2256
|
-
var i18next = new I18n();
|
|
2257
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
2258
|
-
if (source == null)
|
|
2259
|
-
return {};
|
|
2260
|
-
var target = {};
|
|
2261
|
-
var sourceKeys = Object.keys(source);
|
|
2262
|
-
var key, i2;
|
|
2263
|
-
for (i2 = 0; i2 < sourceKeys.length; i2++) {
|
|
2264
|
-
key = sourceKeys[i2];
|
|
2265
|
-
if (excluded.indexOf(key) >= 0)
|
|
2266
|
-
continue;
|
|
2267
|
-
target[key] = source[key];
|
|
2268
|
-
}
|
|
2269
|
-
return target;
|
|
2270
|
-
}
|
|
2271
|
-
function _objectWithoutProperties(source, excluded) {
|
|
2272
|
-
if (source == null)
|
|
2273
|
-
return {};
|
|
2274
|
-
var target = _objectWithoutPropertiesLoose(source, excluded);
|
|
2275
|
-
var key, i2;
|
|
2276
|
-
if (Object.getOwnPropertySymbols) {
|
|
2277
|
-
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
2278
|
-
for (i2 = 0; i2 < sourceSymbolKeys.length; i2++) {
|
|
2279
|
-
key = sourceSymbolKeys[i2];
|
|
2280
|
-
if (excluded.indexOf(key) >= 0)
|
|
2281
|
-
continue;
|
|
2282
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key))
|
|
2283
|
-
continue;
|
|
2284
|
-
target[key] = source[key];
|
|
2285
|
-
}
|
|
2286
|
-
}
|
|
2287
|
-
return target;
|
|
2288
|
-
}
|
|
2289
|
-
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
2290
|
-
function commonjsRequire(path2) {
|
|
2291
|
-
throw new Error('Could not dynamically require "' + path2 + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
2292
|
-
}
|
|
2293
|
-
var voidElements = {
|
|
2294
|
-
"area": true,
|
|
2295
|
-
"base": true,
|
|
2296
|
-
"br": true,
|
|
2297
|
-
"col": true,
|
|
2298
|
-
"embed": true,
|
|
2299
|
-
"hr": true,
|
|
2300
|
-
"img": true,
|
|
2301
|
-
"input": true,
|
|
2302
|
-
"link": true,
|
|
2303
|
-
"meta": true,
|
|
2304
|
-
"param": true,
|
|
2305
|
-
"source": true,
|
|
2306
|
-
"track": true,
|
|
2307
|
-
"wbr": true
|
|
2308
|
-
};
|
|
2309
|
-
var t = /\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;
|
|
2310
|
-
function n(n2) {
|
|
2311
|
-
var r2 = { type: "tag", name: "", voidElement: false, attrs: {}, children: [] }, i2 = n2.match(/<\/?([^\s]+?)[/\s>]/);
|
|
2312
|
-
if (i2 && (r2.name = i2[1], (voidElements[i2[1]] || n2.charAt(n2.length - 2) === "/") && (r2.voidElement = true), r2.name.startsWith("!--"))) {
|
|
2313
|
-
var s2 = n2.indexOf("-->");
|
|
2314
|
-
return { type: "comment", comment: s2 !== -1 ? n2.slice(4, s2) : "" };
|
|
2315
|
-
}
|
|
2316
|
-
for (var a2 = new RegExp(t), c2 = null; (c2 = a2.exec(n2)) !== null; )
|
|
2317
|
-
if (c2[0].trim())
|
|
2318
|
-
if (c2[1]) {
|
|
2319
|
-
var o = c2[1].trim(), l = [o, ""];
|
|
2320
|
-
o.indexOf("=") > -1 && (l = o.split("=")), r2.attrs[l[0]] = l[1], a2.lastIndex--;
|
|
2321
|
-
} else
|
|
2322
|
-
c2[2] && (r2.attrs[c2[2]] = c2[3].trim().substring(1, c2[3].length - 1));
|
|
2323
|
-
return r2;
|
|
2324
|
-
}
|
|
2325
|
-
var r = /<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g, i = /^\s*$/, s = Object.create(null);
|
|
2326
|
-
function a(e, t2) {
|
|
2327
|
-
switch (t2.type) {
|
|
2328
|
-
case "text":
|
|
2329
|
-
return e + t2.content;
|
|
2330
|
-
case "tag":
|
|
2331
|
-
return e += "<" + t2.name + (t2.attrs ? function(e2) {
|
|
2332
|
-
var t3 = [];
|
|
2333
|
-
for (var n2 in e2)
|
|
2334
|
-
t3.push(n2 + '="' + e2[n2] + '"');
|
|
2335
|
-
return t3.length ? " " + t3.join(" ") : "";
|
|
2336
|
-
}(t2.attrs) : "") + (t2.voidElement ? "/>" : ">"), t2.voidElement ? e : e + t2.children.reduce(a, "") + "</" + t2.name + ">";
|
|
2337
|
-
case "comment":
|
|
2338
|
-
return e + "<!--" + t2.comment + "-->";
|
|
2339
|
-
}
|
|
2340
|
-
}
|
|
2341
|
-
var c = { parse: function(e, t2) {
|
|
2342
|
-
t2 || (t2 = {}), t2.components || (t2.components = s);
|
|
2343
|
-
var a2, c2 = [], o = [], l = -1, m = false;
|
|
2344
|
-
if (e.indexOf("<") !== 0) {
|
|
2345
|
-
var u = e.indexOf("<");
|
|
2346
|
-
c2.push({ type: "text", content: u === -1 ? e : e.substring(0, u) });
|
|
2347
|
-
}
|
|
2348
|
-
return e.replace(r, function(r2, s2) {
|
|
2349
|
-
if (m) {
|
|
2350
|
-
if (r2 !== "</" + a2.name + ">")
|
|
2351
|
-
return;
|
|
2352
|
-
m = false;
|
|
2353
|
-
}
|
|
2354
|
-
var u2, f = r2.charAt(1) !== "/", h = r2.startsWith("<!--"), p = s2 + r2.length, d = e.charAt(p);
|
|
2355
|
-
if (h) {
|
|
2356
|
-
var v = n(r2);
|
|
2357
|
-
return l < 0 ? (c2.push(v), c2) : ((u2 = o[l]).children.push(v), c2);
|
|
2358
|
-
}
|
|
2359
|
-
if (f && (l++, (a2 = n(r2)).type === "tag" && t2.components[a2.name] && (a2.type = "component", m = true), a2.voidElement || m || !d || d === "<" || a2.children.push({ type: "text", content: e.slice(p, e.indexOf("<", p)) }), l === 0 && c2.push(a2), (u2 = o[l - 1]) && u2.children.push(a2), o[l] = a2), (!f || a2.voidElement) && (l > -1 && (a2.voidElement || a2.name === r2.slice(2, -1)) && (l--, a2 = l === -1 ? c2 : o[l]), !m && d !== "<" && d)) {
|
|
2360
|
-
u2 = l === -1 ? c2 : o[l].children;
|
|
2361
|
-
var x = e.indexOf("<", p), g = e.slice(p, x === -1 ? void 0 : x);
|
|
2362
|
-
i.test(g) && (g = " "), (x > -1 && l + u2.length >= 0 || g !== " ") && u2.push({ type: "text", content: g });
|
|
2363
|
-
}
|
|
2364
|
-
}), c2;
|
|
2365
|
-
}, stringify: function(e) {
|
|
2366
|
-
return e.reduce(function(e2, t2) {
|
|
2367
|
-
return e2 + a("", t2);
|
|
2368
|
-
}, "");
|
|
2369
|
-
} };
|
|
2370
|
-
function ownKeys$2(object, enumerableOnly) {
|
|
2371
|
-
var keys = Object.keys(object);
|
|
2372
|
-
if (Object.getOwnPropertySymbols) {
|
|
2373
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
2374
|
-
if (enumerableOnly) {
|
|
2375
|
-
symbols = symbols.filter(function(sym) {
|
|
2376
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
2377
|
-
});
|
|
2378
|
-
}
|
|
2379
|
-
keys.push.apply(keys, symbols);
|
|
2380
|
-
}
|
|
2381
|
-
return keys;
|
|
2382
|
-
}
|
|
2383
|
-
function _objectSpread$2(target) {
|
|
2384
|
-
for (var i2 = 1; i2 < arguments.length; i2++) {
|
|
2385
|
-
var source = arguments[i2] != null ? arguments[i2] : {};
|
|
2386
|
-
if (i2 % 2) {
|
|
2387
|
-
ownKeys$2(Object(source), true).forEach(function(key) {
|
|
2388
|
-
_defineProperty$1(target, key, source[key]);
|
|
2389
|
-
});
|
|
2390
|
-
} else if (Object.getOwnPropertyDescriptors) {
|
|
2391
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
2392
|
-
} else {
|
|
2393
|
-
ownKeys$2(Object(source)).forEach(function(key) {
|
|
2394
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
2395
|
-
});
|
|
2396
|
-
}
|
|
2397
|
-
}
|
|
2398
|
-
return target;
|
|
2399
|
-
}
|
|
2400
|
-
var defaultOptions = {
|
|
2401
|
-
bindI18n: "languageChanged",
|
|
2402
|
-
bindI18nStore: "",
|
|
2403
|
-
transEmptyNodeValue: "",
|
|
2404
|
-
transSupportBasicHtmlNodes: true,
|
|
2405
|
-
transWrapTextNodes: "",
|
|
2406
|
-
transKeepBasicHtmlNodesFor: ["br", "strong", "i", "p"],
|
|
2407
|
-
useSuspense: true
|
|
2408
|
-
};
|
|
2409
|
-
var i18nInstance;
|
|
2410
|
-
var I18nContext = React__default.createContext();
|
|
2411
|
-
function setDefaults() {
|
|
2412
|
-
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
2413
|
-
defaultOptions = _objectSpread$2(_objectSpread$2({}, defaultOptions), options);
|
|
2414
|
-
}
|
|
2415
|
-
function getDefaults$2() {
|
|
2416
|
-
return defaultOptions;
|
|
2417
|
-
}
|
|
2418
|
-
var ReportNamespaces = function() {
|
|
2419
|
-
function ReportNamespaces2() {
|
|
2420
|
-
_classCallCheck$1(this, ReportNamespaces2);
|
|
2421
|
-
this.usedNamespaces = {};
|
|
2422
|
-
}
|
|
2423
|
-
_createClass$1(ReportNamespaces2, [{
|
|
2424
|
-
key: "addUsedNamespaces",
|
|
2425
|
-
value: function addUsedNamespaces(namespaces) {
|
|
2426
|
-
var _this = this;
|
|
2427
|
-
namespaces.forEach(function(ns) {
|
|
2428
|
-
if (!_this.usedNamespaces[ns])
|
|
2429
|
-
_this.usedNamespaces[ns] = true;
|
|
2430
|
-
});
|
|
2431
|
-
}
|
|
2432
|
-
}, {
|
|
2433
|
-
key: "getUsedNamespaces",
|
|
2434
|
-
value: function getUsedNamespaces() {
|
|
2435
|
-
return Object.keys(this.usedNamespaces);
|
|
2436
|
-
}
|
|
2437
|
-
}]);
|
|
2438
|
-
return ReportNamespaces2;
|
|
2439
|
-
}();
|
|
2440
|
-
function setI18n(instance) {
|
|
2441
|
-
i18nInstance = instance;
|
|
2442
|
-
}
|
|
2443
|
-
function getI18n() {
|
|
2444
|
-
return i18nInstance;
|
|
2445
|
-
}
|
|
2446
|
-
var initReactI18next = {
|
|
2447
|
-
type: "3rdParty",
|
|
2448
|
-
init: function init(instance) {
|
|
2449
|
-
setDefaults(instance.options.react);
|
|
2450
|
-
setI18n(instance);
|
|
2451
|
-
}
|
|
2452
|
-
};
|
|
2453
|
-
function warn2() {
|
|
2454
|
-
if (console && console.warn) {
|
|
2455
|
-
var _console;
|
|
2456
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2457
|
-
args[_key] = arguments[_key];
|
|
2458
|
-
}
|
|
2459
|
-
if (typeof args[0] === "string")
|
|
2460
|
-
args[0] = "react-i18next:: ".concat(args[0]);
|
|
2461
|
-
(_console = console).warn.apply(_console, args);
|
|
2462
|
-
}
|
|
2463
|
-
}
|
|
2464
|
-
var alreadyWarned = {};
|
|
2465
|
-
function warnOnce() {
|
|
2466
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
2467
|
-
args[_key2] = arguments[_key2];
|
|
2468
|
-
}
|
|
2469
|
-
if (typeof args[0] === "string" && alreadyWarned[args[0]])
|
|
2470
|
-
return;
|
|
2471
|
-
if (typeof args[0] === "string")
|
|
2472
|
-
alreadyWarned[args[0]] = new Date();
|
|
2473
|
-
warn2.apply(void 0, args);
|
|
2474
|
-
}
|
|
2475
|
-
function loadNamespaces(i18n, ns, cb) {
|
|
2476
|
-
i18n.loadNamespaces(ns, function() {
|
|
2477
|
-
if (i18n.isInitialized) {
|
|
2478
|
-
cb();
|
|
2479
|
-
} else {
|
|
2480
|
-
var initialized = function initialized2() {
|
|
2481
|
-
setTimeout(function() {
|
|
2482
|
-
i18n.off("initialized", initialized2);
|
|
2483
|
-
}, 0);
|
|
2484
|
-
cb();
|
|
2485
|
-
};
|
|
2486
|
-
i18n.on("initialized", initialized);
|
|
2487
|
-
}
|
|
2488
|
-
});
|
|
2489
|
-
}
|
|
2490
|
-
function hasLoadedNamespace(ns, i18n) {
|
|
2491
|
-
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
2492
|
-
if (!i18n.languages || !i18n.languages.length) {
|
|
2493
|
-
warnOnce("i18n.languages were undefined or empty", i18n.languages);
|
|
2494
|
-
return true;
|
|
2495
|
-
}
|
|
2496
|
-
var lng = i18n.languages[0];
|
|
2497
|
-
var fallbackLng = i18n.options ? i18n.options.fallbackLng : false;
|
|
2498
|
-
var lastLng = i18n.languages[i18n.languages.length - 1];
|
|
2499
|
-
if (lng.toLowerCase() === "cimode")
|
|
2500
|
-
return true;
|
|
2501
|
-
var loadNotPending = function loadNotPending2(l, n2) {
|
|
2502
|
-
var loadState = i18n.services.backendConnector.state["".concat(l, "|").concat(n2)];
|
|
2503
|
-
return loadState === -1 || loadState === 2;
|
|
2504
|
-
};
|
|
2505
|
-
if (options.bindI18n && options.bindI18n.indexOf("languageChanging") > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns))
|
|
2506
|
-
return false;
|
|
2507
|
-
if (i18n.hasResourceBundle(lng, ns))
|
|
2508
|
-
return true;
|
|
2509
|
-
if (!i18n.services.backendConnector.backend)
|
|
2510
|
-
return true;
|
|
2511
|
-
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns)))
|
|
2512
|
-
return true;
|
|
2513
|
-
return false;
|
|
2514
|
-
}
|
|
2515
|
-
var _excluded = ["format"], _excluded2 = ["children", "count", "parent", "i18nKey", "tOptions", "values", "defaults", "components", "ns", "i18n", "t"];
|
|
2516
|
-
function ownKeys$1(object, enumerableOnly) {
|
|
2517
|
-
var keys = Object.keys(object);
|
|
2518
|
-
if (Object.getOwnPropertySymbols) {
|
|
2519
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
2520
|
-
if (enumerableOnly) {
|
|
2521
|
-
symbols = symbols.filter(function(sym) {
|
|
2522
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
2523
|
-
});
|
|
2524
|
-
}
|
|
2525
|
-
keys.push.apply(keys, symbols);
|
|
2526
|
-
}
|
|
2527
|
-
return keys;
|
|
2528
|
-
}
|
|
2529
|
-
function _objectSpread$1(target) {
|
|
2530
|
-
for (var i2 = 1; i2 < arguments.length; i2++) {
|
|
2531
|
-
var source = arguments[i2] != null ? arguments[i2] : {};
|
|
2532
|
-
if (i2 % 2) {
|
|
2533
|
-
ownKeys$1(Object(source), true).forEach(function(key) {
|
|
2534
|
-
_defineProperty$1(target, key, source[key]);
|
|
2535
|
-
});
|
|
2536
|
-
} else if (Object.getOwnPropertyDescriptors) {
|
|
2537
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
2538
|
-
} else {
|
|
2539
|
-
ownKeys$1(Object(source)).forEach(function(key) {
|
|
2540
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
2541
|
-
});
|
|
2542
|
-
}
|
|
2543
|
-
}
|
|
2544
|
-
return target;
|
|
2545
|
-
}
|
|
2546
|
-
function hasChildren(node, checkLength) {
|
|
2547
|
-
if (!node)
|
|
2548
|
-
return false;
|
|
2549
|
-
var base = node.props ? node.props.children : node.children;
|
|
2550
|
-
if (checkLength)
|
|
2551
|
-
return base.length > 0;
|
|
2552
|
-
return !!base;
|
|
2553
|
-
}
|
|
2554
|
-
function getChildren(node) {
|
|
2555
|
-
if (!node)
|
|
2556
|
-
return [];
|
|
2557
|
-
return node && node.children ? node.children : node.props && node.props.children;
|
|
2558
|
-
}
|
|
2559
|
-
function hasValidReactChildren(children) {
|
|
2560
|
-
if (Object.prototype.toString.call(children) !== "[object Array]")
|
|
2561
|
-
return false;
|
|
2562
|
-
return children.every(function(child) {
|
|
2563
|
-
return React__default.isValidElement(child);
|
|
2564
|
-
});
|
|
2565
|
-
}
|
|
2566
|
-
function getAsArray(data) {
|
|
2567
|
-
return Array.isArray(data) ? data : [data];
|
|
2568
|
-
}
|
|
2569
|
-
function mergeProps(source, target) {
|
|
2570
|
-
var newTarget = _objectSpread$1({}, target);
|
|
2571
|
-
newTarget.props = Object.assign(source.props, target.props);
|
|
2572
|
-
return newTarget;
|
|
2573
|
-
}
|
|
2574
|
-
function nodesToString(children, i18nOptions) {
|
|
2575
|
-
if (!children)
|
|
2576
|
-
return "";
|
|
2577
|
-
var stringNode = "";
|
|
2578
|
-
var childrenArray = getAsArray(children);
|
|
2579
|
-
var keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
|
|
2580
|
-
childrenArray.forEach(function(child, childIndex) {
|
|
2581
|
-
if (typeof child === "string") {
|
|
2582
|
-
stringNode += "".concat(child);
|
|
2583
|
-
} else if (React__default.isValidElement(child)) {
|
|
2584
|
-
var childPropsCount = Object.keys(child.props).length;
|
|
2585
|
-
var shouldKeepChild = keepArray.indexOf(child.type) > -1;
|
|
2586
|
-
var childChildren = child.props.children;
|
|
2587
|
-
if (!childChildren && shouldKeepChild && childPropsCount === 0) {
|
|
2588
|
-
stringNode += "<".concat(child.type, "/>");
|
|
2589
|
-
} else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) {
|
|
2590
|
-
stringNode += "<".concat(childIndex, "></").concat(childIndex, ">");
|
|
2591
|
-
} else if (child.props.i18nIsDynamicList) {
|
|
2592
|
-
stringNode += "<".concat(childIndex, "></").concat(childIndex, ">");
|
|
2593
|
-
} else if (shouldKeepChild && childPropsCount === 1 && typeof childChildren === "string") {
|
|
2594
|
-
stringNode += "<".concat(child.type, ">").concat(childChildren, "</").concat(child.type, ">");
|
|
2595
|
-
} else {
|
|
2596
|
-
var content = nodesToString(childChildren, i18nOptions);
|
|
2597
|
-
stringNode += "<".concat(childIndex, ">").concat(content, "</").concat(childIndex, ">");
|
|
2598
|
-
}
|
|
2599
|
-
} else if (child === null) {
|
|
2600
|
-
warn2("Trans: the passed in value is invalid - seems you passed in a null child.");
|
|
2601
|
-
} else if (_typeof$2(child) === "object") {
|
|
2602
|
-
var format = child.format, clone = _objectWithoutProperties(child, _excluded);
|
|
2603
|
-
var keys = Object.keys(clone);
|
|
2604
|
-
if (keys.length === 1) {
|
|
2605
|
-
var value = format ? "".concat(keys[0], ", ").concat(format) : keys[0];
|
|
2606
|
-
stringNode += "{{".concat(value, "}}");
|
|
2607
|
-
} else {
|
|
2608
|
-
warn2("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.", child);
|
|
2609
|
-
}
|
|
2610
|
-
} else {
|
|
2611
|
-
warn2("Trans: the passed in value is invalid - seems you passed in a variable like {number} - please pass in variables for interpolation as full objects like {{number}}.", child);
|
|
2612
|
-
}
|
|
2613
|
-
});
|
|
2614
|
-
return stringNode;
|
|
2615
|
-
}
|
|
2616
|
-
function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts) {
|
|
2617
|
-
if (targetString === "")
|
|
2618
|
-
return [];
|
|
2619
|
-
var keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
|
|
2620
|
-
var emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.join("|")).test(targetString);
|
|
2621
|
-
if (!children && !emptyChildrenButNeedsHandling)
|
|
2622
|
-
return [targetString];
|
|
2623
|
-
var data = {};
|
|
2624
|
-
function getData(childs) {
|
|
2625
|
-
var childrenArray = getAsArray(childs);
|
|
2626
|
-
childrenArray.forEach(function(child) {
|
|
2627
|
-
if (typeof child === "string")
|
|
2628
|
-
return;
|
|
2629
|
-
if (hasChildren(child))
|
|
2630
|
-
getData(getChildren(child));
|
|
2631
|
-
else if (_typeof$2(child) === "object" && !React__default.isValidElement(child))
|
|
2632
|
-
Object.assign(data, child);
|
|
2633
|
-
});
|
|
2634
|
-
}
|
|
2635
|
-
getData(children);
|
|
2636
|
-
var ast = c.parse("<0>".concat(targetString, "</0>"));
|
|
2637
|
-
var opts = _objectSpread$1(_objectSpread$1({}, data), combinedTOpts);
|
|
2638
|
-
function renderInner(child, node, rootReactNode) {
|
|
2639
|
-
var childs = getChildren(child);
|
|
2640
|
-
var mappedChildren = mapAST(childs, node.children, rootReactNode);
|
|
2641
|
-
return hasValidReactChildren(childs) && mappedChildren.length === 0 ? childs : mappedChildren;
|
|
2642
|
-
}
|
|
2643
|
-
function pushTranslatedJSX(child, inner, mem, i2, isVoid) {
|
|
2644
|
-
if (child.dummy)
|
|
2645
|
-
child.children = inner;
|
|
2646
|
-
mem.push(React__default.cloneElement(child, _objectSpread$1(_objectSpread$1({}, child.props), {}, {
|
|
2647
|
-
key: i2
|
|
2648
|
-
}), isVoid ? void 0 : inner));
|
|
2649
|
-
}
|
|
2650
|
-
function mapAST(reactNode, astNode, rootReactNode) {
|
|
2651
|
-
var reactNodes = getAsArray(reactNode);
|
|
2652
|
-
var astNodes = getAsArray(astNode);
|
|
2653
|
-
return astNodes.reduce(function(mem, node, i2) {
|
|
2654
|
-
var translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
|
|
2655
|
-
if (node.type === "tag") {
|
|
2656
|
-
var tmp = reactNodes[parseInt(node.name, 10)];
|
|
2657
|
-
if (!tmp && rootReactNode.length === 1 && rootReactNode[0][node.name])
|
|
2658
|
-
tmp = rootReactNode[0][node.name];
|
|
2659
|
-
if (!tmp)
|
|
2660
|
-
tmp = {};
|
|
2661
|
-
var child = Object.keys(node.attrs).length !== 0 ? mergeProps({
|
|
2662
|
-
props: node.attrs
|
|
2663
|
-
}, tmp) : tmp;
|
|
2664
|
-
var isElement = React__default.isValidElement(child);
|
|
2665
|
-
var isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
|
|
2666
|
-
var isEmptyTransWithHTML = emptyChildrenButNeedsHandling && _typeof$2(child) === "object" && child.dummy && !isElement;
|
|
2667
|
-
var isKnownComponent = _typeof$2(children) === "object" && children !== null && Object.hasOwnProperty.call(children, node.name);
|
|
2668
|
-
if (typeof child === "string") {
|
|
2669
|
-
var value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
|
|
2670
|
-
mem.push(value);
|
|
2671
|
-
} else if (hasChildren(child) || isValidTranslationWithChildren) {
|
|
2672
|
-
var inner = renderInner(child, node, rootReactNode);
|
|
2673
|
-
pushTranslatedJSX(child, inner, mem, i2);
|
|
2674
|
-
} else if (isEmptyTransWithHTML) {
|
|
2675
|
-
var _inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
2676
|
-
mem.push(React__default.cloneElement(child, _objectSpread$1(_objectSpread$1({}, child.props), {}, {
|
|
2677
|
-
key: i2
|
|
2678
|
-
}), _inner));
|
|
2679
|
-
} else if (Number.isNaN(parseFloat(node.name))) {
|
|
2680
|
-
if (isKnownComponent) {
|
|
2681
|
-
var _inner2 = renderInner(child, node, rootReactNode);
|
|
2682
|
-
pushTranslatedJSX(child, _inner2, mem, i2, node.voidElement);
|
|
2683
|
-
} else if (i18nOptions.transSupportBasicHtmlNodes && keepArray.indexOf(node.name) > -1) {
|
|
2684
|
-
if (node.voidElement) {
|
|
2685
|
-
mem.push(React__default.createElement(node.name, {
|
|
2686
|
-
key: "".concat(node.name, "-").concat(i2)
|
|
2687
|
-
}));
|
|
2688
|
-
} else {
|
|
2689
|
-
var _inner3 = mapAST(reactNodes, node.children, rootReactNode);
|
|
2690
|
-
mem.push(React__default.createElement(node.name, {
|
|
2691
|
-
key: "".concat(node.name, "-").concat(i2)
|
|
2692
|
-
}, _inner3));
|
|
2693
|
-
}
|
|
2694
|
-
} else if (node.voidElement) {
|
|
2695
|
-
mem.push("<".concat(node.name, " />"));
|
|
2696
|
-
} else {
|
|
2697
|
-
var _inner4 = mapAST(reactNodes, node.children, rootReactNode);
|
|
2698
|
-
mem.push("<".concat(node.name, ">").concat(_inner4, "</").concat(node.name, ">"));
|
|
2699
|
-
}
|
|
2700
|
-
} else if (_typeof$2(child) === "object" && !isElement) {
|
|
2701
|
-
var content = node.children[0] ? translationContent : null;
|
|
2702
|
-
if (content)
|
|
2703
|
-
mem.push(content);
|
|
2704
|
-
} else if (node.children.length === 1 && translationContent) {
|
|
2705
|
-
mem.push(React__default.cloneElement(child, _objectSpread$1(_objectSpread$1({}, child.props), {}, {
|
|
2706
|
-
key: i2
|
|
2707
|
-
}), translationContent));
|
|
2708
|
-
} else {
|
|
2709
|
-
mem.push(React__default.cloneElement(child, _objectSpread$1(_objectSpread$1({}, child.props), {}, {
|
|
2710
|
-
key: i2
|
|
2711
|
-
})));
|
|
2712
|
-
}
|
|
2713
|
-
} else if (node.type === "text") {
|
|
2714
|
-
var wrapTextNodes = i18nOptions.transWrapTextNodes;
|
|
2715
|
-
var _content = i18n.services.interpolator.interpolate(node.content, opts, i18n.language);
|
|
2716
|
-
if (wrapTextNodes) {
|
|
2717
|
-
mem.push(React__default.createElement(wrapTextNodes, {
|
|
2718
|
-
key: "".concat(node.name, "-").concat(i2)
|
|
2719
|
-
}, _content));
|
|
2720
|
-
} else {
|
|
2721
|
-
mem.push(_content);
|
|
2722
|
-
}
|
|
2723
|
-
}
|
|
2724
|
-
return mem;
|
|
2725
|
-
}, []);
|
|
2726
|
-
}
|
|
2727
|
-
var result = mapAST([{
|
|
2728
|
-
dummy: true,
|
|
2729
|
-
children: children || []
|
|
2730
|
-
}], ast, getAsArray(children || []));
|
|
2731
|
-
return getChildren(result[0]);
|
|
2732
|
-
}
|
|
2733
|
-
function Trans(_ref) {
|
|
2734
|
-
var children = _ref.children, count = _ref.count, parent = _ref.parent, i18nKey = _ref.i18nKey, _ref$tOptions = _ref.tOptions, tOptions = _ref$tOptions === void 0 ? {} : _ref$tOptions, values = _ref.values, defaults2 = _ref.defaults, components = _ref.components, ns = _ref.ns, i18nFromProps = _ref.i18n, tFromProps = _ref.t, additionalProps = _objectWithoutProperties(_ref, _excluded2);
|
|
2735
|
-
var _ref2 = useContext(I18nContext) || {}, i18nFromContext = _ref2.i18n, defaultNSFromContext = _ref2.defaultNS;
|
|
2736
|
-
var i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
2737
|
-
if (!i18n) {
|
|
2738
|
-
warnOnce("You will need to pass in an i18next instance by using i18nextReactModule");
|
|
2739
|
-
return children;
|
|
2740
|
-
}
|
|
2741
|
-
var t2 = tFromProps || i18n.t.bind(i18n) || function(k) {
|
|
2742
|
-
return k;
|
|
2743
|
-
};
|
|
2744
|
-
var reactI18nextOptions = _objectSpread$1(_objectSpread$1({}, getDefaults$2()), i18n.options && i18n.options.react);
|
|
2745
|
-
var namespaces = ns || t2.ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
|
|
2746
|
-
namespaces = typeof namespaces === "string" ? [namespaces] : namespaces || ["translation"];
|
|
2747
|
-
var defaultValue = defaults2 || nodesToString(children, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue || i18nKey;
|
|
2748
|
-
var hashTransKey = reactI18nextOptions.hashTransKey;
|
|
2749
|
-
var key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
|
|
2750
|
-
var interpolationOverride = values ? tOptions.interpolation : {
|
|
2751
|
-
interpolation: _objectSpread$1(_objectSpread$1({}, tOptions.interpolation), {}, {
|
|
2752
|
-
prefix: "#$?",
|
|
2753
|
-
suffix: "?$#"
|
|
2754
|
-
})
|
|
2755
|
-
};
|
|
2756
|
-
var combinedTOpts = _objectSpread$1(_objectSpread$1(_objectSpread$1(_objectSpread$1({}, tOptions), {}, {
|
|
2757
|
-
count
|
|
2758
|
-
}, values), interpolationOverride), {}, {
|
|
2759
|
-
defaultValue,
|
|
2760
|
-
ns: namespaces
|
|
2761
|
-
});
|
|
2762
|
-
var translation = key ? t2(key, combinedTOpts) : defaultValue;
|
|
2763
|
-
var content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts);
|
|
2764
|
-
var useAsParent = parent !== void 0 ? parent : reactI18nextOptions.defaultTransParent;
|
|
2765
|
-
return useAsParent ? React__default.createElement(useAsParent, additionalProps, content) : content;
|
|
2766
|
-
}
|
|
2767
|
-
function _arrayWithHoles(arr2) {
|
|
2768
|
-
if (Array.isArray(arr2))
|
|
2769
|
-
return arr2;
|
|
2770
|
-
}
|
|
2771
|
-
function _iterableToArrayLimit(arr2, i2) {
|
|
2772
|
-
var _i = arr2 == null ? null : typeof Symbol !== "undefined" && arr2[Symbol.iterator] || arr2["@@iterator"];
|
|
2773
|
-
if (_i == null)
|
|
2774
|
-
return;
|
|
2775
|
-
var _arr = [];
|
|
2776
|
-
var _n = true;
|
|
2777
|
-
var _d = false;
|
|
2778
|
-
var _s, _e;
|
|
2779
|
-
try {
|
|
2780
|
-
for (_i = _i.call(arr2); !(_n = (_s = _i.next()).done); _n = true) {
|
|
2781
|
-
_arr.push(_s.value);
|
|
2782
|
-
if (i2 && _arr.length === i2)
|
|
2783
|
-
break;
|
|
2784
|
-
}
|
|
2785
|
-
} catch (err) {
|
|
2786
|
-
_d = true;
|
|
2787
|
-
_e = err;
|
|
2788
|
-
} finally {
|
|
2789
|
-
try {
|
|
2790
|
-
if (!_n && _i["return"] != null)
|
|
2791
|
-
_i["return"]();
|
|
2792
|
-
} finally {
|
|
2793
|
-
if (_d)
|
|
2794
|
-
throw _e;
|
|
2795
|
-
}
|
|
2796
|
-
}
|
|
2797
|
-
return _arr;
|
|
2798
|
-
}
|
|
2799
|
-
function _arrayLikeToArray(arr2, len) {
|
|
2800
|
-
if (len == null || len > arr2.length)
|
|
2801
|
-
len = arr2.length;
|
|
2802
|
-
for (var i2 = 0, arr22 = new Array(len); i2 < len; i2++) {
|
|
2803
|
-
arr22[i2] = arr2[i2];
|
|
2804
|
-
}
|
|
2805
|
-
return arr22;
|
|
2806
|
-
}
|
|
2807
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
2808
|
-
if (!o)
|
|
2809
|
-
return;
|
|
2810
|
-
if (typeof o === "string")
|
|
2811
|
-
return _arrayLikeToArray(o, minLen);
|
|
2812
|
-
var n2 = Object.prototype.toString.call(o).slice(8, -1);
|
|
2813
|
-
if (n2 === "Object" && o.constructor)
|
|
2814
|
-
n2 = o.constructor.name;
|
|
2815
|
-
if (n2 === "Map" || n2 === "Set")
|
|
2816
|
-
return Array.from(o);
|
|
2817
|
-
if (n2 === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n2))
|
|
2818
|
-
return _arrayLikeToArray(o, minLen);
|
|
2819
|
-
}
|
|
2820
|
-
function _nonIterableRest() {
|
|
2821
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
2822
|
-
}
|
|
2823
|
-
function _slicedToArray(arr2, i2) {
|
|
2824
|
-
return _arrayWithHoles(arr2) || _iterableToArrayLimit(arr2, i2) || _unsupportedIterableToArray(arr2, i2) || _nonIterableRest();
|
|
2825
|
-
}
|
|
2826
|
-
function ownKeys(object, enumerableOnly) {
|
|
2827
|
-
var keys = Object.keys(object);
|
|
2828
|
-
if (Object.getOwnPropertySymbols) {
|
|
2829
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
2830
|
-
if (enumerableOnly) {
|
|
2831
|
-
symbols = symbols.filter(function(sym) {
|
|
2832
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
2833
|
-
});
|
|
2834
|
-
}
|
|
2835
|
-
keys.push.apply(keys, symbols);
|
|
2836
|
-
}
|
|
2837
|
-
return keys;
|
|
2838
|
-
}
|
|
2839
|
-
function _objectSpread(target) {
|
|
2840
|
-
for (var i2 = 1; i2 < arguments.length; i2++) {
|
|
2841
|
-
var source = arguments[i2] != null ? arguments[i2] : {};
|
|
2842
|
-
if (i2 % 2) {
|
|
2843
|
-
ownKeys(Object(source), true).forEach(function(key) {
|
|
2844
|
-
_defineProperty$1(target, key, source[key]);
|
|
2845
|
-
});
|
|
2846
|
-
} else if (Object.getOwnPropertyDescriptors) {
|
|
2847
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
2848
|
-
} else {
|
|
2849
|
-
ownKeys(Object(source)).forEach(function(key) {
|
|
2850
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
2851
|
-
});
|
|
2852
|
-
}
|
|
2853
|
-
}
|
|
2854
|
-
return target;
|
|
2855
|
-
}
|
|
2856
|
-
function useTranslation(ns) {
|
|
2857
|
-
var props = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
2858
|
-
var i18nFromProps = props.i18n;
|
|
2859
|
-
var _ref = useContext(I18nContext) || {}, i18nFromContext = _ref.i18n, defaultNSFromContext = _ref.defaultNS;
|
|
2860
|
-
var i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
2861
|
-
if (i18n && !i18n.reportNamespaces)
|
|
2862
|
-
i18n.reportNamespaces = new ReportNamespaces();
|
|
2863
|
-
if (!i18n) {
|
|
2864
|
-
warnOnce("You will need to pass in an i18next instance by using initReactI18next");
|
|
2865
|
-
var notReadyT = function notReadyT2(k) {
|
|
2866
|
-
return Array.isArray(k) ? k[k.length - 1] : k;
|
|
2867
|
-
};
|
|
2868
|
-
var retNotReady = [notReadyT, {}, false];
|
|
2869
|
-
retNotReady.t = notReadyT;
|
|
2870
|
-
retNotReady.i18n = {};
|
|
2871
|
-
retNotReady.ready = false;
|
|
2872
|
-
return retNotReady;
|
|
2873
|
-
}
|
|
2874
|
-
if (i18n.options.react && i18n.options.react.wait !== void 0)
|
|
2875
|
-
warnOnce("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");
|
|
2876
|
-
var i18nOptions = _objectSpread(_objectSpread(_objectSpread({}, getDefaults$2()), i18n.options.react), props);
|
|
2877
|
-
var useSuspense = i18nOptions.useSuspense, keyPrefix = i18nOptions.keyPrefix;
|
|
2878
|
-
var namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
|
|
2879
|
-
namespaces = typeof namespaces === "string" ? [namespaces] : namespaces || ["translation"];
|
|
2880
|
-
if (i18n.reportNamespaces.addUsedNamespaces)
|
|
2881
|
-
i18n.reportNamespaces.addUsedNamespaces(namespaces);
|
|
2882
|
-
var ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(function(n2) {
|
|
2883
|
-
return hasLoadedNamespace(n2, i18n, i18nOptions);
|
|
2884
|
-
});
|
|
2885
|
-
function getT() {
|
|
2886
|
-
return i18n.getFixedT(null, i18nOptions.nsMode === "fallback" ? namespaces : namespaces[0], keyPrefix);
|
|
2887
|
-
}
|
|
2888
|
-
var _useState = useState(getT), _useState2 = _slicedToArray(_useState, 2), t2 = _useState2[0], setT = _useState2[1];
|
|
2889
|
-
var isMounted = useRef(true);
|
|
2890
|
-
useEffect(function() {
|
|
2891
|
-
var bindI18n = i18nOptions.bindI18n, bindI18nStore = i18nOptions.bindI18nStore;
|
|
2892
|
-
isMounted.current = true;
|
|
2893
|
-
if (!ready && !useSuspense) {
|
|
2894
|
-
loadNamespaces(i18n, namespaces, function() {
|
|
2895
|
-
if (isMounted.current)
|
|
2896
|
-
setT(getT);
|
|
2897
|
-
});
|
|
2898
|
-
}
|
|
2899
|
-
function boundReset() {
|
|
2900
|
-
if (isMounted.current)
|
|
2901
|
-
setT(getT);
|
|
2902
|
-
}
|
|
2903
|
-
if (bindI18n && i18n)
|
|
2904
|
-
i18n.on(bindI18n, boundReset);
|
|
2905
|
-
if (bindI18nStore && i18n)
|
|
2906
|
-
i18n.store.on(bindI18nStore, boundReset);
|
|
2907
|
-
return function() {
|
|
2908
|
-
isMounted.current = false;
|
|
2909
|
-
if (bindI18n && i18n)
|
|
2910
|
-
bindI18n.split(" ").forEach(function(e) {
|
|
2911
|
-
return i18n.off(e, boundReset);
|
|
2912
|
-
});
|
|
2913
|
-
if (bindI18nStore && i18n)
|
|
2914
|
-
bindI18nStore.split(" ").forEach(function(e) {
|
|
2915
|
-
return i18n.store.off(e, boundReset);
|
|
2916
|
-
});
|
|
2917
|
-
};
|
|
2918
|
-
}, [i18n, namespaces.join()]);
|
|
2919
|
-
var isInitial = useRef(true);
|
|
2920
|
-
useEffect(function() {
|
|
2921
|
-
if (isMounted.current && !isInitial.current) {
|
|
2922
|
-
setT(getT);
|
|
2923
|
-
}
|
|
2924
|
-
isInitial.current = false;
|
|
2925
|
-
}, [i18n]);
|
|
2926
|
-
var ret = [t2, i18n, ready];
|
|
2927
|
-
ret.t = t2;
|
|
2928
|
-
ret.i18n = i18n;
|
|
2929
|
-
ret.ready = ready;
|
|
2930
|
-
if (ready)
|
|
2931
|
-
return ret;
|
|
2932
|
-
if (!ready && !useSuspense)
|
|
2933
|
-
return ret;
|
|
2934
|
-
throw new Promise(function(resolve) {
|
|
2935
|
-
loadNamespaces(i18n, namespaces, function() {
|
|
2936
|
-
resolve();
|
|
2937
|
-
});
|
|
2938
|
-
});
|
|
2939
|
-
}
|
|
2940
|
-
function _typeof$1(obj) {
|
|
2941
|
-
"@babel/helpers - typeof";
|
|
2942
|
-
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
|
2943
|
-
_typeof$1 = function _typeof2(obj2) {
|
|
2944
|
-
return typeof obj2;
|
|
2945
|
-
};
|
|
2946
|
-
} else {
|
|
2947
|
-
_typeof$1 = function _typeof2(obj2) {
|
|
2948
|
-
return obj2 && typeof Symbol === "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
|
2949
|
-
};
|
|
2950
|
-
}
|
|
2951
|
-
return _typeof$1(obj);
|
|
2952
|
-
}
|
|
2953
|
-
var arr$1 = [];
|
|
2954
|
-
var each$1 = arr$1.forEach;
|
|
2955
|
-
var slice$1 = arr$1.slice;
|
|
2956
|
-
function defaults$1(obj) {
|
|
2957
|
-
each$1.call(slice$1.call(arguments, 1), function(source) {
|
|
2958
|
-
if (source) {
|
|
2959
|
-
for (var prop in source) {
|
|
2960
|
-
if (obj[prop] === void 0)
|
|
2961
|
-
obj[prop] = source[prop];
|
|
2962
|
-
}
|
|
2963
|
-
}
|
|
2964
|
-
});
|
|
2965
|
-
return obj;
|
|
2966
|
-
}
|
|
2967
|
-
function hasXMLHttpRequest() {
|
|
2968
|
-
return typeof XMLHttpRequest === "function" || (typeof XMLHttpRequest === "undefined" ? "undefined" : _typeof$1(XMLHttpRequest)) === "object";
|
|
2969
|
-
}
|
|
2970
|
-
function isPromise(maybePromise) {
|
|
2971
|
-
return !!maybePromise && typeof maybePromise.then === "function";
|
|
2972
|
-
}
|
|
2973
|
-
function makePromise(maybePromise) {
|
|
2974
|
-
if (isPromise(maybePromise)) {
|
|
2975
|
-
return maybePromise;
|
|
2976
|
-
}
|
|
2977
|
-
return Promise.resolve(maybePromise);
|
|
2978
|
-
}
|
|
2979
|
-
var getFetch$1 = { exports: {} };
|
|
2980
|
-
var browserPonyfill = { exports: {} };
|
|
2981
|
-
(function(module, exports) {
|
|
2982
|
-
var global2 = typeof self !== "undefined" ? self : commonjsGlobal;
|
|
2983
|
-
var __self__ = function() {
|
|
2984
|
-
function F() {
|
|
2985
|
-
this.fetch = false;
|
|
2986
|
-
this.DOMException = global2.DOMException;
|
|
2987
|
-
}
|
|
2988
|
-
F.prototype = global2;
|
|
2989
|
-
return new F();
|
|
2990
|
-
}();
|
|
2991
|
-
(function(self2) {
|
|
2992
|
-
(function(exports2) {
|
|
2993
|
-
var support = {
|
|
2994
|
-
searchParams: "URLSearchParams" in self2,
|
|
2995
|
-
iterable: "Symbol" in self2 && "iterator" in Symbol,
|
|
2996
|
-
blob: "FileReader" in self2 && "Blob" in self2 && function() {
|
|
2997
|
-
try {
|
|
2998
|
-
new Blob();
|
|
2999
|
-
return true;
|
|
3000
|
-
} catch (e) {
|
|
3001
|
-
return false;
|
|
3002
|
-
}
|
|
3003
|
-
}(),
|
|
3004
|
-
formData: "FormData" in self2,
|
|
3005
|
-
arrayBuffer: "ArrayBuffer" in self2
|
|
3006
|
-
};
|
|
3007
|
-
function isDataView(obj) {
|
|
3008
|
-
return obj && DataView.prototype.isPrototypeOf(obj);
|
|
3009
|
-
}
|
|
3010
|
-
if (support.arrayBuffer) {
|
|
3011
|
-
var viewClasses = [
|
|
3012
|
-
"[object Int8Array]",
|
|
3013
|
-
"[object Uint8Array]",
|
|
3014
|
-
"[object Uint8ClampedArray]",
|
|
3015
|
-
"[object Int16Array]",
|
|
3016
|
-
"[object Uint16Array]",
|
|
3017
|
-
"[object Int32Array]",
|
|
3018
|
-
"[object Uint32Array]",
|
|
3019
|
-
"[object Float32Array]",
|
|
3020
|
-
"[object Float64Array]"
|
|
3021
|
-
];
|
|
3022
|
-
var isArrayBufferView = ArrayBuffer.isView || function(obj) {
|
|
3023
|
-
return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1;
|
|
3024
|
-
};
|
|
3025
|
-
}
|
|
3026
|
-
function normalizeName(name) {
|
|
3027
|
-
if (typeof name !== "string") {
|
|
3028
|
-
name = String(name);
|
|
3029
|
-
}
|
|
3030
|
-
if (/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(name)) {
|
|
3031
|
-
throw new TypeError("Invalid character in header field name");
|
|
3032
|
-
}
|
|
3033
|
-
return name.toLowerCase();
|
|
3034
|
-
}
|
|
3035
|
-
function normalizeValue(value) {
|
|
3036
|
-
if (typeof value !== "string") {
|
|
3037
|
-
value = String(value);
|
|
3038
|
-
}
|
|
3039
|
-
return value;
|
|
3040
|
-
}
|
|
3041
|
-
function iteratorFor(items) {
|
|
3042
|
-
var iterator = {
|
|
3043
|
-
next: function() {
|
|
3044
|
-
var value = items.shift();
|
|
3045
|
-
return { done: value === void 0, value };
|
|
3046
|
-
}
|
|
3047
|
-
};
|
|
3048
|
-
if (support.iterable) {
|
|
3049
|
-
iterator[Symbol.iterator] = function() {
|
|
3050
|
-
return iterator;
|
|
3051
|
-
};
|
|
3052
|
-
}
|
|
3053
|
-
return iterator;
|
|
3054
|
-
}
|
|
3055
|
-
function Headers(headers) {
|
|
3056
|
-
this.map = {};
|
|
3057
|
-
if (headers instanceof Headers) {
|
|
3058
|
-
headers.forEach(function(value, name) {
|
|
3059
|
-
this.append(name, value);
|
|
3060
|
-
}, this);
|
|
3061
|
-
} else if (Array.isArray(headers)) {
|
|
3062
|
-
headers.forEach(function(header) {
|
|
3063
|
-
this.append(header[0], header[1]);
|
|
3064
|
-
}, this);
|
|
3065
|
-
} else if (headers) {
|
|
3066
|
-
Object.getOwnPropertyNames(headers).forEach(function(name) {
|
|
3067
|
-
this.append(name, headers[name]);
|
|
3068
|
-
}, this);
|
|
3069
|
-
}
|
|
3070
|
-
}
|
|
3071
|
-
Headers.prototype.append = function(name, value) {
|
|
3072
|
-
name = normalizeName(name);
|
|
3073
|
-
value = normalizeValue(value);
|
|
3074
|
-
var oldValue = this.map[name];
|
|
3075
|
-
this.map[name] = oldValue ? oldValue + ", " + value : value;
|
|
3076
|
-
};
|
|
3077
|
-
Headers.prototype["delete"] = function(name) {
|
|
3078
|
-
delete this.map[normalizeName(name)];
|
|
3079
|
-
};
|
|
3080
|
-
Headers.prototype.get = function(name) {
|
|
3081
|
-
name = normalizeName(name);
|
|
3082
|
-
return this.has(name) ? this.map[name] : null;
|
|
3083
|
-
};
|
|
3084
|
-
Headers.prototype.has = function(name) {
|
|
3085
|
-
return this.map.hasOwnProperty(normalizeName(name));
|
|
3086
|
-
};
|
|
3087
|
-
Headers.prototype.set = function(name, value) {
|
|
3088
|
-
this.map[normalizeName(name)] = normalizeValue(value);
|
|
3089
|
-
};
|
|
3090
|
-
Headers.prototype.forEach = function(callback, thisArg) {
|
|
3091
|
-
for (var name in this.map) {
|
|
3092
|
-
if (this.map.hasOwnProperty(name)) {
|
|
3093
|
-
callback.call(thisArg, this.map[name], name, this);
|
|
3094
|
-
}
|
|
3095
|
-
}
|
|
3096
|
-
};
|
|
3097
|
-
Headers.prototype.keys = function() {
|
|
3098
|
-
var items = [];
|
|
3099
|
-
this.forEach(function(value, name) {
|
|
3100
|
-
items.push(name);
|
|
3101
|
-
});
|
|
3102
|
-
return iteratorFor(items);
|
|
3103
|
-
};
|
|
3104
|
-
Headers.prototype.values = function() {
|
|
3105
|
-
var items = [];
|
|
3106
|
-
this.forEach(function(value) {
|
|
3107
|
-
items.push(value);
|
|
3108
|
-
});
|
|
3109
|
-
return iteratorFor(items);
|
|
3110
|
-
};
|
|
3111
|
-
Headers.prototype.entries = function() {
|
|
3112
|
-
var items = [];
|
|
3113
|
-
this.forEach(function(value, name) {
|
|
3114
|
-
items.push([name, value]);
|
|
3115
|
-
});
|
|
3116
|
-
return iteratorFor(items);
|
|
3117
|
-
};
|
|
3118
|
-
if (support.iterable) {
|
|
3119
|
-
Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
|
|
3120
|
-
}
|
|
3121
|
-
function consumed(body) {
|
|
3122
|
-
if (body.bodyUsed) {
|
|
3123
|
-
return Promise.reject(new TypeError("Already read"));
|
|
3124
|
-
}
|
|
3125
|
-
body.bodyUsed = true;
|
|
3126
|
-
}
|
|
3127
|
-
function fileReaderReady(reader) {
|
|
3128
|
-
return new Promise(function(resolve, reject) {
|
|
3129
|
-
reader.onload = function() {
|
|
3130
|
-
resolve(reader.result);
|
|
3131
|
-
};
|
|
3132
|
-
reader.onerror = function() {
|
|
3133
|
-
reject(reader.error);
|
|
3134
|
-
};
|
|
3135
|
-
});
|
|
3136
|
-
}
|
|
3137
|
-
function readBlobAsArrayBuffer(blob) {
|
|
3138
|
-
var reader = new FileReader();
|
|
3139
|
-
var promise = fileReaderReady(reader);
|
|
3140
|
-
reader.readAsArrayBuffer(blob);
|
|
3141
|
-
return promise;
|
|
3142
|
-
}
|
|
3143
|
-
function readBlobAsText(blob) {
|
|
3144
|
-
var reader = new FileReader();
|
|
3145
|
-
var promise = fileReaderReady(reader);
|
|
3146
|
-
reader.readAsText(blob);
|
|
3147
|
-
return promise;
|
|
3148
|
-
}
|
|
3149
|
-
function readArrayBufferAsText(buf) {
|
|
3150
|
-
var view = new Uint8Array(buf);
|
|
3151
|
-
var chars = new Array(view.length);
|
|
3152
|
-
for (var i2 = 0; i2 < view.length; i2++) {
|
|
3153
|
-
chars[i2] = String.fromCharCode(view[i2]);
|
|
3154
|
-
}
|
|
3155
|
-
return chars.join("");
|
|
3156
|
-
}
|
|
3157
|
-
function bufferClone(buf) {
|
|
3158
|
-
if (buf.slice) {
|
|
3159
|
-
return buf.slice(0);
|
|
3160
|
-
} else {
|
|
3161
|
-
var view = new Uint8Array(buf.byteLength);
|
|
3162
|
-
view.set(new Uint8Array(buf));
|
|
3163
|
-
return view.buffer;
|
|
3164
|
-
}
|
|
3165
|
-
}
|
|
3166
|
-
function Body() {
|
|
3167
|
-
this.bodyUsed = false;
|
|
3168
|
-
this._initBody = function(body) {
|
|
3169
|
-
this._bodyInit = body;
|
|
3170
|
-
if (!body) {
|
|
3171
|
-
this._bodyText = "";
|
|
3172
|
-
} else if (typeof body === "string") {
|
|
3173
|
-
this._bodyText = body;
|
|
3174
|
-
} else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
|
|
3175
|
-
this._bodyBlob = body;
|
|
3176
|
-
} else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
|
|
3177
|
-
this._bodyFormData = body;
|
|
3178
|
-
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
|
|
3179
|
-
this._bodyText = body.toString();
|
|
3180
|
-
} else if (support.arrayBuffer && support.blob && isDataView(body)) {
|
|
3181
|
-
this._bodyArrayBuffer = bufferClone(body.buffer);
|
|
3182
|
-
this._bodyInit = new Blob([this._bodyArrayBuffer]);
|
|
3183
|
-
} else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
|
|
3184
|
-
this._bodyArrayBuffer = bufferClone(body);
|
|
3185
|
-
} else {
|
|
3186
|
-
this._bodyText = body = Object.prototype.toString.call(body);
|
|
3187
|
-
}
|
|
3188
|
-
if (!this.headers.get("content-type")) {
|
|
3189
|
-
if (typeof body === "string") {
|
|
3190
|
-
this.headers.set("content-type", "text/plain;charset=UTF-8");
|
|
3191
|
-
} else if (this._bodyBlob && this._bodyBlob.type) {
|
|
3192
|
-
this.headers.set("content-type", this._bodyBlob.type);
|
|
3193
|
-
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
|
|
3194
|
-
this.headers.set("content-type", "application/x-www-form-urlencoded;charset=UTF-8");
|
|
3195
|
-
}
|
|
3196
|
-
}
|
|
3197
|
-
};
|
|
3198
|
-
if (support.blob) {
|
|
3199
|
-
this.blob = function() {
|
|
3200
|
-
var rejected = consumed(this);
|
|
3201
|
-
if (rejected) {
|
|
3202
|
-
return rejected;
|
|
3203
|
-
}
|
|
3204
|
-
if (this._bodyBlob) {
|
|
3205
|
-
return Promise.resolve(this._bodyBlob);
|
|
3206
|
-
} else if (this._bodyArrayBuffer) {
|
|
3207
|
-
return Promise.resolve(new Blob([this._bodyArrayBuffer]));
|
|
3208
|
-
} else if (this._bodyFormData) {
|
|
3209
|
-
throw new Error("could not read FormData body as blob");
|
|
3210
|
-
} else {
|
|
3211
|
-
return Promise.resolve(new Blob([this._bodyText]));
|
|
3212
|
-
}
|
|
3213
|
-
};
|
|
3214
|
-
this.arrayBuffer = function() {
|
|
3215
|
-
if (this._bodyArrayBuffer) {
|
|
3216
|
-
return consumed(this) || Promise.resolve(this._bodyArrayBuffer);
|
|
3217
|
-
} else {
|
|
3218
|
-
return this.blob().then(readBlobAsArrayBuffer);
|
|
3219
|
-
}
|
|
3220
|
-
};
|
|
3221
|
-
}
|
|
3222
|
-
this.text = function() {
|
|
3223
|
-
var rejected = consumed(this);
|
|
3224
|
-
if (rejected) {
|
|
3225
|
-
return rejected;
|
|
3226
|
-
}
|
|
3227
|
-
if (this._bodyBlob) {
|
|
3228
|
-
return readBlobAsText(this._bodyBlob);
|
|
3229
|
-
} else if (this._bodyArrayBuffer) {
|
|
3230
|
-
return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer));
|
|
3231
|
-
} else if (this._bodyFormData) {
|
|
3232
|
-
throw new Error("could not read FormData body as text");
|
|
3233
|
-
} else {
|
|
3234
|
-
return Promise.resolve(this._bodyText);
|
|
3235
|
-
}
|
|
3236
|
-
};
|
|
3237
|
-
if (support.formData) {
|
|
3238
|
-
this.formData = function() {
|
|
3239
|
-
return this.text().then(decode);
|
|
3240
|
-
};
|
|
3241
|
-
}
|
|
3242
|
-
this.json = function() {
|
|
3243
|
-
return this.text().then(JSON.parse);
|
|
3244
|
-
};
|
|
3245
|
-
return this;
|
|
3246
|
-
}
|
|
3247
|
-
var methods = ["DELETE", "GET", "HEAD", "OPTIONS", "POST", "PUT"];
|
|
3248
|
-
function normalizeMethod(method) {
|
|
3249
|
-
var upcased = method.toUpperCase();
|
|
3250
|
-
return methods.indexOf(upcased) > -1 ? upcased : method;
|
|
3251
|
-
}
|
|
3252
|
-
function Request(input, options) {
|
|
3253
|
-
options = options || {};
|
|
3254
|
-
var body = options.body;
|
|
3255
|
-
if (input instanceof Request) {
|
|
3256
|
-
if (input.bodyUsed) {
|
|
3257
|
-
throw new TypeError("Already read");
|
|
3258
|
-
}
|
|
3259
|
-
this.url = input.url;
|
|
3260
|
-
this.credentials = input.credentials;
|
|
3261
|
-
if (!options.headers) {
|
|
3262
|
-
this.headers = new Headers(input.headers);
|
|
3263
|
-
}
|
|
3264
|
-
this.method = input.method;
|
|
3265
|
-
this.mode = input.mode;
|
|
3266
|
-
this.signal = input.signal;
|
|
3267
|
-
if (!body && input._bodyInit != null) {
|
|
3268
|
-
body = input._bodyInit;
|
|
3269
|
-
input.bodyUsed = true;
|
|
3270
|
-
}
|
|
3271
|
-
} else {
|
|
3272
|
-
this.url = String(input);
|
|
3273
|
-
}
|
|
3274
|
-
this.credentials = options.credentials || this.credentials || "same-origin";
|
|
3275
|
-
if (options.headers || !this.headers) {
|
|
3276
|
-
this.headers = new Headers(options.headers);
|
|
3277
|
-
}
|
|
3278
|
-
this.method = normalizeMethod(options.method || this.method || "GET");
|
|
3279
|
-
this.mode = options.mode || this.mode || null;
|
|
3280
|
-
this.signal = options.signal || this.signal;
|
|
3281
|
-
this.referrer = null;
|
|
3282
|
-
if ((this.method === "GET" || this.method === "HEAD") && body) {
|
|
3283
|
-
throw new TypeError("Body not allowed for GET or HEAD requests");
|
|
3284
|
-
}
|
|
3285
|
-
this._initBody(body);
|
|
3286
|
-
}
|
|
3287
|
-
Request.prototype.clone = function() {
|
|
3288
|
-
return new Request(this, { body: this._bodyInit });
|
|
3289
|
-
};
|
|
3290
|
-
function decode(body) {
|
|
3291
|
-
var form = new FormData();
|
|
3292
|
-
body.trim().split("&").forEach(function(bytes) {
|
|
3293
|
-
if (bytes) {
|
|
3294
|
-
var split = bytes.split("=");
|
|
3295
|
-
var name = split.shift().replace(/\+/g, " ");
|
|
3296
|
-
var value = split.join("=").replace(/\+/g, " ");
|
|
3297
|
-
form.append(decodeURIComponent(name), decodeURIComponent(value));
|
|
3298
|
-
}
|
|
3299
|
-
});
|
|
3300
|
-
return form;
|
|
3301
|
-
}
|
|
3302
|
-
function parseHeaders(rawHeaders) {
|
|
3303
|
-
var headers = new Headers();
|
|
3304
|
-
var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, " ");
|
|
3305
|
-
preProcessedHeaders.split(/\r?\n/).forEach(function(line) {
|
|
3306
|
-
var parts = line.split(":");
|
|
3307
|
-
var key = parts.shift().trim();
|
|
3308
|
-
if (key) {
|
|
3309
|
-
var value = parts.join(":").trim();
|
|
3310
|
-
headers.append(key, value);
|
|
3311
|
-
}
|
|
3312
|
-
});
|
|
3313
|
-
return headers;
|
|
3314
|
-
}
|
|
3315
|
-
Body.call(Request.prototype);
|
|
3316
|
-
function Response(bodyInit, options) {
|
|
3317
|
-
if (!options) {
|
|
3318
|
-
options = {};
|
|
3319
|
-
}
|
|
3320
|
-
this.type = "default";
|
|
3321
|
-
this.status = options.status === void 0 ? 200 : options.status;
|
|
3322
|
-
this.ok = this.status >= 200 && this.status < 300;
|
|
3323
|
-
this.statusText = "statusText" in options ? options.statusText : "OK";
|
|
3324
|
-
this.headers = new Headers(options.headers);
|
|
3325
|
-
this.url = options.url || "";
|
|
3326
|
-
this._initBody(bodyInit);
|
|
3327
|
-
}
|
|
3328
|
-
Body.call(Response.prototype);
|
|
3329
|
-
Response.prototype.clone = function() {
|
|
3330
|
-
return new Response(this._bodyInit, {
|
|
3331
|
-
status: this.status,
|
|
3332
|
-
statusText: this.statusText,
|
|
3333
|
-
headers: new Headers(this.headers),
|
|
3334
|
-
url: this.url
|
|
3335
|
-
});
|
|
3336
|
-
};
|
|
3337
|
-
Response.error = function() {
|
|
3338
|
-
var response = new Response(null, { status: 0, statusText: "" });
|
|
3339
|
-
response.type = "error";
|
|
3340
|
-
return response;
|
|
3341
|
-
};
|
|
3342
|
-
var redirectStatuses = [301, 302, 303, 307, 308];
|
|
3343
|
-
Response.redirect = function(url, status) {
|
|
3344
|
-
if (redirectStatuses.indexOf(status) === -1) {
|
|
3345
|
-
throw new RangeError("Invalid status code");
|
|
3346
|
-
}
|
|
3347
|
-
return new Response(null, { status, headers: { location: url } });
|
|
3348
|
-
};
|
|
3349
|
-
exports2.DOMException = self2.DOMException;
|
|
3350
|
-
try {
|
|
3351
|
-
new exports2.DOMException();
|
|
3352
|
-
} catch (err) {
|
|
3353
|
-
exports2.DOMException = function(message, name) {
|
|
3354
|
-
this.message = message;
|
|
3355
|
-
this.name = name;
|
|
3356
|
-
var error2 = Error(message);
|
|
3357
|
-
this.stack = error2.stack;
|
|
3358
|
-
};
|
|
3359
|
-
exports2.DOMException.prototype = Object.create(Error.prototype);
|
|
3360
|
-
exports2.DOMException.prototype.constructor = exports2.DOMException;
|
|
3361
|
-
}
|
|
3362
|
-
function fetch2(input, init2) {
|
|
3363
|
-
return new Promise(function(resolve, reject) {
|
|
3364
|
-
var request3 = new Request(input, init2);
|
|
3365
|
-
if (request3.signal && request3.signal.aborted) {
|
|
3366
|
-
return reject(new exports2.DOMException("Aborted", "AbortError"));
|
|
3367
|
-
}
|
|
3368
|
-
var xhr = new XMLHttpRequest();
|
|
3369
|
-
function abortXhr() {
|
|
3370
|
-
xhr.abort();
|
|
3371
|
-
}
|
|
3372
|
-
xhr.onload = function() {
|
|
3373
|
-
var options = {
|
|
3374
|
-
status: xhr.status,
|
|
3375
|
-
statusText: xhr.statusText,
|
|
3376
|
-
headers: parseHeaders(xhr.getAllResponseHeaders() || "")
|
|
3377
|
-
};
|
|
3378
|
-
options.url = "responseURL" in xhr ? xhr.responseURL : options.headers.get("X-Request-URL");
|
|
3379
|
-
var body = "response" in xhr ? xhr.response : xhr.responseText;
|
|
3380
|
-
resolve(new Response(body, options));
|
|
3381
|
-
};
|
|
3382
|
-
xhr.onerror = function() {
|
|
3383
|
-
reject(new TypeError("Network request failed"));
|
|
3384
|
-
};
|
|
3385
|
-
xhr.ontimeout = function() {
|
|
3386
|
-
reject(new TypeError("Network request failed"));
|
|
3387
|
-
};
|
|
3388
|
-
xhr.onabort = function() {
|
|
3389
|
-
reject(new exports2.DOMException("Aborted", "AbortError"));
|
|
3390
|
-
};
|
|
3391
|
-
xhr.open(request3.method, request3.url, true);
|
|
3392
|
-
if (request3.credentials === "include") {
|
|
3393
|
-
xhr.withCredentials = true;
|
|
3394
|
-
} else if (request3.credentials === "omit") {
|
|
3395
|
-
xhr.withCredentials = false;
|
|
3396
|
-
}
|
|
3397
|
-
if ("responseType" in xhr && support.blob) {
|
|
3398
|
-
xhr.responseType = "blob";
|
|
3399
|
-
}
|
|
3400
|
-
request3.headers.forEach(function(value, name) {
|
|
3401
|
-
xhr.setRequestHeader(name, value);
|
|
3402
|
-
});
|
|
3403
|
-
if (request3.signal) {
|
|
3404
|
-
request3.signal.addEventListener("abort", abortXhr);
|
|
3405
|
-
xhr.onreadystatechange = function() {
|
|
3406
|
-
if (xhr.readyState === 4) {
|
|
3407
|
-
request3.signal.removeEventListener("abort", abortXhr);
|
|
3408
|
-
}
|
|
3409
|
-
};
|
|
3410
|
-
}
|
|
3411
|
-
xhr.send(typeof request3._bodyInit === "undefined" ? null : request3._bodyInit);
|
|
3412
|
-
});
|
|
3413
|
-
}
|
|
3414
|
-
fetch2.polyfill = true;
|
|
3415
|
-
if (!self2.fetch) {
|
|
3416
|
-
self2.fetch = fetch2;
|
|
3417
|
-
self2.Headers = Headers;
|
|
3418
|
-
self2.Request = Request;
|
|
3419
|
-
self2.Response = Response;
|
|
3420
|
-
}
|
|
3421
|
-
exports2.Headers = Headers;
|
|
3422
|
-
exports2.Request = Request;
|
|
3423
|
-
exports2.Response = Response;
|
|
3424
|
-
exports2.fetch = fetch2;
|
|
3425
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
3426
|
-
return exports2;
|
|
3427
|
-
})({});
|
|
3428
|
-
})(__self__);
|
|
3429
|
-
__self__.fetch.ponyfill = true;
|
|
3430
|
-
delete __self__.fetch.polyfill;
|
|
3431
|
-
var ctx = __self__;
|
|
3432
|
-
exports = ctx.fetch;
|
|
3433
|
-
exports.default = ctx.fetch;
|
|
3434
|
-
exports.fetch = ctx.fetch;
|
|
3435
|
-
exports.Headers = ctx.Headers;
|
|
3436
|
-
exports.Request = ctx.Request;
|
|
3437
|
-
exports.Response = ctx.Response;
|
|
3438
|
-
module.exports = exports;
|
|
3439
|
-
})(browserPonyfill, browserPonyfill.exports);
|
|
3440
|
-
(function(module, exports) {
|
|
3441
|
-
var fetchApi2;
|
|
3442
|
-
if (typeof fetch === "function") {
|
|
3443
|
-
if (typeof commonjsGlobal !== "undefined" && commonjsGlobal.fetch) {
|
|
3444
|
-
fetchApi2 = commonjsGlobal.fetch;
|
|
3445
|
-
} else if (typeof window !== "undefined" && window.fetch) {
|
|
3446
|
-
fetchApi2 = window.fetch;
|
|
3447
|
-
}
|
|
3448
|
-
}
|
|
3449
|
-
if (typeof commonjsRequire !== "undefined" && (typeof window === "undefined" || typeof window.document === "undefined")) {
|
|
3450
|
-
var f = fetchApi2 || browserPonyfill.exports;
|
|
3451
|
-
if (f.default)
|
|
3452
|
-
f = f.default;
|
|
3453
|
-
exports.default = f;
|
|
3454
|
-
module.exports = exports.default;
|
|
3455
|
-
}
|
|
3456
|
-
})(getFetch$1, getFetch$1.exports);
|
|
3457
|
-
var getFetch = getFetch$1.exports;
|
|
3458
|
-
var fetchNode = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ _mergeNamespaces({
|
|
3459
|
-
__proto__: null,
|
|
3460
|
-
[Symbol.toStringTag]: "Module",
|
|
3461
|
-
"default": getFetch
|
|
3462
|
-
}, [getFetch$1.exports]));
|
|
3463
|
-
function _typeof(obj) {
|
|
3464
|
-
"@babel/helpers - typeof";
|
|
3465
|
-
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
|
3466
|
-
_typeof = function _typeof2(obj2) {
|
|
3467
|
-
return typeof obj2;
|
|
3468
|
-
};
|
|
3469
|
-
} else {
|
|
3470
|
-
_typeof = function _typeof2(obj2) {
|
|
3471
|
-
return obj2 && typeof Symbol === "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
|
3472
|
-
};
|
|
3473
|
-
}
|
|
3474
|
-
return _typeof(obj);
|
|
3475
|
-
}
|
|
3476
|
-
var fetchApi;
|
|
3477
|
-
if (typeof fetch === "function") {
|
|
3478
|
-
if (typeof global !== "undefined" && global.fetch) {
|
|
3479
|
-
fetchApi = global.fetch;
|
|
3480
|
-
} else if (typeof window !== "undefined" && window.fetch) {
|
|
3481
|
-
fetchApi = window.fetch;
|
|
3482
|
-
}
|
|
3483
|
-
}
|
|
3484
|
-
var XmlHttpRequestApi;
|
|
3485
|
-
if (hasXMLHttpRequest) {
|
|
3486
|
-
if (typeof global !== "undefined" && global.XMLHttpRequest) {
|
|
3487
|
-
XmlHttpRequestApi = global.XMLHttpRequest;
|
|
3488
|
-
} else if (typeof window !== "undefined" && window.XMLHttpRequest) {
|
|
3489
|
-
XmlHttpRequestApi = window.XMLHttpRequest;
|
|
3490
|
-
}
|
|
3491
|
-
}
|
|
3492
|
-
var ActiveXObjectApi;
|
|
3493
|
-
if (typeof ActiveXObject === "function") {
|
|
3494
|
-
if (typeof global !== "undefined" && global.ActiveXObject) {
|
|
3495
|
-
ActiveXObjectApi = global.ActiveXObject;
|
|
3496
|
-
} else if (typeof window !== "undefined" && window.ActiveXObject) {
|
|
3497
|
-
ActiveXObjectApi = window.ActiveXObject;
|
|
3498
|
-
}
|
|
3499
|
-
}
|
|
3500
|
-
if (!fetchApi && fetchNode && !XmlHttpRequestApi && !ActiveXObjectApi)
|
|
3501
|
-
fetchApi = getFetch || fetchNode;
|
|
3502
|
-
if (typeof fetchApi !== "function")
|
|
3503
|
-
fetchApi = void 0;
|
|
3504
|
-
var addQueryString = function addQueryString2(url, params) {
|
|
3505
|
-
if (params && _typeof(params) === "object") {
|
|
3506
|
-
var queryString = "";
|
|
3507
|
-
for (var paramName in params) {
|
|
3508
|
-
queryString += "&" + encodeURIComponent(paramName) + "=" + encodeURIComponent(params[paramName]);
|
|
3509
|
-
}
|
|
3510
|
-
if (!queryString)
|
|
3511
|
-
return url;
|
|
3512
|
-
url = url + (url.indexOf("?") !== -1 ? "&" : "?") + queryString.slice(1);
|
|
3513
|
-
}
|
|
3514
|
-
return url;
|
|
3515
|
-
};
|
|
3516
|
-
var requestWithFetch = function requestWithFetch2(options, url, payload, callback) {
|
|
3517
|
-
if (options.queryStringParams) {
|
|
3518
|
-
url = addQueryString(url, options.queryStringParams);
|
|
3519
|
-
}
|
|
3520
|
-
var headers = defaults$1({}, typeof options.customHeaders === "function" ? options.customHeaders() : options.customHeaders);
|
|
3521
|
-
if (payload)
|
|
3522
|
-
headers["Content-Type"] = "application/json";
|
|
3523
|
-
fetchApi(url, defaults$1({
|
|
3524
|
-
method: payload ? "POST" : "GET",
|
|
3525
|
-
body: payload ? options.stringify(payload) : void 0,
|
|
3526
|
-
headers
|
|
3527
|
-
}, typeof options.requestOptions === "function" ? options.requestOptions(payload) : options.requestOptions)).then(function(response) {
|
|
3528
|
-
if (!response.ok)
|
|
3529
|
-
return callback(response.statusText || "Error", {
|
|
3530
|
-
status: response.status
|
|
3531
|
-
});
|
|
3532
|
-
response.text().then(function(data) {
|
|
3533
|
-
callback(null, {
|
|
3534
|
-
status: response.status,
|
|
3535
|
-
data
|
|
3536
|
-
});
|
|
3537
|
-
}).catch(callback);
|
|
3538
|
-
}).catch(callback);
|
|
3539
|
-
};
|
|
3540
|
-
var requestWithXmlHttpRequest = function requestWithXmlHttpRequest2(options, url, payload, callback) {
|
|
3541
|
-
if (payload && _typeof(payload) === "object") {
|
|
3542
|
-
payload = addQueryString("", payload).slice(1);
|
|
3543
|
-
}
|
|
3544
|
-
if (options.queryStringParams) {
|
|
3545
|
-
url = addQueryString(url, options.queryStringParams);
|
|
3546
|
-
}
|
|
3547
|
-
try {
|
|
3548
|
-
var x;
|
|
3549
|
-
if (XmlHttpRequestApi) {
|
|
3550
|
-
x = new XmlHttpRequestApi();
|
|
3551
|
-
} else {
|
|
3552
|
-
x = new ActiveXObjectApi("MSXML2.XMLHTTP.3.0");
|
|
3553
|
-
}
|
|
3554
|
-
x.open(payload ? "POST" : "GET", url, 1);
|
|
3555
|
-
if (!options.crossDomain) {
|
|
3556
|
-
x.setRequestHeader("X-Requested-With", "XMLHttpRequest");
|
|
3557
|
-
}
|
|
3558
|
-
x.withCredentials = !!options.withCredentials;
|
|
3559
|
-
if (payload) {
|
|
3560
|
-
x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
3561
|
-
}
|
|
3562
|
-
if (x.overrideMimeType) {
|
|
3563
|
-
x.overrideMimeType("application/json");
|
|
3564
|
-
}
|
|
3565
|
-
var h = options.customHeaders;
|
|
3566
|
-
h = typeof h === "function" ? h() : h;
|
|
3567
|
-
if (h) {
|
|
3568
|
-
for (var i2 in h) {
|
|
3569
|
-
x.setRequestHeader(i2, h[i2]);
|
|
3570
|
-
}
|
|
3571
|
-
}
|
|
3572
|
-
x.onreadystatechange = function() {
|
|
3573
|
-
x.readyState > 3 && callback(x.status >= 400 ? x.statusText : null, {
|
|
3574
|
-
status: x.status,
|
|
3575
|
-
data: x.responseText
|
|
3576
|
-
});
|
|
3577
|
-
};
|
|
3578
|
-
x.send(payload);
|
|
3579
|
-
} catch (e) {
|
|
3580
|
-
console && console.log(e);
|
|
3581
|
-
}
|
|
3582
|
-
};
|
|
3583
|
-
var request = function request2(options, url, payload, callback) {
|
|
3584
|
-
if (typeof payload === "function") {
|
|
3585
|
-
callback = payload;
|
|
3586
|
-
payload = void 0;
|
|
3587
|
-
}
|
|
3588
|
-
callback = callback || function() {
|
|
3589
|
-
};
|
|
3590
|
-
if (fetchApi) {
|
|
3591
|
-
return requestWithFetch(options, url, payload, callback);
|
|
3592
|
-
}
|
|
3593
|
-
if (hasXMLHttpRequest || typeof ActiveXObject === "function") {
|
|
3594
|
-
return requestWithXmlHttpRequest(options, url, payload, callback);
|
|
3595
|
-
}
|
|
3596
|
-
};
|
|
3597
|
-
function _classCallCheck(instance, Constructor) {
|
|
3598
|
-
if (!(instance instanceof Constructor)) {
|
|
3599
|
-
throw new TypeError("Cannot call a class as a function");
|
|
3600
|
-
}
|
|
3601
|
-
}
|
|
3602
|
-
function _defineProperties(target, props) {
|
|
3603
|
-
for (var i2 = 0; i2 < props.length; i2++) {
|
|
3604
|
-
var descriptor = props[i2];
|
|
3605
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
3606
|
-
descriptor.configurable = true;
|
|
3607
|
-
if ("value" in descriptor)
|
|
3608
|
-
descriptor.writable = true;
|
|
3609
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
3610
|
-
}
|
|
3611
|
-
}
|
|
3612
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
3613
|
-
if (protoProps)
|
|
3614
|
-
_defineProperties(Constructor.prototype, protoProps);
|
|
3615
|
-
if (staticProps)
|
|
3616
|
-
_defineProperties(Constructor, staticProps);
|
|
3617
|
-
return Constructor;
|
|
3618
|
-
}
|
|
3619
|
-
function _defineProperty(obj, key, value) {
|
|
3620
|
-
if (key in obj) {
|
|
3621
|
-
Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
|
|
3622
|
-
} else {
|
|
3623
|
-
obj[key] = value;
|
|
3624
|
-
}
|
|
3625
|
-
return obj;
|
|
3626
|
-
}
|
|
3627
|
-
var getDefaults$1 = function getDefaults() {
|
|
3628
|
-
return {
|
|
3629
|
-
loadPath: "/locales/{{lng}}/{{ns}}.json",
|
|
3630
|
-
addPath: "/locales/add/{{lng}}/{{ns}}",
|
|
3631
|
-
allowMultiLoading: false,
|
|
3632
|
-
parse: function parse(data) {
|
|
3633
|
-
return JSON.parse(data);
|
|
3634
|
-
},
|
|
3635
|
-
stringify: JSON.stringify,
|
|
3636
|
-
parsePayload: function parsePayload(namespace, key, fallbackValue) {
|
|
3637
|
-
return _defineProperty({}, key, fallbackValue || "");
|
|
3638
|
-
},
|
|
3639
|
-
request,
|
|
3640
|
-
reloadInterval: typeof window !== "undefined" ? false : 60 * 60 * 1e3,
|
|
3641
|
-
customHeaders: {},
|
|
3642
|
-
queryStringParams: {},
|
|
3643
|
-
crossDomain: false,
|
|
3644
|
-
withCredentials: false,
|
|
3645
|
-
overrideMimeType: false,
|
|
3646
|
-
requestOptions: {
|
|
3647
|
-
mode: "cors",
|
|
3648
|
-
credentials: "same-origin",
|
|
3649
|
-
cache: "default"
|
|
3650
|
-
}
|
|
3651
|
-
};
|
|
3652
|
-
};
|
|
3653
|
-
var Backend = function() {
|
|
3654
|
-
function Backend2(services) {
|
|
3655
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
3656
|
-
var allOptions = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
3657
|
-
_classCallCheck(this, Backend2);
|
|
3658
|
-
this.services = services;
|
|
3659
|
-
this.options = options;
|
|
3660
|
-
this.allOptions = allOptions;
|
|
3661
|
-
this.type = "backend";
|
|
3662
|
-
this.init(services, options, allOptions);
|
|
3663
|
-
}
|
|
3664
|
-
_createClass(Backend2, [{
|
|
3665
|
-
key: "init",
|
|
3666
|
-
value: function init2(services) {
|
|
3667
|
-
var _this = this;
|
|
3668
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
3669
|
-
var allOptions = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
3670
|
-
this.services = services;
|
|
3671
|
-
this.options = defaults$1(options, this.options || {}, getDefaults$1());
|
|
3672
|
-
this.allOptions = allOptions;
|
|
3673
|
-
if (this.services && this.options.reloadInterval) {
|
|
3674
|
-
setInterval(function() {
|
|
3675
|
-
return _this.reload();
|
|
3676
|
-
}, this.options.reloadInterval);
|
|
3677
|
-
}
|
|
3678
|
-
}
|
|
3679
|
-
}, {
|
|
3680
|
-
key: "readMulti",
|
|
3681
|
-
value: function readMulti(languages, namespaces, callback) {
|
|
3682
|
-
this._readAny(languages, languages, namespaces, namespaces, callback);
|
|
3683
|
-
}
|
|
3684
|
-
}, {
|
|
3685
|
-
key: "read",
|
|
3686
|
-
value: function read2(language, namespace, callback) {
|
|
3687
|
-
this._readAny([language], language, [namespace], namespace, callback);
|
|
3688
|
-
}
|
|
3689
|
-
}, {
|
|
3690
|
-
key: "_readAny",
|
|
3691
|
-
value: function _readAny(languages, loadUrlLanguages, namespaces, loadUrlNamespaces, callback) {
|
|
3692
|
-
var _this2 = this;
|
|
3693
|
-
var loadPath = this.options.loadPath;
|
|
3694
|
-
if (typeof this.options.loadPath === "function") {
|
|
3695
|
-
loadPath = this.options.loadPath(languages, namespaces);
|
|
3696
|
-
}
|
|
3697
|
-
loadPath = makePromise(loadPath);
|
|
3698
|
-
loadPath.then(function(resolvedLoadPath) {
|
|
3699
|
-
var url = _this2.services.interpolator.interpolate(resolvedLoadPath, {
|
|
3700
|
-
lng: languages.join("+"),
|
|
3701
|
-
ns: namespaces.join("+")
|
|
3702
|
-
});
|
|
3703
|
-
_this2.loadUrl(url, callback, loadUrlLanguages, loadUrlNamespaces);
|
|
3704
|
-
});
|
|
3705
|
-
}
|
|
3706
|
-
}, {
|
|
3707
|
-
key: "loadUrl",
|
|
3708
|
-
value: function loadUrl(url, callback, languages, namespaces) {
|
|
3709
|
-
var _this3 = this;
|
|
3710
|
-
this.options.request(this.options, url, void 0, function(err, res) {
|
|
3711
|
-
if (res && (res.status >= 500 && res.status < 600 || !res.status))
|
|
3712
|
-
return callback("failed loading " + url + "; status code: " + res.status, true);
|
|
3713
|
-
if (res && res.status >= 400 && res.status < 500)
|
|
3714
|
-
return callback("failed loading " + url + "; status code: " + res.status, false);
|
|
3715
|
-
if (!res && err && err.message && err.message.indexOf("Failed to fetch") > -1)
|
|
3716
|
-
return callback("failed loading " + url + ": " + err.message, true);
|
|
3717
|
-
if (err)
|
|
3718
|
-
return callback(err, false);
|
|
3719
|
-
var ret, parseErr;
|
|
3720
|
-
try {
|
|
3721
|
-
if (typeof res.data === "string") {
|
|
3722
|
-
ret = _this3.options.parse(res.data, languages, namespaces);
|
|
3723
|
-
} else {
|
|
3724
|
-
ret = res.data;
|
|
3725
|
-
}
|
|
3726
|
-
} catch (e) {
|
|
3727
|
-
parseErr = "failed parsing " + url + " to json";
|
|
3728
|
-
}
|
|
3729
|
-
if (parseErr)
|
|
3730
|
-
return callback(parseErr, false);
|
|
3731
|
-
callback(null, ret);
|
|
3732
|
-
});
|
|
3733
|
-
}
|
|
3734
|
-
}, {
|
|
3735
|
-
key: "create",
|
|
3736
|
-
value: function create2(languages, namespace, key, fallbackValue, callback) {
|
|
3737
|
-
var _this4 = this;
|
|
3738
|
-
if (!this.options.addPath)
|
|
3739
|
-
return;
|
|
3740
|
-
if (typeof languages === "string")
|
|
3741
|
-
languages = [languages];
|
|
3742
|
-
var payload = this.options.parsePayload(namespace, key, fallbackValue);
|
|
3743
|
-
var finished = 0;
|
|
3744
|
-
var dataArray = [];
|
|
3745
|
-
var resArray = [];
|
|
3746
|
-
languages.forEach(function(lng) {
|
|
3747
|
-
var addPath = _this4.options.addPath;
|
|
3748
|
-
if (typeof _this4.options.addPath === "function") {
|
|
3749
|
-
addPath = _this4.options.addPath(lng, namespace);
|
|
3750
|
-
}
|
|
3751
|
-
var url = _this4.services.interpolator.interpolate(addPath, {
|
|
3752
|
-
lng,
|
|
3753
|
-
ns: namespace
|
|
3754
|
-
});
|
|
3755
|
-
_this4.options.request(_this4.options, url, payload, function(data, res) {
|
|
3756
|
-
finished += 1;
|
|
3757
|
-
dataArray.push(data);
|
|
3758
|
-
resArray.push(res);
|
|
3759
|
-
if (finished === languages.length) {
|
|
3760
|
-
if (callback)
|
|
3761
|
-
callback(dataArray, resArray);
|
|
3762
|
-
}
|
|
3763
|
-
});
|
|
3764
|
-
});
|
|
3765
|
-
}
|
|
3766
|
-
}, {
|
|
3767
|
-
key: "reload",
|
|
3768
|
-
value: function reload() {
|
|
3769
|
-
var _this5 = this;
|
|
3770
|
-
var _this$services = this.services, backendConnector = _this$services.backendConnector, languageUtils = _this$services.languageUtils, logger = _this$services.logger;
|
|
3771
|
-
var currentLanguage = backendConnector.language;
|
|
3772
|
-
if (currentLanguage && currentLanguage.toLowerCase() === "cimode")
|
|
3773
|
-
return;
|
|
3774
|
-
var toLoad = [];
|
|
3775
|
-
var append = function append2(lng) {
|
|
3776
|
-
var lngs = languageUtils.toResolveHierarchy(lng);
|
|
3777
|
-
lngs.forEach(function(l) {
|
|
3778
|
-
if (toLoad.indexOf(l) < 0)
|
|
3779
|
-
toLoad.push(l);
|
|
3780
|
-
});
|
|
3781
|
-
};
|
|
3782
|
-
append(currentLanguage);
|
|
3783
|
-
if (this.allOptions.preload)
|
|
3784
|
-
this.allOptions.preload.forEach(function(l) {
|
|
3785
|
-
return append(l);
|
|
3786
|
-
});
|
|
3787
|
-
toLoad.forEach(function(lng) {
|
|
3788
|
-
_this5.allOptions.ns.forEach(function(ns) {
|
|
3789
|
-
backendConnector.read(lng, ns, "read", null, null, function(err, data) {
|
|
3790
|
-
if (err)
|
|
3791
|
-
logger.warn("loading namespace ".concat(ns, " for language ").concat(lng, " failed"), err);
|
|
3792
|
-
if (!err && data)
|
|
3793
|
-
logger.log("loaded namespace ".concat(ns, " for language ").concat(lng), data);
|
|
3794
|
-
backendConnector.loaded("".concat(lng, "|").concat(ns), err, data);
|
|
3795
|
-
});
|
|
3796
|
-
});
|
|
3797
|
-
});
|
|
3798
|
-
}
|
|
3799
|
-
}]);
|
|
3800
|
-
return Backend2;
|
|
3801
|
-
}();
|
|
3802
|
-
Backend.type = "backend";
|
|
3803
|
-
var arr = [];
|
|
3804
|
-
var each = arr.forEach;
|
|
3805
|
-
var slice = arr.slice;
|
|
3806
|
-
function defaults(obj) {
|
|
3807
|
-
each.call(slice.call(arguments, 1), function(source) {
|
|
3808
|
-
if (source) {
|
|
3809
|
-
for (var prop in source) {
|
|
3810
|
-
if (obj[prop] === void 0)
|
|
3811
|
-
obj[prop] = source[prop];
|
|
3812
|
-
}
|
|
3813
|
-
}
|
|
3814
|
-
});
|
|
3815
|
-
return obj;
|
|
3816
|
-
}
|
|
3817
|
-
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
3818
|
-
var serializeCookie = function serializeCookie2(name, val, options) {
|
|
3819
|
-
var opt = options || {};
|
|
3820
|
-
opt.path = opt.path || "/";
|
|
3821
|
-
var value = encodeURIComponent(val);
|
|
3822
|
-
var str = name + "=" + value;
|
|
3823
|
-
if (opt.maxAge > 0) {
|
|
3824
|
-
var maxAge = opt.maxAge - 0;
|
|
3825
|
-
if (isNaN(maxAge))
|
|
3826
|
-
throw new Error("maxAge should be a Number");
|
|
3827
|
-
str += "; Max-Age=" + Math.floor(maxAge);
|
|
3828
|
-
}
|
|
3829
|
-
if (opt.domain) {
|
|
3830
|
-
if (!fieldContentRegExp.test(opt.domain)) {
|
|
3831
|
-
throw new TypeError("option domain is invalid");
|
|
3832
|
-
}
|
|
3833
|
-
str += "; Domain=" + opt.domain;
|
|
3834
|
-
}
|
|
3835
|
-
if (opt.path) {
|
|
3836
|
-
if (!fieldContentRegExp.test(opt.path)) {
|
|
3837
|
-
throw new TypeError("option path is invalid");
|
|
3838
|
-
}
|
|
3839
|
-
str += "; Path=" + opt.path;
|
|
3840
|
-
}
|
|
3841
|
-
if (opt.expires) {
|
|
3842
|
-
if (typeof opt.expires.toUTCString !== "function") {
|
|
3843
|
-
throw new TypeError("option expires is invalid");
|
|
3844
|
-
}
|
|
3845
|
-
str += "; Expires=" + opt.expires.toUTCString();
|
|
3846
|
-
}
|
|
3847
|
-
if (opt.httpOnly)
|
|
3848
|
-
str += "; HttpOnly";
|
|
3849
|
-
if (opt.secure)
|
|
3850
|
-
str += "; Secure";
|
|
3851
|
-
if (opt.sameSite) {
|
|
3852
|
-
var sameSite = typeof opt.sameSite === "string" ? opt.sameSite.toLowerCase() : opt.sameSite;
|
|
3853
|
-
switch (sameSite) {
|
|
3854
|
-
case true:
|
|
3855
|
-
str += "; SameSite=Strict";
|
|
3856
|
-
break;
|
|
3857
|
-
case "lax":
|
|
3858
|
-
str += "; SameSite=Lax";
|
|
3859
|
-
break;
|
|
3860
|
-
case "strict":
|
|
3861
|
-
str += "; SameSite=Strict";
|
|
3862
|
-
break;
|
|
3863
|
-
case "none":
|
|
3864
|
-
str += "; SameSite=None";
|
|
3865
|
-
break;
|
|
3866
|
-
default:
|
|
3867
|
-
throw new TypeError("option sameSite is invalid");
|
|
3868
|
-
}
|
|
3869
|
-
}
|
|
3870
|
-
return str;
|
|
3871
|
-
};
|
|
3872
|
-
var cookie = {
|
|
3873
|
-
create: function create(name, value, minutes, domain) {
|
|
3874
|
-
var cookieOptions = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : {
|
|
3875
|
-
path: "/",
|
|
3876
|
-
sameSite: "strict"
|
|
3877
|
-
};
|
|
3878
|
-
if (minutes) {
|
|
3879
|
-
cookieOptions.expires = new Date();
|
|
3880
|
-
cookieOptions.expires.setTime(cookieOptions.expires.getTime() + minutes * 60 * 1e3);
|
|
3881
|
-
}
|
|
3882
|
-
if (domain)
|
|
3883
|
-
cookieOptions.domain = domain;
|
|
3884
|
-
document.cookie = serializeCookie(name, encodeURIComponent(value), cookieOptions);
|
|
3885
|
-
},
|
|
3886
|
-
read: function read(name) {
|
|
3887
|
-
var nameEQ = name + "=";
|
|
3888
|
-
var ca = document.cookie.split(";");
|
|
3889
|
-
for (var i2 = 0; i2 < ca.length; i2++) {
|
|
3890
|
-
var c2 = ca[i2];
|
|
3891
|
-
while (c2.charAt(0) === " ") {
|
|
3892
|
-
c2 = c2.substring(1, c2.length);
|
|
3893
|
-
}
|
|
3894
|
-
if (c2.indexOf(nameEQ) === 0)
|
|
3895
|
-
return c2.substring(nameEQ.length, c2.length);
|
|
3896
|
-
}
|
|
3897
|
-
return null;
|
|
3898
|
-
},
|
|
3899
|
-
remove: function remove2(name) {
|
|
3900
|
-
this.create(name, "", -1);
|
|
3901
|
-
}
|
|
3902
|
-
};
|
|
3903
|
-
var cookie$1 = {
|
|
3904
|
-
name: "cookie",
|
|
3905
|
-
lookup: function lookup(options) {
|
|
3906
|
-
var found;
|
|
3907
|
-
if (options.lookupCookie && typeof document !== "undefined") {
|
|
3908
|
-
var c2 = cookie.read(options.lookupCookie);
|
|
3909
|
-
if (c2)
|
|
3910
|
-
found = c2;
|
|
3911
|
-
}
|
|
3912
|
-
return found;
|
|
3913
|
-
},
|
|
3914
|
-
cacheUserLanguage: function cacheUserLanguage(lng, options) {
|
|
3915
|
-
if (options.lookupCookie && typeof document !== "undefined") {
|
|
3916
|
-
cookie.create(options.lookupCookie, lng, options.cookieMinutes, options.cookieDomain, options.cookieOptions);
|
|
3917
|
-
}
|
|
3918
|
-
}
|
|
3919
|
-
};
|
|
3920
|
-
var querystring = {
|
|
3921
|
-
name: "querystring",
|
|
3922
|
-
lookup: function lookup2(options) {
|
|
3923
|
-
var found;
|
|
3924
|
-
if (typeof window !== "undefined") {
|
|
3925
|
-
var query = window.location.search.substring(1);
|
|
3926
|
-
var params = query.split("&");
|
|
3927
|
-
for (var i2 = 0; i2 < params.length; i2++) {
|
|
3928
|
-
var pos = params[i2].indexOf("=");
|
|
3929
|
-
if (pos > 0) {
|
|
3930
|
-
var key = params[i2].substring(0, pos);
|
|
3931
|
-
if (key === options.lookupQuerystring) {
|
|
3932
|
-
found = params[i2].substring(pos + 1);
|
|
3933
|
-
}
|
|
3934
|
-
}
|
|
3935
|
-
}
|
|
3936
|
-
}
|
|
3937
|
-
return found;
|
|
3938
|
-
}
|
|
3939
|
-
};
|
|
3940
|
-
var hasLocalStorageSupport;
|
|
3941
|
-
try {
|
|
3942
|
-
hasLocalStorageSupport = window !== "undefined" && window.localStorage !== null;
|
|
3943
|
-
var testKey = "i18next.translate.boo";
|
|
3944
|
-
window.localStorage.setItem(testKey, "foo");
|
|
3945
|
-
window.localStorage.removeItem(testKey);
|
|
3946
|
-
} catch (e) {
|
|
3947
|
-
hasLocalStorageSupport = false;
|
|
3948
|
-
}
|
|
3949
|
-
var localStorage = {
|
|
3950
|
-
name: "localStorage",
|
|
3951
|
-
lookup: function lookup3(options) {
|
|
3952
|
-
var found;
|
|
3953
|
-
if (options.lookupLocalStorage && hasLocalStorageSupport) {
|
|
3954
|
-
var lng = window.localStorage.getItem(options.lookupLocalStorage);
|
|
3955
|
-
if (lng)
|
|
3956
|
-
found = lng;
|
|
3957
|
-
}
|
|
3958
|
-
return found;
|
|
3959
|
-
},
|
|
3960
|
-
cacheUserLanguage: function cacheUserLanguage2(lng, options) {
|
|
3961
|
-
if (options.lookupLocalStorage && hasLocalStorageSupport) {
|
|
3962
|
-
window.localStorage.setItem(options.lookupLocalStorage, lng);
|
|
3963
|
-
}
|
|
3964
|
-
}
|
|
3965
|
-
};
|
|
3966
|
-
var hasSessionStorageSupport;
|
|
3967
|
-
try {
|
|
3968
|
-
hasSessionStorageSupport = window !== "undefined" && window.sessionStorage !== null;
|
|
3969
|
-
var testKey$1 = "i18next.translate.boo";
|
|
3970
|
-
window.sessionStorage.setItem(testKey$1, "foo");
|
|
3971
|
-
window.sessionStorage.removeItem(testKey$1);
|
|
3972
|
-
} catch (e) {
|
|
3973
|
-
hasSessionStorageSupport = false;
|
|
3974
|
-
}
|
|
3975
|
-
var sessionStorage = {
|
|
3976
|
-
name: "sessionStorage",
|
|
3977
|
-
lookup: function lookup4(options) {
|
|
3978
|
-
var found;
|
|
3979
|
-
if (options.lookupsessionStorage && hasSessionStorageSupport) {
|
|
3980
|
-
var lng = window.sessionStorage.getItem(options.lookupsessionStorage);
|
|
3981
|
-
if (lng)
|
|
3982
|
-
found = lng;
|
|
3983
|
-
}
|
|
3984
|
-
return found;
|
|
3985
|
-
},
|
|
3986
|
-
cacheUserLanguage: function cacheUserLanguage3(lng, options) {
|
|
3987
|
-
if (options.lookupsessionStorage && hasSessionStorageSupport) {
|
|
3988
|
-
window.sessionStorage.setItem(options.lookupsessionStorage, lng);
|
|
3989
|
-
}
|
|
3990
|
-
}
|
|
3991
|
-
};
|
|
3992
|
-
var navigator$1 = {
|
|
3993
|
-
name: "navigator",
|
|
3994
|
-
lookup: function lookup5(options) {
|
|
3995
|
-
var found = [];
|
|
3996
|
-
if (typeof navigator !== "undefined") {
|
|
3997
|
-
if (navigator.languages) {
|
|
3998
|
-
for (var i2 = 0; i2 < navigator.languages.length; i2++) {
|
|
3999
|
-
found.push(navigator.languages[i2]);
|
|
4000
|
-
}
|
|
4001
|
-
}
|
|
4002
|
-
if (navigator.userLanguage) {
|
|
4003
|
-
found.push(navigator.userLanguage);
|
|
4004
|
-
}
|
|
4005
|
-
if (navigator.language) {
|
|
4006
|
-
found.push(navigator.language);
|
|
4007
|
-
}
|
|
4008
|
-
}
|
|
4009
|
-
return found.length > 0 ? found : void 0;
|
|
4010
|
-
}
|
|
4011
|
-
};
|
|
4012
|
-
var htmlTag = {
|
|
4013
|
-
name: "htmlTag",
|
|
4014
|
-
lookup: function lookup6(options) {
|
|
4015
|
-
var found;
|
|
4016
|
-
var htmlTag2 = options.htmlTag || (typeof document !== "undefined" ? document.documentElement : null);
|
|
4017
|
-
if (htmlTag2 && typeof htmlTag2.getAttribute === "function") {
|
|
4018
|
-
found = htmlTag2.getAttribute("lang");
|
|
4019
|
-
}
|
|
4020
|
-
return found;
|
|
4021
|
-
}
|
|
4022
|
-
};
|
|
4023
|
-
var path = {
|
|
4024
|
-
name: "path",
|
|
4025
|
-
lookup: function lookup7(options) {
|
|
4026
|
-
var found;
|
|
4027
|
-
if (typeof window !== "undefined") {
|
|
4028
|
-
var language = window.location.pathname.match(/\/([a-zA-Z-]*)/g);
|
|
4029
|
-
if (language instanceof Array) {
|
|
4030
|
-
if (typeof options.lookupFromPathIndex === "number") {
|
|
4031
|
-
if (typeof language[options.lookupFromPathIndex] !== "string") {
|
|
4032
|
-
return void 0;
|
|
4033
|
-
}
|
|
4034
|
-
found = language[options.lookupFromPathIndex].replace("/", "");
|
|
4035
|
-
} else {
|
|
4036
|
-
found = language[0].replace("/", "");
|
|
4037
|
-
}
|
|
4038
|
-
}
|
|
4039
|
-
}
|
|
4040
|
-
return found;
|
|
4041
|
-
}
|
|
4042
|
-
};
|
|
4043
|
-
var subdomain = {
|
|
4044
|
-
name: "subdomain",
|
|
4045
|
-
lookup: function lookup8(options) {
|
|
4046
|
-
var found;
|
|
4047
|
-
if (typeof window !== "undefined") {
|
|
4048
|
-
var language = window.location.href.match(/(?:http[s]*\:\/\/)*(.*?)\.(?=[^\/]*\..{2,5})/gi);
|
|
4049
|
-
if (language instanceof Array) {
|
|
4050
|
-
if (typeof options.lookupFromSubdomainIndex === "number") {
|
|
4051
|
-
found = language[options.lookupFromSubdomainIndex].replace("http://", "").replace("https://", "").replace(".", "");
|
|
4052
|
-
} else {
|
|
4053
|
-
found = language[0].replace("http://", "").replace("https://", "").replace(".", "");
|
|
4054
|
-
}
|
|
4055
|
-
}
|
|
4056
|
-
}
|
|
4057
|
-
return found;
|
|
4058
|
-
}
|
|
4059
|
-
};
|
|
4060
|
-
function getDefaults2() {
|
|
4061
|
-
return {
|
|
4062
|
-
order: ["querystring", "cookie", "localStorage", "sessionStorage", "navigator", "htmlTag"],
|
|
4063
|
-
lookupQuerystring: "lng",
|
|
4064
|
-
lookupCookie: "i18next",
|
|
4065
|
-
lookupLocalStorage: "i18nextLng",
|
|
4066
|
-
caches: ["localStorage"],
|
|
4067
|
-
excludeCacheFor: ["cimode"]
|
|
4068
|
-
};
|
|
4069
|
-
}
|
|
4070
|
-
var Browser = /* @__PURE__ */ function() {
|
|
4071
|
-
function Browser2(services) {
|
|
4072
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
4073
|
-
_classCallCheck$1(this, Browser2);
|
|
4074
|
-
this.type = "languageDetector";
|
|
4075
|
-
this.detectors = {};
|
|
4076
|
-
this.init(services, options);
|
|
4077
|
-
}
|
|
4078
|
-
_createClass$1(Browser2, [{
|
|
4079
|
-
key: "init",
|
|
4080
|
-
value: function init2(services) {
|
|
4081
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
4082
|
-
var i18nOptions = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
4083
|
-
this.services = services;
|
|
4084
|
-
this.options = defaults(options, this.options || {}, getDefaults2());
|
|
4085
|
-
if (this.options.lookupFromUrlIndex)
|
|
4086
|
-
this.options.lookupFromPathIndex = this.options.lookupFromUrlIndex;
|
|
4087
|
-
this.i18nOptions = i18nOptions;
|
|
4088
|
-
this.addDetector(cookie$1);
|
|
4089
|
-
this.addDetector(querystring);
|
|
4090
|
-
this.addDetector(localStorage);
|
|
4091
|
-
this.addDetector(sessionStorage);
|
|
4092
|
-
this.addDetector(navigator$1);
|
|
4093
|
-
this.addDetector(htmlTag);
|
|
4094
|
-
this.addDetector(path);
|
|
4095
|
-
this.addDetector(subdomain);
|
|
4096
|
-
}
|
|
4097
|
-
}, {
|
|
4098
|
-
key: "addDetector",
|
|
4099
|
-
value: function addDetector(detector) {
|
|
4100
|
-
this.detectors[detector.name] = detector;
|
|
4101
|
-
}
|
|
4102
|
-
}, {
|
|
4103
|
-
key: "detect",
|
|
4104
|
-
value: function detect(detectionOrder) {
|
|
4105
|
-
var _this = this;
|
|
4106
|
-
if (!detectionOrder)
|
|
4107
|
-
detectionOrder = this.options.order;
|
|
4108
|
-
var detected = [];
|
|
4109
|
-
detectionOrder.forEach(function(detectorName) {
|
|
4110
|
-
if (_this.detectors[detectorName]) {
|
|
4111
|
-
var lookup9 = _this.detectors[detectorName].lookup(_this.options);
|
|
4112
|
-
if (lookup9 && typeof lookup9 === "string")
|
|
4113
|
-
lookup9 = [lookup9];
|
|
4114
|
-
if (lookup9)
|
|
4115
|
-
detected = detected.concat(lookup9);
|
|
4116
|
-
}
|
|
4117
|
-
});
|
|
4118
|
-
if (this.services.languageUtils.getBestMatchFromCodes)
|
|
4119
|
-
return detected;
|
|
4120
|
-
return detected.length > 0 ? detected[0] : null;
|
|
4121
|
-
}
|
|
4122
|
-
}, {
|
|
4123
|
-
key: "cacheUserLanguage",
|
|
4124
|
-
value: function cacheUserLanguage4(lng, caches) {
|
|
4125
|
-
var _this2 = this;
|
|
4126
|
-
if (!caches)
|
|
4127
|
-
caches = this.options.caches;
|
|
4128
|
-
if (!caches)
|
|
4129
|
-
return;
|
|
4130
|
-
if (this.options.excludeCacheFor && this.options.excludeCacheFor.indexOf(lng) > -1)
|
|
4131
|
-
return;
|
|
4132
|
-
caches.forEach(function(cacheName) {
|
|
4133
|
-
if (_this2.detectors[cacheName])
|
|
4134
|
-
_this2.detectors[cacheName].cacheUserLanguage(lng, _this2.options);
|
|
4135
|
-
});
|
|
4136
|
-
}
|
|
4137
|
-
}]);
|
|
4138
|
-
return Browser2;
|
|
4139
|
-
}();
|
|
4140
|
-
Browser.type = "languageDetector";
|
|
4141
|
-
function localize(_a) {
|
|
4142
|
-
var _b = _a, {
|
|
4143
|
-
detectorConfig,
|
|
4144
|
-
translationPath,
|
|
4145
|
-
customDetectors
|
|
4146
|
-
} = _b, i18nConfig = __objRest(_b, [
|
|
4147
|
-
"detectorConfig",
|
|
4148
|
-
"translationPath",
|
|
4149
|
-
"customDetectors"
|
|
4150
|
-
]);
|
|
4151
|
-
const languageDetector = new Browser();
|
|
4152
|
-
const hashRouterQuerystringDetector = {
|
|
4153
|
-
name: "hashRouterQuerystringDetector",
|
|
4154
|
-
lookup: (options) => {
|
|
4155
|
-
try {
|
|
4156
|
-
const lookupQuerystring = options && options.lookupQuerystring || "lang";
|
|
4157
|
-
const regex = new RegExp(`[?&]${lookupQuerystring}(=([^&#]*)|&|#|$)`);
|
|
4158
|
-
const results = regex.exec(window.location.href);
|
|
4159
|
-
if (results && results[2]) {
|
|
4160
|
-
const lang = decodeURIComponent(results[2].replace(/\+/g, " "));
|
|
4161
|
-
if (lang) {
|
|
4162
|
-
return lang;
|
|
4163
|
-
}
|
|
4164
|
-
}
|
|
4165
|
-
} catch (err) {
|
|
4166
|
-
console.error(err);
|
|
4167
|
-
}
|
|
4168
|
-
return void 0;
|
|
4169
|
-
}
|
|
4170
|
-
};
|
|
4171
|
-
languageDetector.addDetector(hashRouterQuerystringDetector);
|
|
4172
|
-
if (Array.isArray(customDetectors)) {
|
|
4173
|
-
customDetectors.forEach((customDetector) => {
|
|
4174
|
-
languageDetector.addDetector(customDetector);
|
|
4175
|
-
});
|
|
4176
|
-
}
|
|
4177
|
-
const detectionObject = detectorConfig || {
|
|
4178
|
-
order: [
|
|
4179
|
-
"querystring",
|
|
4180
|
-
"hashRouterQuerystringDetector",
|
|
4181
|
-
"cookie",
|
|
4182
|
-
"localStorage"
|
|
4183
|
-
],
|
|
4184
|
-
lookupQuerystring: "lang",
|
|
4185
|
-
lookupCookie: "lang",
|
|
4186
|
-
lookupSessionStorage: "lang",
|
|
4187
|
-
lookupLocalStorage: "lang",
|
|
4188
|
-
caches: ["localStorage", "cookie"],
|
|
4189
|
-
excludeCacheFor: ["cimode"],
|
|
4190
|
-
cookieOptions: { path: "/", sameSite: "strict" }
|
|
4191
|
-
};
|
|
4192
|
-
const transPath = translationPath || "/locales/{{lng}}/{{ns}}.json";
|
|
4193
|
-
const mergedConfig = __spreadValues({
|
|
4194
|
-
fallbackLng: "en-US",
|
|
4195
|
-
debug: true,
|
|
4196
|
-
keySeparator: ".",
|
|
4197
|
-
backend: {
|
|
4198
|
-
loadPath: transPath
|
|
4199
|
-
},
|
|
4200
|
-
interpolation: {
|
|
4201
|
-
escapeValue: false
|
|
4202
|
-
},
|
|
4203
|
-
detection: detectionObject
|
|
4204
|
-
}, i18nConfig);
|
|
4205
|
-
return i18next.use(Backend).use(languageDetector).use(initReactI18next).init(mergedConfig);
|
|
4206
|
-
}
|
|
4207
|
-
function SpsLanguage(_c) {
|
|
4208
|
-
var _d = _c, { children } = _d, rest = __objRest(_d, ["children"]);
|
|
4209
|
-
return /* @__PURE__ */ React.createElement(Trans, __spreadValues({}, rest), children);
|
|
4210
|
-
}
|
|
4211
|
-
function useSpsLanguage(ns = "translation", options) {
|
|
4212
|
-
return useTranslation([ns, "design-system"], options);
|
|
4213
|
-
}
|
|
4214
|
-
export { SpsLanguage, localize, useSpsLanguage };
|