@codee-sh/medusa-plugin-notification-emails 0.0.1 → 0.0.2

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.
@@ -7,8 +7,8 @@ import Medusa from "@medusajs/js-sdk";
7
7
  import { useState, useMemo, createContext, useContext, useReducer, useEffect, Fragment as Fragment$1, useRef, forwardRef, Suspense, createElement } from "react";
8
8
  import { InformationCircleSolid, ChatBubbleLeftRight, ArrowUpRightOnBox, XMarkMini, TriangleDownMini, Check, SquareTwoStack, ListBullet } from "@medusajs/icons";
9
9
  import { Outlet } from "react-router-dom";
10
- import "@react-email/components";
11
10
  import "@react-email/render";
11
+ import "@react-email/components";
12
12
  const sdk = new Medusa({
13
13
  baseUrl: "/",
14
14
  debug: false,
@@ -7437,7 +7437,7 @@ const setPath = (object, path, newValue) => {
7437
7437
  e = `${p[p.length - 1]}.${e}`;
7438
7438
  p = p.slice(0, p.length - 1);
7439
7439
  last = getLastOfPath(object, p, Object);
7440
- if (last && last.obj && typeof last.obj[`${last.k}.${e}`] !== "undefined") {
7440
+ if ((last == null ? void 0 : last.obj) && typeof last.obj[`${last.k}.${e}`] !== "undefined") {
7441
7441
  last.obj = void 0;
7442
7442
  }
7443
7443
  }
@@ -7457,6 +7457,7 @@ const getPath = (object, path) => {
7457
7457
  k
7458
7458
  } = getLastOfPath(object, path);
7459
7459
  if (!obj) return void 0;
7460
+ if (!Object.prototype.hasOwnProperty.call(obj, k)) return void 0;
7460
7461
  return obj[k];
7461
7462
  };
7462
7463
  const getPathWithDefaults = (data, defaultData, key) => {
@@ -7534,10 +7535,12 @@ const looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
7534
7535
  }
7535
7536
  return matched;
7536
7537
  };
7537
- const deepFind = function(obj, path) {
7538
- let keySeparator = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : ".";
7538
+ const deepFind = (obj, path, keySeparator = ".") => {
7539
7539
  if (!obj) return void 0;
7540
- if (obj[path]) return obj[path];
7540
+ if (obj[path]) {
7541
+ if (!Object.prototype.hasOwnProperty.call(obj, path)) return void 0;
7542
+ return obj[path];
7543
+ }
7541
7544
  const tokens = path.split(keySeparator);
7542
7545
  let current = obj;
7543
7546
  for (let i = 0; i < tokens.length; ) {
@@ -7564,7 +7567,7 @@ const deepFind = function(obj, path) {
7564
7567
  }
7565
7568
  return current;
7566
7569
  };
7567
- const getCleanedCode = (code) => code && code.replace("_", "-");
7570
+ const getCleanedCode = (code) => code == null ? void 0 : code.replace("_", "-");
7568
7571
  const consoleLogger = {
7569
7572
  type: "logger",
7570
7573
  log(args) {
@@ -7577,43 +7580,30 @@ const consoleLogger = {
7577
7580
  this.output("error", args);
7578
7581
  },
7579
7582
  output(type, args) {
7580
- if (console && console[type]) console[type].apply(console, args);
7583
+ var _a, _b;
7584
+ (_b = (_a = console == null ? void 0 : console[type]) == null ? void 0 : _a.apply) == null ? void 0 : _b.call(_a, console, args);
7581
7585
  }
7582
7586
  };
7583
7587
  class Logger {
7584
- constructor(concreteLogger) {
7585
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
7588
+ constructor(concreteLogger, options = {}) {
7586
7589
  this.init(concreteLogger, options);
7587
7590
  }
7588
- init(concreteLogger) {
7589
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
7591
+ init(concreteLogger, options = {}) {
7590
7592
  this.prefix = options.prefix || "i18next:";
7591
7593
  this.logger = concreteLogger || consoleLogger;
7592
7594
  this.options = options;
7593
7595
  this.debug = options.debug;
7594
7596
  }
7595
- log() {
7596
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
7597
- args[_key] = arguments[_key];
7598
- }
7597
+ log(...args) {
7599
7598
  return this.forward(args, "log", "", true);
7600
7599
  }
7601
- warn() {
7602
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
7603
- args[_key2] = arguments[_key2];
7604
- }
7600
+ warn(...args) {
7605
7601
  return this.forward(args, "warn", "", true);
7606
7602
  }
7607
- error() {
7608
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
7609
- args[_key3] = arguments[_key3];
7610
- }
7603
+ error(...args) {
7611
7604
  return this.forward(args, "error", "");
7612
7605
  }
7613
- deprecate() {
7614
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
7615
- args[_key4] = arguments[_key4];
7616
- }
7606
+ deprecate(...args) {
7617
7607
  return this.forward(args, "warn", "WARNING DEPRECATED: ", true);
7618
7608
  }
7619
7609
  forward(args, lvl, prefix, debugOnly) {
@@ -7656,14 +7646,10 @@ class EventEmitter {
7656
7646
  }
7657
7647
  this.observers[event].delete(listener);
7658
7648
  }
7659
- emit(event) {
7660
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
7661
- args[_key - 1] = arguments[_key];
7662
- }
7649
+ emit(event, ...args) {
7663
7650
  if (this.observers[event]) {
7664
7651
  const cloned = Array.from(this.observers[event].entries());
7665
- cloned.forEach((_ref) => {
7666
- let [observer, numTimesAdded] = _ref;
7652
+ cloned.forEach(([observer, numTimesAdded]) => {
7667
7653
  for (let i = 0; i < numTimesAdded; i++) {
7668
7654
  observer(...args);
7669
7655
  }
@@ -7671,8 +7657,7 @@ class EventEmitter {
7671
7657
  }
7672
7658
  if (this.observers["*"]) {
7673
7659
  const cloned = Array.from(this.observers["*"].entries());
7674
- cloned.forEach((_ref2) => {
7675
- let [observer, numTimesAdded] = _ref2;
7660
+ cloned.forEach(([observer, numTimesAdded]) => {
7676
7661
  for (let i = 0; i < numTimesAdded; i++) {
7677
7662
  observer.apply(observer, [event, ...args]);
7678
7663
  }
@@ -7681,11 +7666,10 @@ class EventEmitter {
7681
7666
  }
7682
7667
  }
7683
7668
  class ResourceStore extends EventEmitter {
7684
- constructor(data) {
7685
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
7686
- ns: ["translation"],
7687
- defaultNS: "translation"
7688
- };
7669
+ constructor(data, options = {
7670
+ ns: ["translation"],
7671
+ defaultNS: "translation"
7672
+ }) {
7689
7673
  super();
7690
7674
  this.data = data || {};
7691
7675
  this.options = options;
@@ -7707,8 +7691,8 @@ class ResourceStore extends EventEmitter {
7707
7691
  this.options.ns.splice(index, 1);
7708
7692
  }
7709
7693
  }
7710
- getResource(lng, ns, key) {
7711
- let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
7694
+ getResource(lng, ns, key, options = {}) {
7695
+ var _a, _b;
7712
7696
  const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
7713
7697
  const ignoreJSONStructure = options.ignoreJSONStructure !== void 0 ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
7714
7698
  let path;
@@ -7733,12 +7717,11 @@ class ResourceStore extends EventEmitter {
7733
7717
  key = path.slice(2).join(".");
7734
7718
  }
7735
7719
  if (result || !ignoreJSONStructure || !isString(key)) return result;
7736
- return deepFind(this.data && this.data[lng] && this.data[lng][ns], key, keySeparator);
7720
+ return deepFind((_b = (_a = this.data) == null ? void 0 : _a[lng]) == null ? void 0 : _b[ns], key, keySeparator);
7737
7721
  }
7738
- addResource(lng, ns, key, value) {
7739
- let options = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : {
7740
- silent: false
7741
- };
7722
+ addResource(lng, ns, key, value, options = {
7723
+ silent: false
7724
+ }) {
7742
7725
  const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
7743
7726
  let path = [lng, ns];
7744
7727
  if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
@@ -7751,10 +7734,9 @@ class ResourceStore extends EventEmitter {
7751
7734
  setPath(this.data, path, value);
7752
7735
  if (!options.silent) this.emit("added", lng, ns, key, value);
7753
7736
  }
7754
- addResources(lng, ns, resources) {
7755
- let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {
7756
- silent: false
7757
- };
7737
+ addResources(lng, ns, resources, options = {
7738
+ silent: false
7739
+ }) {
7758
7740
  for (const m in resources) {
7759
7741
  if (isString(resources[m]) || Array.isArray(resources[m])) this.addResource(lng, ns, m, resources[m], {
7760
7742
  silent: true
@@ -7762,11 +7744,10 @@ class ResourceStore extends EventEmitter {
7762
7744
  }
7763
7745
  if (!options.silent) this.emit("added", lng, ns, resources);
7764
7746
  }
7765
- addResourceBundle(lng, ns, resources, deep, overwrite) {
7766
- let options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {
7767
- silent: false,
7768
- skipCopy: false
7769
- };
7747
+ addResourceBundle(lng, ns, resources, deep, overwrite, options = {
7748
+ silent: false,
7749
+ skipCopy: false
7750
+ }) {
7770
7751
  let path = [lng, ns];
7771
7752
  if (lng.indexOf(".") > -1) {
7772
7753
  path = lng.split(".");
@@ -7800,10 +7781,6 @@ class ResourceStore extends EventEmitter {
7800
7781
  }
7801
7782
  getResourceBundle(lng, ns) {
7802
7783
  if (!ns) ns = this.options.defaultNS;
7803
- if (this.options.compatibilityAPI === "v1") return {
7804
- ...{},
7805
- ...this.getResource(lng, ns)
7806
- };
7807
7784
  return this.getResource(lng, ns);
7808
7785
  }
7809
7786
  getDataByLanguage(lng) {
@@ -7825,15 +7802,37 @@ var postProcessor = {
7825
7802
  },
7826
7803
  handle(processors, value, key, options, translator) {
7827
7804
  processors.forEach((processor) => {
7828
- if (this.processors[processor]) value = this.processors[processor].process(value, key, options, translator);
7805
+ var _a;
7806
+ value = ((_a = this.processors[processor]) == null ? void 0 : _a.process(value, key, options, translator)) ?? value;
7829
7807
  });
7830
7808
  return value;
7831
7809
  }
7832
7810
  };
7811
+ const PATH_KEY = Symbol("i18next/PATH_KEY");
7812
+ function createProxy() {
7813
+ const state = [];
7814
+ const handler = /* @__PURE__ */ Object.create(null);
7815
+ let proxy;
7816
+ handler.get = (target, key) => {
7817
+ var _a;
7818
+ (_a = proxy == null ? void 0 : proxy.revoke) == null ? void 0 : _a.call(proxy);
7819
+ if (key === PATH_KEY) return state;
7820
+ state.push(key);
7821
+ proxy = Proxy.revocable(target, handler);
7822
+ return proxy.proxy;
7823
+ };
7824
+ return Proxy.revocable(/* @__PURE__ */ Object.create(null), handler).proxy;
7825
+ }
7826
+ function keysFromSelector(selector, opts) {
7827
+ const {
7828
+ [PATH_KEY]: path
7829
+ } = selector(createProxy());
7830
+ return path.join((opts == null ? void 0 : opts.keySeparator) ?? ".");
7831
+ }
7833
7832
  const checkedLoadedFor = {};
7833
+ const shouldHandleAsObject = (res) => !isString(res) && typeof res !== "boolean" && typeof res !== "number";
7834
7834
  class Translator extends EventEmitter {
7835
- constructor(services) {
7836
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
7835
+ constructor(services, options = {}) {
7837
7836
  super();
7838
7837
  copy(["resourceStore", "languageUtils", "pluralResolver", "interpolator", "backendConnector", "i18nFormat", "utils"], services, this);
7839
7838
  this.options = options;
@@ -7845,23 +7844,28 @@ class Translator extends EventEmitter {
7845
7844
  changeLanguage(lng) {
7846
7845
  if (lng) this.language = lng;
7847
7846
  }
7848
- exists(key) {
7849
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
7850
- interpolation: {}
7847
+ exists(key, o = {
7848
+ interpolation: {}
7849
+ }) {
7850
+ const opt = {
7851
+ ...o
7851
7852
  };
7852
- if (key === void 0 || key === null) {
7853
+ if (key == null) return false;
7854
+ const resolved = this.resolve(key, opt);
7855
+ if ((resolved == null ? void 0 : resolved.res) === void 0) return false;
7856
+ const isObject = shouldHandleAsObject(resolved.res);
7857
+ if (opt.returnObjects === false && isObject) {
7853
7858
  return false;
7854
7859
  }
7855
- const resolved = this.resolve(key, options);
7856
- return resolved && resolved.res !== void 0;
7860
+ return true;
7857
7861
  }
7858
- extractFromKey(key, options) {
7859
- let nsSeparator = options.nsSeparator !== void 0 ? options.nsSeparator : this.options.nsSeparator;
7862
+ extractFromKey(key, opt) {
7863
+ let nsSeparator = opt.nsSeparator !== void 0 ? opt.nsSeparator : this.options.nsSeparator;
7860
7864
  if (nsSeparator === void 0) nsSeparator = ":";
7861
- const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
7862
- let namespaces = options.ns || this.options.defaultNS || [];
7865
+ const keySeparator = opt.keySeparator !== void 0 ? opt.keySeparator : this.options.keySeparator;
7866
+ let namespaces = opt.ns || this.options.defaultNS || [];
7863
7867
  const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
7864
- const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
7868
+ const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !opt.keySeparator && !this.options.userDefinedNsSeparator && !opt.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
7865
7869
  if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
7866
7870
  const m = key.match(this.interpolator.nestingRegexp);
7867
7871
  if (m && m.length > 0) {
@@ -7879,28 +7883,36 @@ class Translator extends EventEmitter {
7879
7883
  namespaces: isString(namespaces) ? [namespaces] : namespaces
7880
7884
  };
7881
7885
  }
7882
- translate(keys, options, lastKey) {
7883
- if (typeof options !== "object" && this.options.overloadTranslationOptionHandler) {
7884
- options = this.options.overloadTranslationOptionHandler(arguments);
7886
+ translate(keys, o, lastKey) {
7887
+ let opt = typeof o === "object" ? {
7888
+ ...o
7889
+ } : o;
7890
+ if (typeof opt !== "object" && this.options.overloadTranslationOptionHandler) {
7891
+ opt = this.options.overloadTranslationOptionHandler(arguments);
7885
7892
  }
7886
- if (typeof options === "object") options = {
7887
- ...options
7893
+ if (typeof opt === "object") opt = {
7894
+ ...opt
7888
7895
  };
7889
- if (!options) options = {};
7890
- if (keys === void 0 || keys === null) return "";
7896
+ if (!opt) opt = {};
7897
+ if (keys == null) return "";
7898
+ if (typeof keys === "function") keys = keysFromSelector(keys, {
7899
+ ...this.options,
7900
+ ...opt
7901
+ });
7891
7902
  if (!Array.isArray(keys)) keys = [String(keys)];
7892
- const returnDetails = options.returnDetails !== void 0 ? options.returnDetails : this.options.returnDetails;
7893
- const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
7903
+ const returnDetails = opt.returnDetails !== void 0 ? opt.returnDetails : this.options.returnDetails;
7904
+ const keySeparator = opt.keySeparator !== void 0 ? opt.keySeparator : this.options.keySeparator;
7894
7905
  const {
7895
7906
  key,
7896
7907
  namespaces
7897
- } = this.extractFromKey(keys[keys.length - 1], options);
7908
+ } = this.extractFromKey(keys[keys.length - 1], opt);
7898
7909
  const namespace = namespaces[namespaces.length - 1];
7899
- const lng = options.lng || this.language;
7900
- const appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
7901
- if (lng && lng.toLowerCase() === "cimode") {
7910
+ let nsSeparator = opt.nsSeparator !== void 0 ? opt.nsSeparator : this.options.nsSeparator;
7911
+ if (nsSeparator === void 0) nsSeparator = ":";
7912
+ const lng = opt.lng || this.language;
7913
+ const appendNamespaceToCIMode = opt.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
7914
+ if ((lng == null ? void 0 : lng.toLowerCase()) === "cimode") {
7902
7915
  if (appendNamespaceToCIMode) {
7903
- const nsSeparator = options.nsSeparator || this.options.nsSeparator;
7904
7916
  if (returnDetails) {
7905
7917
  return {
7906
7918
  res: `${namespace}${nsSeparator}${key}`,
@@ -7908,7 +7920,7 @@ class Translator extends EventEmitter {
7908
7920
  exactUsedKey: key,
7909
7921
  usedLng: lng,
7910
7922
  usedNS: namespace,
7911
- usedParams: this.getUsedParamsDetails(options)
7923
+ usedParams: this.getUsedParamsDetails(opt)
7912
7924
  };
7913
7925
  }
7914
7926
  return `${namespace}${nsSeparator}${key}`;
@@ -7920,69 +7932,84 @@ class Translator extends EventEmitter {
7920
7932
  exactUsedKey: key,
7921
7933
  usedLng: lng,
7922
7934
  usedNS: namespace,
7923
- usedParams: this.getUsedParamsDetails(options)
7935
+ usedParams: this.getUsedParamsDetails(opt)
7924
7936
  };
7925
7937
  }
7926
7938
  return key;
7927
7939
  }
7928
- const resolved = this.resolve(keys, options);
7929
- let res = resolved && resolved.res;
7930
- const resUsedKey = resolved && resolved.usedKey || key;
7931
- const resExactUsedKey = resolved && resolved.exactUsedKey || key;
7932
- const resType = Object.prototype.toString.apply(res);
7940
+ const resolved = this.resolve(keys, opt);
7941
+ let res = resolved == null ? void 0 : resolved.res;
7942
+ const resUsedKey = (resolved == null ? void 0 : resolved.usedKey) || key;
7943
+ const resExactUsedKey = (resolved == null ? void 0 : resolved.exactUsedKey) || key;
7933
7944
  const noObject = ["[object Number]", "[object Function]", "[object RegExp]"];
7934
- const joinArrays = options.joinArrays !== void 0 ? options.joinArrays : this.options.joinArrays;
7945
+ const joinArrays = opt.joinArrays !== void 0 ? opt.joinArrays : this.options.joinArrays;
7935
7946
  const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
7936
- const handleAsObject = !isString(res) && typeof res !== "boolean" && typeof res !== "number";
7937
- if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(isString(joinArrays) && Array.isArray(res))) {
7938
- if (!options.returnObjects && !this.options.returnObjects) {
7947
+ const needsPluralHandling = opt.count !== void 0 && !isString(opt.count);
7948
+ const hasDefaultValue = Translator.hasDefaultValue(opt);
7949
+ const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, opt) : "";
7950
+ const defaultValueSuffixOrdinalFallback = opt.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, {
7951
+ ordinal: false
7952
+ }) : "";
7953
+ const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
7954
+ const defaultValue = needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] || opt[`defaultValue${defaultValueSuffix}`] || opt[`defaultValue${defaultValueSuffixOrdinalFallback}`] || opt.defaultValue;
7955
+ let resForObjHndl = res;
7956
+ if (handleAsObjectInI18nFormat && !res && hasDefaultValue) {
7957
+ resForObjHndl = defaultValue;
7958
+ }
7959
+ const handleAsObject = shouldHandleAsObject(resForObjHndl);
7960
+ const resType = Object.prototype.toString.apply(resForObjHndl);
7961
+ if (handleAsObjectInI18nFormat && resForObjHndl && handleAsObject && noObject.indexOf(resType) < 0 && !(isString(joinArrays) && Array.isArray(resForObjHndl))) {
7962
+ if (!opt.returnObjects && !this.options.returnObjects) {
7939
7963
  if (!this.options.returnedObjectHandler) {
7940
7964
  this.logger.warn("accessing an object - but returnObjects options is not enabled!");
7941
7965
  }
7942
- const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, {
7943
- ...options,
7966
+ const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, resForObjHndl, {
7967
+ ...opt,
7944
7968
  ns: namespaces
7945
7969
  }) : `key '${key} (${this.language})' returned an object instead of string.`;
7946
7970
  if (returnDetails) {
7947
7971
  resolved.res = r;
7948
- resolved.usedParams = this.getUsedParamsDetails(options);
7972
+ resolved.usedParams = this.getUsedParamsDetails(opt);
7949
7973
  return resolved;
7950
7974
  }
7951
7975
  return r;
7952
7976
  }
7953
7977
  if (keySeparator) {
7954
- const resTypeIsArray = Array.isArray(res);
7978
+ const resTypeIsArray = Array.isArray(resForObjHndl);
7955
7979
  const copy2 = resTypeIsArray ? [] : {};
7956
7980
  const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
7957
- for (const m in res) {
7958
- if (Object.prototype.hasOwnProperty.call(res, m)) {
7981
+ for (const m in resForObjHndl) {
7982
+ if (Object.prototype.hasOwnProperty.call(resForObjHndl, m)) {
7959
7983
  const deepKey = `${newKeyToUse}${keySeparator}${m}`;
7960
- copy2[m] = this.translate(deepKey, {
7961
- ...options,
7962
- ...{
7963
- joinArrays: false,
7964
- ns: namespaces
7965
- }
7966
- });
7967
- if (copy2[m] === deepKey) copy2[m] = res[m];
7984
+ if (hasDefaultValue && !res) {
7985
+ copy2[m] = this.translate(deepKey, {
7986
+ ...opt,
7987
+ defaultValue: shouldHandleAsObject(defaultValue) ? defaultValue[m] : void 0,
7988
+ ...{
7989
+ joinArrays: false,
7990
+ ns: namespaces
7991
+ }
7992
+ });
7993
+ } else {
7994
+ copy2[m] = this.translate(deepKey, {
7995
+ ...opt,
7996
+ ...{
7997
+ joinArrays: false,
7998
+ ns: namespaces
7999
+ }
8000
+ });
8001
+ }
8002
+ if (copy2[m] === deepKey) copy2[m] = resForObjHndl[m];
7968
8003
  }
7969
8004
  }
7970
8005
  res = copy2;
7971
8006
  }
7972
8007
  } else if (handleAsObjectInI18nFormat && isString(joinArrays) && Array.isArray(res)) {
7973
8008
  res = res.join(joinArrays);
7974
- if (res) res = this.extendTranslation(res, keys, options, lastKey);
8009
+ if (res) res = this.extendTranslation(res, keys, opt, lastKey);
7975
8010
  } else {
7976
8011
  let usedDefault = false;
7977
8012
  let usedKey = false;
7978
- const needsPluralHandling = options.count !== void 0 && !isString(options.count);
7979
- const hasDefaultValue = Translator.hasDefaultValue(options);
7980
- const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : "";
7981
- const defaultValueSuffixOrdinalFallback = options.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, {
7982
- ordinal: false
7983
- }) : "";
7984
- const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
7985
- const defaultValue = needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] || options[`defaultValue${defaultValueSuffix}`] || options[`defaultValue${defaultValueSuffixOrdinalFallback}`] || options.defaultValue;
7986
8013
  if (!this.isValidLookup(res) && hasDefaultValue) {
7987
8014
  usedDefault = true;
7988
8015
  res = defaultValue;
@@ -7991,47 +8018,48 @@ class Translator extends EventEmitter {
7991
8018
  usedKey = true;
7992
8019
  res = key;
7993
8020
  }
7994
- const missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
8021
+ const missingKeyNoValueFallbackToKey = opt.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
7995
8022
  const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? void 0 : res;
7996
8023
  const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
7997
8024
  if (usedKey || usedDefault || updateMissing) {
7998
8025
  this.logger.log(updateMissing ? "updateKey" : "missingKey", lng, namespace, key, updateMissing ? defaultValue : res);
7999
8026
  if (keySeparator) {
8000
8027
  const fk = this.resolve(key, {
8001
- ...options,
8028
+ ...opt,
8002
8029
  keySeparator: false
8003
8030
  });
8004
8031
  if (fk && fk.res) this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.");
8005
8032
  }
8006
8033
  let lngs = [];
8007
- const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
8034
+ const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, opt.lng || this.language);
8008
8035
  if (this.options.saveMissingTo === "fallback" && fallbackLngs && fallbackLngs[0]) {
8009
8036
  for (let i = 0; i < fallbackLngs.length; i++) {
8010
8037
  lngs.push(fallbackLngs[i]);
8011
8038
  }
8012
8039
  } else if (this.options.saveMissingTo === "all") {
8013
- lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
8040
+ lngs = this.languageUtils.toResolveHierarchy(opt.lng || this.language);
8014
8041
  } else {
8015
- lngs.push(options.lng || this.language);
8042
+ lngs.push(opt.lng || this.language);
8016
8043
  }
8017
8044
  const send = (l, k, specificDefaultValue) => {
8045
+ var _a;
8018
8046
  const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
8019
8047
  if (this.options.missingKeyHandler) {
8020
- this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
8021
- } else if (this.backendConnector && this.backendConnector.saveMissing) {
8022
- this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
8048
+ this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, opt);
8049
+ } else if ((_a = this.backendConnector) == null ? void 0 : _a.saveMissing) {
8050
+ this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, opt);
8023
8051
  }
8024
8052
  this.emit("missingKey", l, namespace, k, res);
8025
8053
  };
8026
8054
  if (this.options.saveMissing) {
8027
8055
  if (this.options.saveMissingPlurals && needsPluralHandling) {
8028
8056
  lngs.forEach((language) => {
8029
- const suffixes = this.pluralResolver.getSuffixes(language, options);
8030
- if (needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.indexOf(`${this.options.pluralSeparator}zero`) < 0) {
8057
+ const suffixes = this.pluralResolver.getSuffixes(language, opt);
8058
+ if (needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.indexOf(`${this.options.pluralSeparator}zero`) < 0) {
8031
8059
  suffixes.push(`${this.options.pluralSeparator}zero`);
8032
8060
  }
8033
8061
  suffixes.forEach((suffix) => {
8034
- send([language], key + suffix, options[`defaultValue${suffix}`] || defaultValue);
8062
+ send([language], key + suffix, opt[`defaultValue${suffix}`] || defaultValue);
8035
8063
  });
8036
8064
  });
8037
8065
  } else {
@@ -8039,87 +8067,81 @@ class Translator extends EventEmitter {
8039
8067
  }
8040
8068
  }
8041
8069
  }
8042
- res = this.extendTranslation(res, keys, options, resolved, lastKey);
8043
- if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
8070
+ res = this.extendTranslation(res, keys, opt, resolved, lastKey);
8071
+ if (usedKey && res === key && this.options.appendNamespaceToMissingKey) {
8072
+ res = `${namespace}${nsSeparator}${key}`;
8073
+ }
8044
8074
  if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
8045
- if (this.options.compatibilityAPI !== "v1") {
8046
- res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : void 0);
8047
- } else {
8048
- res = this.options.parseMissingKeyHandler(res);
8049
- }
8075
+ res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}${nsSeparator}${key}` : key, usedDefault ? res : void 0, opt);
8050
8076
  }
8051
8077
  }
8052
8078
  if (returnDetails) {
8053
8079
  resolved.res = res;
8054
- resolved.usedParams = this.getUsedParamsDetails(options);
8080
+ resolved.usedParams = this.getUsedParamsDetails(opt);
8055
8081
  return resolved;
8056
8082
  }
8057
8083
  return res;
8058
8084
  }
8059
- extendTranslation(res, key, options, resolved, lastKey) {
8060
- var _this = this;
8061
- if (this.i18nFormat && this.i18nFormat.parse) {
8085
+ extendTranslation(res, key, opt, resolved, lastKey) {
8086
+ var _a, _b;
8087
+ if ((_a = this.i18nFormat) == null ? void 0 : _a.parse) {
8062
8088
  res = this.i18nFormat.parse(res, {
8063
8089
  ...this.options.interpolation.defaultVariables,
8064
- ...options
8065
- }, options.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
8090
+ ...opt
8091
+ }, opt.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
8066
8092
  resolved
8067
8093
  });
8068
- } else if (!options.skipInterpolation) {
8069
- if (options.interpolation) this.interpolator.init({
8070
- ...options,
8094
+ } else if (!opt.skipInterpolation) {
8095
+ if (opt.interpolation) this.interpolator.init({
8096
+ ...opt,
8071
8097
  ...{
8072
8098
  interpolation: {
8073
8099
  ...this.options.interpolation,
8074
- ...options.interpolation
8100
+ ...opt.interpolation
8075
8101
  }
8076
8102
  }
8077
8103
  });
8078
- const skipOnVariables = isString(res) && (options && options.interpolation && options.interpolation.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
8104
+ const skipOnVariables = isString(res) && (((_b = opt == null ? void 0 : opt.interpolation) == null ? void 0 : _b.skipOnVariables) !== void 0 ? opt.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
8079
8105
  let nestBef;
8080
8106
  if (skipOnVariables) {
8081
8107
  const nb = res.match(this.interpolator.nestingRegexp);
8082
8108
  nestBef = nb && nb.length;
8083
8109
  }
8084
- let data = options.replace && !isString(options.replace) ? options.replace : options;
8110
+ let data = opt.replace && !isString(opt.replace) ? opt.replace : opt;
8085
8111
  if (this.options.interpolation.defaultVariables) data = {
8086
8112
  ...this.options.interpolation.defaultVariables,
8087
8113
  ...data
8088
8114
  };
8089
- res = this.interpolator.interpolate(res, data, options.lng || this.language || resolved.usedLng, options);
8115
+ res = this.interpolator.interpolate(res, data, opt.lng || this.language || resolved.usedLng, opt);
8090
8116
  if (skipOnVariables) {
8091
8117
  const na = res.match(this.interpolator.nestingRegexp);
8092
8118
  const nestAft = na && na.length;
8093
- if (nestBef < nestAft) options.nest = false;
8119
+ if (nestBef < nestAft) opt.nest = false;
8094
8120
  }
8095
- if (!options.lng && this.options.compatibilityAPI !== "v1" && resolved && resolved.res) options.lng = this.language || resolved.usedLng;
8096
- if (options.nest !== false) res = this.interpolator.nest(res, function() {
8097
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
8098
- args[_key] = arguments[_key];
8099
- }
8100
- if (lastKey && lastKey[0] === args[0] && !options.context) {
8101
- _this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
8121
+ if (!opt.lng && resolved && resolved.res) opt.lng = this.language || resolved.usedLng;
8122
+ if (opt.nest !== false) res = this.interpolator.nest(res, (...args) => {
8123
+ if ((lastKey == null ? void 0 : lastKey[0]) === args[0] && !opt.context) {
8124
+ this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
8102
8125
  return null;
8103
8126
  }
8104
- return _this.translate(...args, key);
8105
- }, options);
8106
- if (options.interpolation) this.interpolator.reset();
8127
+ return this.translate(...args, key);
8128
+ }, opt);
8129
+ if (opt.interpolation) this.interpolator.reset();
8107
8130
  }
8108
- const postProcess = options.postProcess || this.options.postProcess;
8131
+ const postProcess = opt.postProcess || this.options.postProcess;
8109
8132
  const postProcessorNames = isString(postProcess) ? [postProcess] : postProcess;
8110
- if (res !== void 0 && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) {
8133
+ if (res != null && (postProcessorNames == null ? void 0 : postProcessorNames.length) && opt.applyPostProcessor !== false) {
8111
8134
  res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
8112
8135
  i18nResolved: {
8113
8136
  ...resolved,
8114
- usedParams: this.getUsedParamsDetails(options)
8137
+ usedParams: this.getUsedParamsDetails(opt)
8115
8138
  },
8116
- ...options
8117
- } : options, this);
8139
+ ...opt
8140
+ } : opt, this);
8118
8141
  }
8119
8142
  return res;
8120
8143
  }
8121
- resolve(keys) {
8122
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
8144
+ resolve(keys, opt = {}) {
8123
8145
  let found;
8124
8146
  let usedKey;
8125
8147
  let exactUsedKey;
@@ -8128,50 +8150,52 @@ class Translator extends EventEmitter {
8128
8150
  if (isString(keys)) keys = [keys];
8129
8151
  keys.forEach((k) => {
8130
8152
  if (this.isValidLookup(found)) return;
8131
- const extracted = this.extractFromKey(k, options);
8153
+ const extracted = this.extractFromKey(k, opt);
8132
8154
  const key = extracted.key;
8133
8155
  usedKey = key;
8134
8156
  let namespaces = extracted.namespaces;
8135
8157
  if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
8136
- const needsPluralHandling = options.count !== void 0 && !isString(options.count);
8137
- const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
8138
- const needsContextHandling = options.context !== void 0 && (isString(options.context) || typeof options.context === "number") && options.context !== "";
8139
- const codes = options.lngs ? options.lngs : this.languageUtils.toResolveHierarchy(options.lng || this.language, options.fallbackLng);
8158
+ const needsPluralHandling = opt.count !== void 0 && !isString(opt.count);
8159
+ const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
8160
+ const needsContextHandling = opt.context !== void 0 && (isString(opt.context) || typeof opt.context === "number") && opt.context !== "";
8161
+ const codes = opt.lngs ? opt.lngs : this.languageUtils.toResolveHierarchy(opt.lng || this.language, opt.fallbackLng);
8140
8162
  namespaces.forEach((ns) => {
8163
+ var _a, _b;
8141
8164
  if (this.isValidLookup(found)) return;
8142
8165
  usedNS = ns;
8143
- if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils && this.utils.hasLoadedNamespace && !this.utils.hasLoadedNamespace(usedNS)) {
8166
+ if (!checkedLoadedFor[`${codes[0]}-${ns}`] && ((_a = this.utils) == null ? void 0 : _a.hasLoadedNamespace) && !((_b = this.utils) == null ? void 0 : _b.hasLoadedNamespace(usedNS))) {
8144
8167
  checkedLoadedFor[`${codes[0]}-${ns}`] = true;
8145
8168
  this.logger.warn(`key "${usedKey}" for languages "${codes.join(", ")}" won't get resolved as namespace "${usedNS}" 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!!!");
8146
8169
  }
8147
8170
  codes.forEach((code) => {
8171
+ var _a2;
8148
8172
  if (this.isValidLookup(found)) return;
8149
8173
  usedLng = code;
8150
8174
  const finalKeys = [key];
8151
- if (this.i18nFormat && this.i18nFormat.addLookupKeys) {
8152
- this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
8175
+ if ((_a2 = this.i18nFormat) == null ? void 0 : _a2.addLookupKeys) {
8176
+ this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, opt);
8153
8177
  } else {
8154
8178
  let pluralSuffix;
8155
- if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, options.count, options);
8179
+ if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, opt.count, opt);
8156
8180
  const zeroSuffix = `${this.options.pluralSeparator}zero`;
8157
8181
  const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
8158
8182
  if (needsPluralHandling) {
8159
- finalKeys.push(key + pluralSuffix);
8160
- if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
8183
+ if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
8161
8184
  finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
8162
8185
  }
8186
+ finalKeys.push(key + pluralSuffix);
8163
8187
  if (needsZeroSuffixLookup) {
8164
8188
  finalKeys.push(key + zeroSuffix);
8165
8189
  }
8166
8190
  }
8167
8191
  if (needsContextHandling) {
8168
- const contextKey = `${key}${this.options.contextSeparator}${options.context}`;
8192
+ const contextKey = `${key}${this.options.contextSeparator || "_"}${opt.context}`;
8169
8193
  finalKeys.push(contextKey);
8170
8194
  if (needsPluralHandling) {
8171
- finalKeys.push(contextKey + pluralSuffix);
8172
- if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
8195
+ if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
8173
8196
  finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
8174
8197
  }
8198
+ finalKeys.push(contextKey + pluralSuffix);
8175
8199
  if (needsZeroSuffixLookup) {
8176
8200
  finalKeys.push(contextKey + zeroSuffix);
8177
8201
  }
@@ -8182,7 +8206,7 @@ class Translator extends EventEmitter {
8182
8206
  while (possibleKey = finalKeys.pop()) {
8183
8207
  if (!this.isValidLookup(found)) {
8184
8208
  exactUsedKey = possibleKey;
8185
- found = this.getResource(code, ns, possibleKey, options);
8209
+ found = this.getResource(code, ns, possibleKey, opt);
8186
8210
  }
8187
8211
  }
8188
8212
  });
@@ -8199,13 +8223,12 @@ class Translator extends EventEmitter {
8199
8223
  isValidLookup(res) {
8200
8224
  return res !== void 0 && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === "");
8201
8225
  }
8202
- getResource(code, ns, key) {
8203
- let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
8204
- if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options);
8226
+ getResource(code, ns, key, options = {}) {
8227
+ var _a;
8228
+ if ((_a = this.i18nFormat) == null ? void 0 : _a.getResource) return this.i18nFormat.getResource(code, ns, key, options);
8205
8229
  return this.resourceStore.getResource(code, ns, key, options);
8206
8230
  }
8207
- getUsedParamsDetails() {
8208
- let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
8231
+ getUsedParamsDetails(options = {}) {
8209
8232
  const optionsKeys = ["defaultValue", "ordinal", "context", "replace", "lng", "lngs", "fallbackLng", "ns", "keySeparator", "nsSeparator", "returnObjects", "returnDetails", "joinArrays", "postProcess", "interpolation"];
8210
8233
  const useOptionsReplaceForData = options.replace && !isString(options.replace);
8211
8234
  let data = useOptionsReplaceForData ? options.replace : options;
@@ -8238,7 +8261,6 @@ class Translator extends EventEmitter {
8238
8261
  return false;
8239
8262
  }
8240
8263
  }
8241
- const capitalize = (string) => string.charAt(0).toUpperCase() + string.slice(1);
8242
8264
  class LanguageUtil {
8243
8265
  constructor(options) {
8244
8266
  this.options = options;
@@ -8262,32 +8284,19 @@ class LanguageUtil {
8262
8284
  }
8263
8285
  formatLanguageCode(code) {
8264
8286
  if (isString(code) && code.indexOf("-") > -1) {
8265
- if (typeof Intl !== "undefined" && typeof Intl.getCanonicalLocales !== "undefined") {
8266
- try {
8267
- let formattedCode = Intl.getCanonicalLocales(code)[0];
8268
- if (formattedCode && this.options.lowerCaseLng) {
8269
- formattedCode = formattedCode.toLowerCase();
8270
- }
8271
- if (formattedCode) return formattedCode;
8272
- } catch (e) {
8273
- }
8287
+ let formattedCode;
8288
+ try {
8289
+ formattedCode = Intl.getCanonicalLocales(code)[0];
8290
+ } catch (e) {
8274
8291
  }
8275
- const specialCases = ["hans", "hant", "latn", "cyrl", "cans", "mong", "arab"];
8276
- let p = code.split("-");
8292
+ if (formattedCode && this.options.lowerCaseLng) {
8293
+ formattedCode = formattedCode.toLowerCase();
8294
+ }
8295
+ if (formattedCode) return formattedCode;
8277
8296
  if (this.options.lowerCaseLng) {
8278
- p = p.map((part) => part.toLowerCase());
8279
- } else if (p.length === 2) {
8280
- p[0] = p[0].toLowerCase();
8281
- p[1] = p[1].toUpperCase();
8282
- if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
8283
- } else if (p.length === 3) {
8284
- p[0] = p[0].toLowerCase();
8285
- if (p[1].length === 2) p[1] = p[1].toUpperCase();
8286
- if (p[0] !== "sgn" && p[2].length === 2) p[2] = p[2].toUpperCase();
8287
- if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
8288
- if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize(p[2].toLowerCase());
8297
+ return code.toLowerCase();
8289
8298
  }
8290
- return p.join("-");
8299
+ return code;
8291
8300
  }
8292
8301
  return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
8293
8302
  }
@@ -8308,6 +8317,8 @@ class LanguageUtil {
8308
8317
  if (!found && this.options.supportedLngs) {
8309
8318
  codes.forEach((code) => {
8310
8319
  if (found) return;
8320
+ const lngScOnly = this.getScriptPartFromCode(code);
8321
+ if (this.isSupportedCode(lngScOnly)) return found = lngScOnly;
8311
8322
  const lngOnly = this.getLanguagePartFromCode(code);
8312
8323
  if (this.isSupportedCode(lngOnly)) return found = lngOnly;
8313
8324
  found = this.options.supportedLngs.find((supportedLng) => {
@@ -8335,7 +8346,7 @@ class LanguageUtil {
8335
8346
  return found || [];
8336
8347
  }
8337
8348
  toResolveHierarchy(code, fallbackCode) {
8338
- const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
8349
+ const fallbackCodes = this.getFallbackCodes((fallbackCode === false ? [] : fallbackCode) || this.options.fallbackLng || [], code);
8339
8350
  const codes = [];
8340
8351
  const addCode = (c) => {
8341
8352
  if (!c) return;
@@ -8358,125 +8369,6 @@ class LanguageUtil {
8358
8369
  return codes;
8359
8370
  }
8360
8371
  }
8361
- let sets = [{
8362
- lngs: ["ach", "ak", "am", "arn", "br", "fil", "gun", "ln", "mfe", "mg", "mi", "oc", "pt", "pt-BR", "tg", "tl", "ti", "tr", "uz", "wa"],
8363
- nr: [1, 2],
8364
- fc: 1
8365
- }, {
8366
- lngs: ["af", "an", "ast", "az", "bg", "bn", "ca", "da", "de", "dev", "el", "en", "eo", "es", "et", "eu", "fi", "fo", "fur", "fy", "gl", "gu", "ha", "hi", "hu", "hy", "ia", "it", "kk", "kn", "ku", "lb", "mai", "ml", "mn", "mr", "nah", "nap", "nb", "ne", "nl", "nn", "no", "nso", "pa", "pap", "pms", "ps", "pt-PT", "rm", "sco", "se", "si", "so", "son", "sq", "sv", "sw", "ta", "te", "tk", "ur", "yo"],
8367
- nr: [1, 2],
8368
- fc: 2
8369
- }, {
8370
- lngs: ["ay", "bo", "cgg", "fa", "ht", "id", "ja", "jbo", "ka", "km", "ko", "ky", "lo", "ms", "sah", "su", "th", "tt", "ug", "vi", "wo", "zh"],
8371
- nr: [1],
8372
- fc: 3
8373
- }, {
8374
- lngs: ["be", "bs", "cnr", "dz", "hr", "ru", "sr", "uk"],
8375
- nr: [1, 2, 5],
8376
- fc: 4
8377
- }, {
8378
- lngs: ["ar"],
8379
- nr: [0, 1, 2, 3, 11, 100],
8380
- fc: 5
8381
- }, {
8382
- lngs: ["cs", "sk"],
8383
- nr: [1, 2, 5],
8384
- fc: 6
8385
- }, {
8386
- lngs: ["csb", "pl"],
8387
- nr: [1, 2, 5],
8388
- fc: 7
8389
- }, {
8390
- lngs: ["cy"],
8391
- nr: [1, 2, 3, 8],
8392
- fc: 8
8393
- }, {
8394
- lngs: ["fr"],
8395
- nr: [1, 2],
8396
- fc: 9
8397
- }, {
8398
- lngs: ["ga"],
8399
- nr: [1, 2, 3, 7, 11],
8400
- fc: 10
8401
- }, {
8402
- lngs: ["gd"],
8403
- nr: [1, 2, 3, 20],
8404
- fc: 11
8405
- }, {
8406
- lngs: ["is"],
8407
- nr: [1, 2],
8408
- fc: 12
8409
- }, {
8410
- lngs: ["jv"],
8411
- nr: [0, 1],
8412
- fc: 13
8413
- }, {
8414
- lngs: ["kw"],
8415
- nr: [1, 2, 3, 4],
8416
- fc: 14
8417
- }, {
8418
- lngs: ["lt"],
8419
- nr: [1, 2, 10],
8420
- fc: 15
8421
- }, {
8422
- lngs: ["lv"],
8423
- nr: [1, 2, 0],
8424
- fc: 16
8425
- }, {
8426
- lngs: ["mk"],
8427
- nr: [1, 2],
8428
- fc: 17
8429
- }, {
8430
- lngs: ["mnk"],
8431
- nr: [0, 1, 2],
8432
- fc: 18
8433
- }, {
8434
- lngs: ["mt"],
8435
- nr: [1, 2, 11, 20],
8436
- fc: 19
8437
- }, {
8438
- lngs: ["or"],
8439
- nr: [2, 1],
8440
- fc: 2
8441
- }, {
8442
- lngs: ["ro"],
8443
- nr: [1, 2, 20],
8444
- fc: 20
8445
- }, {
8446
- lngs: ["sl"],
8447
- nr: [5, 1, 2, 3],
8448
- fc: 21
8449
- }, {
8450
- lngs: ["he", "iw"],
8451
- nr: [1, 2, 20, 21],
8452
- fc: 22
8453
- }];
8454
- let _rulesPluralsTypes = {
8455
- 1: (n) => Number(n > 1),
8456
- 2: (n) => Number(n != 1),
8457
- 3: (n) => 0,
8458
- 4: (n) => Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2),
8459
- 5: (n) => Number(n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5),
8460
- 6: (n) => Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2),
8461
- 7: (n) => Number(n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2),
8462
- 8: (n) => Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3),
8463
- 9: (n) => Number(n >= 2),
8464
- 10: (n) => Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4),
8465
- 11: (n) => Number(n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3),
8466
- 12: (n) => Number(n % 10 != 1 || n % 100 == 11),
8467
- 13: (n) => Number(n !== 0),
8468
- 14: (n) => Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3),
8469
- 15: (n) => Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2),
8470
- 16: (n) => Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2),
8471
- 17: (n) => Number(n == 1 || n % 10 == 1 && n % 100 != 11 ? 0 : 1),
8472
- 18: (n) => Number(n == 0 ? 0 : n == 1 ? 1 : 2),
8473
- 19: (n) => Number(n == 1 ? 0 : n == 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3),
8474
- 20: (n) => Number(n == 1 ? 0 : n == 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2),
8475
- 21: (n) => Number(n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0),
8476
- 22: (n) => Number(n == 1 ? 0 : n == 2 ? 1 : (n < 0 || n > 10) && n % 10 == 0 ? 2 : 3)
8477
- };
8478
- const nonIntlVersions = ["v1", "v2", "v3"];
8479
- const intlVersions = ["v4"];
8480
8372
  const suffixesOrder = {
8481
8373
  zero: 0,
8482
8374
  one: 1,
@@ -8485,29 +8377,17 @@ const suffixesOrder = {
8485
8377
  many: 4,
8486
8378
  other: 5
8487
8379
  };
8488
- const createRules = () => {
8489
- const rules = {};
8490
- sets.forEach((set) => {
8491
- set.lngs.forEach((l) => {
8492
- rules[l] = {
8493
- numbers: set.nr,
8494
- plurals: _rulesPluralsTypes[set.fc]
8495
- };
8496
- });
8497
- });
8498
- return rules;
8380
+ const dummyRule = {
8381
+ select: (count) => count === 1 ? "one" : "other",
8382
+ resolvedOptions: () => ({
8383
+ pluralCategories: ["one", "other"]
8384
+ })
8499
8385
  };
8500
8386
  class PluralResolver {
8501
- constructor(languageUtils) {
8502
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
8387
+ constructor(languageUtils, options = {}) {
8503
8388
  this.languageUtils = languageUtils;
8504
8389
  this.options = options;
8505
8390
  this.logger = baseLogger.create("pluralResolver");
8506
- if ((!this.options.compatibilityJSON || intlVersions.includes(this.options.compatibilityJSON)) && (typeof Intl === "undefined" || !Intl.PluralRules)) {
8507
- this.options.compatibilityJSON = "v3";
8508
- this.logger.error("Your environment seems not to be Intl API compatible, use an Intl.PluralRules polyfill. Will fallback to the compatibilityJSON v3 format handling.");
8509
- }
8510
- this.rules = createRules();
8511
8391
  this.pluralRulesCache = {};
8512
8392
  }
8513
8393
  addRule(lng, obj) {
@@ -8516,97 +8396,57 @@ class PluralResolver {
8516
8396
  clearCache() {
8517
8397
  this.pluralRulesCache = {};
8518
8398
  }
8519
- getRule(code) {
8520
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
8521
- if (this.shouldUseIntlApi()) {
8522
- const cleanedCode = getCleanedCode(code === "dev" ? "en" : code);
8523
- const type = options.ordinal ? "ordinal" : "cardinal";
8524
- const cacheKey = JSON.stringify({
8525
- cleanedCode,
8399
+ getRule(code, options = {}) {
8400
+ const cleanedCode = getCleanedCode(code === "dev" ? "en" : code);
8401
+ const type = options.ordinal ? "ordinal" : "cardinal";
8402
+ const cacheKey = JSON.stringify({
8403
+ cleanedCode,
8404
+ type
8405
+ });
8406
+ if (cacheKey in this.pluralRulesCache) {
8407
+ return this.pluralRulesCache[cacheKey];
8408
+ }
8409
+ let rule;
8410
+ try {
8411
+ rule = new Intl.PluralRules(cleanedCode, {
8526
8412
  type
8527
8413
  });
8528
- if (cacheKey in this.pluralRulesCache) {
8529
- return this.pluralRulesCache[cacheKey];
8414
+ } catch (err) {
8415
+ if (!Intl) {
8416
+ this.logger.error("No Intl support, please use an Intl polyfill!");
8417
+ return dummyRule;
8530
8418
  }
8531
- let rule;
8532
- try {
8533
- rule = new Intl.PluralRules(cleanedCode, {
8534
- type
8535
- });
8536
- } catch (err) {
8537
- if (!code.match(/-|_/)) return;
8538
- const lngPart = this.languageUtils.getLanguagePartFromCode(code);
8539
- rule = this.getRule(lngPart, options);
8540
- }
8541
- this.pluralRulesCache[cacheKey] = rule;
8542
- return rule;
8419
+ if (!code.match(/-|_/)) return dummyRule;
8420
+ const lngPart = this.languageUtils.getLanguagePartFromCode(code);
8421
+ rule = this.getRule(lngPart, options);
8543
8422
  }
8544
- return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
8423
+ this.pluralRulesCache[cacheKey] = rule;
8424
+ return rule;
8545
8425
  }
8546
- needsPlural(code) {
8547
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
8548
- const rule = this.getRule(code, options);
8549
- if (this.shouldUseIntlApi()) {
8550
- return rule && rule.resolvedOptions().pluralCategories.length > 1;
8551
- }
8552
- return rule && rule.numbers.length > 1;
8426
+ needsPlural(code, options = {}) {
8427
+ let rule = this.getRule(code, options);
8428
+ if (!rule) rule = this.getRule("dev", options);
8429
+ return (rule == null ? void 0 : rule.resolvedOptions().pluralCategories.length) > 1;
8553
8430
  }
8554
- getPluralFormsOfKey(code, key) {
8555
- let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
8431
+ getPluralFormsOfKey(code, key, options = {}) {
8556
8432
  return this.getSuffixes(code, options).map((suffix) => `${key}${suffix}`);
8557
8433
  }
8558
- getSuffixes(code) {
8559
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
8560
- const rule = this.getRule(code, options);
8561
- if (!rule) {
8562
- return [];
8563
- }
8564
- if (this.shouldUseIntlApi()) {
8565
- return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map((pluralCategory) => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${pluralCategory}`);
8566
- }
8567
- return rule.numbers.map((number) => this.getSuffix(code, number, options));
8434
+ getSuffixes(code, options = {}) {
8435
+ let rule = this.getRule(code, options);
8436
+ if (!rule) rule = this.getRule("dev", options);
8437
+ if (!rule) return [];
8438
+ return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map((pluralCategory) => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${pluralCategory}`);
8568
8439
  }
8569
- getSuffix(code, count) {
8570
- let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
8440
+ getSuffix(code, count, options = {}) {
8571
8441
  const rule = this.getRule(code, options);
8572
8442
  if (rule) {
8573
- if (this.shouldUseIntlApi()) {
8574
- return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${rule.select(count)}`;
8575
- }
8576
- return this.getSuffixRetroCompatible(rule, count);
8443
+ return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${rule.select(count)}`;
8577
8444
  }
8578
8445
  this.logger.warn(`no plural rule found for: ${code}`);
8579
- return "";
8580
- }
8581
- getSuffixRetroCompatible(rule, count) {
8582
- const idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
8583
- let suffix = rule.numbers[idx];
8584
- if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
8585
- if (suffix === 2) {
8586
- suffix = "plural";
8587
- } else if (suffix === 1) {
8588
- suffix = "";
8589
- }
8590
- }
8591
- const returnSuffix = () => this.options.prepend && suffix.toString() ? this.options.prepend + suffix.toString() : suffix.toString();
8592
- if (this.options.compatibilityJSON === "v1") {
8593
- if (suffix === 1) return "";
8594
- if (typeof suffix === "number") return `_plural_${suffix.toString()}`;
8595
- return returnSuffix();
8596
- } else if (this.options.compatibilityJSON === "v2") {
8597
- return returnSuffix();
8598
- } else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
8599
- return returnSuffix();
8600
- }
8601
- return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
8602
- }
8603
- shouldUseIntlApi() {
8604
- return !nonIntlVersions.includes(this.options.compatibilityJSON);
8446
+ return this.getSuffix("dev", count, options);
8605
8447
  }
8606
8448
  }
8607
- const deepFindWithDefaults = function(data, defaultData, key) {
8608
- let keySeparator = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : ".";
8609
- let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : true;
8449
+ const deepFindWithDefaults = (data, defaultData, key, keySeparator = ".", ignoreJSONStructure = true) => {
8610
8450
  let path = getPathWithDefaults(data, defaultData, key);
8611
8451
  if (!path && ignoreJSONStructure && isString(key)) {
8612
8452
  path = deepFind(data, key, keySeparator);
@@ -8616,15 +8456,14 @@ const deepFindWithDefaults = function(data, defaultData, key) {
8616
8456
  };
8617
8457
  const regexSafe = (val) => val.replace(/\$/g, "$$$$");
8618
8458
  class Interpolator {
8619
- constructor() {
8620
- let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
8459
+ constructor(options = {}) {
8460
+ var _a;
8621
8461
  this.logger = baseLogger.create("interpolator");
8622
8462
  this.options = options;
8623
- this.format = options.interpolation && options.interpolation.format || ((value) => value);
8463
+ this.format = ((_a = options == null ? void 0 : options.interpolation) == null ? void 0 : _a.format) || ((value) => value);
8624
8464
  this.init(options);
8625
8465
  }
8626
- init() {
8627
- let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
8466
+ init(options = {}) {
8628
8467
  if (!options.interpolation) options.interpolation = {
8629
8468
  escapeValue: true
8630
8469
  };
@@ -8667,7 +8506,7 @@ class Interpolator {
8667
8506
  }
8668
8507
  resetRegExp() {
8669
8508
  const getOrResetRegExp = (existingRegExp, pattern) => {
8670
- if (existingRegExp && existingRegExp.source === pattern) {
8509
+ if ((existingRegExp == null ? void 0 : existingRegExp.source) === pattern) {
8671
8510
  existingRegExp.lastIndex = 0;
8672
8511
  return existingRegExp;
8673
8512
  }
@@ -8675,9 +8514,10 @@ class Interpolator {
8675
8514
  };
8676
8515
  this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
8677
8516
  this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
8678
- this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}(.+?)${this.nestingSuffix}`);
8517
+ this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}((?:[^()"']+|"[^"]*"|'[^']*'|\\((?:[^()]|"[^"]*"|'[^']*')*\\))*?)${this.nestingSuffix}`);
8679
8518
  }
8680
8519
  interpolate(str, data, lng, options) {
8520
+ var _a;
8681
8521
  let match2;
8682
8522
  let value;
8683
8523
  let replaces;
@@ -8701,8 +8541,8 @@ class Interpolator {
8701
8541
  });
8702
8542
  };
8703
8543
  this.resetRegExp();
8704
- const missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler;
8705
- const skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
8544
+ const missingInterpolationHandler = (options == null ? void 0 : options.missingInterpolationHandler) || this.options.missingInterpolationHandler;
8545
+ const skipOnVariables = ((_a = options == null ? void 0 : options.interpolation) == null ? void 0 : _a.skipOnVariables) !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
8706
8546
  const todos = [{
8707
8547
  regex: this.regexpUnescape,
8708
8548
  safeValue: (val) => regexSafe(val)
@@ -8747,8 +8587,7 @@ class Interpolator {
8747
8587
  });
8748
8588
  return str;
8749
8589
  }
8750
- nest(str, fc) {
8751
- let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
8590
+ nest(str, fc, options = {}) {
8752
8591
  let match2;
8753
8592
  let value;
8754
8593
  let clonedOptions;
@@ -8761,7 +8600,7 @@ class Interpolator {
8761
8600
  optionsString = this.interpolate(optionsString, clonedOptions);
8762
8601
  const matchedSingleQuotes = optionsString.match(/'/g);
8763
8602
  const matchedDoubleQuotes = optionsString.match(/"/g);
8764
- if (matchedSingleQuotes && matchedSingleQuotes.length % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
8603
+ if (((matchedSingleQuotes == null ? void 0 : matchedSingleQuotes.length) ?? 0) % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
8765
8604
  optionsString = optionsString.replace(/'/g, '"');
8766
8605
  }
8767
8606
  try {
@@ -8785,12 +8624,10 @@ class Interpolator {
8785
8624
  clonedOptions = clonedOptions.replace && !isString(clonedOptions.replace) ? clonedOptions.replace : clonedOptions;
8786
8625
  clonedOptions.applyPostProcessor = false;
8787
8626
  delete clonedOptions.defaultValue;
8788
- let doReduce = false;
8789
- if (match2[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match2[1])) {
8790
- const r = match2[1].split(this.formatSeparator).map((elem) => elem.trim());
8791
- match2[1] = r.shift();
8792
- formatters2 = r;
8793
- doReduce = true;
8627
+ const keyEndIndex = /{.*}/.test(match2[1]) ? match2[1].lastIndexOf("}") + 1 : match2[1].indexOf(this.formatSeparator);
8628
+ if (keyEndIndex !== -1) {
8629
+ formatters2 = match2[1].slice(keyEndIndex).split(this.formatSeparator).map((elem) => elem.trim()).filter(Boolean);
8630
+ match2[1] = match2[1].slice(0, keyEndIndex);
8794
8631
  }
8795
8632
  value = fc(handleHasOptions.call(this, match2[1].trim(), clonedOptions), clonedOptions);
8796
8633
  if (value && match2[0] === str && !isString(value)) return value;
@@ -8799,7 +8636,7 @@ class Interpolator {
8799
8636
  this.logger.warn(`missed to resolve ${match2[1]} for nesting ${str}`);
8800
8637
  value = "";
8801
8638
  }
8802
- if (doReduce) {
8639
+ if (formatters2.length) {
8803
8640
  value = formatters2.reduce((v, f) => this.format(v, f, options.lng, {
8804
8641
  ...options,
8805
8642
  interpolationkey: match2[1].trim()
@@ -8844,68 +8681,68 @@ const parseFormatStr = (formatStr) => {
8844
8681
  };
8845
8682
  const createCachedFormatter = (fn) => {
8846
8683
  const cache = {};
8847
- return (val, lng, options) => {
8848
- let optForCache = options;
8849
- if (options && options.interpolationkey && options.formatParams && options.formatParams[options.interpolationkey] && options[options.interpolationkey]) {
8684
+ return (v, l, o) => {
8685
+ let optForCache = o;
8686
+ if (o && o.interpolationkey && o.formatParams && o.formatParams[o.interpolationkey] && o[o.interpolationkey]) {
8850
8687
  optForCache = {
8851
8688
  ...optForCache,
8852
- [options.interpolationkey]: void 0
8689
+ [o.interpolationkey]: void 0
8853
8690
  };
8854
8691
  }
8855
- const key = lng + JSON.stringify(optForCache);
8856
- let formatter = cache[key];
8857
- if (!formatter) {
8858
- formatter = fn(getCleanedCode(lng), options);
8859
- cache[key] = formatter;
8692
+ const key = l + JSON.stringify(optForCache);
8693
+ let frm = cache[key];
8694
+ if (!frm) {
8695
+ frm = fn(getCleanedCode(l), o);
8696
+ cache[key] = frm;
8860
8697
  }
8861
- return formatter(val);
8698
+ return frm(v);
8862
8699
  };
8863
8700
  };
8701
+ const createNonCachedFormatter = (fn) => (v, l, o) => fn(getCleanedCode(l), o)(v);
8864
8702
  class Formatter {
8865
- constructor() {
8866
- let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
8703
+ constructor(options = {}) {
8867
8704
  this.logger = baseLogger.create("formatter");
8868
8705
  this.options = options;
8706
+ this.init(options);
8707
+ }
8708
+ init(services, options = {
8709
+ interpolation: {}
8710
+ }) {
8711
+ this.formatSeparator = options.interpolation.formatSeparator || ",";
8712
+ const cf = options.cacheInBuiltFormats ? createCachedFormatter : createNonCachedFormatter;
8869
8713
  this.formats = {
8870
- number: createCachedFormatter((lng, opt) => {
8714
+ number: cf((lng, opt) => {
8871
8715
  const formatter = new Intl.NumberFormat(lng, {
8872
8716
  ...opt
8873
8717
  });
8874
8718
  return (val) => formatter.format(val);
8875
8719
  }),
8876
- currency: createCachedFormatter((lng, opt) => {
8720
+ currency: cf((lng, opt) => {
8877
8721
  const formatter = new Intl.NumberFormat(lng, {
8878
8722
  ...opt,
8879
8723
  style: "currency"
8880
8724
  });
8881
8725
  return (val) => formatter.format(val);
8882
8726
  }),
8883
- datetime: createCachedFormatter((lng, opt) => {
8727
+ datetime: cf((lng, opt) => {
8884
8728
  const formatter = new Intl.DateTimeFormat(lng, {
8885
8729
  ...opt
8886
8730
  });
8887
8731
  return (val) => formatter.format(val);
8888
8732
  }),
8889
- relativetime: createCachedFormatter((lng, opt) => {
8733
+ relativetime: cf((lng, opt) => {
8890
8734
  const formatter = new Intl.RelativeTimeFormat(lng, {
8891
8735
  ...opt
8892
8736
  });
8893
8737
  return (val) => formatter.format(val, opt.range || "day");
8894
8738
  }),
8895
- list: createCachedFormatter((lng, opt) => {
8739
+ list: cf((lng, opt) => {
8896
8740
  const formatter = new Intl.ListFormat(lng, {
8897
8741
  ...opt
8898
8742
  });
8899
8743
  return (val) => formatter.format(val);
8900
8744
  })
8901
8745
  };
8902
- this.init(options);
8903
- }
8904
- init(services) {
8905
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
8906
- interpolation: {}
8907
- };
8908
- this.formatSeparator = options.interpolation.formatSeparator || ",";
8909
8746
  }
8910
8747
  add(name, fc) {
8911
8748
  this.formats[name.toLowerCase().trim()] = fc;
@@ -8913,14 +8750,14 @@ class Formatter {
8913
8750
  addCached(name, fc) {
8914
8751
  this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
8915
8752
  }
8916
- format(value, format2, lng) {
8917
- let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
8753
+ format(value, format2, lng, options = {}) {
8918
8754
  const formats = format2.split(this.formatSeparator);
8919
8755
  if (formats.length > 1 && formats[0].indexOf("(") > 1 && formats[0].indexOf(")") < 0 && formats.find((f) => f.indexOf(")") > -1)) {
8920
8756
  const lastIndex = formats.findIndex((f) => f.indexOf(")") > -1);
8921
8757
  formats[0] = [formats[0], ...formats.splice(1, lastIndex)].join(this.formatSeparator);
8922
8758
  }
8923
8759
  const result = formats.reduce((mem, f) => {
8760
+ var _a;
8924
8761
  const {
8925
8762
  formatName,
8926
8763
  formatOptions
@@ -8928,7 +8765,7 @@ class Formatter {
8928
8765
  if (this.formats[formatName]) {
8929
8766
  let formatted = mem;
8930
8767
  try {
8931
- const valOptions = options && options.formatParams && options.formatParams[options.interpolationkey] || {};
8768
+ const valOptions = ((_a = options == null ? void 0 : options.formatParams) == null ? void 0 : _a[options.interpolationkey]) || {};
8932
8769
  const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
8933
8770
  formatted = this.formats[formatName](mem, l, {
8934
8771
  ...formatOptions,
@@ -8954,8 +8791,8 @@ const removePending = (q, name) => {
8954
8791
  }
8955
8792
  };
8956
8793
  class Connector extends EventEmitter {
8957
- constructor(backend, store, services) {
8958
- let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
8794
+ constructor(backend, store, services, options = {}) {
8795
+ var _a, _b;
8959
8796
  super();
8960
8797
  this.backend = backend;
8961
8798
  this.store = store;
@@ -8970,9 +8807,7 @@ class Connector extends EventEmitter {
8970
8807
  this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
8971
8808
  this.state = {};
8972
8809
  this.queue = [];
8973
- if (this.backend && this.backend.init) {
8974
- this.backend.init(services, options.backend, options);
8975
- }
8810
+ (_b = (_a = this.backend) == null ? void 0 : _a.init) == null ? void 0 : _b.call(_a, services, options.backend, options);
8976
8811
  }
8977
8812
  queueLoad(languages, namespaces, options, callback) {
8978
8813
  const toLoad = {};
@@ -9052,10 +8887,7 @@ class Connector extends EventEmitter {
9052
8887
  this.emit("loaded", loaded);
9053
8888
  this.queue = this.queue.filter((q) => !q.done);
9054
8889
  }
9055
- read(lng, ns, fcName) {
9056
- let tried = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0;
9057
- let wait = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : this.retryTimeout;
9058
- let callback = arguments.length > 5 ? arguments[5] : void 0;
8890
+ read(lng, ns, fcName, tried = 0, wait = this.retryTimeout, callback) {
9059
8891
  if (!lng.length) return callback(null, {});
9060
8892
  if (this.readingCalls >= this.maxParallelReads) {
9061
8893
  this.waitingReads.push({
@@ -9099,9 +8931,7 @@ class Connector extends EventEmitter {
9099
8931
  }
9100
8932
  return fc(lng, ns, resolver);
9101
8933
  }
9102
- prepareLoading(languages, namespaces) {
9103
- let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
9104
- let callback = arguments.length > 3 ? arguments[3] : void 0;
8934
+ prepareLoading(languages, namespaces, options = {}, callback) {
9105
8935
  if (!this.backend) {
9106
8936
  this.logger.warn("No backend was added via i18next.use. Will not load resources.");
9107
8937
  return callback && callback();
@@ -9125,8 +8955,7 @@ class Connector extends EventEmitter {
9125
8955
  reload: true
9126
8956
  }, callback);
9127
8957
  }
9128
- loadOne(name) {
9129
- let prefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
8958
+ loadOne(name, prefix = "") {
9130
8959
  const s = name.split("|");
9131
8960
  const lng = s[0];
9132
8961
  const ns = s[1];
@@ -9136,16 +8965,15 @@ class Connector extends EventEmitter {
9136
8965
  this.loaded(name, err, data);
9137
8966
  });
9138
8967
  }
9139
- saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
9140
- let options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {};
9141
- let clb = arguments.length > 6 && arguments[6] !== void 0 ? arguments[6] : () => {
9142
- };
9143
- if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
8968
+ saveMissing(languages, namespace, key, fallbackValue, isUpdate, options = {}, clb = () => {
8969
+ }) {
8970
+ var _a, _b, _c, _d, _e;
8971
+ if (((_b = (_a = this.services) == null ? void 0 : _a.utils) == null ? void 0 : _b.hasLoadedNamespace) && !((_d = (_c = this.services) == null ? void 0 : _c.utils) == null ? void 0 : _d.hasLoadedNamespace(namespace))) {
9144
8972
  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!!!");
9145
8973
  return;
9146
8974
  }
9147
8975
  if (key === void 0 || key === null || key === "") return;
9148
- if (this.backend && this.backend.create) {
8976
+ if ((_e = this.backend) == null ? void 0 : _e.create) {
9149
8977
  const opts = {
9150
8978
  ...options,
9151
8979
  isUpdate
@@ -9177,7 +9005,7 @@ class Connector extends EventEmitter {
9177
9005
  }
9178
9006
  const get = () => ({
9179
9007
  debug: false,
9180
- initImmediate: true,
9008
+ initAsync: true,
9181
9009
  ns: ["translation"],
9182
9010
  defaultNS: ["translation"],
9183
9011
  fallbackLng: ["dev"],
@@ -9233,15 +9061,18 @@ const get = () => ({
9233
9061
  nestingOptionsSeparator: ",",
9234
9062
  maxReplaces: 1e3,
9235
9063
  skipOnVariables: true
9236
- }
9064
+ },
9065
+ cacheInBuiltFormats: true
9237
9066
  });
9238
9067
  const transformOptions = (options) => {
9068
+ var _a, _b;
9239
9069
  if (isString(options.ns)) options.ns = [options.ns];
9240
9070
  if (isString(options.fallbackLng)) options.fallbackLng = [options.fallbackLng];
9241
9071
  if (isString(options.fallbackNS)) options.fallbackNS = [options.fallbackNS];
9242
- if (options.supportedLngs && options.supportedLngs.indexOf("cimode") < 0) {
9072
+ if (((_b = (_a = options.supportedLngs) == null ? void 0 : _a.indexOf) == null ? void 0 : _b.call(_a, "cimode")) < 0) {
9243
9073
  options.supportedLngs = options.supportedLngs.concat(["cimode"]);
9244
9074
  }
9075
+ if (typeof options.initImmediate === "boolean") options.initAsync = options.initImmediate;
9245
9076
  return options;
9246
9077
  };
9247
9078
  const noop = () => {
@@ -9255,9 +9086,7 @@ const bindMemberFunctions = (inst) => {
9255
9086
  });
9256
9087
  };
9257
9088
  class I18n extends EventEmitter {
9258
- constructor() {
9259
- let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
9260
- let callback = arguments.length > 1 ? arguments[1] : void 0;
9089
+ constructor(options = {}, callback) {
9261
9090
  super();
9262
9091
  this.options = transformOptions(options);
9263
9092
  this.services = {};
@@ -9267,7 +9096,7 @@ class I18n extends EventEmitter {
9267
9096
  };
9268
9097
  bindMemberFunctions(this);
9269
9098
  if (callback && !this.isInitialized && !options.isClone) {
9270
- if (!this.options.initImmediate) {
9099
+ if (!this.options.initAsync) {
9271
9100
  this.init(options, callback);
9272
9101
  return this;
9273
9102
  }
@@ -9276,16 +9105,13 @@ class I18n extends EventEmitter {
9276
9105
  }, 0);
9277
9106
  }
9278
9107
  }
9279
- init() {
9280
- var _this = this;
9281
- let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
9282
- let callback = arguments.length > 1 ? arguments[1] : void 0;
9108
+ init(options = {}, callback) {
9283
9109
  this.isInitializing = true;
9284
9110
  if (typeof options === "function") {
9285
9111
  callback = options;
9286
9112
  options = {};
9287
9113
  }
9288
- if (!options.defaultNS && options.defaultNS !== false && options.ns) {
9114
+ if (options.defaultNS == null && options.ns) {
9289
9115
  if (isString(options.ns)) {
9290
9116
  options.defaultNS = options.ns;
9291
9117
  } else if (options.ns.indexOf("translation") < 0) {
@@ -9298,12 +9124,10 @@ class I18n extends EventEmitter {
9298
9124
  ...this.options,
9299
9125
  ...transformOptions(options)
9300
9126
  };
9301
- if (this.options.compatibilityAPI !== "v1") {
9302
- this.options.interpolation = {
9303
- ...defOpts.interpolation,
9304
- ...this.options.interpolation
9305
- };
9306
- }
9127
+ this.options.interpolation = {
9128
+ ...defOpts.interpolation,
9129
+ ...this.options.interpolation
9130
+ };
9307
9131
  if (options.keySeparator !== void 0) {
9308
9132
  this.options.userDefinedKeySeparator = options.keySeparator;
9309
9133
  }
@@ -9324,7 +9148,7 @@ class I18n extends EventEmitter {
9324
9148
  let formatter;
9325
9149
  if (this.modules.formatter) {
9326
9150
  formatter = this.modules.formatter;
9327
- } else if (typeof Intl !== "undefined") {
9151
+ } else {
9328
9152
  formatter = Formatter;
9329
9153
  }
9330
9154
  const lu = new LanguageUtil(this.options);
@@ -9335,12 +9159,15 @@ class I18n extends EventEmitter {
9335
9159
  s.languageUtils = lu;
9336
9160
  s.pluralResolver = new PluralResolver(lu, {
9337
9161
  prepend: this.options.pluralSeparator,
9338
- compatibilityJSON: this.options.compatibilityJSON,
9339
9162
  simplifyPluralSuffix: this.options.simplifyPluralSuffix
9340
9163
  });
9164
+ const usingLegacyFormatFunction = this.options.interpolation.format && this.options.interpolation.format !== defOpts.interpolation.format;
9165
+ if (usingLegacyFormatFunction) {
9166
+ this.logger.deprecate(`init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting`);
9167
+ }
9341
9168
  if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
9342
9169
  s.formatter = createClassOnDemand(formatter);
9343
- s.formatter.init(s, this.options);
9170
+ if (s.formatter.init) s.formatter.init(s, this.options);
9344
9171
  this.options.interpolation.format = s.formatter.format.bind(s.formatter);
9345
9172
  }
9346
9173
  s.interpolator = new Interpolator(this.options);
@@ -9348,11 +9175,8 @@ class I18n extends EventEmitter {
9348
9175
  hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
9349
9176
  };
9350
9177
  s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
9351
- s.backendConnector.on("*", function(event) {
9352
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
9353
- args[_key - 1] = arguments[_key];
9354
- }
9355
- _this.emit(event, ...args);
9178
+ s.backendConnector.on("*", (event, ...args) => {
9179
+ this.emit(event, ...args);
9356
9180
  });
9357
9181
  if (this.modules.languageDetector) {
9358
9182
  s.languageDetector = createClassOnDemand(this.modules.languageDetector);
@@ -9363,11 +9187,8 @@ class I18n extends EventEmitter {
9363
9187
  if (s.i18nFormat.init) s.i18nFormat.init(this);
9364
9188
  }
9365
9189
  this.translator = new Translator(this.services, this.options);
9366
- this.translator.on("*", function(event) {
9367
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
9368
- args[_key2 - 1] = arguments[_key2];
9369
- }
9370
- _this.emit(event, ...args);
9190
+ this.translator.on("*", (event, ...args) => {
9191
+ this.emit(event, ...args);
9371
9192
  });
9372
9193
  this.modules.external.forEach((m) => {
9373
9194
  if (m.init) m.init(this);
@@ -9384,15 +9205,13 @@ class I18n extends EventEmitter {
9384
9205
  }
9385
9206
  const storeApi = ["getResource", "hasResourceBundle", "getResourceBundle", "getDataByLanguage"];
9386
9207
  storeApi.forEach((fcName) => {
9387
- this[fcName] = function() {
9388
- return _this.store[fcName](...arguments);
9389
- };
9208
+ this[fcName] = (...args) => this.store[fcName](...args);
9390
9209
  });
9391
9210
  const storeApiChained = ["addResource", "addResources", "addResourceBundle", "removeResourceBundle"];
9392
9211
  storeApiChained.forEach((fcName) => {
9393
- this[fcName] = function() {
9394
- _this.store[fcName](...arguments);
9395
- return _this;
9212
+ this[fcName] = (...args) => {
9213
+ this.store[fcName](...args);
9214
+ return this;
9396
9215
  };
9397
9216
  });
9398
9217
  const deferred = defer();
@@ -9406,23 +9225,23 @@ class I18n extends EventEmitter {
9406
9225
  deferred.resolve(t);
9407
9226
  callback(err, t);
9408
9227
  };
9409
- if (this.languages && this.options.compatibilityAPI !== "v1" && !this.isInitialized) return finish(null, this.t.bind(this));
9228
+ if (this.languages && !this.isInitialized) return finish(null, this.t.bind(this));
9410
9229
  this.changeLanguage(this.options.lng, finish);
9411
9230
  };
9412
- if (this.options.resources || !this.options.initImmediate) {
9231
+ if (this.options.resources || !this.options.initAsync) {
9413
9232
  load();
9414
9233
  } else {
9415
9234
  setTimeout(load, 0);
9416
9235
  }
9417
9236
  return deferred;
9418
9237
  }
9419
- loadResources(language) {
9420
- let callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
9238
+ loadResources(language, callback = noop) {
9239
+ var _a, _b;
9421
9240
  let usedCallback = callback;
9422
9241
  const usedLng = isString(language) ? language : this.language;
9423
9242
  if (typeof language === "function") usedCallback = language;
9424
9243
  if (!this.options.resources || this.options.partialBundledLanguages) {
9425
- if (usedLng && usedLng.toLowerCase() === "cimode" && (!this.options.preload || this.options.preload.length === 0)) return usedCallback();
9244
+ if ((usedLng == null ? void 0 : usedLng.toLowerCase()) === "cimode" && (!this.options.preload || this.options.preload.length === 0)) return usedCallback();
9426
9245
  const toLoad = [];
9427
9246
  const append = (lng) => {
9428
9247
  if (!lng) return;
@@ -9439,9 +9258,7 @@ class I18n extends EventEmitter {
9439
9258
  } else {
9440
9259
  append(usedLng);
9441
9260
  }
9442
- if (this.options.preload) {
9443
- this.options.preload.forEach((l) => append(l));
9444
- }
9261
+ (_b = (_a = this.options.preload) == null ? void 0 : _a.forEach) == null ? void 0 : _b.call(_a, (l) => append(l));
9445
9262
  this.services.backendConnector.load(toLoad, this.options.ns, (e) => {
9446
9263
  if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
9447
9264
  usedCallback(e);
@@ -9506,9 +9323,12 @@ class I18n extends EventEmitter {
9506
9323
  break;
9507
9324
  }
9508
9325
  }
9326
+ if (!this.resolvedLanguage && this.languages.indexOf(l) < 0 && this.store.hasLanguageSomeTranslations(l)) {
9327
+ this.resolvedLanguage = l;
9328
+ this.languages.unshift(l);
9329
+ }
9509
9330
  }
9510
9331
  changeLanguage(lng, callback) {
9511
- var _this2 = this;
9512
9332
  this.isLanguageChangingTo = lng;
9513
9333
  const deferred = defer();
9514
9334
  this.emit("languageChanging", lng);
@@ -9520,30 +9340,30 @@ class I18n extends EventEmitter {
9520
9340
  };
9521
9341
  const done = (err, l) => {
9522
9342
  if (l) {
9523
- setLngProps(l);
9524
- this.translator.changeLanguage(l);
9525
- this.isLanguageChangingTo = void 0;
9526
- this.emit("languageChanged", l);
9527
- this.logger.log("languageChanged", l);
9343
+ if (this.isLanguageChangingTo === lng) {
9344
+ setLngProps(l);
9345
+ this.translator.changeLanguage(l);
9346
+ this.isLanguageChangingTo = void 0;
9347
+ this.emit("languageChanged", l);
9348
+ this.logger.log("languageChanged", l);
9349
+ }
9528
9350
  } else {
9529
9351
  this.isLanguageChangingTo = void 0;
9530
9352
  }
9531
- deferred.resolve(function() {
9532
- return _this2.t(...arguments);
9533
- });
9534
- if (callback) callback(err, function() {
9535
- return _this2.t(...arguments);
9536
- });
9353
+ deferred.resolve((...args) => this.t(...args));
9354
+ if (callback) callback(err, (...args) => this.t(...args));
9537
9355
  };
9538
9356
  const setLng = (lngs) => {
9357
+ var _a, _b;
9539
9358
  if (!lng && !lngs && this.services.languageDetector) lngs = [];
9540
- const l = isString(lngs) ? lngs : this.services.languageUtils.getBestMatchFromCodes(lngs);
9359
+ const fl = isString(lngs) ? lngs : lngs && lngs[0];
9360
+ const l = this.store.hasLanguageSomeTranslations(fl) ? fl : this.services.languageUtils.getBestMatchFromCodes(isString(lngs) ? [lngs] : lngs);
9541
9361
  if (l) {
9542
9362
  if (!this.language) {
9543
9363
  setLngProps(l);
9544
9364
  }
9545
9365
  if (!this.translator.language) this.translator.changeLanguage(l);
9546
- if (this.services.languageDetector && this.services.languageDetector.cacheUserLanguage) this.services.languageDetector.cacheUserLanguage(l);
9366
+ (_b = (_a = this.services.languageDetector) == null ? void 0 : _a.cacheUserLanguage) == null ? void 0 : _b.call(_a, l);
9547
9367
  }
9548
9368
  this.loadResources(l, (err) => {
9549
9369
  done(err, l);
@@ -9563,31 +9383,37 @@ class I18n extends EventEmitter {
9563
9383
  return deferred;
9564
9384
  }
9565
9385
  getFixedT(lng, ns, keyPrefix) {
9566
- var _this3 = this;
9567
- const fixedT = function(key, opts) {
9568
- let options;
9386
+ const fixedT = (key, opts, ...rest) => {
9387
+ let o;
9569
9388
  if (typeof opts !== "object") {
9570
- for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
9571
- rest[_key3 - 2] = arguments[_key3];
9572
- }
9573
- options = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
9389
+ o = this.options.overloadTranslationOptionHandler([key, opts].concat(rest));
9574
9390
  } else {
9575
- options = {
9391
+ o = {
9576
9392
  ...opts
9577
9393
  };
9578
9394
  }
9579
- options.lng = options.lng || fixedT.lng;
9580
- options.lngs = options.lngs || fixedT.lngs;
9581
- options.ns = options.ns || fixedT.ns;
9582
- if (options.keyPrefix !== "") options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
9583
- const keySeparator = _this3.options.keySeparator || ".";
9395
+ o.lng = o.lng || fixedT.lng;
9396
+ o.lngs = o.lngs || fixedT.lngs;
9397
+ o.ns = o.ns || fixedT.ns;
9398
+ if (o.keyPrefix !== "") o.keyPrefix = o.keyPrefix || keyPrefix || fixedT.keyPrefix;
9399
+ const keySeparator = this.options.keySeparator || ".";
9584
9400
  let resultKey;
9585
- if (options.keyPrefix && Array.isArray(key)) {
9586
- resultKey = key.map((k) => `${options.keyPrefix}${keySeparator}${k}`);
9401
+ if (o.keyPrefix && Array.isArray(key)) {
9402
+ resultKey = key.map((k) => {
9403
+ if (typeof k === "function") k = keysFromSelector(k, {
9404
+ ...this.options,
9405
+ ...opts
9406
+ });
9407
+ return `${o.keyPrefix}${keySeparator}${k}`;
9408
+ });
9587
9409
  } else {
9588
- resultKey = options.keyPrefix ? `${options.keyPrefix}${keySeparator}${key}` : key;
9410
+ if (typeof key === "function") key = keysFromSelector(key, {
9411
+ ...this.options,
9412
+ ...opts
9413
+ });
9414
+ resultKey = o.keyPrefix ? `${o.keyPrefix}${keySeparator}${key}` : key;
9589
9415
  }
9590
- return _this3.t(resultKey, options);
9416
+ return this.t(resultKey, o);
9591
9417
  };
9592
9418
  if (isString(lng)) {
9593
9419
  fixedT.lng = lng;
@@ -9598,17 +9424,18 @@ class I18n extends EventEmitter {
9598
9424
  fixedT.keyPrefix = keyPrefix;
9599
9425
  return fixedT;
9600
9426
  }
9601
- t() {
9602
- return this.translator && this.translator.translate(...arguments);
9427
+ t(...args) {
9428
+ var _a;
9429
+ return (_a = this.translator) == null ? void 0 : _a.translate(...args);
9603
9430
  }
9604
- exists() {
9605
- return this.translator && this.translator.exists(...arguments);
9431
+ exists(...args) {
9432
+ var _a;
9433
+ return (_a = this.translator) == null ? void 0 : _a.exists(...args);
9606
9434
  }
9607
9435
  setDefaultNamespace(ns) {
9608
9436
  this.options.defaultNS = ns;
9609
9437
  }
9610
- hasLoadedNamespace(ns) {
9611
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
9438
+ hasLoadedNamespace(ns, options = {}) {
9612
9439
  if (!this.isInitialized) {
9613
9440
  this.logger.warn("hasLoadedNamespace: i18next was not initialized", this.languages);
9614
9441
  return false;
@@ -9667,20 +9494,28 @@ class I18n extends EventEmitter {
9667
9494
  return deferred;
9668
9495
  }
9669
9496
  dir(lng) {
9670
- if (!lng) lng = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language);
9497
+ var _a, _b;
9498
+ if (!lng) lng = this.resolvedLanguage || (((_a = this.languages) == null ? void 0 : _a.length) > 0 ? this.languages[0] : this.language);
9671
9499
  if (!lng) return "rtl";
9500
+ try {
9501
+ const l = new Intl.Locale(lng);
9502
+ if (l && l.getTextInfo) {
9503
+ const ti = l.getTextInfo();
9504
+ if (ti && ti.direction) return ti.direction;
9505
+ }
9506
+ } catch (e) {
9507
+ }
9672
9508
  const rtlLngs = ["ar", "shu", "sqr", "ssh", "xaa", "yhd", "yud", "aao", "abh", "abv", "acm", "acq", "acw", "acx", "acy", "adf", "ads", "aeb", "aec", "afb", "ajp", "apc", "apd", "arb", "arq", "ars", "ary", "arz", "auz", "avl", "ayh", "ayl", "ayn", "ayp", "bbz", "pga", "he", "iw", "ps", "pbt", "pbu", "pst", "prp", "prd", "ug", "ur", "ydd", "yds", "yih", "ji", "yi", "hbo", "men", "xmn", "fa", "jpr", "peo", "pes", "prs", "dv", "sam", "ckb"];
9673
- const languageUtils = this.services && this.services.languageUtils || new LanguageUtil(get());
9509
+ const languageUtils = ((_b = this.services) == null ? void 0 : _b.languageUtils) || new LanguageUtil(get());
9510
+ if (lng.toLowerCase().indexOf("-latn") > 1) return "ltr";
9674
9511
  return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf("-arab") > 1 ? "rtl" : "ltr";
9675
9512
  }
9676
- static createInstance() {
9677
- let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
9678
- let callback = arguments.length > 1 ? arguments[1] : void 0;
9679
- return new I18n(options, callback);
9513
+ static createInstance(options = {}, callback) {
9514
+ const instance2 = new I18n(options, callback);
9515
+ instance2.createInstance = I18n.createInstance;
9516
+ return instance2;
9680
9517
  }
9681
- cloneInstance() {
9682
- let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
9683
- let callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
9518
+ cloneInstance(options = {}, callback = noop) {
9684
9519
  const forkResourceStore = options.forkResourceStore;
9685
9520
  if (forkResourceStore) delete options.forkResourceStore;
9686
9521
  const mergedOptions = {
@@ -9705,14 +9540,23 @@ class I18n extends EventEmitter {
9705
9540
  hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
9706
9541
  };
9707
9542
  if (forkResourceStore) {
9708
- clone.store = new ResourceStore(this.store.data, mergedOptions);
9543
+ const clonedData = Object.keys(this.store.data).reduce((prev, l) => {
9544
+ prev[l] = {
9545
+ ...this.store.data[l]
9546
+ };
9547
+ prev[l] = Object.keys(prev[l]).reduce((acc, n) => {
9548
+ acc[n] = {
9549
+ ...prev[l][n]
9550
+ };
9551
+ return acc;
9552
+ }, prev[l]);
9553
+ return prev;
9554
+ }, {});
9555
+ clone.store = new ResourceStore(clonedData, mergedOptions);
9709
9556
  clone.services.resourceStore = clone.store;
9710
9557
  }
9711
9558
  clone.translator = new Translator(clone.services, mergedOptions);
9712
- clone.translator.on("*", function(event) {
9713
- for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
9714
- args[_key4 - 1] = arguments[_key4];
9715
- }
9559
+ clone.translator.on("*", (event, ...args) => {
9716
9560
  clone.emit(event, ...args);
9717
9561
  });
9718
9562
  clone.init(mergedOptions, callback);
@@ -9733,7 +9577,6 @@ class I18n extends EventEmitter {
9733
9577
  }
9734
9578
  }
9735
9579
  const instance = I18n.createInstance();
9736
- instance.createInstance = I18n.createInstance;
9737
9580
  instance.createInstance;
9738
9581
  instance.dir;
9739
9582
  instance.init;