@coveo/atomic 3.31.2-pre.112f5b2d65 → 3.31.2-pre.126a57e490
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/atomic/_atomic.esm.js +1 -1
- package/dist/atomic/components/analytics-config.js +299 -235
- package/dist/atomic/components/analytics-config.js.map +1 -1
- package/dist/atomic/components/global/environment.js +1 -1
- package/dist/atomic/{p-f393a585.entry.js → p-1cec9f19.entry.js} +2 -2
- package/dist/atomic/p-5194f64b.js +2 -0
- package/dist/atomic/p-5194f64b.js.map +1 -0
- package/dist/atomic/{p-6ef3f0c3.entry.js → p-8fd558c4.entry.js} +2 -2
- package/dist/atomic/{p-b3b35f61.entry.js → p-f1581341.entry.js} +2 -2
- package/dist/cjs/{analytics-config-8028010e.js → analytics-config-5f89b58d.js} +300 -236
- package/dist/cjs/analytics-config-5f89b58d.js.map +1 -0
- package/dist/cjs/atomic-insight-interface.cjs.entry.js +1 -1
- package/dist/cjs/atomic-recs-interface.cjs.entry.js +1 -1
- package/dist/cjs/atomic-search-interface.cjs.entry.js +1 -1
- package/dist/cjs/version.cjs.js +2 -2
- package/dist/esm/{analytics-config-9520fa9e.js → analytics-config-d9cff4a8.js} +300 -236
- package/dist/esm/analytics-config-d9cff4a8.js.map +1 -0
- package/dist/esm/atomic-insight-interface.entry.js +1 -1
- package/dist/esm/atomic-recs-interface.entry.js +1 -1
- package/dist/esm/atomic-search-interface.entry.js +1 -1
- package/dist/esm/version.js +2 -2
- package/docs/atomic-docs.json +8 -3
- package/package.json +6 -6
- package/dist/atomic/p-8a246bda.js +0 -2
- package/dist/atomic/p-8a246bda.js.map +0 -1
- package/dist/cjs/analytics-config-8028010e.js.map +0 -1
- package/dist/esm/analytics-config-9520fa9e.js.map +0 -1
- /package/dist/atomic/{p-f393a585.entry.js.map → p-1cec9f19.entry.js.map} +0 -0
- /package/dist/atomic/{p-6ef3f0c3.entry.js.map → p-8fd558c4.entry.js.map} +0 -0
- /package/dist/atomic/{p-b3b35f61.entry.js.map → p-f1581341.entry.js.map} +0 -0
|
@@ -161,7 +161,8 @@ const looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
|
|
|
161
161
|
}
|
|
162
162
|
return matched;
|
|
163
163
|
};
|
|
164
|
-
const deepFind = (obj, path
|
|
164
|
+
const deepFind = function (obj, path) {
|
|
165
|
+
let keySeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
|
|
165
166
|
if (!obj) return undefined;
|
|
166
167
|
if (obj[path]) {
|
|
167
168
|
if (!Object.prototype.hasOwnProperty.call(obj, path)) return undefined;
|
|
@@ -211,25 +212,39 @@ const consoleLogger = {
|
|
|
211
212
|
}
|
|
212
213
|
};
|
|
213
214
|
class Logger {
|
|
214
|
-
constructor(concreteLogger
|
|
215
|
+
constructor(concreteLogger) {
|
|
216
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
215
217
|
this.init(concreteLogger, options);
|
|
216
218
|
}
|
|
217
|
-
init(concreteLogger
|
|
219
|
+
init(concreteLogger) {
|
|
220
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
218
221
|
this.prefix = options.prefix || 'i18next:';
|
|
219
222
|
this.logger = concreteLogger || consoleLogger;
|
|
220
223
|
this.options = options;
|
|
221
224
|
this.debug = options.debug;
|
|
222
225
|
}
|
|
223
|
-
log(
|
|
226
|
+
log() {
|
|
227
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
228
|
+
args[_key] = arguments[_key];
|
|
229
|
+
}
|
|
224
230
|
return this.forward(args, 'log', '', true);
|
|
225
231
|
}
|
|
226
|
-
warn(
|
|
232
|
+
warn() {
|
|
233
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
234
|
+
args[_key2] = arguments[_key2];
|
|
235
|
+
}
|
|
227
236
|
return this.forward(args, 'warn', '', true);
|
|
228
237
|
}
|
|
229
|
-
error(
|
|
238
|
+
error() {
|
|
239
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
240
|
+
args[_key3] = arguments[_key3];
|
|
241
|
+
}
|
|
230
242
|
return this.forward(args, 'error', '');
|
|
231
243
|
}
|
|
232
|
-
deprecate(
|
|
244
|
+
deprecate() {
|
|
245
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
246
|
+
args[_key4] = arguments[_key4];
|
|
247
|
+
}
|
|
233
248
|
return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
|
|
234
249
|
}
|
|
235
250
|
forward(args, lvl, prefix, debugOnly) {
|
|
@@ -273,10 +288,14 @@ class EventEmitter {
|
|
|
273
288
|
}
|
|
274
289
|
this.observers[event].delete(listener);
|
|
275
290
|
}
|
|
276
|
-
emit(event
|
|
291
|
+
emit(event) {
|
|
292
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
293
|
+
args[_key - 1] = arguments[_key];
|
|
294
|
+
}
|
|
277
295
|
if (this.observers[event]) {
|
|
278
296
|
const cloned = Array.from(this.observers[event].entries());
|
|
279
|
-
cloned.forEach(
|
|
297
|
+
cloned.forEach(_ref => {
|
|
298
|
+
let [observer, numTimesAdded] = _ref;
|
|
280
299
|
for (let i = 0; i < numTimesAdded; i++) {
|
|
281
300
|
observer(...args);
|
|
282
301
|
}
|
|
@@ -284,7 +303,8 @@ class EventEmitter {
|
|
|
284
303
|
}
|
|
285
304
|
if (this.observers['*']) {
|
|
286
305
|
const cloned = Array.from(this.observers['*'].entries());
|
|
287
|
-
cloned.forEach(
|
|
306
|
+
cloned.forEach(_ref2 => {
|
|
307
|
+
let [observer, numTimesAdded] = _ref2;
|
|
288
308
|
for (let i = 0; i < numTimesAdded; i++) {
|
|
289
309
|
observer.apply(observer, [event, ...args]);
|
|
290
310
|
}
|
|
@@ -294,10 +314,11 @@ class EventEmitter {
|
|
|
294
314
|
}
|
|
295
315
|
|
|
296
316
|
class ResourceStore extends EventEmitter {
|
|
297
|
-
constructor(data
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
317
|
+
constructor(data) {
|
|
318
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
319
|
+
ns: ['translation'],
|
|
320
|
+
defaultNS: 'translation'
|
|
321
|
+
};
|
|
301
322
|
super();
|
|
302
323
|
this.data = data || {};
|
|
303
324
|
this.options = options;
|
|
@@ -319,7 +340,8 @@ class ResourceStore extends EventEmitter {
|
|
|
319
340
|
this.options.ns.splice(index, 1);
|
|
320
341
|
}
|
|
321
342
|
}
|
|
322
|
-
getResource(lng, ns, key
|
|
343
|
+
getResource(lng, ns, key) {
|
|
344
|
+
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
323
345
|
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
324
346
|
const ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
325
347
|
let path;
|
|
@@ -346,9 +368,10 @@ class ResourceStore extends EventEmitter {
|
|
|
346
368
|
if (result || !ignoreJSONStructure || !isString(key)) return result;
|
|
347
369
|
return deepFind(this.data?.[lng]?.[ns], key, keySeparator);
|
|
348
370
|
}
|
|
349
|
-
addResource(lng, ns, key, value
|
|
350
|
-
|
|
351
|
-
|
|
371
|
+
addResource(lng, ns, key, value) {
|
|
372
|
+
let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
|
373
|
+
silent: false
|
|
374
|
+
};
|
|
352
375
|
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
353
376
|
let path = [lng, ns];
|
|
354
377
|
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
@@ -361,9 +384,10 @@ class ResourceStore extends EventEmitter {
|
|
|
361
384
|
setPath(this.data, path, value);
|
|
362
385
|
if (!options.silent) this.emit('added', lng, ns, key, value);
|
|
363
386
|
}
|
|
364
|
-
addResources(lng, ns, resources
|
|
365
|
-
|
|
366
|
-
|
|
387
|
+
addResources(lng, ns, resources) {
|
|
388
|
+
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
389
|
+
silent: false
|
|
390
|
+
};
|
|
367
391
|
for (const m in resources) {
|
|
368
392
|
if (isString(resources[m]) || Array.isArray(resources[m])) this.addResource(lng, ns, m, resources[m], {
|
|
369
393
|
silent: true
|
|
@@ -371,10 +395,11 @@ class ResourceStore extends EventEmitter {
|
|
|
371
395
|
}
|
|
372
396
|
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
373
397
|
}
|
|
374
|
-
addResourceBundle(lng, ns, resources, deep, overwrite
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
398
|
+
addResourceBundle(lng, ns, resources, deep, overwrite) {
|
|
399
|
+
let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {
|
|
400
|
+
silent: false,
|
|
401
|
+
skipCopy: false
|
|
402
|
+
};
|
|
378
403
|
let path = [lng, ns];
|
|
379
404
|
if (lng.indexOf('.') > -1) {
|
|
380
405
|
path = lng.split('.');
|
|
@@ -439,7 +464,8 @@ var postProcessor = {
|
|
|
439
464
|
const checkedLoadedFor = {};
|
|
440
465
|
const shouldHandleAsObject = res => !isString(res) && typeof res !== 'boolean' && typeof res !== 'number';
|
|
441
466
|
class Translator extends EventEmitter {
|
|
442
|
-
constructor(services
|
|
467
|
+
constructor(services) {
|
|
468
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
443
469
|
super();
|
|
444
470
|
copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector', 'i18nFormat', 'utils'], services, this);
|
|
445
471
|
this.options = options;
|
|
@@ -451,23 +477,23 @@ class Translator extends EventEmitter {
|
|
|
451
477
|
changeLanguage(lng) {
|
|
452
478
|
if (lng) this.language = lng;
|
|
453
479
|
}
|
|
454
|
-
exists(key
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
const opt = {
|
|
458
|
-
...o
|
|
480
|
+
exists(key) {
|
|
481
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
482
|
+
interpolation: {}
|
|
459
483
|
};
|
|
460
|
-
if (key == null)
|
|
461
|
-
|
|
484
|
+
if (key == null) {
|
|
485
|
+
return false;
|
|
486
|
+
}
|
|
487
|
+
const resolved = this.resolve(key, options);
|
|
462
488
|
return resolved?.res !== undefined;
|
|
463
489
|
}
|
|
464
|
-
extractFromKey(key,
|
|
465
|
-
let nsSeparator =
|
|
490
|
+
extractFromKey(key, options) {
|
|
491
|
+
let nsSeparator = options.nsSeparator !== undefined ? options.nsSeparator : this.options.nsSeparator;
|
|
466
492
|
if (nsSeparator === undefined) nsSeparator = ':';
|
|
467
|
-
const keySeparator =
|
|
468
|
-
let namespaces =
|
|
493
|
+
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
494
|
+
let namespaces = options.ns || this.options.defaultNS || [];
|
|
469
495
|
const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
|
|
470
|
-
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !
|
|
496
|
+
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
471
497
|
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
472
498
|
const m = key.match(this.interpolator.nestingRegexp);
|
|
473
499
|
if (m && m.length > 0) {
|
|
@@ -485,32 +511,28 @@ class Translator extends EventEmitter {
|
|
|
485
511
|
namespaces: isString(namespaces) ? [namespaces] : namespaces
|
|
486
512
|
};
|
|
487
513
|
}
|
|
488
|
-
translate(keys,
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
} : o;
|
|
492
|
-
if (typeof opt !== 'object' && this.options.overloadTranslationOptionHandler) {
|
|
493
|
-
opt = this.options.overloadTranslationOptionHandler(arguments);
|
|
514
|
+
translate(keys, options, lastKey) {
|
|
515
|
+
if (typeof options !== 'object' && this.options.overloadTranslationOptionHandler) {
|
|
516
|
+
options = this.options.overloadTranslationOptionHandler(arguments);
|
|
494
517
|
}
|
|
495
|
-
if (typeof options === 'object')
|
|
496
|
-
...
|
|
518
|
+
if (typeof options === 'object') options = {
|
|
519
|
+
...options
|
|
497
520
|
};
|
|
498
|
-
if (!
|
|
521
|
+
if (!options) options = {};
|
|
499
522
|
if (keys == null) return '';
|
|
500
523
|
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
501
|
-
const returnDetails =
|
|
502
|
-
const keySeparator =
|
|
524
|
+
const returnDetails = options.returnDetails !== undefined ? options.returnDetails : this.options.returnDetails;
|
|
525
|
+
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
503
526
|
const {
|
|
504
527
|
key,
|
|
505
528
|
namespaces
|
|
506
|
-
} = this.extractFromKey(keys[keys.length - 1],
|
|
529
|
+
} = this.extractFromKey(keys[keys.length - 1], options);
|
|
507
530
|
const namespace = namespaces[namespaces.length - 1];
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
const lng = opt.lng || this.language;
|
|
511
|
-
const appendNamespaceToCIMode = opt.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
531
|
+
const lng = options.lng || this.language;
|
|
532
|
+
const appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
512
533
|
if (lng?.toLowerCase() === 'cimode') {
|
|
513
534
|
if (appendNamespaceToCIMode) {
|
|
535
|
+
const nsSeparator = options.nsSeparator || this.options.nsSeparator;
|
|
514
536
|
if (returnDetails) {
|
|
515
537
|
return {
|
|
516
538
|
res: `${namespace}${nsSeparator}${key}`,
|
|
@@ -518,7 +540,7 @@ class Translator extends EventEmitter {
|
|
|
518
540
|
exactUsedKey: key,
|
|
519
541
|
usedLng: lng,
|
|
520
542
|
usedNS: namespace,
|
|
521
|
-
usedParams: this.getUsedParamsDetails(
|
|
543
|
+
usedParams: this.getUsedParamsDetails(options)
|
|
522
544
|
};
|
|
523
545
|
}
|
|
524
546
|
return `${namespace}${nsSeparator}${key}`;
|
|
@@ -530,26 +552,26 @@ class Translator extends EventEmitter {
|
|
|
530
552
|
exactUsedKey: key,
|
|
531
553
|
usedLng: lng,
|
|
532
554
|
usedNS: namespace,
|
|
533
|
-
usedParams: this.getUsedParamsDetails(
|
|
555
|
+
usedParams: this.getUsedParamsDetails(options)
|
|
534
556
|
};
|
|
535
557
|
}
|
|
536
558
|
return key;
|
|
537
559
|
}
|
|
538
|
-
const resolved = this.resolve(keys,
|
|
560
|
+
const resolved = this.resolve(keys, options);
|
|
539
561
|
let res = resolved?.res;
|
|
540
562
|
const resUsedKey = resolved?.usedKey || key;
|
|
541
563
|
const resExactUsedKey = resolved?.exactUsedKey || key;
|
|
542
564
|
const noObject = ['[object Number]', '[object Function]', '[object RegExp]'];
|
|
543
|
-
const joinArrays =
|
|
565
|
+
const joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays;
|
|
544
566
|
const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
545
|
-
const needsPluralHandling =
|
|
546
|
-
const hasDefaultValue = Translator.hasDefaultValue(
|
|
547
|
-
const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng,
|
|
548
|
-
const defaultValueSuffixOrdinalFallback =
|
|
567
|
+
const needsPluralHandling = options.count !== undefined && !isString(options.count);
|
|
568
|
+
const hasDefaultValue = Translator.hasDefaultValue(options);
|
|
569
|
+
const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : '';
|
|
570
|
+
const defaultValueSuffixOrdinalFallback = options.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, {
|
|
549
571
|
ordinal: false
|
|
550
572
|
}) : '';
|
|
551
|
-
const needsZeroSuffixLookup = needsPluralHandling && !
|
|
552
|
-
const defaultValue = needsZeroSuffixLookup &&
|
|
573
|
+
const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0;
|
|
574
|
+
const defaultValue = needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] || options[`defaultValue${defaultValueSuffix}`] || options[`defaultValue${defaultValueSuffixOrdinalFallback}`] || options.defaultValue;
|
|
553
575
|
let resForObjHndl = res;
|
|
554
576
|
if (handleAsObjectInI18nFormat && !res && hasDefaultValue) {
|
|
555
577
|
resForObjHndl = defaultValue;
|
|
@@ -557,17 +579,17 @@ class Translator extends EventEmitter {
|
|
|
557
579
|
const handleAsObject = shouldHandleAsObject(resForObjHndl);
|
|
558
580
|
const resType = Object.prototype.toString.apply(resForObjHndl);
|
|
559
581
|
if (handleAsObjectInI18nFormat && resForObjHndl && handleAsObject && noObject.indexOf(resType) < 0 && !(isString(joinArrays) && Array.isArray(resForObjHndl))) {
|
|
560
|
-
if (!
|
|
582
|
+
if (!options.returnObjects && !this.options.returnObjects) {
|
|
561
583
|
if (!this.options.returnedObjectHandler) {
|
|
562
584
|
this.logger.warn('accessing an object - but returnObjects options is not enabled!');
|
|
563
585
|
}
|
|
564
586
|
const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, resForObjHndl, {
|
|
565
|
-
...
|
|
587
|
+
...options,
|
|
566
588
|
ns: namespaces
|
|
567
589
|
}) : `key '${key} (${this.language})' returned an object instead of string.`;
|
|
568
590
|
if (returnDetails) {
|
|
569
591
|
resolved.res = r;
|
|
570
|
-
resolved.usedParams = this.getUsedParamsDetails(
|
|
592
|
+
resolved.usedParams = this.getUsedParamsDetails(options);
|
|
571
593
|
return resolved;
|
|
572
594
|
}
|
|
573
595
|
return r;
|
|
@@ -581,7 +603,7 @@ class Translator extends EventEmitter {
|
|
|
581
603
|
const deepKey = `${newKeyToUse}${keySeparator}${m}`;
|
|
582
604
|
if (hasDefaultValue && !res) {
|
|
583
605
|
copy[m] = this.translate(deepKey, {
|
|
584
|
-
...
|
|
606
|
+
...options,
|
|
585
607
|
defaultValue: shouldHandleAsObject(defaultValue) ? defaultValue[m] : undefined,
|
|
586
608
|
...{
|
|
587
609
|
joinArrays: false,
|
|
@@ -590,7 +612,7 @@ class Translator extends EventEmitter {
|
|
|
590
612
|
});
|
|
591
613
|
} else {
|
|
592
614
|
copy[m] = this.translate(deepKey, {
|
|
593
|
-
...
|
|
615
|
+
...options,
|
|
594
616
|
...{
|
|
595
617
|
joinArrays: false,
|
|
596
618
|
ns: namespaces
|
|
@@ -604,7 +626,7 @@ class Translator extends EventEmitter {
|
|
|
604
626
|
}
|
|
605
627
|
} else if (handleAsObjectInI18nFormat && isString(joinArrays) && Array.isArray(res)) {
|
|
606
628
|
res = res.join(joinArrays);
|
|
607
|
-
if (res) res = this.extendTranslation(res, keys,
|
|
629
|
+
if (res) res = this.extendTranslation(res, keys, options, lastKey);
|
|
608
630
|
} else {
|
|
609
631
|
let usedDefault = false;
|
|
610
632
|
let usedKey = false;
|
|
@@ -616,47 +638,47 @@ class Translator extends EventEmitter {
|
|
|
616
638
|
usedKey = true;
|
|
617
639
|
res = key;
|
|
618
640
|
}
|
|
619
|
-
const missingKeyNoValueFallbackToKey =
|
|
641
|
+
const missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
|
|
620
642
|
const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? undefined : res;
|
|
621
643
|
const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
622
644
|
if (usedKey || usedDefault || updateMissing) {
|
|
623
645
|
this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? defaultValue : res);
|
|
624
646
|
if (keySeparator) {
|
|
625
647
|
const fk = this.resolve(key, {
|
|
626
|
-
...
|
|
648
|
+
...options,
|
|
627
649
|
keySeparator: false
|
|
628
650
|
});
|
|
629
651
|
if (fk && fk.res) this.logger.warn('Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.');
|
|
630
652
|
}
|
|
631
653
|
let lngs = [];
|
|
632
|
-
const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng,
|
|
654
|
+
const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
|
|
633
655
|
if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) {
|
|
634
656
|
for (let i = 0; i < fallbackLngs.length; i++) {
|
|
635
657
|
lngs.push(fallbackLngs[i]);
|
|
636
658
|
}
|
|
637
659
|
} else if (this.options.saveMissingTo === 'all') {
|
|
638
|
-
lngs = this.languageUtils.toResolveHierarchy(
|
|
660
|
+
lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
|
|
639
661
|
} else {
|
|
640
|
-
lngs.push(
|
|
662
|
+
lngs.push(options.lng || this.language);
|
|
641
663
|
}
|
|
642
664
|
const send = (l, k, specificDefaultValue) => {
|
|
643
665
|
const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
644
666
|
if (this.options.missingKeyHandler) {
|
|
645
|
-
this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing,
|
|
667
|
+
this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
646
668
|
} else if (this.backendConnector?.saveMissing) {
|
|
647
|
-
this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing,
|
|
669
|
+
this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
648
670
|
}
|
|
649
671
|
this.emit('missingKey', l, namespace, k, res);
|
|
650
672
|
};
|
|
651
673
|
if (this.options.saveMissing) {
|
|
652
674
|
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
653
675
|
lngs.forEach(language => {
|
|
654
|
-
const suffixes = this.pluralResolver.getSuffixes(language,
|
|
655
|
-
if (needsZeroSuffixLookup &&
|
|
676
|
+
const suffixes = this.pluralResolver.getSuffixes(language, options);
|
|
677
|
+
if (needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.indexOf(`${this.options.pluralSeparator}zero`) < 0) {
|
|
656
678
|
suffixes.push(`${this.options.pluralSeparator}zero`);
|
|
657
679
|
}
|
|
658
680
|
suffixes.forEach(suffix => {
|
|
659
|
-
send([language], key + suffix,
|
|
681
|
+
send([language], key + suffix, options[`defaultValue${suffix}`] || defaultValue);
|
|
660
682
|
});
|
|
661
683
|
});
|
|
662
684
|
} else {
|
|
@@ -664,80 +686,83 @@ class Translator extends EventEmitter {
|
|
|
664
686
|
}
|
|
665
687
|
}
|
|
666
688
|
}
|
|
667
|
-
res = this.extendTranslation(res, keys,
|
|
668
|
-
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) {
|
|
669
|
-
res = `${namespace}${nsSeparator}${key}`;
|
|
670
|
-
}
|
|
689
|
+
res = this.extendTranslation(res, keys, options, resolved, lastKey);
|
|
690
|
+
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
|
|
671
691
|
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
|
|
672
|
-
res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}
|
|
692
|
+
res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : undefined);
|
|
673
693
|
}
|
|
674
694
|
}
|
|
675
695
|
if (returnDetails) {
|
|
676
696
|
resolved.res = res;
|
|
677
|
-
resolved.usedParams = this.getUsedParamsDetails(
|
|
697
|
+
resolved.usedParams = this.getUsedParamsDetails(options);
|
|
678
698
|
return resolved;
|
|
679
699
|
}
|
|
680
700
|
return res;
|
|
681
701
|
}
|
|
682
|
-
extendTranslation(res, key,
|
|
702
|
+
extendTranslation(res, key, options, resolved, lastKey) {
|
|
703
|
+
var _this = this;
|
|
683
704
|
if (this.i18nFormat?.parse) {
|
|
684
705
|
res = this.i18nFormat.parse(res, {
|
|
685
706
|
...this.options.interpolation.defaultVariables,
|
|
686
|
-
...
|
|
687
|
-
},
|
|
707
|
+
...options
|
|
708
|
+
}, options.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
|
|
688
709
|
resolved
|
|
689
710
|
});
|
|
690
|
-
} else if (!
|
|
691
|
-
if (
|
|
692
|
-
...
|
|
711
|
+
} else if (!options.skipInterpolation) {
|
|
712
|
+
if (options.interpolation) this.interpolator.init({
|
|
713
|
+
...options,
|
|
693
714
|
...{
|
|
694
715
|
interpolation: {
|
|
695
716
|
...this.options.interpolation,
|
|
696
|
-
...
|
|
717
|
+
...options.interpolation
|
|
697
718
|
}
|
|
698
719
|
}
|
|
699
720
|
});
|
|
700
|
-
const skipOnVariables = isString(res) && (
|
|
721
|
+
const skipOnVariables = isString(res) && (options?.interpolation?.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
701
722
|
let nestBef;
|
|
702
723
|
if (skipOnVariables) {
|
|
703
724
|
const nb = res.match(this.interpolator.nestingRegexp);
|
|
704
725
|
nestBef = nb && nb.length;
|
|
705
726
|
}
|
|
706
|
-
let data =
|
|
727
|
+
let data = options.replace && !isString(options.replace) ? options.replace : options;
|
|
707
728
|
if (this.options.interpolation.defaultVariables) data = {
|
|
708
729
|
...this.options.interpolation.defaultVariables,
|
|
709
730
|
...data
|
|
710
731
|
};
|
|
711
|
-
res = this.interpolator.interpolate(res, data,
|
|
732
|
+
res = this.interpolator.interpolate(res, data, options.lng || this.language || resolved.usedLng, options);
|
|
712
733
|
if (skipOnVariables) {
|
|
713
734
|
const na = res.match(this.interpolator.nestingRegexp);
|
|
714
735
|
const nestAft = na && na.length;
|
|
715
|
-
if (nestBef < nestAft)
|
|
736
|
+
if (nestBef < nestAft) options.nest = false;
|
|
716
737
|
}
|
|
717
|
-
if (!
|
|
718
|
-
if (
|
|
719
|
-
|
|
720
|
-
|
|
738
|
+
if (!options.lng && resolved && resolved.res) options.lng = this.language || resolved.usedLng;
|
|
739
|
+
if (options.nest !== false) res = this.interpolator.nest(res, function () {
|
|
740
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
741
|
+
args[_key] = arguments[_key];
|
|
742
|
+
}
|
|
743
|
+
if (lastKey?.[0] === args[0] && !options.context) {
|
|
744
|
+
_this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
|
|
721
745
|
return null;
|
|
722
746
|
}
|
|
723
|
-
return
|
|
724
|
-
},
|
|
725
|
-
if (
|
|
747
|
+
return _this.translate(...args, key);
|
|
748
|
+
}, options);
|
|
749
|
+
if (options.interpolation) this.interpolator.reset();
|
|
726
750
|
}
|
|
727
|
-
const postProcess =
|
|
751
|
+
const postProcess = options.postProcess || this.options.postProcess;
|
|
728
752
|
const postProcessorNames = isString(postProcess) ? [postProcess] : postProcess;
|
|
729
|
-
if (res != null && postProcessorNames?.length &&
|
|
753
|
+
if (res != null && postProcessorNames?.length && options.applyPostProcessor !== false) {
|
|
730
754
|
res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
|
|
731
755
|
i18nResolved: {
|
|
732
756
|
...resolved,
|
|
733
|
-
usedParams: this.getUsedParamsDetails(
|
|
757
|
+
usedParams: this.getUsedParamsDetails(options)
|
|
734
758
|
},
|
|
735
|
-
...
|
|
736
|
-
} :
|
|
759
|
+
...options
|
|
760
|
+
} : options, this);
|
|
737
761
|
}
|
|
738
762
|
return res;
|
|
739
763
|
}
|
|
740
|
-
resolve(keys
|
|
764
|
+
resolve(keys) {
|
|
765
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
741
766
|
let found;
|
|
742
767
|
let usedKey;
|
|
743
768
|
let exactUsedKey;
|
|
@@ -746,15 +771,15 @@ class Translator extends EventEmitter {
|
|
|
746
771
|
if (isString(keys)) keys = [keys];
|
|
747
772
|
keys.forEach(k => {
|
|
748
773
|
if (this.isValidLookup(found)) return;
|
|
749
|
-
const extracted = this.extractFromKey(k,
|
|
774
|
+
const extracted = this.extractFromKey(k, options);
|
|
750
775
|
const key = extracted.key;
|
|
751
776
|
usedKey = key;
|
|
752
777
|
let namespaces = extracted.namespaces;
|
|
753
778
|
if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
|
|
754
|
-
const needsPluralHandling =
|
|
755
|
-
const needsZeroSuffixLookup = needsPluralHandling && !
|
|
756
|
-
const needsContextHandling =
|
|
757
|
-
const codes =
|
|
779
|
+
const needsPluralHandling = options.count !== undefined && !isString(options.count);
|
|
780
|
+
const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0;
|
|
781
|
+
const needsContextHandling = options.context !== undefined && (isString(options.context) || typeof options.context === 'number') && options.context !== '';
|
|
782
|
+
const codes = options.lngs ? options.lngs : this.languageUtils.toResolveHierarchy(options.lng || this.language, options.fallbackLng);
|
|
758
783
|
namespaces.forEach(ns => {
|
|
759
784
|
if (this.isValidLookup(found)) return;
|
|
760
785
|
usedNS = ns;
|
|
@@ -767,15 +792,15 @@ class Translator extends EventEmitter {
|
|
|
767
792
|
usedLng = code;
|
|
768
793
|
const finalKeys = [key];
|
|
769
794
|
if (this.i18nFormat?.addLookupKeys) {
|
|
770
|
-
this.i18nFormat.addLookupKeys(finalKeys, key, code, ns,
|
|
795
|
+
this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
|
|
771
796
|
} else {
|
|
772
797
|
let pluralSuffix;
|
|
773
|
-
if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code,
|
|
798
|
+
if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, options.count, options);
|
|
774
799
|
const zeroSuffix = `${this.options.pluralSeparator}zero`;
|
|
775
800
|
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
|
|
776
801
|
if (needsPluralHandling) {
|
|
777
802
|
finalKeys.push(key + pluralSuffix);
|
|
778
|
-
if (
|
|
803
|
+
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
779
804
|
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
780
805
|
}
|
|
781
806
|
if (needsZeroSuffixLookup) {
|
|
@@ -783,11 +808,11 @@ class Translator extends EventEmitter {
|
|
|
783
808
|
}
|
|
784
809
|
}
|
|
785
810
|
if (needsContextHandling) {
|
|
786
|
-
const contextKey = `${key}${this.options.contextSeparator}${
|
|
811
|
+
const contextKey = `${key}${this.options.contextSeparator}${options.context}`;
|
|
787
812
|
finalKeys.push(contextKey);
|
|
788
813
|
if (needsPluralHandling) {
|
|
789
814
|
finalKeys.push(contextKey + pluralSuffix);
|
|
790
|
-
if (
|
|
815
|
+
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
791
816
|
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
792
817
|
}
|
|
793
818
|
if (needsZeroSuffixLookup) {
|
|
@@ -800,7 +825,7 @@ class Translator extends EventEmitter {
|
|
|
800
825
|
while (possibleKey = finalKeys.pop()) {
|
|
801
826
|
if (!this.isValidLookup(found)) {
|
|
802
827
|
exactUsedKey = possibleKey;
|
|
803
|
-
found = this.getResource(code, ns, possibleKey,
|
|
828
|
+
found = this.getResource(code, ns, possibleKey, options);
|
|
804
829
|
}
|
|
805
830
|
}
|
|
806
831
|
});
|
|
@@ -817,11 +842,13 @@ class Translator extends EventEmitter {
|
|
|
817
842
|
isValidLookup(res) {
|
|
818
843
|
return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === '');
|
|
819
844
|
}
|
|
820
|
-
getResource(code, ns, key
|
|
845
|
+
getResource(code, ns, key) {
|
|
846
|
+
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
821
847
|
if (this.i18nFormat?.getResource) return this.i18nFormat.getResource(code, ns, key, options);
|
|
822
848
|
return this.resourceStore.getResource(code, ns, key, options);
|
|
823
849
|
}
|
|
824
|
-
getUsedParamsDetails(
|
|
850
|
+
getUsedParamsDetails() {
|
|
851
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
825
852
|
const optionsKeys = ['defaultValue', 'ordinal', 'context', 'replace', 'lng', 'lngs', 'fallbackLng', 'ns', 'keySeparator', 'nsSeparator', 'returnObjects', 'returnDetails', 'joinArrays', 'postProcess', 'interpolation'];
|
|
826
853
|
const useOptionsReplaceForData = options.replace && !isString(options.replace);
|
|
827
854
|
let data = useOptionsReplaceForData ? options.replace : options;
|
|
@@ -910,8 +937,6 @@ class LanguageUtil {
|
|
|
910
937
|
if (!found && this.options.supportedLngs) {
|
|
911
938
|
codes.forEach(code => {
|
|
912
939
|
if (found) return;
|
|
913
|
-
const lngScOnly = this.getScriptPartFromCode(code);
|
|
914
|
-
if (this.isSupportedCode(lngScOnly)) return found = lngScOnly;
|
|
915
940
|
const lngOnly = this.getLanguagePartFromCode(code);
|
|
916
941
|
if (this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
917
942
|
found = this.options.supportedLngs.find(supportedLng => {
|
|
@@ -939,7 +964,7 @@ class LanguageUtil {
|
|
|
939
964
|
return found || [];
|
|
940
965
|
}
|
|
941
966
|
toResolveHierarchy(code, fallbackCode) {
|
|
942
|
-
const fallbackCodes = this.getFallbackCodes(
|
|
967
|
+
const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
|
|
943
968
|
const codes = [];
|
|
944
969
|
const addCode = c => {
|
|
945
970
|
if (!c) return;
|
|
@@ -978,7 +1003,8 @@ const dummyRule = {
|
|
|
978
1003
|
})
|
|
979
1004
|
};
|
|
980
1005
|
class PluralResolver {
|
|
981
|
-
constructor(languageUtils
|
|
1006
|
+
constructor(languageUtils) {
|
|
1007
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
982
1008
|
this.languageUtils = languageUtils;
|
|
983
1009
|
this.options = options;
|
|
984
1010
|
this.logger = baseLogger.create('pluralResolver');
|
|
@@ -990,7 +1016,8 @@ class PluralResolver {
|
|
|
990
1016
|
clearCache() {
|
|
991
1017
|
this.pluralRulesCache = {};
|
|
992
1018
|
}
|
|
993
|
-
getRule(code
|
|
1019
|
+
getRule(code) {
|
|
1020
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
994
1021
|
const cleanedCode = getCleanedCode(code === 'dev' ? 'en' : code);
|
|
995
1022
|
const type = options.ordinal ? 'ordinal' : 'cardinal';
|
|
996
1023
|
const cacheKey = JSON.stringify({
|
|
@@ -1017,21 +1044,25 @@ class PluralResolver {
|
|
|
1017
1044
|
this.pluralRulesCache[cacheKey] = rule;
|
|
1018
1045
|
return rule;
|
|
1019
1046
|
}
|
|
1020
|
-
needsPlural(code
|
|
1047
|
+
needsPlural(code) {
|
|
1048
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1021
1049
|
let rule = this.getRule(code, options);
|
|
1022
1050
|
if (!rule) rule = this.getRule('dev', options);
|
|
1023
1051
|
return rule?.resolvedOptions().pluralCategories.length > 1;
|
|
1024
1052
|
}
|
|
1025
|
-
getPluralFormsOfKey(code, key
|
|
1053
|
+
getPluralFormsOfKey(code, key) {
|
|
1054
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1026
1055
|
return this.getSuffixes(code, options).map(suffix => `${key}${suffix}`);
|
|
1027
1056
|
}
|
|
1028
|
-
getSuffixes(code
|
|
1057
|
+
getSuffixes(code) {
|
|
1058
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1029
1059
|
let rule = this.getRule(code, options);
|
|
1030
1060
|
if (!rule) rule = this.getRule('dev', options);
|
|
1031
1061
|
if (!rule) return [];
|
|
1032
1062
|
return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map(pluralCategory => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${pluralCategory}`);
|
|
1033
1063
|
}
|
|
1034
|
-
getSuffix(code, count
|
|
1064
|
+
getSuffix(code, count) {
|
|
1065
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1035
1066
|
const rule = this.getRule(code, options);
|
|
1036
1067
|
if (rule) {
|
|
1037
1068
|
return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${rule.select(count)}`;
|
|
@@ -1041,7 +1072,9 @@ class PluralResolver {
|
|
|
1041
1072
|
}
|
|
1042
1073
|
}
|
|
1043
1074
|
|
|
1044
|
-
const deepFindWithDefaults = (data, defaultData, key
|
|
1075
|
+
const deepFindWithDefaults = function (data, defaultData, key) {
|
|
1076
|
+
let keySeparator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '.';
|
|
1077
|
+
let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
1045
1078
|
let path = getPathWithDefaults(data, defaultData, key);
|
|
1046
1079
|
if (!path && ignoreJSONStructure && isString(key)) {
|
|
1047
1080
|
path = deepFind(data, key, keySeparator);
|
|
@@ -1051,13 +1084,15 @@ const deepFindWithDefaults = (data, defaultData, key, keySeparator = '.', ignore
|
|
|
1051
1084
|
};
|
|
1052
1085
|
const regexSafe = val => val.replace(/\$/g, '$$$$');
|
|
1053
1086
|
class Interpolator {
|
|
1054
|
-
constructor(
|
|
1087
|
+
constructor() {
|
|
1088
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1055
1089
|
this.logger = baseLogger.create('interpolator');
|
|
1056
1090
|
this.options = options;
|
|
1057
1091
|
this.format = options?.interpolation?.format || (value => value);
|
|
1058
1092
|
this.init(options);
|
|
1059
1093
|
}
|
|
1060
|
-
init(
|
|
1094
|
+
init() {
|
|
1095
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1061
1096
|
if (!options.interpolation) options.interpolation = {
|
|
1062
1097
|
escapeValue: true
|
|
1063
1098
|
};
|
|
@@ -1180,7 +1215,8 @@ class Interpolator {
|
|
|
1180
1215
|
});
|
|
1181
1216
|
return str;
|
|
1182
1217
|
}
|
|
1183
|
-
nest(str, fc
|
|
1218
|
+
nest(str, fc) {
|
|
1219
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1184
1220
|
let match;
|
|
1185
1221
|
let value;
|
|
1186
1222
|
let clonedOptions;
|
|
@@ -1217,10 +1253,12 @@ class Interpolator {
|
|
|
1217
1253
|
clonedOptions = clonedOptions.replace && !isString(clonedOptions.replace) ? clonedOptions.replace : clonedOptions;
|
|
1218
1254
|
clonedOptions.applyPostProcessor = false;
|
|
1219
1255
|
delete clonedOptions.defaultValue;
|
|
1220
|
-
|
|
1221
|
-
if (
|
|
1222
|
-
|
|
1223
|
-
match[1] =
|
|
1256
|
+
let doReduce = false;
|
|
1257
|
+
if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
|
|
1258
|
+
const r = match[1].split(this.formatSeparator).map(elem => elem.trim());
|
|
1259
|
+
match[1] = r.shift();
|
|
1260
|
+
formatters = r;
|
|
1261
|
+
doReduce = true;
|
|
1224
1262
|
}
|
|
1225
1263
|
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
1226
1264
|
if (value && match[0] === str && !isString(value)) return value;
|
|
@@ -1229,7 +1267,7 @@ class Interpolator {
|
|
|
1229
1267
|
this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
|
|
1230
1268
|
value = '';
|
|
1231
1269
|
}
|
|
1232
|
-
if (
|
|
1270
|
+
if (doReduce) {
|
|
1233
1271
|
value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
|
|
1234
1272
|
...options,
|
|
1235
1273
|
interpolationkey: match[1].trim()
|
|
@@ -1275,68 +1313,68 @@ const parseFormatStr = formatStr => {
|
|
|
1275
1313
|
};
|
|
1276
1314
|
const createCachedFormatter = fn => {
|
|
1277
1315
|
const cache = {};
|
|
1278
|
-
return (
|
|
1279
|
-
let optForCache =
|
|
1280
|
-
if (
|
|
1316
|
+
return (val, lng, options) => {
|
|
1317
|
+
let optForCache = options;
|
|
1318
|
+
if (options && options.interpolationkey && options.formatParams && options.formatParams[options.interpolationkey] && options[options.interpolationkey]) {
|
|
1281
1319
|
optForCache = {
|
|
1282
1320
|
...optForCache,
|
|
1283
|
-
[
|
|
1321
|
+
[options.interpolationkey]: undefined
|
|
1284
1322
|
};
|
|
1285
1323
|
}
|
|
1286
|
-
const key =
|
|
1287
|
-
let
|
|
1288
|
-
if (!
|
|
1289
|
-
|
|
1290
|
-
cache[key] =
|
|
1324
|
+
const key = lng + JSON.stringify(optForCache);
|
|
1325
|
+
let formatter = cache[key];
|
|
1326
|
+
if (!formatter) {
|
|
1327
|
+
formatter = fn(getCleanedCode(lng), options);
|
|
1328
|
+
cache[key] = formatter;
|
|
1291
1329
|
}
|
|
1292
|
-
return
|
|
1330
|
+
return formatter(val);
|
|
1293
1331
|
};
|
|
1294
1332
|
};
|
|
1295
|
-
const createNonCachedFormatter = fn => (v, l, o) => fn(getCleanedCode(l), o)(v);
|
|
1296
1333
|
class Formatter {
|
|
1297
|
-
constructor(
|
|
1334
|
+
constructor() {
|
|
1335
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1298
1336
|
this.logger = baseLogger.create('formatter');
|
|
1299
1337
|
this.options = options;
|
|
1300
|
-
this.init(options);
|
|
1301
|
-
}
|
|
1302
|
-
init(services, options = {
|
|
1303
|
-
interpolation: {}
|
|
1304
|
-
}) {
|
|
1305
|
-
this.formatSeparator = options.interpolation.formatSeparator || ',';
|
|
1306
|
-
const cf = options.cacheInBuiltFormats ? createCachedFormatter : createNonCachedFormatter;
|
|
1307
1338
|
this.formats = {
|
|
1308
|
-
number:
|
|
1339
|
+
number: createCachedFormatter((lng, opt) => {
|
|
1309
1340
|
const formatter = new Intl.NumberFormat(lng, {
|
|
1310
1341
|
...opt
|
|
1311
1342
|
});
|
|
1312
1343
|
return val => formatter.format(val);
|
|
1313
1344
|
}),
|
|
1314
|
-
currency:
|
|
1345
|
+
currency: createCachedFormatter((lng, opt) => {
|
|
1315
1346
|
const formatter = new Intl.NumberFormat(lng, {
|
|
1316
1347
|
...opt,
|
|
1317
1348
|
style: 'currency'
|
|
1318
1349
|
});
|
|
1319
1350
|
return val => formatter.format(val);
|
|
1320
1351
|
}),
|
|
1321
|
-
datetime:
|
|
1352
|
+
datetime: createCachedFormatter((lng, opt) => {
|
|
1322
1353
|
const formatter = new Intl.DateTimeFormat(lng, {
|
|
1323
1354
|
...opt
|
|
1324
1355
|
});
|
|
1325
1356
|
return val => formatter.format(val);
|
|
1326
1357
|
}),
|
|
1327
|
-
relativetime:
|
|
1358
|
+
relativetime: createCachedFormatter((lng, opt) => {
|
|
1328
1359
|
const formatter = new Intl.RelativeTimeFormat(lng, {
|
|
1329
1360
|
...opt
|
|
1330
1361
|
});
|
|
1331
1362
|
return val => formatter.format(val, opt.range || 'day');
|
|
1332
1363
|
}),
|
|
1333
|
-
list:
|
|
1364
|
+
list: createCachedFormatter((lng, opt) => {
|
|
1334
1365
|
const formatter = new Intl.ListFormat(lng, {
|
|
1335
1366
|
...opt
|
|
1336
1367
|
});
|
|
1337
1368
|
return val => formatter.format(val);
|
|
1338
1369
|
})
|
|
1339
1370
|
};
|
|
1371
|
+
this.init(options);
|
|
1372
|
+
}
|
|
1373
|
+
init(services) {
|
|
1374
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
1375
|
+
interpolation: {}
|
|
1376
|
+
};
|
|
1377
|
+
this.formatSeparator = options.interpolation.formatSeparator || ',';
|
|
1340
1378
|
}
|
|
1341
1379
|
add(name, fc) {
|
|
1342
1380
|
this.formats[name.toLowerCase().trim()] = fc;
|
|
@@ -1344,7 +1382,8 @@ class Formatter {
|
|
|
1344
1382
|
addCached(name, fc) {
|
|
1345
1383
|
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
1346
1384
|
}
|
|
1347
|
-
format(value, format, lng
|
|
1385
|
+
format(value, format, lng) {
|
|
1386
|
+
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1348
1387
|
const formats = format.split(this.formatSeparator);
|
|
1349
1388
|
if (formats.length > 1 && formats[0].indexOf('(') > 1 && formats[0].indexOf(')') < 0 && formats.find(f => f.indexOf(')') > -1)) {
|
|
1350
1389
|
const lastIndex = formats.findIndex(f => f.indexOf(')') > -1);
|
|
@@ -1385,7 +1424,8 @@ const removePending = (q, name) => {
|
|
|
1385
1424
|
}
|
|
1386
1425
|
};
|
|
1387
1426
|
class Connector extends EventEmitter {
|
|
1388
|
-
constructor(backend, store, services
|
|
1427
|
+
constructor(backend, store, services) {
|
|
1428
|
+
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1389
1429
|
super();
|
|
1390
1430
|
this.backend = backend;
|
|
1391
1431
|
this.store = store;
|
|
@@ -1479,7 +1519,10 @@ class Connector extends EventEmitter {
|
|
|
1479
1519
|
this.emit('loaded', loaded);
|
|
1480
1520
|
this.queue = this.queue.filter(q => !q.done);
|
|
1481
1521
|
}
|
|
1482
|
-
read(lng, ns, fcName
|
|
1522
|
+
read(lng, ns, fcName) {
|
|
1523
|
+
let tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
1524
|
+
let wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
|
|
1525
|
+
let callback = arguments.length > 5 ? arguments[5] : undefined;
|
|
1483
1526
|
if (!lng.length) return callback(null, {});
|
|
1484
1527
|
if (this.readingCalls >= this.maxParallelReads) {
|
|
1485
1528
|
this.waitingReads.push({
|
|
@@ -1523,7 +1566,9 @@ class Connector extends EventEmitter {
|
|
|
1523
1566
|
}
|
|
1524
1567
|
return fc(lng, ns, resolver);
|
|
1525
1568
|
}
|
|
1526
|
-
prepareLoading(languages, namespaces
|
|
1569
|
+
prepareLoading(languages, namespaces) {
|
|
1570
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1571
|
+
let callback = arguments.length > 3 ? arguments[3] : undefined;
|
|
1527
1572
|
if (!this.backend) {
|
|
1528
1573
|
this.logger.warn('No backend was added via i18next.use. Will not load resources.');
|
|
1529
1574
|
return callback && callback();
|
|
@@ -1547,7 +1592,8 @@ class Connector extends EventEmitter {
|
|
|
1547
1592
|
reload: true
|
|
1548
1593
|
}, callback);
|
|
1549
1594
|
}
|
|
1550
|
-
loadOne(name
|
|
1595
|
+
loadOne(name) {
|
|
1596
|
+
let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
1551
1597
|
const s = name.split('|');
|
|
1552
1598
|
const lng = s[0];
|
|
1553
1599
|
const ns = s[1];
|
|
@@ -1557,7 +1603,9 @@ class Connector extends EventEmitter {
|
|
|
1557
1603
|
this.loaded(name, err, data);
|
|
1558
1604
|
});
|
|
1559
1605
|
}
|
|
1560
|
-
saveMissing(languages, namespace, key, fallbackValue, isUpdate
|
|
1606
|
+
saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
|
|
1607
|
+
let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
1608
|
+
let clb = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : () => {};
|
|
1561
1609
|
if (this.services?.utils?.hasLoadedNamespace && !this.services?.utils?.hasLoadedNamespace(namespace)) {
|
|
1562
1610
|
this.logger.warn(`did not save key "${key}" as the namespace "${namespace}" was not yet loaded`, 'This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!');
|
|
1563
1611
|
return;
|
|
@@ -1652,8 +1700,7 @@ const get = () => ({
|
|
|
1652
1700
|
nestingOptionsSeparator: ',',
|
|
1653
1701
|
maxReplaces: 1000,
|
|
1654
1702
|
skipOnVariables: true
|
|
1655
|
-
}
|
|
1656
|
-
cacheInBuiltFormats: true
|
|
1703
|
+
}
|
|
1657
1704
|
});
|
|
1658
1705
|
const transformOptions = options => {
|
|
1659
1706
|
if (isString(options.ns)) options.ns = [options.ns];
|
|
@@ -1676,7 +1723,9 @@ const bindMemberFunctions = inst => {
|
|
|
1676
1723
|
});
|
|
1677
1724
|
};
|
|
1678
1725
|
class I18n extends EventEmitter {
|
|
1679
|
-
constructor(
|
|
1726
|
+
constructor() {
|
|
1727
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1728
|
+
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
1680
1729
|
super();
|
|
1681
1730
|
this.options = transformOptions(options);
|
|
1682
1731
|
this.services = {};
|
|
@@ -1695,7 +1744,10 @@ class I18n extends EventEmitter {
|
|
|
1695
1744
|
}, 0);
|
|
1696
1745
|
}
|
|
1697
1746
|
}
|
|
1698
|
-
init(
|
|
1747
|
+
init() {
|
|
1748
|
+
var _this = this;
|
|
1749
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1750
|
+
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
1699
1751
|
this.isInitializing = true;
|
|
1700
1752
|
if (typeof options === 'function') {
|
|
1701
1753
|
callback = options;
|
|
@@ -1751,13 +1803,9 @@ class I18n extends EventEmitter {
|
|
|
1751
1803
|
prepend: this.options.pluralSeparator,
|
|
1752
1804
|
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
1753
1805
|
});
|
|
1754
|
-
const usingLegacyFormatFunction = this.options.interpolation.format && this.options.interpolation.format !== defOpts.interpolation.format;
|
|
1755
|
-
if (usingLegacyFormatFunction) {
|
|
1756
|
-
this.logger.warn(`init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting`);
|
|
1757
|
-
}
|
|
1758
1806
|
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
|
|
1759
1807
|
s.formatter = createClassOnDemand(formatter);
|
|
1760
|
-
|
|
1808
|
+
s.formatter.init(s, this.options);
|
|
1761
1809
|
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
1762
1810
|
}
|
|
1763
1811
|
s.interpolator = new Interpolator(this.options);
|
|
@@ -1765,8 +1813,11 @@ class I18n extends EventEmitter {
|
|
|
1765
1813
|
hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
|
|
1766
1814
|
};
|
|
1767
1815
|
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
1768
|
-
s.backendConnector.on('*', (event
|
|
1769
|
-
|
|
1816
|
+
s.backendConnector.on('*', function (event) {
|
|
1817
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1818
|
+
args[_key - 1] = arguments[_key];
|
|
1819
|
+
}
|
|
1820
|
+
_this.emit(event, ...args);
|
|
1770
1821
|
});
|
|
1771
1822
|
if (this.modules.languageDetector) {
|
|
1772
1823
|
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
@@ -1777,8 +1828,11 @@ class I18n extends EventEmitter {
|
|
|
1777
1828
|
if (s.i18nFormat.init) s.i18nFormat.init(this);
|
|
1778
1829
|
}
|
|
1779
1830
|
this.translator = new Translator(this.services, this.options);
|
|
1780
|
-
this.translator.on('*', (event
|
|
1781
|
-
|
|
1831
|
+
this.translator.on('*', function (event) {
|
|
1832
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
1833
|
+
args[_key2 - 1] = arguments[_key2];
|
|
1834
|
+
}
|
|
1835
|
+
_this.emit(event, ...args);
|
|
1782
1836
|
});
|
|
1783
1837
|
this.modules.external.forEach(m => {
|
|
1784
1838
|
if (m.init) m.init(this);
|
|
@@ -1795,13 +1849,15 @@ class I18n extends EventEmitter {
|
|
|
1795
1849
|
}
|
|
1796
1850
|
const storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
|
|
1797
1851
|
storeApi.forEach(fcName => {
|
|
1798
|
-
this[fcName] = (
|
|
1852
|
+
this[fcName] = function () {
|
|
1853
|
+
return _this.store[fcName](...arguments);
|
|
1854
|
+
};
|
|
1799
1855
|
});
|
|
1800
1856
|
const storeApiChained = ['addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle'];
|
|
1801
1857
|
storeApiChained.forEach(fcName => {
|
|
1802
|
-
this[fcName] = (
|
|
1803
|
-
|
|
1804
|
-
return
|
|
1858
|
+
this[fcName] = function () {
|
|
1859
|
+
_this.store[fcName](...arguments);
|
|
1860
|
+
return _this;
|
|
1805
1861
|
};
|
|
1806
1862
|
});
|
|
1807
1863
|
const deferred = defer();
|
|
@@ -1825,7 +1881,8 @@ class I18n extends EventEmitter {
|
|
|
1825
1881
|
}
|
|
1826
1882
|
return deferred;
|
|
1827
1883
|
}
|
|
1828
|
-
loadResources(language
|
|
1884
|
+
loadResources(language) {
|
|
1885
|
+
let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
|
|
1829
1886
|
let usedCallback = callback;
|
|
1830
1887
|
const usedLng = isString(language) ? language : this.language;
|
|
1831
1888
|
if (typeof language === 'function') usedCallback = language;
|
|
@@ -1912,12 +1969,9 @@ class I18n extends EventEmitter {
|
|
|
1912
1969
|
break;
|
|
1913
1970
|
}
|
|
1914
1971
|
}
|
|
1915
|
-
if (!this.resolvedLanguage && this.languages.indexOf(l) < 0 && this.store.hasLanguageSomeTranslations(l)) {
|
|
1916
|
-
this.resolvedLanguage = l;
|
|
1917
|
-
this.languages.unshift(l);
|
|
1918
|
-
}
|
|
1919
1972
|
}
|
|
1920
1973
|
changeLanguage(lng, callback) {
|
|
1974
|
+
var _this2 = this;
|
|
1921
1975
|
this.isLanguageChangingTo = lng;
|
|
1922
1976
|
const deferred = defer();
|
|
1923
1977
|
this.emit('languageChanging', lng);
|
|
@@ -1929,23 +1983,24 @@ class I18n extends EventEmitter {
|
|
|
1929
1983
|
};
|
|
1930
1984
|
const done = (err, l) => {
|
|
1931
1985
|
if (l) {
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
this.logger.log('languageChanged', l);
|
|
1938
|
-
}
|
|
1986
|
+
setLngProps(l);
|
|
1987
|
+
this.translator.changeLanguage(l);
|
|
1988
|
+
this.isLanguageChangingTo = undefined;
|
|
1989
|
+
this.emit('languageChanged', l);
|
|
1990
|
+
this.logger.log('languageChanged', l);
|
|
1939
1991
|
} else {
|
|
1940
1992
|
this.isLanguageChangingTo = undefined;
|
|
1941
1993
|
}
|
|
1942
|
-
deferred.resolve((
|
|
1943
|
-
|
|
1994
|
+
deferred.resolve(function () {
|
|
1995
|
+
return _this2.t(...arguments);
|
|
1996
|
+
});
|
|
1997
|
+
if (callback) callback(err, function () {
|
|
1998
|
+
return _this2.t(...arguments);
|
|
1999
|
+
});
|
|
1944
2000
|
};
|
|
1945
2001
|
const setLng = lngs => {
|
|
1946
2002
|
if (!lng && !lngs && this.services.languageDetector) lngs = [];
|
|
1947
|
-
const
|
|
1948
|
-
const l = this.store.hasLanguageSomeTranslations(fl) ? fl : this.services.languageUtils.getBestMatchFromCodes(isString(lngs) ? [lngs] : lngs);
|
|
2003
|
+
const l = isString(lngs) ? lngs : this.services.languageUtils.getBestMatchFromCodes(lngs);
|
|
1949
2004
|
if (l) {
|
|
1950
2005
|
if (!this.language) {
|
|
1951
2006
|
setLngProps(l);
|
|
@@ -1971,27 +2026,31 @@ class I18n extends EventEmitter {
|
|
|
1971
2026
|
return deferred;
|
|
1972
2027
|
}
|
|
1973
2028
|
getFixedT(lng, ns, keyPrefix) {
|
|
1974
|
-
|
|
1975
|
-
|
|
2029
|
+
var _this3 = this;
|
|
2030
|
+
const fixedT = function (key, opts) {
|
|
2031
|
+
let options;
|
|
1976
2032
|
if (typeof opts !== 'object') {
|
|
1977
|
-
|
|
2033
|
+
for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
2034
|
+
rest[_key3 - 2] = arguments[_key3];
|
|
2035
|
+
}
|
|
2036
|
+
options = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
1978
2037
|
} else {
|
|
1979
|
-
|
|
2038
|
+
options = {
|
|
1980
2039
|
...opts
|
|
1981
2040
|
};
|
|
1982
2041
|
}
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
if (
|
|
1987
|
-
const keySeparator =
|
|
2042
|
+
options.lng = options.lng || fixedT.lng;
|
|
2043
|
+
options.lngs = options.lngs || fixedT.lngs;
|
|
2044
|
+
options.ns = options.ns || fixedT.ns;
|
|
2045
|
+
if (options.keyPrefix !== '') options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
|
|
2046
|
+
const keySeparator = _this3.options.keySeparator || '.';
|
|
1988
2047
|
let resultKey;
|
|
1989
|
-
if (
|
|
1990
|
-
resultKey = key.map(k => `${
|
|
2048
|
+
if (options.keyPrefix && Array.isArray(key)) {
|
|
2049
|
+
resultKey = key.map(k => `${options.keyPrefix}${keySeparator}${k}`);
|
|
1991
2050
|
} else {
|
|
1992
|
-
resultKey =
|
|
2051
|
+
resultKey = options.keyPrefix ? `${options.keyPrefix}${keySeparator}${key}` : key;
|
|
1993
2052
|
}
|
|
1994
|
-
return
|
|
2053
|
+
return _this3.t(resultKey, options);
|
|
1995
2054
|
};
|
|
1996
2055
|
if (isString(lng)) {
|
|
1997
2056
|
fixedT.lng = lng;
|
|
@@ -2002,16 +2061,23 @@ class I18n extends EventEmitter {
|
|
|
2002
2061
|
fixedT.keyPrefix = keyPrefix;
|
|
2003
2062
|
return fixedT;
|
|
2004
2063
|
}
|
|
2005
|
-
t(
|
|
2064
|
+
t() {
|
|
2065
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
2066
|
+
args[_key4] = arguments[_key4];
|
|
2067
|
+
}
|
|
2006
2068
|
return this.translator?.translate(...args);
|
|
2007
2069
|
}
|
|
2008
|
-
exists(
|
|
2070
|
+
exists() {
|
|
2071
|
+
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
2072
|
+
args[_key5] = arguments[_key5];
|
|
2073
|
+
}
|
|
2009
2074
|
return this.translator?.exists(...args);
|
|
2010
2075
|
}
|
|
2011
2076
|
setDefaultNamespace(ns) {
|
|
2012
2077
|
this.options.defaultNS = ns;
|
|
2013
2078
|
}
|
|
2014
|
-
hasLoadedNamespace(ns
|
|
2079
|
+
hasLoadedNamespace(ns) {
|
|
2080
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2015
2081
|
if (!this.isInitialized) {
|
|
2016
2082
|
this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
|
|
2017
2083
|
return false;
|
|
@@ -2072,22 +2138,18 @@ class I18n extends EventEmitter {
|
|
|
2072
2138
|
dir(lng) {
|
|
2073
2139
|
if (!lng) lng = this.resolvedLanguage || (this.languages?.length > 0 ? this.languages[0] : this.language);
|
|
2074
2140
|
if (!lng) return 'rtl';
|
|
2075
|
-
try {
|
|
2076
|
-
const l = new Intl.Locale(lng);
|
|
2077
|
-
if (l && l.getTextInfo) {
|
|
2078
|
-
const ti = l.getTextInfo();
|
|
2079
|
-
if (ti && ti.direction) return ti.direction;
|
|
2080
|
-
}
|
|
2081
|
-
} catch (e) {}
|
|
2082
2141
|
const rtlLngs = ['ar', 'shu', 'sqr', 'ssh', 'xaa', 'yhd', 'yud', 'aao', 'abh', 'abv', 'acm', 'acq', 'acw', 'acx', 'acy', 'adf', 'ads', 'aeb', 'aec', 'afb', 'ajp', 'apc', 'apd', 'arb', 'arq', 'ars', 'ary', 'arz', 'auz', 'avl', 'ayh', 'ayl', 'ayn', 'ayp', 'bbz', 'pga', 'he', 'iw', 'ps', 'pbt', 'pbu', 'pst', 'prp', 'prd', 'ug', 'ur', 'ydd', 'yds', 'yih', 'ji', 'yi', 'hbo', 'men', 'xmn', 'fa', 'jpr', 'peo', 'pes', 'prs', 'dv', 'sam', 'ckb'];
|
|
2083
2142
|
const languageUtils = this.services?.languageUtils || new LanguageUtil(get());
|
|
2084
|
-
if (lng.toLowerCase().indexOf('-latn') > 1) return 'ltr';
|
|
2085
2143
|
return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
|
|
2086
2144
|
}
|
|
2087
|
-
static createInstance(
|
|
2145
|
+
static createInstance() {
|
|
2146
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2147
|
+
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
2088
2148
|
return new I18n(options, callback);
|
|
2089
2149
|
}
|
|
2090
|
-
cloneInstance(
|
|
2150
|
+
cloneInstance() {
|
|
2151
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2152
|
+
let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
|
|
2091
2153
|
const forkResourceStore = options.forkResourceStore;
|
|
2092
2154
|
if (forkResourceStore) delete options.forkResourceStore;
|
|
2093
2155
|
const mergedOptions = {
|
|
@@ -2116,19 +2178,21 @@ class I18n extends EventEmitter {
|
|
|
2116
2178
|
prev[l] = {
|
|
2117
2179
|
...this.store.data[l]
|
|
2118
2180
|
};
|
|
2119
|
-
|
|
2181
|
+
return Object.keys(prev[l]).reduce((acc, n) => {
|
|
2120
2182
|
acc[n] = {
|
|
2121
2183
|
...prev[l][n]
|
|
2122
2184
|
};
|
|
2123
2185
|
return acc;
|
|
2124
|
-
},
|
|
2125
|
-
return prev;
|
|
2186
|
+
}, {});
|
|
2126
2187
|
}, {});
|
|
2127
2188
|
clone.store = new ResourceStore(clonedData, mergedOptions);
|
|
2128
2189
|
clone.services.resourceStore = clone.store;
|
|
2129
2190
|
}
|
|
2130
2191
|
clone.translator = new Translator(clone.services, mergedOptions);
|
|
2131
|
-
clone.translator.on('*', (event
|
|
2192
|
+
clone.translator.on('*', function (event) {
|
|
2193
|
+
for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
|
|
2194
|
+
args[_key6 - 1] = arguments[_key6];
|
|
2195
|
+
}
|
|
2132
2196
|
clone.emit(event, ...args);
|
|
2133
2197
|
});
|
|
2134
2198
|
clone.init(mergedOptions, callback);
|
|
@@ -2156,7 +2220,7 @@ function getWindow() {
|
|
|
2156
2220
|
}
|
|
2157
2221
|
function getAtomicEnvironment() {
|
|
2158
2222
|
return {
|
|
2159
|
-
version: "3.31.2-pre.
|
|
2223
|
+
version: "3.31.2-pre.126a57e490",
|
|
2160
2224
|
headlessVersion: VERSION,
|
|
2161
2225
|
};
|
|
2162
2226
|
}
|