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.
@@ -162,8 +162,7 @@
162
162
  }
163
163
  return matched;
164
164
  };
165
- const deepFind = function (obj, path) {
166
- let keySeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
165
+ const deepFind = (obj, path, keySeparator = '.') => {
167
166
  if (!obj) return undefined;
168
167
  if (obj[path]) {
169
168
  if (!Object.prototype.hasOwnProperty.call(obj, path)) return undefined;
@@ -213,39 +212,25 @@
213
212
  }
214
213
  };
215
214
  class Logger {
216
- constructor(concreteLogger) {
217
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
215
+ constructor(concreteLogger, options = {}) {
218
216
  this.init(concreteLogger, options);
219
217
  }
220
- init(concreteLogger) {
221
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
218
+ init(concreteLogger, options = {}) {
222
219
  this.prefix = options.prefix || 'i18next:';
223
220
  this.logger = concreteLogger || consoleLogger;
224
221
  this.options = options;
225
222
  this.debug = options.debug;
226
223
  }
227
- log() {
228
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
229
- args[_key] = arguments[_key];
230
- }
224
+ log(...args) {
231
225
  return this.forward(args, 'log', '', true);
232
226
  }
233
- warn() {
234
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
235
- args[_key2] = arguments[_key2];
236
- }
227
+ warn(...args) {
237
228
  return this.forward(args, 'warn', '', true);
238
229
  }
239
- error() {
240
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
241
- args[_key3] = arguments[_key3];
242
- }
230
+ error(...args) {
243
231
  return this.forward(args, 'error', '');
244
232
  }
245
- deprecate() {
246
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
247
- args[_key4] = arguments[_key4];
248
- }
233
+ deprecate(...args) {
249
234
  return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
250
235
  }
251
236
  forward(args, lvl, prefix, debugOnly) {
@@ -289,14 +274,10 @@
289
274
  }
290
275
  this.observers[event].delete(listener);
291
276
  }
292
- emit(event) {
293
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
294
- args[_key - 1] = arguments[_key];
295
- }
277
+ emit(event, ...args) {
296
278
  if (this.observers[event]) {
297
279
  const cloned = Array.from(this.observers[event].entries());
298
- cloned.forEach(_ref => {
299
- let [observer, numTimesAdded] = _ref;
280
+ cloned.forEach(([observer, numTimesAdded]) => {
300
281
  for (let i = 0; i < numTimesAdded; i++) {
301
282
  observer(...args);
302
283
  }
@@ -304,8 +285,7 @@
304
285
  }
305
286
  if (this.observers['*']) {
306
287
  const cloned = Array.from(this.observers['*'].entries());
307
- cloned.forEach(_ref2 => {
308
- let [observer, numTimesAdded] = _ref2;
288
+ cloned.forEach(([observer, numTimesAdded]) => {
309
289
  for (let i = 0; i < numTimesAdded; i++) {
310
290
  observer.apply(observer, [event, ...args]);
311
291
  }
@@ -315,11 +295,10 @@
315
295
  }
316
296
 
317
297
  class ResourceStore extends EventEmitter {
318
- constructor(data) {
319
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
320
- ns: ['translation'],
321
- defaultNS: 'translation'
322
- };
298
+ constructor(data, options = {
299
+ ns: ['translation'],
300
+ defaultNS: 'translation'
301
+ }) {
323
302
  super();
324
303
  this.data = data || {};
325
304
  this.options = options;
@@ -341,8 +320,7 @@
341
320
  this.options.ns.splice(index, 1);
342
321
  }
343
322
  }
344
- getResource(lng, ns, key) {
345
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
323
+ getResource(lng, ns, key, options = {}) {
346
324
  const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
347
325
  const ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
348
326
  let path;
@@ -369,10 +347,9 @@
369
347
  if (result || !ignoreJSONStructure || !isString(key)) return result;
370
348
  return deepFind(this.data?.[lng]?.[ns], key, keySeparator);
371
349
  }
372
- addResource(lng, ns, key, value) {
373
- let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
374
- silent: false
375
- };
350
+ addResource(lng, ns, key, value, options = {
351
+ silent: false
352
+ }) {
376
353
  const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
377
354
  let path = [lng, ns];
378
355
  if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
@@ -385,10 +362,9 @@
385
362
  setPath(this.data, path, value);
386
363
  if (!options.silent) this.emit('added', lng, ns, key, value);
387
364
  }
388
- addResources(lng, ns, resources) {
389
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
390
- silent: false
391
- };
365
+ addResources(lng, ns, resources, options = {
366
+ silent: false
367
+ }) {
392
368
  for (const m in resources) {
393
369
  if (isString(resources[m]) || Array.isArray(resources[m])) this.addResource(lng, ns, m, resources[m], {
394
370
  silent: true
@@ -396,11 +372,10 @@
396
372
  }
397
373
  if (!options.silent) this.emit('added', lng, ns, resources);
398
374
  }
399
- addResourceBundle(lng, ns, resources, deep, overwrite) {
400
- let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {
401
- silent: false,
402
- skipCopy: false
403
- };
375
+ addResourceBundle(lng, ns, resources, deep, overwrite, options = {
376
+ silent: false,
377
+ skipCopy: false
378
+ }) {
404
379
  let path = [lng, ns];
405
380
  if (lng.indexOf('.') > -1) {
406
381
  path = lng.split('.');
@@ -465,8 +440,7 @@
465
440
  const checkedLoadedFor = {};
466
441
  const shouldHandleAsObject = res => !isString(res) && typeof res !== 'boolean' && typeof res !== 'number';
467
442
  class Translator extends EventEmitter {
468
- constructor(services) {
469
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
443
+ constructor(services, options = {}) {
470
444
  super();
471
445
  copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector', 'i18nFormat', 'utils'], services, this);
472
446
  this.options = options;
@@ -478,10 +452,9 @@
478
452
  changeLanguage(lng) {
479
453
  if (lng) this.language = lng;
480
454
  }
481
- exists(key) {
482
- let o = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
483
- interpolation: {}
484
- };
455
+ exists(key, o = {
456
+ interpolation: {}
457
+ }) {
485
458
  const opt = {
486
459
  ...o
487
460
  };
@@ -533,11 +506,12 @@
533
506
  namespaces
534
507
  } = this.extractFromKey(keys[keys.length - 1], opt);
535
508
  const namespace = namespaces[namespaces.length - 1];
509
+ let nsSeparator = opt.nsSeparator !== undefined ? opt.nsSeparator : this.options.nsSeparator;
510
+ if (nsSeparator === undefined) nsSeparator = ':';
536
511
  const lng = opt.lng || this.language;
537
512
  const appendNamespaceToCIMode = opt.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
538
513
  if (lng?.toLowerCase() === 'cimode') {
539
514
  if (appendNamespaceToCIMode) {
540
- const nsSeparator = opt.nsSeparator || this.options.nsSeparator;
541
515
  if (returnDetails) {
542
516
  return {
543
517
  res: `${namespace}${nsSeparator}${key}`,
@@ -692,9 +666,11 @@
692
666
  }
693
667
  }
694
668
  res = this.extendTranslation(res, keys, opt, resolved, lastKey);
695
- if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
669
+ if (usedKey && res === key && this.options.appendNamespaceToMissingKey) {
670
+ res = `${namespace}${nsSeparator}${key}`;
671
+ }
696
672
  if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
697
- res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : undefined, opt);
673
+ res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}${nsSeparator}${key}` : key, usedDefault ? res : undefined, opt);
698
674
  }
699
675
  }
700
676
  if (returnDetails) {
@@ -705,7 +681,6 @@
705
681
  return res;
706
682
  }
707
683
  extendTranslation(res, key, opt, resolved, lastKey) {
708
- var _this = this;
709
684
  if (this.i18nFormat?.parse) {
710
685
  res = this.i18nFormat.parse(res, {
711
686
  ...this.options.interpolation.defaultVariables,
@@ -741,15 +716,12 @@
741
716
  if (nestBef < nestAft) opt.nest = false;
742
717
  }
743
718
  if (!opt.lng && resolved && resolved.res) opt.lng = this.language || resolved.usedLng;
744
- if (opt.nest !== false) res = this.interpolator.nest(res, function () {
745
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
746
- args[_key] = arguments[_key];
747
- }
719
+ if (opt.nest !== false) res = this.interpolator.nest(res, (...args) => {
748
720
  if (lastKey?.[0] === args[0] && !opt.context) {
749
- _this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
721
+ this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
750
722
  return null;
751
723
  }
752
- return _this.translate(...args, key);
724
+ return this.translate(...args, key);
753
725
  }, opt);
754
726
  if (opt.interpolation) this.interpolator.reset();
755
727
  }
@@ -766,8 +738,7 @@
766
738
  }
767
739
  return res;
768
740
  }
769
- resolve(keys) {
770
- let opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
741
+ resolve(keys, opt = {}) {
771
742
  let found;
772
743
  let usedKey;
773
744
  let exactUsedKey;
@@ -847,13 +818,11 @@
847
818
  isValidLookup(res) {
848
819
  return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === '');
849
820
  }
850
- getResource(code, ns, key) {
851
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
821
+ getResource(code, ns, key, options = {}) {
852
822
  if (this.i18nFormat?.getResource) return this.i18nFormat.getResource(code, ns, key, options);
853
823
  return this.resourceStore.getResource(code, ns, key, options);
854
824
  }
855
- getUsedParamsDetails() {
856
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
825
+ getUsedParamsDetails(options = {}) {
857
826
  const optionsKeys = ['defaultValue', 'ordinal', 'context', 'replace', 'lng', 'lngs', 'fallbackLng', 'ns', 'keySeparator', 'nsSeparator', 'returnObjects', 'returnDetails', 'joinArrays', 'postProcess', 'interpolation'];
858
827
  const useOptionsReplaceForData = options.replace && !isString(options.replace);
859
828
  let data = useOptionsReplaceForData ? options.replace : options;
@@ -1010,8 +979,7 @@
1010
979
  })
1011
980
  };
1012
981
  class PluralResolver {
1013
- constructor(languageUtils) {
1014
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
982
+ constructor(languageUtils, options = {}) {
1015
983
  this.languageUtils = languageUtils;
1016
984
  this.options = options;
1017
985
  this.logger = baseLogger.create('pluralResolver');
@@ -1023,8 +991,7 @@
1023
991
  clearCache() {
1024
992
  this.pluralRulesCache = {};
1025
993
  }
1026
- getRule(code) {
1027
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
994
+ getRule(code, options = {}) {
1028
995
  const cleanedCode = getCleanedCode(code === 'dev' ? 'en' : code);
1029
996
  const type = options.ordinal ? 'ordinal' : 'cardinal';
1030
997
  const cacheKey = JSON.stringify({
@@ -1051,25 +1018,21 @@
1051
1018
  this.pluralRulesCache[cacheKey] = rule;
1052
1019
  return rule;
1053
1020
  }
1054
- needsPlural(code) {
1055
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1021
+ needsPlural(code, options = {}) {
1056
1022
  let rule = this.getRule(code, options);
1057
1023
  if (!rule) rule = this.getRule('dev', options);
1058
1024
  return rule?.resolvedOptions().pluralCategories.length > 1;
1059
1025
  }
1060
- getPluralFormsOfKey(code, key) {
1061
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1026
+ getPluralFormsOfKey(code, key, options = {}) {
1062
1027
  return this.getSuffixes(code, options).map(suffix => `${key}${suffix}`);
1063
1028
  }
1064
- getSuffixes(code) {
1065
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1029
+ getSuffixes(code, options = {}) {
1066
1030
  let rule = this.getRule(code, options);
1067
1031
  if (!rule) rule = this.getRule('dev', options);
1068
1032
  if (!rule) return [];
1069
1033
  return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map(pluralCategory => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${pluralCategory}`);
1070
1034
  }
1071
- getSuffix(code, count) {
1072
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1035
+ getSuffix(code, count, options = {}) {
1073
1036
  const rule = this.getRule(code, options);
1074
1037
  if (rule) {
1075
1038
  return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${rule.select(count)}`;
@@ -1079,9 +1042,7 @@
1079
1042
  }
1080
1043
  }
1081
1044
 
1082
- const deepFindWithDefaults = function (data, defaultData, key) {
1083
- let keySeparator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '.';
1084
- let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
1045
+ const deepFindWithDefaults = (data, defaultData, key, keySeparator = '.', ignoreJSONStructure = true) => {
1085
1046
  let path = getPathWithDefaults(data, defaultData, key);
1086
1047
  if (!path && ignoreJSONStructure && isString(key)) {
1087
1048
  path = deepFind(data, key, keySeparator);
@@ -1091,15 +1052,13 @@
1091
1052
  };
1092
1053
  const regexSafe = val => val.replace(/\$/g, '$$$$');
1093
1054
  class Interpolator {
1094
- constructor() {
1095
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1055
+ constructor(options = {}) {
1096
1056
  this.logger = baseLogger.create('interpolator');
1097
1057
  this.options = options;
1098
1058
  this.format = options?.interpolation?.format || (value => value);
1099
1059
  this.init(options);
1100
1060
  }
1101
- init() {
1102
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1061
+ init(options = {}) {
1103
1062
  if (!options.interpolation) options.interpolation = {
1104
1063
  escapeValue: true
1105
1064
  };
@@ -1222,8 +1181,7 @@
1222
1181
  });
1223
1182
  return str;
1224
1183
  }
1225
- nest(str, fc) {
1226
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1184
+ nest(str, fc, options = {}) {
1227
1185
  let match;
1228
1186
  let value;
1229
1187
  let clonedOptions;
@@ -1320,68 +1278,68 @@
1320
1278
  };
1321
1279
  const createCachedFormatter = fn => {
1322
1280
  const cache = {};
1323
- return (val, lng, options) => {
1324
- let optForCache = options;
1325
- if (options && options.interpolationkey && options.formatParams && options.formatParams[options.interpolationkey] && options[options.interpolationkey]) {
1281
+ return (v, l, o) => {
1282
+ let optForCache = o;
1283
+ if (o && o.interpolationkey && o.formatParams && o.formatParams[o.interpolationkey] && o[o.interpolationkey]) {
1326
1284
  optForCache = {
1327
1285
  ...optForCache,
1328
- [options.interpolationkey]: undefined
1286
+ [o.interpolationkey]: undefined
1329
1287
  };
1330
1288
  }
1331
- const key = lng + JSON.stringify(optForCache);
1332
- let formatter = cache[key];
1333
- if (!formatter) {
1334
- formatter = fn(getCleanedCode(lng), options);
1335
- cache[key] = formatter;
1289
+ const key = l + JSON.stringify(optForCache);
1290
+ let frm = cache[key];
1291
+ if (!frm) {
1292
+ frm = fn(getCleanedCode(l), o);
1293
+ cache[key] = frm;
1336
1294
  }
1337
- return formatter(val);
1295
+ return frm(v);
1338
1296
  };
1339
1297
  };
1298
+ const createNonCachedFormatter = fn => (v, l, o) => fn(getCleanedCode(l), o)(v);
1340
1299
  class Formatter {
1341
- constructor() {
1342
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1300
+ constructor(options = {}) {
1343
1301
  this.logger = baseLogger.create('formatter');
1344
1302
  this.options = options;
1303
+ this.init(options);
1304
+ }
1305
+ init(services, options = {
1306
+ interpolation: {}
1307
+ }) {
1308
+ this.formatSeparator = options.interpolation.formatSeparator || ',';
1309
+ const cf = options.cacheInBuiltFormats ? createCachedFormatter : createNonCachedFormatter;
1345
1310
  this.formats = {
1346
- number: createCachedFormatter((lng, opt) => {
1311
+ number: cf((lng, opt) => {
1347
1312
  const formatter = new Intl.NumberFormat(lng, {
1348
1313
  ...opt
1349
1314
  });
1350
1315
  return val => formatter.format(val);
1351
1316
  }),
1352
- currency: createCachedFormatter((lng, opt) => {
1317
+ currency: cf((lng, opt) => {
1353
1318
  const formatter = new Intl.NumberFormat(lng, {
1354
1319
  ...opt,
1355
1320
  style: 'currency'
1356
1321
  });
1357
1322
  return val => formatter.format(val);
1358
1323
  }),
1359
- datetime: createCachedFormatter((lng, opt) => {
1324
+ datetime: cf((lng, opt) => {
1360
1325
  const formatter = new Intl.DateTimeFormat(lng, {
1361
1326
  ...opt
1362
1327
  });
1363
1328
  return val => formatter.format(val);
1364
1329
  }),
1365
- relativetime: createCachedFormatter((lng, opt) => {
1330
+ relativetime: cf((lng, opt) => {
1366
1331
  const formatter = new Intl.RelativeTimeFormat(lng, {
1367
1332
  ...opt
1368
1333
  });
1369
1334
  return val => formatter.format(val, opt.range || 'day');
1370
1335
  }),
1371
- list: createCachedFormatter((lng, opt) => {
1336
+ list: cf((lng, opt) => {
1372
1337
  const formatter = new Intl.ListFormat(lng, {
1373
1338
  ...opt
1374
1339
  });
1375
1340
  return val => formatter.format(val);
1376
1341
  })
1377
1342
  };
1378
- this.init(options);
1379
- }
1380
- init(services) {
1381
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
1382
- interpolation: {}
1383
- };
1384
- this.formatSeparator = options.interpolation.formatSeparator || ',';
1385
1343
  }
1386
1344
  add(name, fc) {
1387
1345
  this.formats[name.toLowerCase().trim()] = fc;
@@ -1389,8 +1347,7 @@
1389
1347
  addCached(name, fc) {
1390
1348
  this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
1391
1349
  }
1392
- format(value, format, lng) {
1393
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1350
+ format(value, format, lng, options = {}) {
1394
1351
  const formats = format.split(this.formatSeparator);
1395
1352
  if (formats.length > 1 && formats[0].indexOf('(') > 1 && formats[0].indexOf(')') < 0 && formats.find(f => f.indexOf(')') > -1)) {
1396
1353
  const lastIndex = formats.findIndex(f => f.indexOf(')') > -1);
@@ -1431,8 +1388,7 @@
1431
1388
  }
1432
1389
  };
1433
1390
  class Connector extends EventEmitter {
1434
- constructor(backend, store, services) {
1435
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1391
+ constructor(backend, store, services, options = {}) {
1436
1392
  super();
1437
1393
  this.backend = backend;
1438
1394
  this.store = store;
@@ -1526,10 +1482,7 @@
1526
1482
  this.emit('loaded', loaded);
1527
1483
  this.queue = this.queue.filter(q => !q.done);
1528
1484
  }
1529
- read(lng, ns, fcName) {
1530
- let tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1531
- let wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
1532
- let callback = arguments.length > 5 ? arguments[5] : undefined;
1485
+ read(lng, ns, fcName, tried = 0, wait = this.retryTimeout, callback) {
1533
1486
  if (!lng.length) return callback(null, {});
1534
1487
  if (this.readingCalls >= this.maxParallelReads) {
1535
1488
  this.waitingReads.push({
@@ -1573,9 +1526,7 @@
1573
1526
  }
1574
1527
  return fc(lng, ns, resolver);
1575
1528
  }
1576
- prepareLoading(languages, namespaces) {
1577
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1578
- let callback = arguments.length > 3 ? arguments[3] : undefined;
1529
+ prepareLoading(languages, namespaces, options = {}, callback) {
1579
1530
  if (!this.backend) {
1580
1531
  this.logger.warn('No backend was added via i18next.use. Will not load resources.');
1581
1532
  return callback && callback();
@@ -1599,8 +1550,7 @@
1599
1550
  reload: true
1600
1551
  }, callback);
1601
1552
  }
1602
- loadOne(name) {
1603
- let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
1553
+ loadOne(name, prefix = '') {
1604
1554
  const s = name.split('|');
1605
1555
  const lng = s[0];
1606
1556
  const ns = s[1];
@@ -1610,9 +1560,7 @@
1610
1560
  this.loaded(name, err, data);
1611
1561
  });
1612
1562
  }
1613
- saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
1614
- let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
1615
- let clb = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : () => {};
1563
+ saveMissing(languages, namespace, key, fallbackValue, isUpdate, options = {}, clb = () => {}) {
1616
1564
  if (this.services?.utils?.hasLoadedNamespace && !this.services?.utils?.hasLoadedNamespace(namespace)) {
1617
1565
  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!!!');
1618
1566
  return;
@@ -1707,7 +1655,8 @@
1707
1655
  nestingOptionsSeparator: ',',
1708
1656
  maxReplaces: 1000,
1709
1657
  skipOnVariables: true
1710
- }
1658
+ },
1659
+ cacheInBuiltFormats: true
1711
1660
  });
1712
1661
  const transformOptions = options => {
1713
1662
  if (isString(options.ns)) options.ns = [options.ns];
@@ -1730,9 +1679,7 @@
1730
1679
  });
1731
1680
  };
1732
1681
  class I18n extends EventEmitter {
1733
- constructor() {
1734
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1735
- let callback = arguments.length > 1 ? arguments[1] : undefined;
1682
+ constructor(options = {}, callback) {
1736
1683
  super();
1737
1684
  this.options = transformOptions(options);
1738
1685
  this.services = {};
@@ -1751,10 +1698,7 @@
1751
1698
  }, 0);
1752
1699
  }
1753
1700
  }
1754
- init() {
1755
- var _this = this;
1756
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1757
- let callback = arguments.length > 1 ? arguments[1] : undefined;
1701
+ init(options = {}, callback) {
1758
1702
  this.isInitializing = true;
1759
1703
  if (typeof options === 'function') {
1760
1704
  callback = options;
@@ -1820,11 +1764,8 @@
1820
1764
  hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
1821
1765
  };
1822
1766
  s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
1823
- s.backendConnector.on('*', function (event) {
1824
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1825
- args[_key - 1] = arguments[_key];
1826
- }
1827
- _this.emit(event, ...args);
1767
+ s.backendConnector.on('*', (event, ...args) => {
1768
+ this.emit(event, ...args);
1828
1769
  });
1829
1770
  if (this.modules.languageDetector) {
1830
1771
  s.languageDetector = createClassOnDemand(this.modules.languageDetector);
@@ -1835,11 +1776,8 @@
1835
1776
  if (s.i18nFormat.init) s.i18nFormat.init(this);
1836
1777
  }
1837
1778
  this.translator = new Translator(this.services, this.options);
1838
- this.translator.on('*', function (event) {
1839
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
1840
- args[_key2 - 1] = arguments[_key2];
1841
- }
1842
- _this.emit(event, ...args);
1779
+ this.translator.on('*', (event, ...args) => {
1780
+ this.emit(event, ...args);
1843
1781
  });
1844
1782
  this.modules.external.forEach(m => {
1845
1783
  if (m.init) m.init(this);
@@ -1856,15 +1794,13 @@
1856
1794
  }
1857
1795
  const storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
1858
1796
  storeApi.forEach(fcName => {
1859
- this[fcName] = function () {
1860
- return _this.store[fcName](...arguments);
1861
- };
1797
+ this[fcName] = (...args) => this.store[fcName](...args);
1862
1798
  });
1863
1799
  const storeApiChained = ['addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle'];
1864
1800
  storeApiChained.forEach(fcName => {
1865
- this[fcName] = function () {
1866
- _this.store[fcName](...arguments);
1867
- return _this;
1801
+ this[fcName] = (...args) => {
1802
+ this.store[fcName](...args);
1803
+ return this;
1868
1804
  };
1869
1805
  });
1870
1806
  const deferred = defer();
@@ -1888,8 +1824,7 @@
1888
1824
  }
1889
1825
  return deferred;
1890
1826
  }
1891
- loadResources(language) {
1892
- let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
1827
+ loadResources(language, callback = noop) {
1893
1828
  let usedCallback = callback;
1894
1829
  const usedLng = isString(language) ? language : this.language;
1895
1830
  if (typeof language === 'function') usedCallback = language;
@@ -1982,7 +1917,6 @@
1982
1917
  }
1983
1918
  }
1984
1919
  changeLanguage(lng, callback) {
1985
- var _this2 = this;
1986
1920
  this.isLanguageChangingTo = lng;
1987
1921
  const deferred = defer();
1988
1922
  this.emit('languageChanging', lng);
@@ -2004,12 +1938,8 @@
2004
1938
  } else {
2005
1939
  this.isLanguageChangingTo = undefined;
2006
1940
  }
2007
- deferred.resolve(function () {
2008
- return _this2.t(...arguments);
2009
- });
2010
- if (callback) callback(err, function () {
2011
- return _this2.t(...arguments);
2012
- });
1941
+ deferred.resolve((...args) => this.t(...args));
1942
+ if (callback) callback(err, (...args) => this.t(...args));
2013
1943
  };
2014
1944
  const setLng = lngs => {
2015
1945
  if (!lng && !lngs && this.services.languageDetector) lngs = [];
@@ -2040,14 +1970,10 @@
2040
1970
  return deferred;
2041
1971
  }
2042
1972
  getFixedT(lng, ns, keyPrefix) {
2043
- var _this3 = this;
2044
- const fixedT = function (key, opts) {
1973
+ const fixedT = (key, opts, ...rest) => {
2045
1974
  let o;
2046
1975
  if (typeof opts !== 'object') {
2047
- for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
2048
- rest[_key3 - 2] = arguments[_key3];
2049
- }
2050
- o = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
1976
+ o = this.options.overloadTranslationOptionHandler([key, opts].concat(rest));
2051
1977
  } else {
2052
1978
  o = {
2053
1979
  ...opts
@@ -2057,14 +1983,14 @@
2057
1983
  o.lngs = o.lngs || fixedT.lngs;
2058
1984
  o.ns = o.ns || fixedT.ns;
2059
1985
  if (o.keyPrefix !== '') o.keyPrefix = o.keyPrefix || keyPrefix || fixedT.keyPrefix;
2060
- const keySeparator = _this3.options.keySeparator || '.';
1986
+ const keySeparator = this.options.keySeparator || '.';
2061
1987
  let resultKey;
2062
1988
  if (o.keyPrefix && Array.isArray(key)) {
2063
1989
  resultKey = key.map(k => `${o.keyPrefix}${keySeparator}${k}`);
2064
1990
  } else {
2065
1991
  resultKey = o.keyPrefix ? `${o.keyPrefix}${keySeparator}${key}` : key;
2066
1992
  }
2067
- return _this3.t(resultKey, o);
1993
+ return this.t(resultKey, o);
2068
1994
  };
2069
1995
  if (isString(lng)) {
2070
1996
  fixedT.lng = lng;
@@ -2075,23 +2001,16 @@
2075
2001
  fixedT.keyPrefix = keyPrefix;
2076
2002
  return fixedT;
2077
2003
  }
2078
- t() {
2079
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
2080
- args[_key4] = arguments[_key4];
2081
- }
2004
+ t(...args) {
2082
2005
  return this.translator?.translate(...args);
2083
2006
  }
2084
- exists() {
2085
- for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
2086
- args[_key5] = arguments[_key5];
2087
- }
2007
+ exists(...args) {
2088
2008
  return this.translator?.exists(...args);
2089
2009
  }
2090
2010
  setDefaultNamespace(ns) {
2091
2011
  this.options.defaultNS = ns;
2092
2012
  }
2093
- hasLoadedNamespace(ns) {
2094
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2013
+ hasLoadedNamespace(ns, options = {}) {
2095
2014
  if (!this.isInitialized) {
2096
2015
  this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
2097
2016
  return false;
@@ -2156,14 +2075,10 @@
2156
2075
  const languageUtils = this.services?.languageUtils || new LanguageUtil(get());
2157
2076
  return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
2158
2077
  }
2159
- static createInstance() {
2160
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2161
- let callback = arguments.length > 1 ? arguments[1] : undefined;
2078
+ static createInstance(options = {}, callback) {
2162
2079
  return new I18n(options, callback);
2163
2080
  }
2164
- cloneInstance() {
2165
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2166
- let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
2081
+ cloneInstance(options = {}, callback = noop) {
2167
2082
  const forkResourceStore = options.forkResourceStore;
2168
2083
  if (forkResourceStore) delete options.forkResourceStore;
2169
2084
  const mergedOptions = {
@@ -2204,10 +2119,7 @@
2204
2119
  clone.services.resourceStore = clone.store;
2205
2120
  }
2206
2121
  clone.translator = new Translator(clone.services, mergedOptions);
2207
- clone.translator.on('*', function (event) {
2208
- for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
2209
- args[_key6 - 1] = arguments[_key6];
2210
- }
2122
+ clone.translator.on('*', (event, ...args) => {
2211
2123
  clone.emit(event, ...args);
2212
2124
  });
2213
2125
  clone.init(mergedOptions, callback);