@andre1502/react-utilities 1.0.4 → 1.0.5

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.
Files changed (49) hide show
  1. package/dist/Config/GoogleAuth.js +10 -13
  2. package/dist/Config/GoogleAuth.js.map +1 -1
  3. package/dist/Config/Sitemap.js +10 -11
  4. package/dist/Config/Sitemap.js.map +1 -1
  5. package/dist/EnvironmentEnum-BjXsfSRZ.js.map +1 -1
  6. package/dist/EnvironmentEnum-UcQ6Il1O.js.map +1 -1
  7. package/dist/NumberFormat-CvvBWhHc.js.map +1 -1
  8. package/dist/NumberFormat-glmpbk7E.js.map +1 -1
  9. package/dist/React-BaJ1KfGF.js.map +1 -1
  10. package/dist/React-qUl0CBmE.js.map +1 -1
  11. package/dist/{ReactNative-Ckbnh5vm.js → ReactNative-B4gt8nBr.js} +22 -2
  12. package/dist/ReactNative-B4gt8nBr.js.map +1 -0
  13. package/dist/{ReactNative-DLA9Xwp4.js → ReactNative-CDMfQFfN.js} +22 -2
  14. package/dist/ReactNative-CDMfQFfN.js.map +1 -0
  15. package/dist/Sentry/Build.js +27 -28
  16. package/dist/Sentry/Build.js.map +1 -1
  17. package/dist/Sentry/React.js +1 -2
  18. package/dist/Sentry/React.js.map +1 -1
  19. package/dist/Sentry/ReactNative.js +1 -2
  20. package/dist/Sentry/ReactNative.js.map +1 -1
  21. package/dist/Utils/Files.js +1 -2
  22. package/dist/Utils/Files.js.map +1 -1
  23. package/dist/Utils-BC1fDy39.js.map +1 -1
  24. package/dist/Utils-Cq948gfa.js.map +1 -1
  25. package/dist/Utils-D7KRF8VU.js.map +1 -1
  26. package/dist/Utils-Dilye04y.js.map +1 -1
  27. package/dist/config-cli.cjs.map +1 -1
  28. package/dist/config-cli.js +38 -44
  29. package/dist/config-cli.js.map +1 -1
  30. package/dist/config-cli.mjs.map +1 -1
  31. package/dist/hooks.js +1 -2
  32. package/dist/hooks.js.map +1 -1
  33. package/dist/i18n.cjs +216 -290
  34. package/dist/i18n.cjs.map +1 -1
  35. package/dist/i18n.mjs +216 -290
  36. package/dist/i18n.mjs.map +1 -1
  37. package/dist/index-rn.cjs +1 -1
  38. package/dist/index-rn.mjs +1 -1
  39. package/dist/sentry-cli.cjs.map +1 -1
  40. package/dist/sentry-cli.js +8 -9
  41. package/dist/sentry-cli.js.map +1 -1
  42. package/dist/sentry-cli.mjs.map +1 -1
  43. package/dist/sentry-rn.cjs +1 -1
  44. package/dist/sentry-rn.mjs +1 -1
  45. package/dist/useWebSocket-B_B6kWXM.js.map +1 -1
  46. package/dist/useWebSocket-YQWaiBz9.js.map +1 -1
  47. package/package.json +30 -26
  48. package/dist/ReactNative-Ckbnh5vm.js.map +0 -1
  49. package/dist/ReactNative-DLA9Xwp4.js.map +0 -1
package/dist/i18n.mjs CHANGED
@@ -159,8 +159,7 @@ const looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
159
159
  }
160
160
  return matched;
161
161
  };
