i18next 25.1.2 → 25.2.0

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.
@@ -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;
@@ -1316,68 +1274,68 @@ const parseFormatStr = formatStr => {
1316
1274
  };
1317
1275
  const createCachedFormatter = fn => {
1318
1276
  const cache = {};
1319
- return (val, lng, options) => {
1320
- let optForCache = options;
1321
- if (options && options.interpolationkey && options.formatParams && options.formatParams[options.interpolationkey] && options[options.interpolationkey]) {
1277
+ return (v, l, o) => {
1278
+ let optForCache = o;
1279
+ if (o && o.interpolationkey && o.formatParams && o.formatParams[o.interpolationkey] && o[o.interpolationkey]) {
1322
1280
  optForCache = {
1323
1281
  ...optForCache,
1324
- [options.interpolationkey]: undefined
1282
+ [o.interpolationkey]: undefined
1325
1283
  };
1326
1284
  }
1327
- const key = lng + JSON.stringify(optForCache);
1328
- let formatter = cache[key];
1329
- if (!formatter) {
1330
- formatter = fn(getCleanedCode(lng), options);
1331
- cache[key] = formatter;
1285
+ const key = l + JSON.stringify(optForCache);
1286
+ let frm = cache[key];
1287
+ if (!frm) {
1288
+ frm = fn(getCleanedCode(l), o);
1289
+ cache[key] = frm;
1332
1290
  }
1333
- return formatter(val);
1291
+ return frm(v);
1334
1292
  };
1335
1293
  };
1294
+ const createNonCachedFormatter = fn => (v, l, o) => fn(getCleanedCode(l), o)(v);
1336
1295
  class Formatter {
1337
- constructor() {
1338
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1296
+ constructor(options = {}) {
1339
1297
  this.logger = baseLogger.create('formatter');
1340
1298
  this.options = options;
1299
+ this.init(options);
1300
+ }
1301
+ init(services, options = {
1302
+ interpolation: {}
1303
+ }) {
1304
+ this.formatSeparator = options.interpolation.formatSeparator || ',';
1305
+ const cf = options.cacheInBuiltFormats ? createCachedFormatter : createNonCachedFormatter;
1341
1306
  this.formats = {
1342
- number: createCachedFormatter((lng, opt) => {
1307
+ number: cf((lng, opt) => {
1343
1308
  const formatter = new Intl.NumberFormat(lng, {
1344
1309
  ...opt
1345
1310
  });
1346
1311
  return val => formatter.format(val);
1347
1312
  }),
1348
- currency: createCachedFormatter((lng, opt) => {
1313
+ currency: cf((lng, opt) => {
1349
1314
  const formatter = new Intl.NumberFormat(lng, {
1350
1315
  ...opt,
1351
1316
  style: 'currency'
1352
1317
  });
1353
1318
  return val => formatter.format(val);
1354
1319
  }),
1355
- datetime: createCachedFormatter((lng, opt) => {
1320
+ datetime: cf((lng, opt) => {
1356
1321
  const formatter = new Intl.DateTimeFormat(lng, {
1357
1322
  ...opt
1358
1323
  });
1359
1324
  return val => formatter.format(val);
1360
1325
  }),
1361
- relativetime: createCachedFormatter((lng, opt) => {
1326
+ relativetime: cf((lng, opt) => {
1362
1327
  const formatter = new Intl.RelativeTimeFormat(lng, {
1363
1328
  ...opt
1364
1329
  });
1365
1330
  return val => formatter.format(val, opt.range || 'day');
1366
1331
  }),
1367
- list: createCachedFormatter((lng, opt) => {
1332
+ list: cf((lng, opt) => {
1368
1333
  const formatter = new Intl.ListFormat(lng, {
1369
1334
  ...opt
1370
1335
  });
1371
1336
  return val => formatter.format(val);
1372
1337
  })
1373
1338
  };
1374
- this.init(options);
1375
- }
1376
- init(services) {
1377
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
1378
- interpolation: {}
1379
- };
1380
- this.formatSeparator = options.interpolation.formatSeparator || ',';
1381
1339
  }
1382
1340
  add(name, fc) {
1383
1341
  this.formats[name.toLowerCase().trim()] = fc;
@@ -1385,8 +1343,7 @@ class Formatter {
1385
1343
  addCached(name, fc) {
1386
1344
  this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
1387
1345
  }
1388
- format(value, format, lng) {
1389
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1346
+ format(value, format, lng, options = {}) {
1390
1347
  const formats = format.split(this.formatSeparator);
1391
1348
  if (formats.length > 1 && formats[0].indexOf('(') > 1 && formats[0].indexOf(')') < 0 && formats.find(f => f.indexOf(')') > -1)) {
1392
1349
  const lastIndex = formats.findIndex(f => f.indexOf(')') > -1);
@@ -1427,8 +1384,7 @@ const removePending = (q, name) => {
1427
1384
  }
1428
1385
  };
1429
1386
  class Connector extends EventEmitter {
1430
- constructor(backend, store, services) {
1431
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1387
+ constructor(backend, store, services, options = {}) {
1432
1388
  super();
1433
1389
  this.backend = backend;
1434
1390
  this.store = store;
@@ -1522,10 +1478,7 @@ class Connector extends EventEmitter {
1522
1478
  this.emit('loaded', loaded);
1523
1479
  this.queue = this.queue.filter(q => !q.done);
1524
1480
  }
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;
1481
+ read(lng, ns, fcName, tried = 0, wait = this.retryTimeout, callback) {
1529
1482
  if (!lng.length) return callback(null, {});
1530
1483
  if (this.readingCalls >= this.maxParallelReads) {
1531
1484
  this.waitingReads.push({
@@ -1569,9 +1522,7 @@ class Connector extends EventEmitter {
1569
1522
  }
1570
1523
  return fc(lng, ns, resolver);
1571
1524
  }
1572
- prepareLoading(languages, namespaces) {
1573
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1574
- let callback = arguments.length > 3 ? arguments[3] : undefined;
1525
+ prepareLoading(languages, namespaces, options = {}, callback) {
1575
1526
  if (!this.backend) {
1576
1527
  this.logger.warn('No backend was added via i18next.use. Will not load resources.');
1577
1528
  return callback && callback();
@@ -1595,8 +1546,7 @@ class Connector extends EventEmitter {
1595
1546
  reload: true
1596
1547
  }, callback);
1597
1548
  }
1598
- loadOne(name) {
1599
- let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
1549
+ loadOne(name, prefix = '') {
1600
1550
  const s = name.split('|');
1601
1551
  const lng = s[0];
1602
1552
  const ns = s[1];
@@ -1606,9 +1556,7 @@ class Connector extends EventEmitter {
1606
1556
  this.loaded(name, err, data);
1607
1557
  });
1608
1558
  }
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] : () => {};
1559
+ saveMissing(languages, namespace, key, fallbackValue, isUpdate, options = {}, clb = () => {}) {
1612
1560
  if (this.services?.utils?.hasLoadedNamespace && !this.services?.utils?.hasLoadedNamespace(namespace)) {
1613
1561
  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
1562
  return;
@@ -1703,7 +1651,8 @@ const get = () => ({
1703
1651
  nestingOptionsSeparator: ',',
1704
1652
  maxReplaces: 1000,
1705
1653
  skipOnVariables: true
1706
- }
1654
+ },
1655
+ cacheInBuiltFormats: true
1707
1656
  });
1708
1657
  const transformOptions = options => {
1709
1658
  if (isString(options.ns)) options.ns = [options.ns];
@@ -1726,9 +1675,7 @@ const bindMemberFunctions = inst => {
1726
1675
  });
1727
1676
  };
1728
1677
  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;
1678
+ constructor(options = {}, callback) {
1732
1679
  super();
1733
1680
  this.options = transformOptions(options);
1734
1681
  this.services = {};
@@ -1747,10 +1694,7 @@ class I18n extends EventEmitter {
1747
1694
  }, 0);
1748
1695
  }
1749
1696
  }
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;
1697
+ init(options = {}, callback) {
1754
1698
  this.isInitializing = true;
1755
1699
  if (typeof options === 'function') {
1756
1700
  callback = options;
@@ -1816,11 +1760,8 @@ class I18n extends EventEmitter {
1816
1760
  hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
1817
1761
  };
1818
1762
  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);
1763
+ s.backendConnector.on('*', (event, ...args) => {
1764
+ this.emit(event, ...args);
1824
1765
  });
1825
1766
  if (this.modules.languageDetector) {
1826
1767
  s.languageDetector = createClassOnDemand(this.modules.languageDetector);
@@ -1831,11 +1772,8 @@ class I18n extends EventEmitter {
1831
1772
  if (s.i18nFormat.init) s.i18nFormat.init(this);
1832
1773
  }
1833
1774
  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);
1775
+ this.translator.on('*', (event, ...args) => {
1776
+ this.emit(event, ...args);
1839
1777
  });
1840
1778
  this.modules.external.forEach(m => {
1841
1779
  if (m.init) m.init(this);
@@ -1852,15 +1790,13 @@ class I18n extends EventEmitter {
1852
1790
  }
1853
1791
  const storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
1854
1792
  storeApi.forEach(fcName => {
1855
- this[fcName] = function () {
1856
- return _this.store[fcName](...arguments);
1857
- };
1793
+ this[fcName] = (...args) => this.store[fcName](...args);
1858
1794
  });
1859
1795
  const storeApiChained = ['addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle'];
1860
1796
  storeApiChained.forEach(fcName => {
1861
- this[fcName] = function () {
1862
- _this.store[fcName](...arguments);
1863
- return _this;
1797
+ this[fcName] = (...args) => {
1798
+ this.store[fcName](...args);
1799
+ return this;
1864
1800
  };
1865
1801
  });
1866
1802
  const deferred = defer();
@@ -1884,8 +1820,7 @@ class I18n extends EventEmitter {
1884
1820
  }
1885
1821
  return deferred;
1886
1822
  }
1887
- loadResources(language) {
1888
- let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
1823
+ loadResources(language, callback = noop) {
1889
1824
  let usedCallback = callback;
1890
1825
  const usedLng = isString(language) ? language : this.language;
1891
1826
  if (typeof language === 'function') usedCallback = language;
@@ -1978,7 +1913,6 @@ class I18n extends EventEmitter {
1978
1913
  }
1979
1914
  }
1980
1915
  changeLanguage(lng, callback) {
1981
- var _this2 = this;
1982
1916
  this.isLanguageChangingTo = lng;
1983
1917
  const deferred = defer();
1984
1918
  this.emit('languageChanging', lng);
@@ -2000,12 +1934,8 @@ class I18n extends EventEmitter {
2000
1934
  } else {
2001
1935
  this.isLanguageChangingTo = undefined;
2002
1936
  }
2003
- deferred.resolve(function () {
2004
- return _this2.t(...arguments);
2005
- });
2006
- if (callback) callback(err, function () {
2007
- return _this2.t(...arguments);
2008
- });
1937
+ deferred.resolve((...args) => this.t(...args));
1938
+ if (callback) callback(err, (...args) => this.t(...args));
2009
1939
  };
2010
1940
  const setLng = lngs => {
2011
1941
  if (!lng && !lngs && this.services.languageDetector) lngs = [];
@@ -2036,14 +1966,10 @@ class I18n extends EventEmitter {
2036
1966
  return deferred;
2037
1967
  }
2038
1968
  getFixedT(lng, ns, keyPrefix) {
2039
- var _this3 = this;
2040
- const fixedT = function (key, opts) {
1969
+ const fixedT = (key, opts, ...rest) => {
2041
1970
  let o;
2042
1971
  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));
1972
+ o = this.options.overloadTranslationOptionHandler([key, opts].concat(rest));
2047
1973
  } else {
2048
1974
  o = {
2049
1975
  ...opts
@@ -2053,14 +1979,14 @@ class I18n extends EventEmitter {
2053
1979
  o.lngs = o.lngs || fixedT.lngs;
2054
1980
  o.ns = o.ns || fixedT.ns;
2055
1981
  if (o.keyPrefix !== '') o.keyPrefix = o.keyPrefix || keyPrefix || fixedT.keyPrefix;
2056
- const keySeparator = _this3.options.keySeparator || '.';
1982
+ const keySeparator = this.options.keySeparator || '.';
2057
1983
  let resultKey;
2058
1984
  if (o.keyPrefix && Array.isArray(key)) {
2059
1985
  resultKey = key.map(k => `${o.keyPrefix}${keySeparator}${k}`);
2060
1986
  } else {
2061
1987
  resultKey = o.keyPrefix ? `${o.keyPrefix}${keySeparator}${key}` : key;
2062
1988
  }
2063
- return _this3.t(resultKey, o);
1989
+ return this.t(resultKey, o);
2064
1990
  };
2065
1991
  if (isString(lng)) {
2066
1992
  fixedT.lng = lng;
@@ -2071,23 +1997,16 @@ class I18n extends EventEmitter {
2071
1997
  fixedT.keyPrefix = keyPrefix;
2072
1998
  return fixedT;
2073
1999
  }
2074
- t() {
2075
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
2076
- args[_key4] = arguments[_key4];
2077
- }
2000
+ t(...args) {
2078
2001
  return this.translator?.translate(...args);
2079
2002
  }
2080
- exists() {
2081
- for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
2082
- args[_key5] = arguments[_key5];
2083
- }
2003
+ exists(...args) {
2084
2004
  return this.translator?.exists(...args);
2085
2005
  }
2086
2006
  setDefaultNamespace(ns) {
2087
2007
  this.options.defaultNS = ns;
2088
2008
  }
2089
- hasLoadedNamespace(ns) {
2090
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2009
+ hasLoadedNamespace(ns, options = {}) {
2091
2010
  if (!this.isInitialized) {
2092
2011
  this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
2093
2012
  return false;
@@ -2152,14 +2071,10 @@ class I18n extends EventEmitter {
2152
2071
  const languageUtils = this.services?.languageUtils || new LanguageUtil(get());
2153
2072
  return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
2154
2073
  }
2155
- static createInstance() {
2156
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2157
- let callback = arguments.length > 1 ? arguments[1] : undefined;
2074
+ static createInstance(options = {}, callback) {
2158
2075
  return new I18n(options, callback);
2159
2076
  }
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;
2077
+ cloneInstance(options = {}, callback = noop) {
2163
2078
  const forkResourceStore = options.forkResourceStore;
2164
2079
  if (forkResourceStore) delete options.forkResourceStore;
2165
2080
  const mergedOptions = {
@@ -2200,10 +2115,7 @@ class I18n extends EventEmitter {
2200
2115
  clone.services.resourceStore = clone.store;
2201
2116
  }
2202
2117
  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
- }
2118
+ clone.translator.on('*', (event, ...args) => {
2207
2119
  clone.emit(event, ...args);
2208
2120
  });
2209
2121
  clone.init(mergedOptions, callback);