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