162
- const deepFind = function (obj, path) {
163
- let keySeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
162
+ const deepFind = (obj, path, keySeparator = '.') => {
164
163
  if (!obj) return undefined;
165
164
  if (obj[path]) {
166
165
  if (!Object.prototype.hasOwnProperty.call(obj, path)) return undefined;
@@ -210,39 +209,25 @@ const consoleLogger = {
210
209
  }
211
210
  };
212
211
  class Logger {
213
- constructor(concreteLogger) {
214
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
212
+ constructor(concreteLogger, options = {}) {
215
213
  this.init(concreteLogger, options);
216
214
  }
217
- init(concreteLogger) {
218
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
215
+ init(concreteLogger, options = {}) {
219
216
  this.prefix = options.prefix || 'i18next:';
220
217
  this.logger = concreteLogger || consoleLogger;
221
218
  this.options = options;
222
219
  this.debug = options.debug;
223
220
  }
224
- log() {
225
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
226
- args[_key] = arguments[_key];
227
- }
221
+ log(...args) {
228
222
  return this.forward(args, 'log', '', true);
229
223
  }
230
- warn() {
231
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
232
- args[_key2] = arguments[_key2];
233
- }
224
+ warn(...args) {
234
225
  return this.forward(args, 'warn', '', true);
235
226
  }
236
- error() {
237
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
238
- args[_key3] = arguments[_key3];
239
- }
227
+ error(...args) {
240
228
  return this.forward(args, 'error', '');
241
229
  }
242
- deprecate() {
243
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
244
- args[_key4] = arguments[_key4];
245
- }
230
+ deprecate(...args) {
246
231
  return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
247
232
  }
248
233
  forward(args, lvl, prefix, debugOnly) {
@@ -286,14 +271,10 @@ class EventEmitter {
286
271
  }
287
272
  this.observers[event].delete(listener);
288
273
  }
289
- emit(event) {
290
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
291
- args[_key - 1] = arguments[_key];
292
- }
274
+ emit(event, ...args) {
293
275
  if (this.observers[event]) {
294
276
  const cloned = Array.from(this.observers[event].entries());
295
- cloned.forEach(_ref => {
296
- let [observer, numTimesAdded] = _ref;
277
+ cloned.forEach(([observer, numTimesAdded]) => {
297
278
  for (let i = 0; i < numTimesAdded; i++) {
298
279
  observer(...args);
299
280
  }
@@ -301,8 +282,7 @@ class EventEmitter {
301
282
  }
302
283
  if (this.observers['*']) {
303
284
  const cloned = Array.from(this.observers['*'].entries());
304
- cloned.forEach(_ref2 => {
305
- let [observer, numTimesAdded] = _ref2;
285
+ cloned.forEach(([observer, numTimesAdded]) => {
306
286
  for (let i = 0; i < numTimesAdded; i++) {
307
287
  observer.apply(observer, [event, ...args]);
308
288
  }
@@ -312,11 +292,10 @@ class EventEmitter {
312
292
  }
313
293
 
314
294
  class ResourceStore extends EventEmitter {
315
- constructor(data) {
316
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
317
- ns: ['translation'],
318
- defaultNS: 'translation'
319
- };
295
+ constructor(data, options = {
296
+ ns: ['translation'],
297
+ defaultNS: 'translation'
298
+ }) {
320
299
  super();
321
300
  this.data = data || {};
322
301
  this.options = options;
@@ -338,8 +317,7 @@ class ResourceStore extends EventEmitter {
338
317
  this.options.ns.splice(index, 1);
339
318
  }
340
319
  }
341
- getResource(lng, ns, key) {
342
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
320
+ getResource(lng, ns, key, options = {}) {
343
321
  const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
344
322
  const ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
345
323
  let path;
@@ -366,10 +344,9 @@ class ResourceStore extends EventEmitter {
366
344
  if (result || !ignoreJSONStructure || !isString(key)) return result;
367
345
  return deepFind(this.data?.[lng]?.[ns], key, keySeparator);
368
346
  }
369
- addResource(lng, ns, key, value) {
370
- let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
371
- silent: false
372
- };
347
+ addResource(lng, ns, key, value, options = {
348
+ silent: false
349
+ }) {
373
350
  const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
374
351
  let path = [lng, ns];
375
352
  if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
@@ -382,10 +359,9 @@ class ResourceStore extends EventEmitter {
382
359
  setPath(this.data, path, value);
383
360
  if (!options.silent) this.emit('added', lng, ns, key, value);
384
361
  }
385
- addResources(lng, ns, resources) {
386
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
387
- silent: false
388
- };
362
+ addResources(lng, ns, resources, options = {
363
+ silent: false
364
+ }) {
389
365
  for (const m in resources) {
390
366
  if (isString(resources[m]) || Array.isArray(resources[m])) this.addResource(lng, ns, m, resources[m], {
391
367
  silent: true
@@ -393,11 +369,10 @@ class ResourceStore extends EventEmitter {
393
369
  }
394
370
  if (!options.silent) this.emit('added', lng, ns, resources);
395
371
  }
396
- addResourceBundle(lng, ns, resources, deep, overwrite) {
397
- let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {
398
- silent: false,
399
- skipCopy: false
400
- };
372
+ addResourceBundle(lng, ns, resources, deep, overwrite, options = {
373
+ silent: false,
374
+ skipCopy: false
375
+ }) {
401
376
  let path = [lng, ns];
402
377
  if (lng.indexOf('.') > -1) {
403
378
  path = lng.split('.');
@@ -462,8 +437,7 @@ var postProcessor = {
462
437
  const checkedLoadedFor = {};
463
438
  const shouldHandleAsObject = res => !isString(res) && typeof res !== 'boolean' && typeof res !== 'number';
464
439
  class Translator extends EventEmitter {
465
- constructor(services) {
466
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
440
+ constructor(services, options = {}) {
467
441
  super();
468
442
  copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector', 'i18nFormat', 'utils'], services, this);
469
443
  this.options = options;
@@ -475,23 +449,23 @@ class Translator extends EventEmitter {
475
449
  changeLanguage(lng) {
476
450
  if (lng) this.language = lng;
477
451
  }
478
- exists(key) {
479
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
480
- interpolation: {}
452
+ exists(key, o = {
453
+ interpolation: {}
454
+ }) {
455
+ const opt = {
456
+ ...o
481
457
  };
482
- if (key == null) {
483
- return false;
484
- }
485
- const resolved = this.resolve(key, options);
458
+ if (key == null) return false;
459
+ const resolved = this.resolve(key, opt);
486
460
  return resolved?.res !== undefined;
487
461
  }
488
- extractFromKey(key, options) {
489
- let nsSeparator = options.nsSeparator !== undefined ? options.nsSeparator : this.options.nsSeparator;
462
+ extractFromKey(key, opt) {
463
+ let nsSeparator = opt.nsSeparator !== undefined ? opt.nsSeparator : this.options.nsSeparator;
490
464
  if (nsSeparator === undefined) nsSeparator = ':';
491
- const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
492
- let namespaces = options.ns || this.options.defaultNS || [];
465
+ const keySeparator = opt.keySeparator !== undefined ? opt.keySeparator : this.options.keySeparator;
466
+ let namespaces = opt.ns || this.options.defaultNS || [];
493
467
  const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
494
- const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
468
+ const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !opt.keySeparator && !this.options.userDefinedNsSeparator && !opt.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
495
469
  if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
496
470
  const m = key.match(this.interpolator.nestingRegexp);
497
471
  if (m && m.length > 0) {
@@ -509,28 +483,32 @@ class Translator extends EventEmitter {
509
483
  namespaces: isString(namespaces) ? [namespaces] : namespaces
510
484
  };
511
485
  }
512
- translate(keys, options, lastKey) {
513
- if (typeof options !== 'object' && this.options.overloadTranslationOptionHandler) {
514
- options = this.options.overloadTranslationOptionHandler(arguments);
486
+ translate(keys, o, lastKey) {
487
+ let opt = typeof o === 'object' ? {
488
+ ...o
489
+ } : o;
490
+ if (typeof opt !== 'object' && this.options.overloadTranslationOptionHandler) {
491
+ opt = this.options.overloadTranslationOptionHandler(arguments);
515
492
  }
516
- if (typeof options === 'object') options = {
517
- ...options
493
+ if (typeof options === 'object') opt = {
494
+ ...opt
518
495
  };
519
- if (!options) options = {};
496
+ if (!opt) opt = {};
520
497
  if (keys == null) return '';
521
498
  if (!Array.isArray(keys)) keys = [String(keys)];
522
- const returnDetails = options.returnDetails !== undefined ? options.returnDetails : this.options.returnDetails;
523
- const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
499
+ const returnDetails = opt.returnDetails !== undefined ? opt.returnDetails : this.options.returnDetails;
500
+ const keySeparator = opt.keySeparator !== undefined ? opt.keySeparator : this.options.keySeparator;
524
501
  const {
525
502
  key,
526
503
  namespaces
527
- } = this.extractFromKey(keys[keys.length - 1], options);
504
+ } = this.extractFromKey(keys[keys.length - 1], opt);
528
505
  const namespace = namespaces[namespaces.length - 1];
529
- const lng = options.lng || this.language;
530
- const appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
506
+ let nsSeparator = opt.nsSeparator !== undefined ? opt.nsSeparator : this.options.nsSeparator;
507
+ if (nsSeparator === undefined) nsSeparator = ':';
508
+ const lng = opt.lng || this.language;
509
+ const appendNamespaceToCIMode = opt.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
531
510
  if (lng?.toLowerCase() === 'cimode') {
532
511
  if (appendNamespaceToCIMode) {
533
- const nsSeparator = options.nsSeparator || this.options.nsSeparator;
534
512
  if (returnDetails) {
535
513
  return {
536
514
  res: `${namespace}${nsSeparator}${key}`,
@@ -538,7 +516,7 @@ class Translator extends EventEmitter {
538
516
  exactUsedKey: key,
539
517
  usedLng: lng,
540
518
  usedNS: namespace,
541
- usedParams: this.getUsedParamsDetails(options)
519
+ usedParams: this.getUsedParamsDetails(opt)
542
520
  };
543
521
  }
544
522
  return `${namespace}${nsSeparator}${key}`;
@@ -550,26 +528,26 @@ class Translator extends EventEmitter {
550
528
  exactUsedKey: key,
551
529
  usedLng: lng,
552
530
  usedNS: namespace,
553
- usedParams: this.getUsedParamsDetails(options)
531
+ usedParams: this.getUsedParamsDetails(opt)
554
532
  };
555
533
  }
556
534
  return key;
557
535
  }
558
- const resolved = this.resolve(keys, options);
536
+ const resolved = this.resolve(keys, opt);
559
537
  let res = resolved?.res;
560
538
  const resUsedKey = resolved?.usedKey || key;
561
539
  const resExactUsedKey = resolved?.exactUsedKey || key;
562
540
  const noObject = ['[object Number]', '[object Function]', '[object RegExp]'];
563
- const joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays;
541
+ const joinArrays = opt.joinArrays !== undefined ? opt.joinArrays : this.options.joinArrays;
564
542
  const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
565
- const needsPluralHandling = options.count !== undefined && !isString(options.count);
566
- const hasDefaultValue = Translator.hasDefaultValue(options);
567
- const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : '';
568
- const defaultValueSuffixOrdinalFallback = options.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, {
543
+ const needsPluralHandling = opt.count !== undefined && !isString(opt.count);
544
+ const hasDefaultValue = Translator.hasDefaultValue(opt);
545
+ const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, opt) : '';
546
+ const defaultValueSuffixOrdinalFallback = opt.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, {
569
547
  ordinal: false
570
548
  }) : '';
571
- const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0;
572
- const defaultValue = needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] || options[`defaultValue${defaultValueSuffix}`] || options[`defaultValue${defaultValueSuffixOrdinalFallback}`] || options.defaultValue;
549
+ const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
550
+ const defaultValue = needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] || opt[`defaultValue${defaultValueSuffix}`] || opt[`defaultValue${defaultValueSuffixOrdinalFallback}`] || opt.defaultValue;
573
551
  let resForObjHndl = res;
574
552
  if (handleAsObjectInI18nFormat && !res && hasDefaultValue) {
575
553
  resForObjHndl = defaultValue;
@@ -577,17 +555,17 @@ class Translator extends EventEmitter {
577
555
  const handleAsObject = shouldHandleAsObject(resForObjHndl);
578
556
  const resType = Object.prototype.toString.apply(resForObjHndl);
579
557
  if (handleAsObjectInI18nFormat && resForObjHndl && handleAsObject && noObject.indexOf(resType) < 0 && !(isString(joinArrays) && Array.isArray(resForObjHndl))) {
580
- if (!options.returnObjects && !this.options.returnObjects) {
558
+ if (!opt.returnObjects && !this.options.returnObjects) {
581
559
  if (!this.options.returnedObjectHandler) {
582
560
  this.logger.warn('accessing an object - but returnObjects options is not enabled!');
583
561
  }
584
562
  const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, resForObjHndl, {
585
- ...options,
563
+ ...opt,
586
564
  ns: namespaces
587
565
  }) : `key '${key} (${this.language})' returned an object instead of string.`;
588
566
  if (returnDetails) {
589
567
  resolved.res = r;
590
- resolved.usedParams = this.getUsedParamsDetails(options);
568
+ resolved.usedParams = this.getUsedParamsDetails(opt);
591
569
  return resolved;
592
570
  }
593
571
  return r;
@@ -601,7 +579,7 @@ class Translator extends EventEmitter {
601
579
  const deepKey = `${newKeyToUse}${keySeparator}${m}`;
602
580
  if (hasDefaultValue && !res) {
603
581
  copy[m] = this.translate(deepKey, {
604
- ...options,
582
+ ...opt,
605
583
  defaultValue: shouldHandleAsObject(defaultValue) ? defaultValue[m] : undefined,
606
584
  ...{
607
585
  joinArrays: false,
@@ -610,7 +588,7 @@ class Translator extends EventEmitter {
610
588
  });
611
589
  } else {
612
590
  copy[m] = this.translate(deepKey, {
613
- ...options,
591
+ ...opt,
614
592
  ...{
615
593
  joinArrays: false,
616
594
  ns: namespaces
@@ -624,7 +602,7 @@ class Translator extends EventEmitter {
624
602
  }
625
603
  } else if (handleAsObjectInI18nFormat && isString(joinArrays) && Array.isArray(res)) {
626
604
  res = res.join(joinArrays);
627
- if (res) res = this.extendTranslation(res, keys, options, lastKey);
605
+ if (res) res = this.extendTranslation(res, keys, opt, lastKey);
628
606
  } else {
629
607
  let usedDefault = false;
630
608
  let usedKey = false;
@@ -636,47 +614,47 @@ class Translator extends EventEmitter {
636
614
  usedKey = true;
637
615
  res = key;
638
616
  }
639
- const missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
617
+ const missingKeyNoValueFallbackToKey = opt.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
640
618
  const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? undefined : res;
641
619
  const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
642
620
  if (usedKey || usedDefault || updateMissing) {
643
621
  this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? defaultValue : res);
644
622
  if (keySeparator) {
645
623
  const fk = this.resolve(key, {
646
- ...options,
624
+ ...opt,
647
625
  keySeparator: false
648
626
  });
649
627
  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.');
650
628
  }
651
629
  let lngs = [];
652
- const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
630
+ const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, opt.lng || this.language);
653
631
  if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) {
654
632
  for (let i = 0; i < fallbackLngs.length; i++) {
655
633
  lngs.push(fallbackLngs[i]);
656
634
  }
657
635
  } else if (this.options.saveMissingTo === 'all') {
658
- lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
636
+ lngs = this.languageUtils.toResolveHierarchy(opt.lng || this.language);
659
637
  } else {
660
- lngs.push(options.lng || this.language);
638
+ lngs.push(opt.lng || this.language);
661
639
  }
662
640
  const send = (l, k, specificDefaultValue) => {
663
641
  const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
664
642
  if (this.options.missingKeyHandler) {
665
- this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
643
+ this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, opt);
666
644
  } else if (this.backendConnector?.saveMissing) {
667
- this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
645
+ this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, opt);
668
646
  }
669
647
  this.emit('missingKey', l, namespace, k, res);
670
648
  };
671
649
  if (this.options.saveMissing) {
672
650
  if (this.options.saveMissingPlurals && needsPluralHandling) {
673
651
  lngs.forEach(language => {
674
- const suffixes = this.pluralResolver.getSuffixes(language, options);
675
- if (needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.indexOf(`${this.options.pluralSeparator}zero`) < 0) {
652
+ const suffixes = this.pluralResolver.getSuffixes(language, opt);
653
+ if (needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.indexOf(`${this.options.pluralSeparator}zero`) < 0) {
676
654
  suffixes.push(`${this.options.pluralSeparator}zero`);
677
655
  }
678
656
  suffixes.forEach(suffix => {
679
- send([language], key + suffix, options[`defaultValue${suffix}`] || defaultValue);
657
+ send([language], key + suffix, opt[`defaultValue${suffix}`] || defaultValue);
680
658
  });
681
659
  });
682
660
  } else {
@@ -684,83 +662,80 @@ class Translator extends EventEmitter {
684
662
  }
685
663
  }
686
664
  }
687
- res = this.extendTranslation(res, keys, options, resolved, lastKey);
688
- if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
665
+ res = this.extendTranslation(res, keys, opt, resolved, lastKey);
666
+ if (usedKey && res === key && this.options.appendNamespaceToMissingKey) {
667
+ res = `${namespace}${nsSeparator}${key}`;
668
+ }
689
669
  if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
690
- res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : undefined);
670
+ res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}${nsSeparator}${key}` : key, usedDefault ? res : undefined, opt);
691
671
  }
692
672
  }
693
673
  if (returnDetails) {
694
674
  resolved.res = res;
695
- resolved.usedParams = this.getUsedParamsDetails(options);
675
+ resolved.usedParams = this.getUsedParamsDetails(opt);
696
676
  return resolved;
697
677
  }
698
678
  return res;
699
679
  }
700
- extendTranslation(res, key, options, resolved, lastKey) {
701
- var _this = this;
680
+ extendTranslation(res, key, opt, resolved, lastKey) {
702
681
  if (this.i18nFormat?.parse) {
703
682
  res = this.i18nFormat.parse(res, {
704
683
  ...this.options.interpolation.defaultVariables,
705
- ...options
706
- }, options.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
684
+ ...opt
685
+ }, opt.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
707
686
  resolved
708
687
  });
709
- } else if (!options.skipInterpolation) {
710
- if (options.interpolation) this.interpolator.init({
711
- ...options,
688
+ } else if (!opt.skipInterpolation) {
689
+ if (opt.interpolation) this.interpolator.init({
690
+ ...opt,
712
691
  ...{
713
692
  interpolation: {
714
693
  ...this.options.interpolation,
715
- ...options.interpolation
694
+ ...opt.interpolation
716
695
  }
717
696
  }
718
697
  });
719
- const skipOnVariables = isString(res) && (options?.interpolation?.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
698
+ const skipOnVariables = isString(res) && (opt?.interpolation?.skipOnVariables !== undefined ? opt.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
720
699
  let nestBef;
721
700
  if (skipOnVariables) {
722
701
  const nb = res.match(this.interpolator.nestingRegexp);
723
702
  nestBef = nb && nb.length;
724
703
  }
725
- let data = options.replace && !isString(options.replace) ? options.replace : options;
704
+ let data = opt.replace && !isString(opt.replace) ? opt.replace : opt;
726
705
  if (this.options.interpolation.defaultVariables) data = {
727
706
  ...this.options.interpolation.defaultVariables,
728
707
  ...data
729
708
  };
730
- res = this.interpolator.interpolate(res, data, options.lng || this.language || resolved.usedLng, options);
709
+ res = this.interpolator.interpolate(res, data, opt.lng || this.language || resolved.usedLng, opt);
731
710
  if (skipOnVariables) {
732
711
  const na = res.match(this.interpolator.nestingRegexp);
733
712
  const nestAft = na && na.length;
734
- if (nestBef < nestAft) options.nest = false;
713
+ if (nestBef < nestAft) opt.nest = false;
735
714
  }
736
- if (!options.lng && resolved && resolved.res) options.lng = this.language || resolved.usedLng;
737
- if (options.nest !== false) res = this.interpolator.nest(res, function () {
738
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
739
- args[_key] = arguments[_key];
740
- }
741
- if (lastKey?.[0] === args[0] && !options.context) {
742
- _this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
715
+ if (!opt.lng && resolved && resolved.res) opt.lng = this.language || resolved.usedLng;
716
+ if (opt.nest !== false) res = this.interpolator.nest(res, (...args) => {
717
+ if (lastKey?.[0] === args[0] && !opt.context) {
718
+ this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
743
719
  return null;
744
720
  }
745
- return _this.translate(...args, key);
746
- }, options);
747
- if (options.interpolation) this.interpolator.reset();
721
+ return this.translate(...args, key);
722
+ }, opt);
723
+ if (opt.interpolation) this.interpolator.reset();
748
724
  }
749
- const postProcess = options.postProcess || this.options.postProcess;
725
+ const postProcess = opt.postProcess || this.options.postProcess;
750
726
  const postProcessorNames = isString(postProcess) ? [postProcess] : postProcess;
751
- if (res != null && postProcessorNames?.length && options.applyPostProcessor !== false) {
727
+ if (res != null && postProcessorNames?.length && opt.applyPostProcessor !== false) {
752
728
  res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
753
729
  i18nResolved: {
754
730
  ...resolved,
755
- usedParams: this.getUsedParamsDetails(options)
731
+ usedParams: this.getUsedParamsDetails(opt)
756
732
  },
757
- ...options
758
- } : options, this);
733
+ ...opt
734
+ } : opt, this);
759
735
  }
760
736
  return res;
761
737
  }
762
- resolve(keys) {
763
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
738
+ resolve(keys, opt = {}) {
764
739
  let found;
765
740
  let usedKey;
766
741
  let exactUsedKey;
@@ -769,15 +744,15 @@ class Translator extends EventEmitter {
769
744
  if (isString(keys)) keys = [keys];
770
745
  keys.forEach(k => {
771
746
  if (this.isValidLookup(found)) return;
772
- const extracted = this.extractFromKey(k, options);
747
+ const extracted = this.extractFromKey(k, opt);
773
748
  const key = extracted.key;
774
749
  usedKey = key;
775
750
  let namespaces = extracted.namespaces;
776
751
  if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
777
- const needsPluralHandling = options.count !== undefined && !isString(options.count);
778
- const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0;
779
- const needsContextHandling = options.context !== undefined && (isString(options.context) || typeof options.context === 'number') && options.context !== '';
780
- const codes = options.lngs ? options.lngs : this.languageUtils.toResolveHierarchy(options.lng || this.language, options.fallbackLng);
752
+ const needsPluralHandling = opt.count !== undefined && !isString(opt.count);
753
+ const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
754
+ const needsContextHandling = opt.context !== undefined && (isString(opt.context) || typeof opt.context === 'number') && opt.context !== '';
755
+ const codes = opt.lngs ? opt.lngs : this.languageUtils.toResolveHierarchy(opt.lng || this.language, opt.fallbackLng);
781
756
  namespaces.forEach(ns => {
782
757
  if (this.isValidLookup(found)) return;
783
758
  usedNS = ns;
@@ -790,15 +765,15 @@ class Translator extends EventEmitter {
790
765
  usedLng = code;
791
766
  const finalKeys = [key];
792
767
  if (this.i18nFormat?.addLookupKeys) {
793
- this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
768
+ this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, opt);
794
769
  } else {
795
770
  let pluralSuffix;
796
- if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, options.count, options);
771
+ if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, opt.count, opt);
797
772
  const zeroSuffix = `${this.options.pluralSeparator}zero`;
798
773
  const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
799
774
  if (needsPluralHandling) {
800
775
  finalKeys.push(key + pluralSuffix);
801
- if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
776
+ if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
802
777
  finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
803
778
  }
804
779
  if (needsZeroSuffixLookup) {
@@ -806,11 +781,11 @@ class Translator extends EventEmitter {
806
781
  }
807
782
  }
808
783
  if (needsContextHandling) {
809
- const contextKey = `${key}${this.options.contextSeparator}${options.context}`;
784
+ const contextKey = `${key}${this.options.contextSeparator}${opt.context}`;
810
785
  finalKeys.push(contextKey);
811
786
  if (needsPluralHandling) {
812
787
  finalKeys.push(contextKey + pluralSuffix);
813
- if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
788
+ if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
814
789
  finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
815
790
  }
816
791
  if (needsZeroSuffixLookup) {
@@ -823,7 +798,7 @@ class Translator extends EventEmitter {
823
798
  while (possibleKey = finalKeys.pop()) {
824
799
  if (!this.isValidLookup(found)) {
825
800
  exactUsedKey = possibleKey;
826
- found = this.getResource(code, ns, possibleKey, options);
801
+ found = this.getResource(code, ns, possibleKey, opt);
827
802
  }
828
803
  }
829
804
  });
@@ -840,13 +815,11 @@ class Translator extends EventEmitter {
840
815
  isValidLookup(res) {
841
816
  return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === '');
842
817
  }
843
- getResource(code, ns, key) {
844
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
818
+ getResource(code, ns, key, options = {}) {
845
819
  if (this.i18nFormat?.getResource) return this.i18nFormat.getResource(code, ns, key, options);
846
820
  return this.resourceStore.getResource(code, ns, key, options);
847
821
  }
848
- getUsedParamsDetails() {
849
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
822
+ getUsedParamsDetails(options = {}) {
850
823
  const optionsKeys = ['defaultValue', 'ordinal', 'context', 'replace', 'lng', 'lngs', 'fallbackLng', 'ns', 'keySeparator', 'nsSeparator', 'returnObjects', 'returnDetails', 'joinArrays', 'postProcess', 'interpolation'];
851
824
  const useOptionsReplaceForData = options.replace && !isString(options.replace);
852
825
  let data = useOptionsReplaceForData ? options.replace : options;
@@ -935,6 +908,8 @@ class LanguageUtil {
935
908
  if (!found && this.options.supportedLngs) {
936
909
  codes.forEach(code => {
937
910
  if (found) return;
911
+ const lngScOnly = this.getScriptPartFromCode(code);
912
+ if (this.isSupportedCode(lngScOnly)) return found = lngScOnly;
938
913
  const lngOnly = this.getLanguagePartFromCode(code);
939
914
  if (this.isSupportedCode(lngOnly)) return found = lngOnly;
940
915
  found = this.options.supportedLngs.find(supportedLng => {
@@ -962,7 +937,7 @@ class LanguageUtil {
962
937
  return found || [];
963
938
  }
964
939
  toResolveHierarchy(code, fallbackCode) {
965
- const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
940
+ const fallbackCodes = this.getFallbackCodes((fallbackCode === false ? [] : fallbackCode) || this.options.fallbackLng || [], code);
966
941
  const codes = [];
967
942
  const addCode = c => {
968
943
  if (!c) return;
@@ -1001,8 +976,7 @@ const dummyRule = {
1001
976
  })
1002
977
  };
1003
978
  class PluralResolver {
1004
- constructor(languageUtils) {
1005
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
979
+ constructor(languageUtils, options = {}) {
1006
980
  this.languageUtils = languageUtils;
1007
981
  this.options = options;
1008
982
  this.logger = baseLogger.create('pluralResolver');
@@ -1014,8 +988,7 @@ class PluralResolver {
1014
988
  clearCache() {
1015
989
  this.pluralRulesCache = {};
1016
990
  }
1017
- getRule(code) {
1018
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
991
+ getRule(code, options = {}) {
1019
992
  const cleanedCode = getCleanedCode(code === 'dev' ? 'en' : code);
1020
993
  const type = options.ordinal ? 'ordinal' : 'cardinal';
1021
994
  const cacheKey = JSON.stringify({
@@ -1042,25 +1015,21 @@ class PluralResolver {
1042
1015
  this.pluralRulesCache[cacheKey] = rule;
1043
1016
  return rule;
1044
1017
  }
1045
- needsPlural(code) {
1046
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1018
+ needsPlural(code, options = {}) {
1047
1019
  let rule = this.getRule(code, options);
1048
1020
  if (!rule) rule = this.getRule('dev', options);
1049
1021
  return rule?.resolvedOptions().pluralCategories.length > 1;
1050
1022
  }
1051
- getPluralFormsOfKey(code, key) {
1052
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1023
+ getPluralFormsOfKey(code, key, options = {}) {
1053
1024
  return this.getSuffixes(code, options).map(suffix => `${key}${suffix}`);
1054
1025
  }
1055
- getSuffixes(code) {
1056
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1026
+ getSuffixes(code, options = {}) {
1057
1027
  let rule = this.getRule(code, options);
1058
1028
  if (!rule) rule = this.getRule('dev', options);
1059
1029
  if (!rule) return [];
1060
1030
  return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map(pluralCategory => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${pluralCategory}`);
1061
1031
  }
1062
- getSuffix(code, count) {
1063
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1032
+ getSuffix(code, count, options = {}) {
1064
1033
  const rule = this.getRule(code, options);
1065
1034
  if (rule) {
1066
1035
  return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${rule.select(count)}`;
@@ -1070,9 +1039,7 @@ class PluralResolver {
1070
1039
  }
1071
1040
  }
1072
1041
 
1073
- const deepFindWithDefaults = function (data, defaultData, key) {
1074
- let keySeparator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '.';
1075
- let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
1042
+ const deepFindWithDefaults = (data, defaultData, key, keySeparator = '.', ignoreJSONStructure = true) => {
1076
1043
  let path = getPathWithDefaults(data, defaultData, key);
1077
1044
  if (!path && ignoreJSONStructure && isString(key)) {
1078
1045
  path = deepFind(data, key, keySeparator);
@@ -1082,15 +1049,13 @@ const deepFindWithDefaults = function (data, defaultData, key) {
1082
1049
  };
1083
1050
  const regexSafe = val => val.replace(/\$/g, '$$$$');
1084
1051
  class Interpolator {
1085
- constructor() {
1086
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1052
+ constructor(options = {}) {
1087
1053
  this.logger = baseLogger.create('interpolator');
1088
1054
  this.options = options;
1089
1055
  this.format = options?.interpolation?.format || (value => value);
1090
1056
  this.init(options);
1091
1057
  }
1092
- init() {
1093
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1058
+ init(options = {}) {
1094
1059
  if (!options.interpolation) options.interpolation = {
1095
1060
  escapeValue: true
1096
1061
  };
@@ -1213,8 +1178,7 @@ class Interpolator {
1213
1178
  });
1214
1179
  return str;
1215
1180
  }
1216
- nest(str, fc) {
1217
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1181
+ nest(str, fc, options = {}) {
1218
1182
  let match;
1219
1183
  let value;
1220
1184
  let clonedOptions;
@@ -1311,68 +1275,68 @@ const parseFormatStr = formatStr => {
1311
1275
  };
1312
1276
  const createCachedFormatter = fn => {
1313
1277
  const cache = {};
1314
- return (val, lng, options) => {
1315
- let optForCache = options;
1316
- if (options && options.interpolationkey && options.formatParams && options.formatParams[options.interpolationkey] && options[options.interpolationkey]) {
1278
+ return (v, l, o) => {
1279
+ let optForCache = o;
1280
+ if (o && o.interpolationkey && o.formatParams && o.formatParams[o.interpolationkey] && o[o.interpolationkey]) {
1317
1281
  optForCache = {
1318
1282
  ...optForCache,
1319
- [options.interpolationkey]: undefined
1283
+ [o.interpolationkey]: undefined
1320
1284
  };
1321
1285
  }
1322
- const key = lng + JSON.stringify(optForCache);
1323
- let formatter = cache[key];
1324
- if (!formatter) {
1325
- formatter = fn(getCleanedCode(lng), options);
1326
- cache[key] = formatter;
1286
+ const key = l + JSON.stringify(optForCache);
1287
+ let frm = cache[key];
1288
+ if (!frm) {
1289
+ frm = fn(getCleanedCode(l), o);
1290
+ cache[key] = frm;
1327
1291
  }
1328
- return formatter(val);
1292
+ return frm(v);
1329
1293
  };
1330
1294
  };
1295
+ const createNonCachedFormatter = fn => (v, l, o) => fn(getCleanedCode(l), o)(v);
1331
1296
  class Formatter {
1332
- constructor() {
1333
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1297
+ constructor(options = {}) {
1334
1298
  this.logger = baseLogger.create('formatter');
1335
1299
  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;
1336
1307
  this.formats = {
1337
- number: createCachedFormatter((lng, opt) => {
1308
+ number: cf((lng, opt) => {
1338
1309
  const formatter = new Intl.NumberFormat(lng, {
1339
1310
  ...opt
1340
1311
  });
1341
1312
  return val => formatter.format(val);
1342
1313
  }),
1343
- currency: createCachedFormatter((lng, opt) => {
1314
+ currency: cf((lng, opt) => {
1344
1315
  const formatter = new Intl.NumberFormat(lng, {
1345
1316
  ...opt,
1346
1317
  style: 'currency'
1347
1318
  });
1348
1319
  return val => formatter.format(val);
1349
1320
  }),
1350
- datetime: createCachedFormatter((lng, opt) => {
1321
+ datetime: cf((lng, opt) => {
1351
1322
  const formatter = new Intl.DateTimeFormat(lng, {
1352
1323
  ...opt
1353
1324
  });
1354
1325
  return val => formatter.format(val);
1355
1326
  }),
1356
- relativetime: createCachedFormatter((lng, opt) => {
1327
+ relativetime: cf((lng, opt) => {
1357
1328
  const formatter = new Intl.RelativeTimeFormat(lng, {
1358
1329
  ...opt
1359
1330
  });
1360
1331
  return val => formatter.format(val, opt.range || 'day');
1361
1332
  }),
1362
- list: createCachedFormatter((lng, opt) => {
1333
+ list: cf((lng, opt) => {
1363
1334
  const formatter = new Intl.ListFormat(lng, {
1364
1335
  ...opt
1365
1336
  });
1366
1337
  return val => formatter.format(val);
1367
1338
  })
1368
1339
  };
1369
- this.init(options);
1370
- }
1371
- init(services) {
1372
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
1373
- interpolation: {}
1374
- };
1375
- this.formatSeparator = options.interpolation.formatSeparator || ',';
1376
1340
  }
1377
1341
  add(name, fc) {
1378
1342
  this.formats[name.toLowerCase().trim()] = fc;
@@ -1380,8 +1344,7 @@ class Formatter {
1380
1344
  addCached(name, fc) {
1381
1345
  this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
1382
1346
  }
1383
- format(value, format, lng) {
1384
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1347
+ format(value, format, lng, options = {}) {
1385
1348
  const formats = format.split(this.formatSeparator);
1386
1349
  if (formats.length > 1 && formats[0].indexOf('(') > 1 && formats[0].indexOf(')') < 0 && formats.find(f => f.indexOf(')') > -1)) {
1387
1350
  const lastIndex = formats.findIndex(f => f.indexOf(')') > -1);
@@ -1422,8 +1385,7 @@ const removePending = (q, name) => {
1422
1385
  }
1423
1386
  };
1424
1387
  class Connector extends EventEmitter {
1425
- constructor(backend, store, services) {
1426
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1388
+ constructor(backend, store, services, options = {}) {
1427
1389
  super();
1428
1390
  this.backend = backend;
1429
1391
  this.store = store;
@@ -1517,10 +1479,7 @@ class Connector extends EventEmitter {
1517
1479
  this.emit('loaded', loaded);
1518
1480
  this.queue = this.queue.filter(q => !q.done);
1519
1481
  }
1520
- read(lng, ns, fcName) {
1521
- let tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1522
- let wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
1523
- let callback = arguments.length > 5 ? arguments[5] : undefined;
1482
+ read(lng, ns, fcName, tried = 0, wait = this.retryTimeout, callback) {
1524
1483
  if (!lng.length) return callback(null, {});
1525
1484
  if (this.readingCalls >= this.maxParallelReads) {
1526
1485
  this.waitingReads.push({
@@ -1564,9 +1523,7 @@ class Connector extends EventEmitter {
1564
1523
  }
1565
1524
  return fc(lng, ns, resolver);
1566
1525
  }
1567
- prepareLoading(languages, namespaces) {
1568
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1569
- let callback = arguments.length > 3 ? arguments[3] : undefined;
1526
+ prepareLoading(languages, namespaces, options = {}, callback) {
1570
1527
  if (!this.backend) {
1571
1528
  this.logger.warn('No backend was added via i18next.use. Will not load resources.');
1572
1529
  return callback && callback();
@@ -1590,8 +1547,7 @@ class Connector extends EventEmitter {
1590
1547
  reload: true
1591
1548
  }, callback);
1592
1549
  }
1593
- loadOne(name) {
1594
- let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
1550
+ loadOne(name, prefix = '') {
1595
1551
  const s = name.split('|');
1596
1552
  const lng = s[0];
1597
1553
  const ns = s[1];
@@ -1601,9 +1557,7 @@ class Connector extends EventEmitter {
1601
1557
  this.loaded(name, err, data);
1602
1558
  });
1603
1559
  }
1604
- saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
1605
- let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
1606
- let clb = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : () => {};
1560
+ saveMissing(languages, namespace, key, fallbackValue, isUpdate, options = {}, clb = () => {}) {
1607
1561
  if (this.services?.utils?.hasLoadedNamespace && !this.services?.utils?.hasLoadedNamespace(namespace)) {
1608
1562
  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!!!');
1609
1563
  return;
@@ -1698,7 +1652,8 @@ const get = () => ({
1698
1652
  nestingOptionsSeparator: ',',
1699
1653
  maxReplaces: 1000,
1700
1654
  skipOnVariables: true
1701
- }
1655
+ },
1656
+ cacheInBuiltFormats: true
1702
1657
  });
1703
1658
  const transformOptions = options => {
1704
1659
  if (isString(options.ns)) options.ns = [options.ns];
@@ -1721,9 +1676,7 @@ const bindMemberFunctions = inst => {
1721
1676
  });
1722
1677
  };
1723
1678
  class I18n extends EventEmitter {
1724
- constructor() {
1725
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1726
- let callback = arguments.length > 1 ? arguments[1] : undefined;
1679
+ constructor(options = {}, callback) {
1727
1680
  super();
1728
1681
  this.options = transformOptions(options);
1729
1682
  this.services = {};
@@ -1742,10 +1695,7 @@ class I18n extends EventEmitter {
1742
1695
  }, 0);
1743
1696
  }
1744
1697
  }
1745
- init() {
1746
- var _this = this;
1747
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1748
- let callback = arguments.length > 1 ? arguments[1] : undefined;
1698
+ init(options = {}, callback) {
1749
1699
  this.isInitializing = true;
1750
1700
  if (typeof options === 'function') {
1751
1701
  callback = options;
@@ -1811,11 +1761,8 @@ class I18n extends EventEmitter {
1811
1761
  hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
1812
1762
  };
1813
1763
  s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
1814
- s.backendConnector.on('*', function (event) {
1815
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1816
- args[_key - 1] = arguments[_key];
1817
- }
1818
- _this.emit(event, ...args);
1764
+ s.backendConnector.on('*', (event, ...args) => {
1765
+ this.emit(event, ...args);
1819
1766
  });
1820
1767
  if (this.modules.languageDetector) {
1821
1768
  s.languageDetector = createClassOnDemand(this.modules.languageDetector);
@@ -1826,11 +1773,8 @@ class I18n extends EventEmitter {
1826
1773
  if (s.i18nFormat.init) s.i18nFormat.init(this);
1827
1774
  }
1828
1775
  this.translator = new Translator(this.services, this.options);
1829
- this.translator.on('*', function (event) {
1830
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
1831
- args[_key2 - 1] = arguments[_key2];
1832
- }
1833
- _this.emit(event, ...args);
1776
+ this.translator.on('*', (event, ...args) => {
1777
+ this.emit(event, ...args);
1834
1778
  });
1835
1779
  this.modules.external.forEach(m => {
1836
1780
  if (m.init) m.init(this);
@@ -1847,15 +1791,13 @@ class I18n extends EventEmitter {
1847
1791
  }
1848
1792
  const storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
1849
1793
  storeApi.forEach(fcName => {
1850
- this[fcName] = function () {
1851
- return _this.store[fcName](...arguments);
1852
- };
1794
+ this[fcName] = (...args) => this.store[fcName](...args);
1853
1795
  });
1854
1796
  const storeApiChained = ['addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle'];
1855
1797
  storeApiChained.forEach(fcName => {
1856
- this[fcName] = function () {
1857
- _this.store[fcName](...arguments);
1858
- return _this;
1798
+ this[fcName] = (...args) => {
1799
+ this.store[fcName](...args);
1800
+ return this;
1859
1801
  };
1860
1802
  });
1861
1803
  const deferred = defer();
@@ -1879,8 +1821,7 @@ class I18n extends EventEmitter {
1879
1821
  }
1880
1822
  return deferred;
1881
1823
  }
1882
- loadResources(language) {
1883
- let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
1824
+ loadResources(language, callback = noop) {
1884
1825
  let usedCallback = callback;
1885
1826
  const usedLng = isString(language) ? language : this.language;
1886
1827
  if (typeof language === 'function') usedCallback = language;
@@ -1967,9 +1908,12 @@ class I18n extends EventEmitter {
1967
1908
  break;
1968
1909
  }
1969
1910
  }
1911
+ if (!this.resolvedLanguage && this.languages.indexOf(l) < 0 && this.store.hasLanguageSomeTranslations(l)) {
1912
+ this.resolvedLanguage = l;
1913
+ this.languages.unshift(l);
1914
+ }
1970
1915
  }
1971
1916
  changeLanguage(lng, callback) {
1972
- var _this2 = this;
1973
1917
  this.isLanguageChangingTo = lng;
1974
1918
  const deferred = defer();
1975
1919
  this.emit('languageChanging', lng);
@@ -1981,24 +1925,23 @@ class I18n extends EventEmitter {
1981
1925
  };
1982
1926
  const done = (err, l) => {
1983
1927
  if (l) {
1984
- setLngProps(l);
1985
- this.translator.changeLanguage(l);
1986
- this.isLanguageChangingTo = undefined;
1987
- this.emit('languageChanged', l);
1988
- this.logger.log('languageChanged', l);
1928
+ if (this.isLanguageChangingTo === lng) {
1929
+ setLngProps(l);
1930
+ this.translator.changeLanguage(l);
1931
+ this.isLanguageChangingTo = undefined;
1932
+ this.emit('languageChanged', l);
1933
+ this.logger.log('languageChanged', l);
1934
+ }
1989
1935
  } else {
1990
1936
  this.isLanguageChangingTo = undefined;
1991
1937
  }
1992
- deferred.resolve(function () {
1993
- return _this2.t(...arguments);
1994
- });
1995
- if (callback) callback(err, function () {
1996
- return _this2.t(...arguments);
1997
- });
1938
+ deferred.resolve((...args) => this.t(...args));
1939
+ if (callback) callback(err, (...args) => this.t(...args));
1998
1940
  };
1999
1941
  const setLng = lngs => {
2000
1942
  if (!lng && !lngs && this.services.languageDetector) lngs = [];
2001
- const l = isString(lngs) ? lngs : this.services.languageUtils.getBestMatchFromCodes(lngs);
1943
+ const fl = isString(lngs) ? lngs : lngs && lngs[0];
1944
+ const l = this.store.hasLanguageSomeTranslations(fl) ? fl : this.services.languageUtils.getBestMatchFromCodes(isString(lngs) ? [lngs] : lngs);
2002
1945
  if (l) {
2003
1946
  if (!this.language) {
2004
1947
  setLngProps(l);
@@ -2024,31 +1967,27 @@ class I18n extends EventEmitter {
2024
1967
  return deferred;
2025
1968
  }
2026
1969
  getFixedT(lng, ns, keyPrefix) {
2027
- var _this3 = this;
2028
- const fixedT = function (key, opts) {
2029
- let options;
1970
+ const fixedT = (key, opts, ...rest) => {
1971
+ let o;
2030
1972
  if (typeof opts !== 'object') {
2031
- for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
2032
- rest[_key3 - 2] = arguments[_key3];
2033
- }
2034
- options = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
1973
+ o = this.options.overloadTranslationOptionHandler([key, opts].concat(rest));
2035
1974
  } else {
2036
- options = {
1975
+ o = {
2037
1976
  ...opts
2038
1977
  };
2039
1978
  }
2040
- options.lng = options.lng || fixedT.lng;
2041
- options.lngs = options.lngs || fixedT.lngs;
2042
- options.ns = options.ns || fixedT.ns;
2043
- if (options.keyPrefix !== '') options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
2044
- const keySeparator = _this3.options.keySeparator || '.';
1979
+ o.lng = o.lng || fixedT.lng;
1980
+ o.lngs = o.lngs || fixedT.lngs;
1981
+ o.ns = o.ns || fixedT.ns;
1982
+ if (o.keyPrefix !== '') o.keyPrefix = o.keyPrefix || keyPrefix || fixedT.keyPrefix;
1983
+ const keySeparator = this.options.keySeparator || '.';
2045
1984
  let resultKey;
2046
- if (options.keyPrefix && Array.isArray(key)) {
2047
- resultKey = key.map(k => `${options.keyPrefix}${keySeparator}${k}`);
1985
+ if (o.keyPrefix && Array.isArray(key)) {
1986
+ resultKey = key.map(k => `${o.keyPrefix}${keySeparator}${k}`);
2048
1987
  } else {
2049
- resultKey = options.keyPrefix ? `${options.keyPrefix}${keySeparator}${key}` : key;
1988
+ resultKey = o.keyPrefix ? `${o.keyPrefix}${keySeparator}${key}` : key;
2050
1989
  }
2051
- return _this3.t(resultKey, options);
1990
+ return this.t(resultKey, o);
2052
1991
  };
2053
1992
  if (isString(lng)) {
2054
1993
  fixedT.lng = lng;
@@ -2059,23 +1998,16 @@ class I18n extends EventEmitter {
2059
1998
  fixedT.keyPrefix = keyPrefix;
2060
1999
  return fixedT;
2061
2000
  }
2062
- t() {
2063
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
2064
- args[_key4] = arguments[_key4];
2065
- }
2001
+ t(...args) {
2066
2002
  return this.translator?.translate(...args);
2067
2003
  }
2068
- exists() {
2069
- for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
2070
- args[_key5] = arguments[_key5];
2071
- }
2004
+ exists(...args) {
2072
2005
  return this.translator?.exists(...args);
2073
2006
  }
2074
2007
  setDefaultNamespace(ns) {
2075
2008
  this.options.defaultNS = ns;
2076
2009
  }
2077
- hasLoadedNamespace(ns) {
2078
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2010
+ hasLoadedNamespace(ns, options = {}) {
2079
2011
  if (!this.isInitialized) {
2080
2012
  this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
2081
2013
  return false;
@@ -2140,14 +2072,10 @@ class I18n extends EventEmitter {
2140
2072
  const languageUtils = this.services?.languageUtils || new LanguageUtil(get());
2141
2073
  return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
2142
2074
  }
2143
- static createInstance() {
2144
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2145
- let callback = arguments.length > 1 ? arguments[1] : undefined;
2075
+ static createInstance(options = {}, callback) {
2146
2076
  return new I18n(options, callback);
2147
2077
  }
2148
- cloneInstance() {
2149
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2150
- let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
2078
+ cloneInstance(options = {}, callback = noop) {
2151
2079
  const forkResourceStore = options.forkResourceStore;
2152
2080
  if (forkResourceStore) delete options.forkResourceStore;
2153
2081
  const mergedOptions = {
@@ -2176,21 +2104,19 @@ class I18n extends EventEmitter {
2176
2104
  prev[l] = {
2177
2105
  ...this.store.data[l]
2178
2106
  };
2179
- return Object.keys(prev[l]).reduce((acc, n) => {
2107
+ prev[l] = Object.keys(prev[l]).reduce((acc, n) => {
2180
2108
  acc[n] = {
2181
2109
  ...prev[l][n]
2182
2110
  };
2183
2111
  return acc;
2184
- }, {});
2112
+ }, prev[l]);
2113
+ return prev;
2185
2114
  }, {});
2186
2115
  clone.store = new ResourceStore(clonedData, mergedOptions);
2187
2116
  clone.services.resourceStore = clone.store;
2188
2117
  }
2189
2118
  clone.translator = new Translator(clone.services, mergedOptions);
2190
- clone.translator.on('*', function (event) {
2191
- for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
2192
- args[_key6 - 1] = arguments[_key6];
2193
- }
2119
+ clone.translator.on('*', (event, ...args) => {
2194
2120
  clone.emit(event, ...args);
2195
2121
  });
2196
2122
  clone.init(mergedOptions, callback);