@fkui/i18next-translate 6.16.0 → 6.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -433,6 +433,27 @@ var postProcessor = {
433
433
  }
434
434
  };
435
435
 
436
+ const PATH_KEY = Symbol('i18next/PATH_KEY');
437
+ function createProxy() {
438
+ const state = [];
439
+ const handler = Object.create(null);
440
+ let proxy;
441
+ handler.get = (target, key) => {
442
+ proxy?.revoke?.();
443
+ if (key === PATH_KEY) return state;
444
+ state.push(key);
445
+ proxy = Proxy.revocable(target, handler);
446
+ return proxy.proxy;
447
+ };
448
+ return Proxy.revocable(Object.create(null), handler).proxy;
449
+ }
450
+ function keysFromSelector(selector, opts) {
451
+ const {
452
+ [PATH_KEY]: path
453
+ } = selector(createProxy());
454
+ return path.join(opts?.keySeparator ?? '.');
455
+ }
456
+
436
457
  const checkedLoadedFor = {};
437
458
  const shouldHandleAsObject = res => !isString(res) && typeof res !== 'boolean' && typeof res !== 'number';
438
459
  class Translator extends EventEmitter {
@@ -489,11 +510,15 @@ class Translator extends EventEmitter {
489
510
  if (typeof opt !== 'object' && this.options.overloadTranslationOptionHandler) {
490
511
  opt = this.options.overloadTranslationOptionHandler(arguments);
491
512
  }
492
- if (typeof options === 'object') opt = {
513
+ if (typeof opt === 'object') opt = {
493
514
  ...opt
494
515
  };
495
516
  if (!opt) opt = {};
496
517
  if (keys == null) return '';
518
+ if (typeof keys === 'function') keys = keysFromSelector(keys, {
519
+ ...this.options,
520
+ ...opt
521
+ });
497
522
  if (!Array.isArray(keys)) keys = [String(keys)];
498
523
  const returnDetails = opt.returnDetails !== undefined ? opt.returnDetails : this.options.returnDetails;
499
524
  const keySeparator = opt.keySeparator !== undefined ? opt.keySeparator : this.options.keySeparator;
@@ -1750,7 +1775,7 @@ class I18n extends EventEmitter {
1750
1775
  });
1751
1776
  const usingLegacyFormatFunction = this.options.interpolation.format && this.options.interpolation.format !== defOpts.interpolation.format;
1752
1777
  if (usingLegacyFormatFunction) {
1753
- this.logger.warn(`init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting`);
1778
+ this.logger.deprecate(`init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting`);
1754
1779
  }
1755
1780
  if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
1756
1781
  s.formatter = createClassOnDemand(formatter);
@@ -1984,8 +2009,18 @@ class I18n extends EventEmitter {
1984
2009
  const keySeparator = this.options.keySeparator || '.';
1985
2010
  let resultKey;
1986
2011
  if (o.keyPrefix && Array.isArray(key)) {
1987
- resultKey = key.map(k => `${o.keyPrefix}${keySeparator}${k}`);
2012
+ resultKey = key.map(k => {
2013
+ if (typeof k === 'function') k = keysFromSelector(k, {
2014
+ ...this.options,
2015
+ ...opts
2016
+ });
2017
+ return `${o.keyPrefix}${keySeparator}${k}`;
2018
+ });
1988
2019
  } else {
2020
+ if (typeof key === 'function') key = keysFromSelector(key, {
2021
+ ...this.options,
2022
+ ...opts
2023
+ });
1989
2024
  resultKey = o.keyPrefix ? `${o.keyPrefix}${keySeparator}${key}` : key;
1990
2025
  }
1991
2026
  return this.t(resultKey, o);