i18next 25.1.2 → 25.1.3

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/.nvmrc CHANGED
@@ -1 +1 @@
1
- 20.18.0
1
+ 22.14.0
@@ -158,8 +158,7 @@ const looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
158
158
  }
159
159
  return matched;
160
160
  };
161
- const deepFind = function (obj, path) {
162
- let keySeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
161
+ const deepFind = (obj, path, keySeparator = '.') => {
163
162
  if (!obj) return undefined;
164
163
  if (obj[path]) {
165
164
  if (!Object.prototype.hasOwnProperty.call(obj, path)) return undefined;
@@ -209,39 +208,25 @@ const consoleLogger = {
209
208
  }
210
209
  };
211
210
  class Logger {
212
- constructor(concreteLogger) {
213
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
211
+ constructor(concreteLogger, options = {}) {
214
212
  this.init(concreteLogger, options);
215
213
  }
216
- init(concreteLogger) {
217
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
214
+ init(concreteLogger, options = {}) {
218
215
  this.prefix = options.prefix || 'i18next:';
219
216
  this.logger = concreteLogger || consoleLogger;
220
217
  this.options = options;
221
218
  this.debug = options.debug;
222
219
  }
223
- log() {
224
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
225
- args[_key] = arguments[_key];
226
- }
220
+ log(...args) {
227
221
  return this.forward(args, 'log', '', true);
228
222
  }
229
- warn() {
230
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
231
- args[_key2] = arguments[_key2];
232
- }
223
+ warn(...args) {
233
224
  return this.forward(args, 'warn', '', true);
234
225
  }
235
- error() {
236
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
237
- args[_key3] = arguments[_key3];
238
- }
226
+ error(...args) {
239
227
  return this.forward(args, 'error', '');
240
228
  }
241
- deprecate() {
242
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
243
- args[_key4] = arguments[_key4];
244
- }
229
+ deprecate(...args) {
245
230
  return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
246
231
  }
247
232
  forward(args, lvl, prefix, debugOnly) {
@@ -285,14 +270,10 @@ class EventEmitter {
285
270
  }
286
271
  this.observers[event].delete(listener);
287
272
  }
288
- emit(event) {
289
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
290
- args[_key - 1] = arguments[_key];
291
- }
273
+ emit(event, ...args) {
292
274
  if (this.observers[event]) {
293
275
  const cloned = Array.from(this.observers[event].entries());
294
- cloned.forEach(_ref => {
295
- let [observer, numTimesAdded] = _ref;
276
+ cloned.forEach(([observer, numTimesAdded]) => {
296
277
  for (let i = 0; i < numTimesAdded; i++) {
297
278
  observer(...args);
298
279
  }
@@ -300,8 +281,7 @@ class EventEmitter {
300
281
  }
301
282
  if (this.observers['*']) {
302
283
  const cloned = Array.from(this.observers['*'].entries());
303
- cloned.forEach(_ref2 => {
304
- let [observer, numTimesAdded] = _ref2;
284
+ cloned.forEach(([observer, numTimesAdded]) => {
305
285
  for (let i = 0; i < numTimesAdded; i++) {
306
286
  observer.apply(observer, [event, ...args]);
307
287
  }
@@ -311,11 +291,10 @@ class EventEmitter {
311
291
  }
312
292
 
313
293
  class ResourceStore extends EventEmitter {
314
- constructor(data) {
315
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
316
- ns: ['translation'],
317
- defaultNS: 'translation'
318
- };
294
+ constructor(data, options = {
295
+ ns: ['translation'],
296
+ defaultNS: 'translation'
297
+ }) {
319
298
  super();
320
299
  this.data = data || {};
321
300
  this.options = options;
@@ -337,8 +316,7 @@ class ResourceStore extends EventEmitter {
337
316
  this.options.ns.splice(index, 1);
338
317
  }
339
318
  }
340
- getResource(lng, ns, key) {
341
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
319
+ getResource(lng, ns, key, options = {}) {
342
320
  const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
343
321
  const ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
344
322
  let path;
@@ -365,10 +343,9 @@ class ResourceStore extends EventEmitter {
365
343
  if (result || !ignoreJSONStructure || !isString(key)) return result;
366
344
  return deepFind(this.data?.[lng]?.[ns], key, keySeparator);
367
345
  }
368
- addResource(lng, ns, key, value) {
369
- let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
370
- silent: false
371
- };
346
+ addResource(lng, ns, key, value, options = {
347
+ silent: false
348
+ }) {
372
349
  const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
373
350
  let path = [lng, ns];
374
351
  if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
@@ -381,10 +358,9 @@ class ResourceStore extends EventEmitter {
381
358
  setPath(this.data, path, value);
382
359
  if (!options.silent) this.emit('added', lng, ns, key, value);
383
360
  }
384
- addResources(lng, ns, resources) {
385
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
386
- silent: false
387
- };
361
+ addResources(lng, ns, resources, options = {
362
+ silent: false
363
+ }) {
388
364
  for (const m in resources) {
389
365
  if (isString(resources[m]) || Array.isArray(resources[m])) this.addResource(lng, ns, m, resources[m], {
390
366
  silent: true
@@ -392,11 +368,10 @@ class ResourceStore extends EventEmitter {
392
368
  }
393
369
  if (!options.silent) this.emit('added', lng, ns, resources);
394
370
  }
395
- addResourceBundle(lng, ns, resources, deep, overwrite) {
396
- let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {
397
- silent: false,
398
- skipCopy: false
399
- };
371
+ addResourceBundle(lng, ns, resources, deep, overwrite, options = {
372
+ silent: false,
373
+ skipCopy: false
374
+ }) {
400
375
  let path = [lng, ns];
401
376
  if (lng.indexOf('.') > -1) {
402
377
  path = lng.split('.');
@@ -461,8 +436,7 @@ var postProcessor = {
461
436
  const checkedLoadedFor = {};
462
437
  const shouldHandleAsObject = res => !isString(res) && typeof res !== 'boolean' && typeof res !== 'number';
463
438
  class Translator extends EventEmitter {
464
- constructor(services) {
465
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
439
+ constructor(services, options = {}) {
466
440
  super();
467
441
  copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector', 'i18nFormat', 'utils'], services, this);
468
442
  this.options = options;
@@ -474,10 +448,9 @@ class Translator extends EventEmitter {
474
448
  changeLanguage(lng) {
475
449
  if (lng) this.language = lng;
476
450
  }
477
- exists(key) {
478
- let o = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
479
- interpolation: {}
480
- };
451
+ exists(key, o = {
452
+ interpolation: {}
453
+ }) {
481
454
  const opt = {
482
455
  ...o
483
456
  };
@@ -529,11 +502,12 @@ class Translator extends EventEmitter {
529
502
  namespaces
530
503
  } = this.extractFromKey(keys[keys.length - 1], opt);
531
504
  const namespace = namespaces[namespaces.length - 1];
505
+ let nsSeparator = opt.nsSeparator !== undefined ? opt.nsSeparator : this.options.nsSeparator;
506
+ if (nsSeparator === undefined) nsSeparator = ':';
532
507
  const lng = opt.lng || this.language;
533
508
  const appendNamespaceToCIMode = opt.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
534
509
  if (lng?.toLowerCase() === 'cimode') {
535
510
  if (appendNamespaceToCIMode) {
536
- const nsSeparator = opt.nsSeparator || this.options.nsSeparator;
537
511
  if (returnDetails) {
538
512
  return {
539
513
  res: `${namespace}${nsSeparator}${key}`,
@@ -688,9 +662,11 @@ class Translator extends EventEmitter {
688
662
  }
689
663
  }
690
664
  res = this.extendTranslation(res, keys, opt, resolved, lastKey);
691
- if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
665
+ if (usedKey && res === key && this.options.appendNamespaceToMissingKey) {
666
+ res = `${namespace}${nsSeparator}${key}`;
667
+ }
692
668
  if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
693
- res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : undefined, opt);
669
+ res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}${nsSeparator}${key}` : key, usedDefault ? res : undefined, opt);
694
670
  }
695
671
  }
696
672
  if (returnDetails) {
@@ -701,7 +677,6 @@ class Translator extends EventEmitter {
701
677
  return res;
702
678
  }
703
679
  extendTranslation(res, key, opt, resolved, lastKey) {
704
- var _this = this;
705
680
  if (this.i18nFormat?.parse) {
706
681
  res = this.i18nFormat.parse(res, {
707
682
  ...this.options.interpolation.defaultVariables,
@@ -737,15 +712,12 @@ class Translator extends EventEmitter {
737
712
  if (nestBef < nestAft) opt.nest = false;
738
713
  }
739
714
  if (!opt.lng && resolved && resolved.res) opt.lng = this.language || resolved.usedLng;
740
- if (opt.nest !== false) res = this.interpolator.nest(res, function () {
741
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
742
- args[_key] = arguments[_key];
743
- }
715
+ if (opt.nest !== false) res = this.interpolator.nest(res, (...args) => {
744
716
  if (lastKey?.[0] === args[0] && !opt.context) {
745
- _this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
717
+ this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
746
718
  return null;
747
719
  }
748
- return _this.translate(...args, key);
720
+ return this.translate(...args, key);
749
721
  }, opt);
750
722
  if (opt.interpolation) this.interpolator.reset();
751
723
  }
@@ -762,8 +734,7 @@ class Translator extends EventEmitter {
762
734
  }
763
735
  return res;
764
736
  }
765
- resolve(keys) {
766
- let opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
737
+ resolve(keys, opt = {}) {
767
738
  let found;
768
739
  let usedKey;
769
740
  let exactUsedKey;
@@ -843,13 +814,11 @@ class Translator extends EventEmitter {
843
814
  isValidLookup(res) {
844
815
  return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === '');
845
816
  }
846
- getResource(code, ns, key) {
847
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
817
+ getResource(code, ns, key, options = {}) {
848
818
  if (this.i18nFormat?.getResource) return this.i18nFormat.getResource(code, ns, key, options);
849
819
  return this.resourceStore.getResource(code, ns, key, options);
850
820
  }
851
- getUsedParamsDetails() {
852
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
821
+ getUsedParamsDetails(options = {}) {
853
822
  const optionsKeys = ['defaultValue', 'ordinal', 'context', 'replace', 'lng', 'lngs', 'fallbackLng', 'ns', 'keySeparator', 'nsSeparator', 'returnObjects', 'returnDetails', 'joinArrays', 'postProcess', 'interpolation'];
854
823
  const useOptionsReplaceForData = options.replace && !isString(options.replace);
855
824
  let data = useOptionsReplaceForData ? options.replace : options;
@@ -1006,8 +975,7 @@ const dummyRule = {
1006
975
  })
1007
976
  };
1008
977
  class PluralResolver {
1009
- constructor(languageUtils) {
1010
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
978
+ constructor(languageUtils, options = {}) {
1011
979
  this.languageUtils = languageUtils;
1012
980
  this.options = options;
1013
981
  this.logger = baseLogger.create('pluralResolver');
@@ -1019,8 +987,7 @@ class PluralResolver {
1019
987
  clearCache() {
1020
988
  this.pluralRulesCache = {};
1021
989
  }
1022
- getRule(code) {
1023
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
990
+ getRule(code, options = {}) {
1024
991
  const cleanedCode = getCleanedCode(code === 'dev' ? 'en' : code);
1025
992
  const type = options.ordinal ? 'ordinal' : 'cardinal';
1026
993
  const cacheKey = JSON.stringify({
@@ -1047,25 +1014,21 @@ class PluralResolver {
1047
1014
  this.pluralRulesCache[cacheKey] = rule;
1048
1015
  return rule;
1049
1016
  }
1050
- needsPlural(code) {
1051
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1017
+ needsPlural(code, options = {}) {
1052
1018
  let rule = this.getRule(code, options);
1053
1019
  if (!rule) rule = this.getRule('dev', options);
1054
1020
  return rule?.resolvedOptions().pluralCategories.length > 1;
1055
1021
  }
1056
- getPluralFormsOfKey(code, key) {
1057
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1022
+ getPluralFormsOfKey(code, key, options = {}) {
1058
1023
  return this.getSuffixes(code, options).map(suffix => `${key}${suffix}`);
1059
1024
  }
1060
- getSuffixes(code) {
1061
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1025
+ getSuffixes(code, options = {}) {
1062
1026
  let rule = this.getRule(code, options);
1063
1027
  if (!rule) rule = this.getRule('dev', options);
1064
1028
  if (!rule) return [];
1065
1029
  return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map(pluralCategory => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${pluralCategory}`);
1066
1030
  }
1067
- getSuffix(code, count) {
1068
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1031
+ getSuffix(code, count, options = {}) {
1069
1032
  const rule = this.getRule(code, options);
1070
1033
  if (rule) {
1071
1034
  return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${rule.select(count)}`;
@@ -1075,9 +1038,7 @@ class PluralResolver {
1075
1038
  }
1076
1039
  }
1077
1040
 
1078
- const deepFindWithDefaults = function (data, defaultData, key) {
1079
- let keySeparator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '.';
1080
- let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
1041
+ const deepFindWithDefaults = (data, defaultData, key, keySeparator = '.', ignoreJSONStructure = true) => {
1081
1042
  let path = getPathWithDefaults(data, defaultData, key);
1082
1043
  if (!path && ignoreJSONStructure && isString(key)) {
1083
1044
  path = deepFind(data, key, keySeparator);
@@ -1087,15 +1048,13 @@ const deepFindWithDefaults = function (data, defaultData, key) {
1087
1048
  };
1088
1049
  const regexSafe = val => val.replace(/\$/g, '$$$$');
1089
1050
  class Interpolator {
1090
- constructor() {
1091
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1051
+ constructor(options = {}) {
1092
1052
  this.logger = baseLogger.create('interpolator');
1093
1053
  this.options = options;
1094
1054
  this.format = options?.interpolation?.format || (value => value);
1095
1055
  this.init(options);
1096
1056
  }
1097
- init() {
1098
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1057
+ init(options = {}) {
1099
1058
  if (!options.interpolation) options.interpolation = {
1100
1059
  escapeValue: true
1101
1060
  };
@@ -1218,8 +1177,7 @@ class Interpolator {
1218
1177
  });
1219
1178
  return str;
1220
1179
  }
1221
- nest(str, fc) {
1222
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1180
+ nest(str, fc, options = {}) {
1223
1181
  let match;
1224
1182
  let value;
1225
1183
  let clonedOptions;
@@ -1334,8 +1292,7 @@ const createCachedFormatter = fn => {
1334
1292
  };
1335
1293
  };
1336
1294
  class Formatter {
1337
- constructor() {
1338
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1295
+ constructor(options = {}) {
1339
1296
  this.logger = baseLogger.create('formatter');
1340
1297
  this.options = options;
1341
1298
  this.formats = {
@@ -1373,10 +1330,9 @@ class Formatter {
1373
1330
  };
1374
1331
  this.init(options);
1375
1332
  }
1376
- init(services) {
1377
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
1378
- interpolation: {}
1379
- };
1333
+ init(services, options = {
1334
+ interpolation: {}
1335
+ }) {
1380
1336
  this.formatSeparator = options.interpolation.formatSeparator || ',';
1381
1337
  }
1382
1338
  add(name, fc) {
@@ -1385,8 +1341,7 @@ class Formatter {
1385
1341
  addCached(name, fc) {
1386
1342
  this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
1387
1343
  }
1388
- format(value, format, lng) {
1389
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1344
+ format(value, format, lng, options = {}) {
1390
1345
  const formats = format.split(this.formatSeparator);
1391
1346
  if (formats.length > 1 && formats[0].indexOf('(') > 1 && formats[0].indexOf(')') < 0 && formats.find(f => f.indexOf(')') > -1)) {
1392
1347
  const lastIndex = formats.findIndex(f => f.indexOf(')') > -1);
@@ -1427,8 +1382,7 @@ const removePending = (q, name) => {
1427
1382
  }
1428
1383
  };
1429
1384
  class Connector extends EventEmitter {
1430
- constructor(backend, store, services) {
1431
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1385
+ constructor(backend, store, services, options = {}) {
1432
1386
  super();
1433
1387
  this.backend = backend;
1434
1388
  this.store = store;
@@ -1522,10 +1476,7 @@ class Connector extends EventEmitter {
1522
1476
  this.emit('loaded', loaded);
1523
1477
  this.queue = this.queue.filter(q => !q.done);
1524
1478
  }
1525
- read(lng, ns, fcName) {
1526
- let tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1527
- let wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
1528
- let callback = arguments.length > 5 ? arguments[5] : undefined;
1479
+ read(lng, ns, fcName, tried = 0, wait = this.retryTimeout, callback) {
1529
1480
  if (!lng.length) return callback(null, {});
1530
1481
  if (this.readingCalls >= this.maxParallelReads) {
1531
1482
  this.waitingReads.push({
@@ -1569,9 +1520,7 @@ class Connector extends EventEmitter {
1569
1520
  }
1570
1521
  return fc(lng, ns, resolver);
1571
1522
  }
1572
- prepareLoading(languages, namespaces) {
1573
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1574
- let callback = arguments.length > 3 ? arguments[3] : undefined;
1523
+ prepareLoading(languages, namespaces, options = {}, callback) {
1575
1524
  if (!this.backend) {
1576
1525
  this.logger.warn('No backend was added via i18next.use. Will not load resources.');
1577
1526
  return callback && callback();
@@ -1595,8 +1544,7 @@ class Connector extends EventEmitter {
1595
1544
  reload: true
1596
1545
  }, callback);
1597
1546
  }
1598
- loadOne(name) {
1599
- let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
1547
+ loadOne(name, prefix = '') {
1600
1548
  const s = name.split('|');
1601
1549
  const lng = s[0];
1602
1550
  const ns = s[1];
@@ -1606,9 +1554,7 @@ class Connector extends EventEmitter {
1606
1554
  this.loaded(name, err, data);
1607
1555
  });
1608
1556
  }
1609
- saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
1610
- let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
1611
- let clb = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : () => {};
1557
+ saveMissing(languages, namespace, key, fallbackValue, isUpdate, options = {}, clb = () => {}) {
1612
1558
  if (this.services?.utils?.hasLoadedNamespace && !this.services?.utils?.hasLoadedNamespace(namespace)) {
1613
1559
  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!!!');
1614
1560
  return;
@@ -1726,9 +1672,7 @@ const bindMemberFunctions = inst => {
1726
1672
  });
1727
1673
  };
1728
1674
  class I18n extends EventEmitter {
1729
- constructor() {
1730
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1731
- let callback = arguments.length > 1 ? arguments[1] : undefined;
1675
+ constructor(options = {}, callback) {
1732
1676
  super();
1733
1677
  this.options = transformOptions(options);
1734
1678
  this.services = {};
@@ -1747,10 +1691,7 @@ class I18n extends EventEmitter {
1747
1691
  }, 0);
1748
1692
  }
1749
1693
  }
1750
- init() {
1751
- var _this = this;
1752
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1753
- let callback = arguments.length > 1 ? arguments[1] : undefined;
1694
+ init(options = {}, callback) {
1754
1695
  this.isInitializing = true;
1755
1696
  if (typeof options === 'function') {
1756
1697
  callback = options;
@@ -1816,11 +1757,8 @@ class I18n extends EventEmitter {
1816
1757
  hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
1817
1758
  };
1818
1759
  s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
1819
- s.backendConnector.on('*', function (event) {
1820
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1821
- args[_key - 1] = arguments[_key];
1822
- }
1823
- _this.emit(event, ...args);
1760
+ s.backendConnector.on('*', (event, ...args) => {
1761
+ this.emit(event, ...args);
1824
1762
  });
1825
1763
  if (this.modules.languageDetector) {
1826
1764
  s.languageDetector = createClassOnDemand(this.modules.languageDetector);
@@ -1831,11 +1769,8 @@ class I18n extends EventEmitter {
1831
1769
  if (s.i18nFormat.init) s.i18nFormat.init(this);
1832
1770
  }
1833
1771
  this.translator = new Translator(this.services, this.options);
1834
- this.translator.on('*', function (event) {
1835
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
1836
- args[_key2 - 1] = arguments[_key2];
1837
- }
1838
- _this.emit(event, ...args);
1772
+ this.translator.on('*', (event, ...args) => {
1773
+ this.emit(event, ...args);
1839
1774
  });
1840
1775
  this.modules.external.forEach(m => {
1841
1776
  if (m.init) m.init(this);
@@ -1852,15 +1787,13 @@ class I18n extends EventEmitter {
1852
1787
  }
1853
1788
  const storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
1854
1789
  storeApi.forEach(fcName => {
1855
- this[fcName] = function () {
1856
- return _this.store[fcName](...arguments);
1857
- };
1790
+ this[fcName] = (...args) => this.store[fcName](...args);
1858
1791
  });
1859
1792
  const storeApiChained = ['addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle'];
1860
1793
  storeApiChained.forEach(fcName => {
1861
- this[fcName] = function () {
1862
- _this.store[fcName](...arguments);
1863
- return _this;
1794
+ this[fcName] = (...args) => {
1795
+ this.store[fcName](...args);
1796
+ return this;
1864
1797
  };
1865
1798
  });
1866
1799
  const deferred = defer();
@@ -1884,8 +1817,7 @@ class I18n extends EventEmitter {
1884
1817
  }
1885
1818
  return deferred;
1886
1819
  }
1887
- loadResources(language) {
1888
- let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
1820
+ loadResources(language, callback = noop) {
1889
1821
  let usedCallback = callback;
1890
1822
  const usedLng = isString(language) ? language : this.language;
1891
1823
  if (typeof language === 'function') usedCallback = language;
@@ -1978,7 +1910,6 @@ class I18n extends EventEmitter {
1978
1910
  }
1979
1911
  }
1980
1912
  changeLanguage(lng, callback) {
1981
- var _this2 = this;
1982
1913
  this.isLanguageChangingTo = lng;
1983
1914
  const deferred = defer();
1984
1915
  this.emit('languageChanging', lng);
@@ -2000,12 +1931,8 @@ class I18n extends EventEmitter {
2000
1931
  } else {
2001
1932
  this.isLanguageChangingTo = undefined;
2002
1933
  }
2003
- deferred.resolve(function () {
2004
- return _this2.t(...arguments);
2005
- });
2006
- if (callback) callback(err, function () {
2007
- return _this2.t(...arguments);
2008
- });
1934
+ deferred.resolve((...args) => this.t(...args));
1935
+ if (callback) callback(err, (...args) => this.t(...args));
2009
1936
  };
2010
1937
  const setLng = lngs => {
2011
1938
  if (!lng && !lngs && this.services.languageDetector) lngs = [];
@@ -2036,14 +1963,10 @@ class I18n extends EventEmitter {
2036
1963
  return deferred;
2037
1964
  }
2038
1965
  getFixedT(lng, ns, keyPrefix) {
2039
- var _this3 = this;
2040
- const fixedT = function (key, opts) {
1966
+ const fixedT = (key, opts, ...rest) => {
2041
1967
  let o;
2042
1968
  if (typeof opts !== 'object') {
2043
- for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
2044
- rest[_key3 - 2] = arguments[_key3];
2045
- }
2046
- o = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
1969
+ o = this.options.overloadTranslationOptionHandler([key, opts].concat(rest));
2047
1970
  } else {
2048
1971
  o = {
2049
1972
  ...opts
@@ -2053,14 +1976,14 @@ class I18n extends EventEmitter {
2053
1976
  o.lngs = o.lngs || fixedT.lngs;
2054
1977
  o.ns = o.ns || fixedT.ns;
2055
1978
  if (o.keyPrefix !== '') o.keyPrefix = o.keyPrefix || keyPrefix || fixedT.keyPrefix;
2056
- const keySeparator = _this3.options.keySeparator || '.';
1979
+ const keySeparator = this.options.keySeparator || '.';
2057
1980
  let resultKey;
2058
1981
  if (o.keyPrefix && Array.isArray(key)) {
2059
1982
  resultKey = key.map(k => `${o.keyPrefix}${keySeparator}${k}`);
2060
1983
  } else {
2061
1984
  resultKey = o.keyPrefix ? `${o.keyPrefix}${keySeparator}${key}` : key;
2062
1985
  }
2063
- return _this3.t(resultKey, o);
1986
+ return this.t(resultKey, o);
2064
1987
  };
2065
1988
  if (isString(lng)) {
2066
1989
  fixedT.lng = lng;
@@ -2071,23 +1994,16 @@ class I18n extends EventEmitter {
2071
1994
  fixedT.keyPrefix = keyPrefix;
2072
1995
  return fixedT;
2073
1996
  }
2074
- t() {
2075
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
2076
- args[_key4] = arguments[_key4];
2077
- }
1997
+ t(...args) {
2078
1998
  return this.translator?.translate(...args);
2079
1999
  }
2080
- exists() {
2081
- for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
2082
- args[_key5] = arguments[_key5];
2083
- }
2000
+ exists(...args) {
2084
2001
  return this.translator?.exists(...args);
2085
2002
  }
2086
2003
  setDefaultNamespace(ns) {
2087
2004
  this.options.defaultNS = ns;
2088
2005
  }
2089
- hasLoadedNamespace(ns) {
2090
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2006
+ hasLoadedNamespace(ns, options = {}) {
2091
2007
  if (!this.isInitialized) {
2092
2008
  this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
2093
2009
  return false;
@@ -2152,14 +2068,10 @@ class I18n extends EventEmitter {
2152
2068
  const languageUtils = this.services?.languageUtils || new LanguageUtil(get());
2153
2069
  return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
2154
2070
  }
2155
- static createInstance() {
2156
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2157
- let callback = arguments.length > 1 ? arguments[1] : undefined;
2071
+ static createInstance(options = {}, callback) {
2158
2072
  return new I18n(options, callback);
2159
2073
  }
2160
- cloneInstance() {
2161
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2162
- let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
2074
+ cloneInstance(options = {}, callback = noop) {
2163
2075
  const forkResourceStore = options.forkResourceStore;
2164
2076
  if (forkResourceStore) delete options.forkResourceStore;
2165
2077
  const mergedOptions = {
@@ -2200,10 +2112,7 @@ class I18n extends EventEmitter {
2200
2112
  clone.services.resourceStore = clone.store;
2201
2113
  }
2202
2114
  clone.translator = new Translator(clone.services, mergedOptions);
2203
- clone.translator.on('*', function (event) {
2204
- for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
2205
- args[_key6 - 1] = arguments[_key6];
2206
- }
2115
+ clone.translator.on('*', (event, ...args) => {
2207
2116
  clone.emit(event, ...args);
2208
2117
  });
2209
2118
  clone.init(mergedOptions, callback);