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