@fctc/sme-widget-ui 1.8.1 → 1.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +6425 -7980
- package/dist/index.mjs +6235 -7790
- package/dist/utils.js +2795 -216
- package/dist/utils.mjs +2795 -216
- package/dist/widgets.js +8102 -9657
- package/dist/widgets.mjs +8089 -9644
- package/package.json +1 -1
package/dist/utils.mjs
CHANGED
|
@@ -131,9 +131,9 @@ var require_moment = __commonJS({
|
|
|
131
131
|
some = Array.prototype.some;
|
|
132
132
|
} else {
|
|
133
133
|
some = function(fun) {
|
|
134
|
-
var
|
|
134
|
+
var t2 = Object(this), len = t2.length >>> 0, i;
|
|
135
135
|
for (i = 0; i < len; i++) {
|
|
136
|
-
if (i in
|
|
136
|
+
if (i in t2 && fun.call(this, t2[i], i, t2)) {
|
|
137
137
|
return true;
|
|
138
138
|
}
|
|
139
139
|
}
|
|
@@ -588,7 +588,7 @@ var require_moment = __commonJS({
|
|
|
588
588
|
return regexes[token2](config._strict, config._locale);
|
|
589
589
|
}
|
|
590
590
|
function unescapeFormat(s) {
|
|
591
|
-
return
|
|
591
|
+
return regexEscape2(
|
|
592
592
|
s.replace("\\", "").replace(
|
|
593
593
|
/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g,
|
|
594
594
|
function(matched, p1, p2, p3, p4) {
|
|
@@ -597,7 +597,7 @@ var require_moment = __commonJS({
|
|
|
597
597
|
)
|
|
598
598
|
);
|
|
599
599
|
}
|
|
600
|
-
function
|
|
600
|
+
function regexEscape2(s) {
|
|
601
601
|
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
602
602
|
}
|
|
603
603
|
function absFloor(number) {
|
|
@@ -687,11 +687,11 @@ var require_moment = __commonJS({
|
|
|
687
687
|
hooks.updateOffset(this, keepTime);
|
|
688
688
|
return this;
|
|
689
689
|
} else {
|
|
690
|
-
return
|
|
690
|
+
return get2(this, unit);
|
|
691
691
|
}
|
|
692
692
|
};
|
|
693
693
|
}
|
|
694
|
-
function
|
|
694
|
+
function get2(mom, unit) {
|
|
695
695
|
if (!mom.isValid()) {
|
|
696
696
|
return NaN;
|
|
697
697
|
}
|
|
@@ -942,7 +942,7 @@ var require_moment = __commonJS({
|
|
|
942
942
|
hooks.updateOffset(this, true);
|
|
943
943
|
return this;
|
|
944
944
|
} else {
|
|
945
|
-
return
|
|
945
|
+
return get2(this, "Month");
|
|
946
946
|
}
|
|
947
947
|
}
|
|
948
948
|
function getDaysInMonth() {
|
|
@@ -989,8 +989,8 @@ var require_moment = __commonJS({
|
|
|
989
989
|
var shortPieces = [], longPieces = [], mixedPieces = [], i, mom, shortP, longP;
|
|
990
990
|
for (i = 0; i < 12; i++) {
|
|
991
991
|
mom = createUTC([2e3, i]);
|
|
992
|
-
shortP =
|
|
993
|
-
longP =
|
|
992
|
+
shortP = regexEscape2(this.monthsShort(mom, ""));
|
|
993
|
+
longP = regexEscape2(this.months(mom, ""));
|
|
994
994
|
shortPieces.push(shortP);
|
|
995
995
|
longPieces.push(longP);
|
|
996
996
|
mixedPieces.push(longP);
|
|
@@ -1294,7 +1294,7 @@ var require_moment = __commonJS({
|
|
|
1294
1294
|
if (!this.isValid()) {
|
|
1295
1295
|
return input != null ? this : NaN;
|
|
1296
1296
|
}
|
|
1297
|
-
var day =
|
|
1297
|
+
var day = get2(this, "Day");
|
|
1298
1298
|
if (input != null) {
|
|
1299
1299
|
input = parseWeekday(input, this.localeData());
|
|
1300
1300
|
return this.add(input - day, "d");
|
|
@@ -1378,9 +1378,9 @@ var require_moment = __commonJS({
|
|
|
1378
1378
|
var minPieces = [], shortPieces = [], longPieces = [], mixedPieces = [], i, mom, minp, shortp, longp;
|
|
1379
1379
|
for (i = 0; i < 7; i++) {
|
|
1380
1380
|
mom = createUTC([2e3, 1]).day(i);
|
|
1381
|
-
minp =
|
|
1382
|
-
shortp =
|
|
1383
|
-
longp =
|
|
1381
|
+
minp = regexEscape2(this.weekdaysMin(mom, ""));
|
|
1382
|
+
shortp = regexEscape2(this.weekdaysShort(mom, ""));
|
|
1383
|
+
longp = regexEscape2(this.weekdays(mom, ""));
|
|
1384
1384
|
minPieces.push(minp);
|
|
1385
1385
|
shortPieces.push(shortp);
|
|
1386
1386
|
longPieces.push(longp);
|
|
@@ -1885,7 +1885,7 @@ var require_moment = __commonJS({
|
|
|
1885
1885
|
config._d = /* @__PURE__ */ new Date(config._i + (config._useUTC ? " UTC" : ""));
|
|
1886
1886
|
}
|
|
1887
1887
|
);
|
|
1888
|
-
function
|
|
1888
|
+
function defaults2(a, b, c) {
|
|
1889
1889
|
if (a != null) {
|
|
1890
1890
|
return a;
|
|
1891
1891
|
}
|
|
@@ -1915,7 +1915,7 @@ var require_moment = __commonJS({
|
|
|
1915
1915
|
dayOfYearFromWeekInfo(config);
|
|
1916
1916
|
}
|
|
1917
1917
|
if (config._dayOfYear != null) {
|
|
1918
|
-
yearToUse =
|
|
1918
|
+
yearToUse = defaults2(config._a[YEAR], currentDate[YEAR]);
|
|
1919
1919
|
if (config._dayOfYear > daysInYear(yearToUse) || config._dayOfYear === 0) {
|
|
1920
1920
|
getParsingFlags(config)._overflowDayOfYear = true;
|
|
1921
1921
|
}
|
|
@@ -1954,13 +1954,13 @@ var require_moment = __commonJS({
|
|
|
1954
1954
|
if (w.GG != null || w.W != null || w.E != null) {
|
|
1955
1955
|
dow = 1;
|
|
1956
1956
|
doy = 4;
|
|
1957
|
-
weekYear =
|
|
1957
|
+
weekYear = defaults2(
|
|
1958
1958
|
w.GG,
|
|
1959
1959
|
config._a[YEAR],
|
|
1960
1960
|
weekOfYear(createLocal(), 1, 4).year
|
|
1961
1961
|
);
|
|
1962
|
-
week =
|
|
1963
|
-
weekday =
|
|
1962
|
+
week = defaults2(w.W, 1);
|
|
1963
|
+
weekday = defaults2(w.E, 1);
|
|
1964
1964
|
if (weekday < 1 || weekday > 7) {
|
|
1965
1965
|
weekdayOverflow = true;
|
|
1966
1966
|
}
|
|
@@ -1968,8 +1968,8 @@ var require_moment = __commonJS({
|
|
|
1968
1968
|
dow = config._locale._week.dow;
|
|
1969
1969
|
doy = config._locale._week.doy;
|
|
1970
1970
|
curWeek = weekOfYear(createLocal(), dow, doy);
|
|
1971
|
-
weekYear =
|
|
1972
|
-
week =
|
|
1971
|
+
weekYear = defaults2(w.gg, config._a[YEAR], curWeek.year);
|
|
1972
|
+
week = defaults2(w.w, curWeek.week);
|
|
1973
1973
|
if (w.d != null) {
|
|
1974
1974
|
weekday = w.d;
|
|
1975
1975
|
if (weekday < 0 || weekday > 6) {
|
|
@@ -2592,10 +2592,10 @@ var require_moment = __commonJS({
|
|
|
2592
2592
|
}
|
|
2593
2593
|
updateOffset = updateOffset == null ? true : updateOffset;
|
|
2594
2594
|
if (months2) {
|
|
2595
|
-
setMonth(mom,
|
|
2595
|
+
setMonth(mom, get2(mom, "Month") + months2 * isAdding);
|
|
2596
2596
|
}
|
|
2597
2597
|
if (days2) {
|
|
2598
|
-
set$1(mom, "Date",
|
|
2598
|
+
set$1(mom, "Date", get2(mom, "Date") + days2 * isAdding);
|
|
2599
2599
|
}
|
|
2600
2600
|
if (milliseconds2) {
|
|
2601
2601
|
mom._d.setTime(mom._d.valueOf() + milliseconds2 * isAdding);
|
|
@@ -2605,11 +2605,11 @@ var require_moment = __commonJS({
|
|
|
2605
2605
|
}
|
|
2606
2606
|
}
|
|
2607
2607
|
var add = createAdder(1, "add"), subtract = createAdder(-1, "subtract");
|
|
2608
|
-
function
|
|
2608
|
+
function isString3(input) {
|
|
2609
2609
|
return typeof input === "string" || input instanceof String;
|
|
2610
2610
|
}
|
|
2611
2611
|
function isMomentInput(input) {
|
|
2612
|
-
return isMoment(input) || isDate(input) ||
|
|
2612
|
+
return isMoment(input) || isDate(input) || isString3(input) || isNumber(input) || isNumberOrStringArray(input) || isMomentInputObject(input) || input === null || input === void 0;
|
|
2613
2613
|
}
|
|
2614
2614
|
function isMomentInputObject(input) {
|
|
2615
2615
|
var objectTest = isObject2(input) && !isObjectEmpty2(input), propertyTest = false, properties = [
|
|
@@ -2648,7 +2648,7 @@ var require_moment = __commonJS({
|
|
|
2648
2648
|
var arrayTest = isArray(input), dataTypeTest = false;
|
|
2649
2649
|
if (arrayTest) {
|
|
2650
2650
|
dataTypeTest = input.filter(function(item) {
|
|
2651
|
-
return !isNumber(item) &&
|
|
2651
|
+
return !isNumber(item) && isString3(input);
|
|
2652
2652
|
}).length === 0;
|
|
2653
2653
|
}
|
|
2654
2654
|
return arrayTest && dataTypeTest;
|
|
@@ -3185,11 +3185,11 @@ var require_moment = __commonJS({
|
|
|
3185
3185
|
}
|
|
3186
3186
|
}
|
|
3187
3187
|
function localeErasConvertYear(era, year) {
|
|
3188
|
-
var
|
|
3188
|
+
var dir2 = era.since <= era.until ? 1 : -1;
|
|
3189
3189
|
if (year === void 0) {
|
|
3190
3190
|
return hooks(era.since).year();
|
|
3191
3191
|
} else {
|
|
3192
|
-
return hooks(era.since).year() + (year - era.offset) *
|
|
3192
|
+
return hooks(era.since).year() + (year - era.offset) * dir2;
|
|
3193
3193
|
}
|
|
3194
3194
|
}
|
|
3195
3195
|
function getEraName() {
|
|
@@ -3232,12 +3232,12 @@ var require_moment = __commonJS({
|
|
|
3232
3232
|
return "";
|
|
3233
3233
|
}
|
|
3234
3234
|
function getEraYear() {
|
|
3235
|
-
var i, l,
|
|
3235
|
+
var i, l, dir2, val, eras = this.localeData().eras();
|
|
3236
3236
|
for (i = 0, l = eras.length; i < l; ++i) {
|
|
3237
|
-
|
|
3237
|
+
dir2 = eras[i].since <= eras[i].until ? 1 : -1;
|
|
3238
3238
|
val = this.clone().startOf("day").valueOf();
|
|
3239
3239
|
if (eras[i].since <= val && val <= eras[i].until || eras[i].until <= val && val <= eras[i].since) {
|
|
3240
|
-
return (this.year() - hooks(eras[i].since).year()) *
|
|
3240
|
+
return (this.year() - hooks(eras[i].since).year()) * dir2 + eras[i].offset;
|
|
3241
3241
|
}
|
|
3242
3242
|
}
|
|
3243
3243
|
return this.year();
|
|
@@ -3275,9 +3275,9 @@ var require_moment = __commonJS({
|
|
|
3275
3275
|
function computeErasParse() {
|
|
3276
3276
|
var abbrPieces = [], namePieces = [], narrowPieces = [], mixedPieces = [], i, l, erasName, erasAbbr, erasNarrow, eras = this.eras();
|
|
3277
3277
|
for (i = 0, l = eras.length; i < l; ++i) {
|
|
3278
|
-
erasName =
|
|
3279
|
-
erasAbbr =
|
|
3280
|
-
erasNarrow =
|
|
3278
|
+
erasName = regexEscape2(eras[i].name);
|
|
3279
|
+
erasAbbr = regexEscape2(eras[i].abbr);
|
|
3280
|
+
erasNarrow = regexEscape2(eras[i].narrow);
|
|
3281
3281
|
namePieces.push(erasName);
|
|
3282
3282
|
abbrPieces.push(erasAbbr);
|
|
3283
3283
|
narrowPieces.push(erasNarrow);
|
|
@@ -4057,6 +4057,9 @@ var require_void_elements = __commonJS({
|
|
|
4057
4057
|
// src/utils/function.ts
|
|
4058
4058
|
var import_moment = __toESM(require_moment());
|
|
4059
4059
|
|
|
4060
|
+
// src/provider/index.tsx
|
|
4061
|
+
import { useEffect as useEffect2, createContext as createContext2, useContext as useContext4 } from "react";
|
|
4062
|
+
|
|
4060
4063
|
// node_modules/react-i18next/dist/es/Trans.js
|
|
4061
4064
|
import { useContext } from "react";
|
|
4062
4065
|
|
|
@@ -4066,69 +4069,6 @@ import { Fragment, isValidElement, cloneElement, createElement, Children } from
|
|
|
4066
4069
|
// node_modules/html-parse-stringify/dist/html-parse-stringify.module.js
|
|
4067
4070
|
var import_void_elements = __toESM(require_void_elements());
|
|
4068
4071
|
|
|
4069
|
-
// node_modules/react-i18next/dist/es/utils.js
|
|
4070
|
-
var warn = (i18n, code, msg, rest) => {
|
|
4071
|
-
const args = [msg, {
|
|
4072
|
-
code,
|
|
4073
|
-
...rest || {}
|
|
4074
|
-
}];
|
|
4075
|
-
if (i18n?.services?.logger?.forward) {
|
|
4076
|
-
return i18n.services.logger.forward(args, "warn", "react-i18next::", true);
|
|
4077
|
-
}
|
|
4078
|
-
if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
|
|
4079
|
-
if (i18n?.services?.logger?.warn) {
|
|
4080
|
-
i18n.services.logger.warn(...args);
|
|
4081
|
-
} else if (console?.warn) {
|
|
4082
|
-
console.warn(...args);
|
|
4083
|
-
}
|
|
4084
|
-
};
|
|
4085
|
-
var alreadyWarned = {};
|
|
4086
|
-
var warnOnce = (i18n, code, msg, rest) => {
|
|
4087
|
-
if (isString(msg) && alreadyWarned[msg]) return;
|
|
4088
|
-
if (isString(msg)) alreadyWarned[msg] = /* @__PURE__ */ new Date();
|
|
4089
|
-
warn(i18n, code, msg, rest);
|
|
4090
|
-
};
|
|
4091
|
-
var loadedClb = (i18n, cb) => () => {
|
|
4092
|
-
if (i18n.isInitialized) {
|
|
4093
|
-
cb();
|
|
4094
|
-
} else {
|
|
4095
|
-
const initialized = () => {
|
|
4096
|
-
setTimeout(() => {
|
|
4097
|
-
i18n.off("initialized", initialized);
|
|
4098
|
-
}, 0);
|
|
4099
|
-
cb();
|
|
4100
|
-
};
|
|
4101
|
-
i18n.on("initialized", initialized);
|
|
4102
|
-
}
|
|
4103
|
-
};
|
|
4104
|
-
var loadNamespaces = (i18n, ns, cb) => {
|
|
4105
|
-
i18n.loadNamespaces(ns, loadedClb(i18n, cb));
|
|
4106
|
-
};
|
|
4107
|
-
var loadLanguages = (i18n, lng, ns, cb) => {
|
|
4108
|
-
if (isString(ns)) ns = [ns];
|
|
4109
|
-
if (i18n.options.preload && i18n.options.preload.indexOf(lng) > -1) return loadNamespaces(i18n, ns, cb);
|
|
4110
|
-
ns.forEach((n) => {
|
|
4111
|
-
if (i18n.options.ns.indexOf(n) < 0) i18n.options.ns.push(n);
|
|
4112
|
-
});
|
|
4113
|
-
i18n.loadLanguages(lng, loadedClb(i18n, cb));
|
|
4114
|
-
};
|
|
4115
|
-
var hasLoadedNamespace = (ns, i18n, options = {}) => {
|
|
4116
|
-
if (!i18n.languages || !i18n.languages.length) {
|
|
4117
|
-
warnOnce(i18n, "NO_LANGUAGES", "i18n.languages were undefined or empty", {
|
|
4118
|
-
languages: i18n.languages
|
|
4119
|
-
});
|
|
4120
|
-
return true;
|
|
4121
|
-
}
|
|
4122
|
-
return i18n.hasLoadedNamespace(ns, {
|
|
4123
|
-
lng: options.lng,
|
|
4124
|
-
precheck: (i18nInstance2, loadNotPending) => {
|
|
4125
|
-
if (options.bindI18n && options.bindI18n.indexOf("languageChanging") > -1 && i18nInstance2.services.backendConnector.backend && i18nInstance2.isLanguageChangingTo && !loadNotPending(i18nInstance2.isLanguageChangingTo, ns)) return false;
|
|
4126
|
-
}
|
|
4127
|
-
});
|
|
4128
|
-
};
|
|
4129
|
-
var isString = (obj) => typeof obj === "string";
|
|
4130
|
-
var isObject = (obj) => typeof obj === "object" && obj !== null;
|
|
4131
|
-
|
|
4132
4072
|
// node_modules/react-i18next/dist/es/unescape.js
|
|
4133
4073
|
var matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
|
|
4134
4074
|
var htmlEntities = {
|
|
@@ -4167,151 +4107,2790 @@ var defaultOptions = {
|
|
|
4167
4107
|
useSuspense: true,
|
|
4168
4108
|
unescape
|
|
4169
4109
|
};
|
|
4170
|
-
var
|
|
4110
|
+
var setDefaults = (options = {}) => {
|
|
4111
|
+
defaultOptions = {
|
|
4112
|
+
...defaultOptions,
|
|
4113
|
+
...options
|
|
4114
|
+
};
|
|
4115
|
+
};
|
|
4171
4116
|
|
|
4172
4117
|
// node_modules/react-i18next/dist/es/i18nInstance.js
|
|
4173
4118
|
var i18nInstance;
|
|
4174
|
-
var
|
|
4119
|
+
var setI18n = (instance2) => {
|
|
4120
|
+
i18nInstance = instance2;
|
|
4121
|
+
};
|
|
4175
4122
|
|
|
4176
4123
|
// node_modules/react-i18next/dist/es/context.js
|
|
4177
4124
|
import { createContext } from "react";
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
|
|
4186
|
-
});
|
|
4187
|
-
}
|
|
4188
|
-
getUsedNamespaces() {
|
|
4189
|
-
return Object.keys(this.usedNamespaces);
|
|
4125
|
+
|
|
4126
|
+
// node_modules/react-i18next/dist/es/initReactI18next.js
|
|
4127
|
+
var initReactI18next = {
|
|
4128
|
+
type: "3rdParty",
|
|
4129
|
+
init(instance2) {
|
|
4130
|
+
setDefaults(instance2.options.react);
|
|
4131
|
+
setI18n(instance2);
|
|
4190
4132
|
}
|
|
4191
4133
|
};
|
|
4192
4134
|
|
|
4135
|
+
// node_modules/react-i18next/dist/es/context.js
|
|
4136
|
+
var I18nContext = createContext();
|
|
4137
|
+
|
|
4193
4138
|
// node_modules/react-i18next/dist/es/useTranslation.js
|
|
4194
4139
|
import { useState, useEffect, useContext as useContext2, useRef, useCallback } from "react";
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4140
|
+
|
|
4141
|
+
// node_modules/react-i18next/dist/es/withTranslation.js
|
|
4142
|
+
import { createElement as createElement2, forwardRef as forwardRefReact } from "react";
|
|
4143
|
+
|
|
4144
|
+
// node_modules/react-i18next/dist/es/I18nextProvider.js
|
|
4145
|
+
import { createElement as createElement3, useMemo } from "react";
|
|
4146
|
+
|
|
4147
|
+
// node_modules/react-i18next/dist/es/withSSR.js
|
|
4148
|
+
import { createElement as createElement4 } from "react";
|
|
4149
|
+
|
|
4150
|
+
// node_modules/react-i18next/dist/es/useSSR.js
|
|
4151
|
+
import { useContext as useContext3 } from "react";
|
|
4152
|
+
|
|
4153
|
+
// node_modules/i18next/dist/esm/i18next.js
|
|
4154
|
+
var isString2 = (obj) => typeof obj === "string";
|
|
4155
|
+
var defer = () => {
|
|
4156
|
+
let res;
|
|
4157
|
+
let rej;
|
|
4158
|
+
const promise = new Promise((resolve, reject) => {
|
|
4159
|
+
res = resolve;
|
|
4160
|
+
rej = reject;
|
|
4161
|
+
});
|
|
4162
|
+
promise.resolve = res;
|
|
4163
|
+
promise.reject = rej;
|
|
4164
|
+
return promise;
|
|
4165
|
+
};
|
|
4166
|
+
var makeString = (object) => {
|
|
4167
|
+
if (object == null) return "";
|
|
4168
|
+
return "" + object;
|
|
4169
|
+
};
|
|
4170
|
+
var copy = (a, s, t2) => {
|
|
4171
|
+
a.forEach((m) => {
|
|
4172
|
+
if (s[m]) t2[m] = s[m];
|
|
4173
|
+
});
|
|
4174
|
+
};
|
|
4175
|
+
var lastOfPathSeparatorRegExp = /###/g;
|
|
4176
|
+
var cleanKey = (key) => key && key.indexOf("###") > -1 ? key.replace(lastOfPathSeparatorRegExp, ".") : key;
|
|
4177
|
+
var canNotTraverseDeeper = (object) => !object || isString2(object);
|
|
4178
|
+
var getLastOfPath = (object, path2, Empty) => {
|
|
4179
|
+
const stack = !isString2(path2) ? path2 : path2.split(".");
|
|
4180
|
+
let stackIndex = 0;
|
|
4181
|
+
while (stackIndex < stack.length - 1) {
|
|
4182
|
+
if (canNotTraverseDeeper(object)) return {};
|
|
4183
|
+
const key = cleanKey(stack[stackIndex]);
|
|
4184
|
+
if (!object[key] && Empty) object[key] = new Empty();
|
|
4185
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
4186
|
+
object = object[key];
|
|
4187
|
+
} else {
|
|
4188
|
+
object = {};
|
|
4189
|
+
}
|
|
4190
|
+
++stackIndex;
|
|
4191
|
+
}
|
|
4192
|
+
if (canNotTraverseDeeper(object)) return {};
|
|
4193
|
+
return {
|
|
4194
|
+
obj: object,
|
|
4195
|
+
k: cleanKey(stack[stackIndex])
|
|
4196
|
+
};
|
|
4201
4197
|
};
|
|
4202
|
-
var
|
|
4203
|
-
var useMemoizedT = (i18n, language, namespace, keyPrefix) => useCallback(alwaysNewT(i18n, language, namespace, keyPrefix), [i18n, language, namespace, keyPrefix]);
|
|
4204
|
-
var useTranslation = (ns, props = {}) => {
|
|
4198
|
+
var setPath = (object, path2, newValue) => {
|
|
4205
4199
|
const {
|
|
4206
|
-
|
|
4207
|
-
|
|
4200
|
+
obj,
|
|
4201
|
+
k
|
|
4202
|
+
} = getLastOfPath(object, path2, Object);
|
|
4203
|
+
if (obj !== void 0 || path2.length === 1) {
|
|
4204
|
+
obj[k] = newValue;
|
|
4205
|
+
return;
|
|
4206
|
+
}
|
|
4207
|
+
let e2 = path2[path2.length - 1];
|
|
4208
|
+
let p = path2.slice(0, path2.length - 1);
|
|
4209
|
+
let last = getLastOfPath(object, p, Object);
|
|
4210
|
+
while (last.obj === void 0 && p.length) {
|
|
4211
|
+
e2 = `${p[p.length - 1]}.${e2}`;
|
|
4212
|
+
p = p.slice(0, p.length - 1);
|
|
4213
|
+
last = getLastOfPath(object, p, Object);
|
|
4214
|
+
if (last?.obj && typeof last.obj[`${last.k}.${e2}`] !== "undefined") {
|
|
4215
|
+
last.obj = void 0;
|
|
4216
|
+
}
|
|
4217
|
+
}
|
|
4218
|
+
last.obj[`${last.k}.${e2}`] = newValue;
|
|
4219
|
+
};
|
|
4220
|
+
var pushPath = (object, path2, newValue, concat) => {
|
|
4208
4221
|
const {
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
} =
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
const notReadyT = (k, optsOrDefaultValue) => {
|
|
4217
|
-
if (isString(optsOrDefaultValue)) return optsOrDefaultValue;
|
|
4218
|
-
if (isObject(optsOrDefaultValue) && isString(optsOrDefaultValue.defaultValue)) return optsOrDefaultValue.defaultValue;
|
|
4219
|
-
return Array.isArray(k) ? k[k.length - 1] : k;
|
|
4220
|
-
};
|
|
4221
|
-
const retNotReady = [notReadyT, {}, false];
|
|
4222
|
-
retNotReady.t = notReadyT;
|
|
4223
|
-
retNotReady.i18n = {};
|
|
4224
|
-
retNotReady.ready = false;
|
|
4225
|
-
return retNotReady;
|
|
4226
|
-
}
|
|
4227
|
-
if (i18n.options.react?.wait) warnOnce(i18n, "DEPRECATED_OPTION", "useTranslation: It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");
|
|
4228
|
-
const i18nOptions = {
|
|
4229
|
-
...getDefaults(),
|
|
4230
|
-
...i18n.options.react,
|
|
4231
|
-
...props
|
|
4232
|
-
};
|
|
4222
|
+
obj,
|
|
4223
|
+
k
|
|
4224
|
+
} = getLastOfPath(object, path2, Object);
|
|
4225
|
+
obj[k] = obj[k] || [];
|
|
4226
|
+
obj[k].push(newValue);
|
|
4227
|
+
};
|
|
4228
|
+
var getPath = (object, path2) => {
|
|
4233
4229
|
const {
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
} =
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
const
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
loadLanguages(i18n, props.lng, namespaces, () => {
|
|
4258
|
-
if (isMounted.current) setT(getNewT);
|
|
4259
|
-
});
|
|
4230
|
+
obj,
|
|
4231
|
+
k
|
|
4232
|
+
} = getLastOfPath(object, path2);
|
|
4233
|
+
if (!obj) return void 0;
|
|
4234
|
+
if (!Object.prototype.hasOwnProperty.call(obj, k)) return void 0;
|
|
4235
|
+
return obj[k];
|
|
4236
|
+
};
|
|
4237
|
+
var getPathWithDefaults = (data, defaultData, key) => {
|
|
4238
|
+
const value = getPath(data, key);
|
|
4239
|
+
if (value !== void 0) {
|
|
4240
|
+
return value;
|
|
4241
|
+
}
|
|
4242
|
+
return getPath(defaultData, key);
|
|
4243
|
+
};
|
|
4244
|
+
var deepExtend = (target, source, overwrite) => {
|
|
4245
|
+
for (const prop in source) {
|
|
4246
|
+
if (prop !== "__proto__" && prop !== "constructor") {
|
|
4247
|
+
if (prop in target) {
|
|
4248
|
+
if (isString2(target[prop]) || target[prop] instanceof String || isString2(source[prop]) || source[prop] instanceof String) {
|
|
4249
|
+
if (overwrite) target[prop] = source[prop];
|
|
4250
|
+
} else {
|
|
4251
|
+
deepExtend(target[prop], source[prop], overwrite);
|
|
4252
|
+
}
|
|
4260
4253
|
} else {
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4254
|
+
target[prop] = source[prop];
|
|
4255
|
+
}
|
|
4256
|
+
}
|
|
4257
|
+
}
|
|
4258
|
+
return target;
|
|
4259
|
+
};
|
|
4260
|
+
var regexEscape = (str) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
|
4261
|
+
var _entityMap = {
|
|
4262
|
+
"&": "&",
|
|
4263
|
+
"<": "<",
|
|
4264
|
+
">": ">",
|
|
4265
|
+
'"': """,
|
|
4266
|
+
"'": "'",
|
|
4267
|
+
"/": "/"
|
|
4268
|
+
};
|
|
4269
|
+
var escape = (data) => {
|
|
4270
|
+
if (isString2(data)) {
|
|
4271
|
+
return data.replace(/[&<>"'\/]/g, (s) => _entityMap[s]);
|
|
4272
|
+
}
|
|
4273
|
+
return data;
|
|
4274
|
+
};
|
|
4275
|
+
var RegExpCache = class {
|
|
4276
|
+
constructor(capacity) {
|
|
4277
|
+
this.capacity = capacity;
|
|
4278
|
+
this.regExpMap = /* @__PURE__ */ new Map();
|
|
4279
|
+
this.regExpQueue = [];
|
|
4280
|
+
}
|
|
4281
|
+
getRegExp(pattern) {
|
|
4282
|
+
const regExpFromCache = this.regExpMap.get(pattern);
|
|
4283
|
+
if (regExpFromCache !== void 0) {
|
|
4284
|
+
return regExpFromCache;
|
|
4285
|
+
}
|
|
4286
|
+
const regExpNew = new RegExp(pattern);
|
|
4287
|
+
if (this.regExpQueue.length === this.capacity) {
|
|
4288
|
+
this.regExpMap.delete(this.regExpQueue.shift());
|
|
4289
|
+
}
|
|
4290
|
+
this.regExpMap.set(pattern, regExpNew);
|
|
4291
|
+
this.regExpQueue.push(pattern);
|
|
4292
|
+
return regExpNew;
|
|
4293
|
+
}
|
|
4294
|
+
};
|
|
4295
|
+
var chars = [" ", ",", "?", "!", ";"];
|
|
4296
|
+
var looksLikeObjectPathRegExpCache = new RegExpCache(20);
|
|
4297
|
+
var looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
|
|
4298
|
+
nsSeparator = nsSeparator || "";
|
|
4299
|
+
keySeparator = keySeparator || "";
|
|
4300
|
+
const possibleChars = chars.filter((c) => nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0);
|
|
4301
|
+
if (possibleChars.length === 0) return true;
|
|
4302
|
+
const r = looksLikeObjectPathRegExpCache.getRegExp(`(${possibleChars.map((c) => c === "?" ? "\\?" : c).join("|")})`);
|
|
4303
|
+
let matched = !r.test(key);
|
|
4304
|
+
if (!matched) {
|
|
4305
|
+
const ki = key.indexOf(keySeparator);
|
|
4306
|
+
if (ki > 0 && !r.test(key.substring(0, ki))) {
|
|
4307
|
+
matched = true;
|
|
4308
|
+
}
|
|
4309
|
+
}
|
|
4310
|
+
return matched;
|
|
4311
|
+
};
|
|
4312
|
+
var deepFind = function(obj, path2) {
|
|
4313
|
+
let keySeparator = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : ".";
|
|
4314
|
+
if (!obj) return void 0;
|
|
4315
|
+
if (obj[path2]) {
|
|
4316
|
+
if (!Object.prototype.hasOwnProperty.call(obj, path2)) return void 0;
|
|
4317
|
+
return obj[path2];
|
|
4318
|
+
}
|
|
4319
|
+
const tokens = path2.split(keySeparator);
|
|
4320
|
+
let current = obj;
|
|
4321
|
+
for (let i = 0; i < tokens.length; ) {
|
|
4322
|
+
if (!current || typeof current !== "object") {
|
|
4323
|
+
return void 0;
|
|
4324
|
+
}
|
|
4325
|
+
let next;
|
|
4326
|
+
let nextPath = "";
|
|
4327
|
+
for (let j = i; j < tokens.length; ++j) {
|
|
4328
|
+
if (j !== i) {
|
|
4329
|
+
nextPath += keySeparator;
|
|
4330
|
+
}
|
|
4331
|
+
nextPath += tokens[j];
|
|
4332
|
+
next = current[nextPath];
|
|
4333
|
+
if (next !== void 0) {
|
|
4334
|
+
if (["string", "number", "boolean"].indexOf(typeof next) > -1 && j < tokens.length - 1) {
|
|
4335
|
+
continue;
|
|
4336
|
+
}
|
|
4337
|
+
i += j - i + 1;
|
|
4338
|
+
break;
|
|
4339
|
+
}
|
|
4340
|
+
}
|
|
4341
|
+
current = next;
|
|
4342
|
+
}
|
|
4343
|
+
return current;
|
|
4344
|
+
};
|
|
4345
|
+
var getCleanedCode = (code) => code?.replace("_", "-");
|
|
4346
|
+
var consoleLogger = {
|
|
4347
|
+
type: "logger",
|
|
4348
|
+
log(args) {
|
|
4349
|
+
this.output("log", args);
|
|
4350
|
+
},
|
|
4351
|
+
warn(args) {
|
|
4352
|
+
this.output("warn", args);
|
|
4353
|
+
},
|
|
4354
|
+
error(args) {
|
|
4355
|
+
this.output("error", args);
|
|
4356
|
+
},
|
|
4357
|
+
output(type, args) {
|
|
4358
|
+
console?.[type]?.apply?.(console, args);
|
|
4359
|
+
}
|
|
4360
|
+
};
|
|
4361
|
+
var Logger = class _Logger {
|
|
4362
|
+
constructor(concreteLogger) {
|
|
4363
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
4364
|
+
this.init(concreteLogger, options);
|
|
4365
|
+
}
|
|
4366
|
+
init(concreteLogger) {
|
|
4367
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
4368
|
+
this.prefix = options.prefix || "i18next:";
|
|
4369
|
+
this.logger = concreteLogger || consoleLogger;
|
|
4370
|
+
this.options = options;
|
|
4371
|
+
this.debug = options.debug;
|
|
4372
|
+
}
|
|
4373
|
+
log() {
|
|
4374
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4375
|
+
args[_key] = arguments[_key];
|
|
4376
|
+
}
|
|
4377
|
+
return this.forward(args, "log", "", true);
|
|
4378
|
+
}
|
|
4379
|
+
warn() {
|
|
4380
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
4381
|
+
args[_key2] = arguments[_key2];
|
|
4382
|
+
}
|
|
4383
|
+
return this.forward(args, "warn", "", true);
|
|
4384
|
+
}
|
|
4385
|
+
error() {
|
|
4386
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
4387
|
+
args[_key3] = arguments[_key3];
|
|
4388
|
+
}
|
|
4389
|
+
return this.forward(args, "error", "");
|
|
4390
|
+
}
|
|
4391
|
+
deprecate() {
|
|
4392
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
4393
|
+
args[_key4] = arguments[_key4];
|
|
4394
|
+
}
|
|
4395
|
+
return this.forward(args, "warn", "WARNING DEPRECATED: ", true);
|
|
4396
|
+
}
|
|
4397
|
+
forward(args, lvl, prefix, debugOnly) {
|
|
4398
|
+
if (debugOnly && !this.debug) return null;
|
|
4399
|
+
if (isString2(args[0])) args[0] = `${prefix}${this.prefix} ${args[0]}`;
|
|
4400
|
+
return this.logger[lvl](args);
|
|
4401
|
+
}
|
|
4402
|
+
create(moduleName) {
|
|
4403
|
+
return new _Logger(this.logger, {
|
|
4404
|
+
...{
|
|
4405
|
+
prefix: `${this.prefix}:${moduleName}:`
|
|
4406
|
+
},
|
|
4407
|
+
...this.options
|
|
4408
|
+
});
|
|
4409
|
+
}
|
|
4410
|
+
clone(options) {
|
|
4411
|
+
options = options || this.options;
|
|
4412
|
+
options.prefix = options.prefix || this.prefix;
|
|
4413
|
+
return new _Logger(this.logger, options);
|
|
4414
|
+
}
|
|
4415
|
+
};
|
|
4416
|
+
var baseLogger = new Logger();
|
|
4417
|
+
var EventEmitter = class {
|
|
4418
|
+
constructor() {
|
|
4419
|
+
this.observers = {};
|
|
4420
|
+
}
|
|
4421
|
+
on(events, listener) {
|
|
4422
|
+
events.split(" ").forEach((event) => {
|
|
4423
|
+
if (!this.observers[event]) this.observers[event] = /* @__PURE__ */ new Map();
|
|
4424
|
+
const numListeners = this.observers[event].get(listener) || 0;
|
|
4425
|
+
this.observers[event].set(listener, numListeners + 1);
|
|
4426
|
+
});
|
|
4427
|
+
return this;
|
|
4428
|
+
}
|
|
4429
|
+
off(event, listener) {
|
|
4430
|
+
if (!this.observers[event]) return;
|
|
4431
|
+
if (!listener) {
|
|
4432
|
+
delete this.observers[event];
|
|
4433
|
+
return;
|
|
4434
|
+
}
|
|
4435
|
+
this.observers[event].delete(listener);
|
|
4436
|
+
}
|
|
4437
|
+
emit(event) {
|
|
4438
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
4439
|
+
args[_key - 1] = arguments[_key];
|
|
4440
|
+
}
|
|
4441
|
+
if (this.observers[event]) {
|
|
4442
|
+
const cloned = Array.from(this.observers[event].entries());
|
|
4443
|
+
cloned.forEach((_ref) => {
|
|
4444
|
+
let [observer, numTimesAdded] = _ref;
|
|
4445
|
+
for (let i = 0; i < numTimesAdded; i++) {
|
|
4446
|
+
observer(...args);
|
|
4447
|
+
}
|
|
4448
|
+
});
|
|
4449
|
+
}
|
|
4450
|
+
if (this.observers["*"]) {
|
|
4451
|
+
const cloned = Array.from(this.observers["*"].entries());
|
|
4452
|
+
cloned.forEach((_ref2) => {
|
|
4453
|
+
let [observer, numTimesAdded] = _ref2;
|
|
4454
|
+
for (let i = 0; i < numTimesAdded; i++) {
|
|
4455
|
+
observer.apply(observer, [event, ...args]);
|
|
4456
|
+
}
|
|
4457
|
+
});
|
|
4458
|
+
}
|
|
4459
|
+
}
|
|
4460
|
+
};
|
|
4461
|
+
var ResourceStore = class extends EventEmitter {
|
|
4462
|
+
constructor(data) {
|
|
4463
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
|
|
4464
|
+
ns: ["translation"],
|
|
4465
|
+
defaultNS: "translation"
|
|
4466
|
+
};
|
|
4467
|
+
super();
|
|
4468
|
+
this.data = data || {};
|
|
4469
|
+
this.options = options;
|
|
4470
|
+
if (this.options.keySeparator === void 0) {
|
|
4471
|
+
this.options.keySeparator = ".";
|
|
4472
|
+
}
|
|
4473
|
+
if (this.options.ignoreJSONStructure === void 0) {
|
|
4474
|
+
this.options.ignoreJSONStructure = true;
|
|
4475
|
+
}
|
|
4476
|
+
}
|
|
4477
|
+
addNamespaces(ns) {
|
|
4478
|
+
if (this.options.ns.indexOf(ns) < 0) {
|
|
4479
|
+
this.options.ns.push(ns);
|
|
4480
|
+
}
|
|
4481
|
+
}
|
|
4482
|
+
removeNamespaces(ns) {
|
|
4483
|
+
const index = this.options.ns.indexOf(ns);
|
|
4484
|
+
if (index > -1) {
|
|
4485
|
+
this.options.ns.splice(index, 1);
|
|
4486
|
+
}
|
|
4487
|
+
}
|
|
4488
|
+
getResource(lng, ns, key) {
|
|
4489
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
4490
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
4491
|
+
const ignoreJSONStructure = options.ignoreJSONStructure !== void 0 ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
4492
|
+
let path2;
|
|
4493
|
+
if (lng.indexOf(".") > -1) {
|
|
4494
|
+
path2 = lng.split(".");
|
|
4495
|
+
} else {
|
|
4496
|
+
path2 = [lng, ns];
|
|
4497
|
+
if (key) {
|
|
4498
|
+
if (Array.isArray(key)) {
|
|
4499
|
+
path2.push(...key);
|
|
4500
|
+
} else if (isString2(key) && keySeparator) {
|
|
4501
|
+
path2.push(...key.split(keySeparator));
|
|
4502
|
+
} else {
|
|
4503
|
+
path2.push(key);
|
|
4504
|
+
}
|
|
4264
4505
|
}
|
|
4265
4506
|
}
|
|
4266
|
-
|
|
4267
|
-
|
|
4507
|
+
const result = getPath(this.data, path2);
|
|
4508
|
+
if (!result && !ns && !key && lng.indexOf(".") > -1) {
|
|
4509
|
+
lng = path2[0];
|
|
4510
|
+
ns = path2[1];
|
|
4511
|
+
key = path2.slice(2).join(".");
|
|
4512
|
+
}
|
|
4513
|
+
if (result || !ignoreJSONStructure || !isString2(key)) return result;
|
|
4514
|
+
return deepFind(this.data?.[lng]?.[ns], key, keySeparator);
|
|
4515
|
+
}
|
|
4516
|
+
addResource(lng, ns, key, value) {
|
|
4517
|
+
let options = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : {
|
|
4518
|
+
silent: false
|
|
4519
|
+
};
|
|
4520
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
4521
|
+
let path2 = [lng, ns];
|
|
4522
|
+
if (key) path2 = path2.concat(keySeparator ? key.split(keySeparator) : key);
|
|
4523
|
+
if (lng.indexOf(".") > -1) {
|
|
4524
|
+
path2 = lng.split(".");
|
|
4525
|
+
value = ns;
|
|
4526
|
+
ns = path2[1];
|
|
4268
4527
|
}
|
|
4269
|
-
|
|
4270
|
-
|
|
4528
|
+
this.addNamespaces(ns);
|
|
4529
|
+
setPath(this.data, path2, value);
|
|
4530
|
+
if (!options.silent) this.emit("added", lng, ns, key, value);
|
|
4531
|
+
}
|
|
4532
|
+
addResources(lng, ns, resources) {
|
|
4533
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {
|
|
4534
|
+
silent: false
|
|
4271
4535
|
};
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4536
|
+
for (const m in resources) {
|
|
4537
|
+
if (isString2(resources[m]) || Array.isArray(resources[m])) this.addResource(lng, ns, m, resources[m], {
|
|
4538
|
+
silent: true
|
|
4539
|
+
});
|
|
4540
|
+
}
|
|
4541
|
+
if (!options.silent) this.emit("added", lng, ns, resources);
|
|
4542
|
+
}
|
|
4543
|
+
addResourceBundle(lng, ns, resources, deep, overwrite) {
|
|
4544
|
+
let options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {
|
|
4545
|
+
silent: false,
|
|
4546
|
+
skipCopy: false
|
|
4278
4547
|
};
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
throw new Promise((resolve) => {
|
|
4292
|
-
if (props.lng) {
|
|
4293
|
-
loadLanguages(i18n, props.lng, namespaces, () => resolve());
|
|
4548
|
+
let path2 = [lng, ns];
|
|
4549
|
+
if (lng.indexOf(".") > -1) {
|
|
4550
|
+
path2 = lng.split(".");
|
|
4551
|
+
deep = resources;
|
|
4552
|
+
resources = ns;
|
|
4553
|
+
ns = path2[1];
|
|
4554
|
+
}
|
|
4555
|
+
this.addNamespaces(ns);
|
|
4556
|
+
let pack = getPath(this.data, path2) || {};
|
|
4557
|
+
if (!options.skipCopy) resources = JSON.parse(JSON.stringify(resources));
|
|
4558
|
+
if (deep) {
|
|
4559
|
+
deepExtend(pack, resources, overwrite);
|
|
4294
4560
|
} else {
|
|
4295
|
-
|
|
4561
|
+
pack = {
|
|
4562
|
+
...pack,
|
|
4563
|
+
...resources
|
|
4564
|
+
};
|
|
4296
4565
|
}
|
|
4297
|
-
|
|
4566
|
+
setPath(this.data, path2, pack);
|
|
4567
|
+
if (!options.silent) this.emit("added", lng, ns, resources);
|
|
4568
|
+
}
|
|
4569
|
+
removeResourceBundle(lng, ns) {
|
|
4570
|
+
if (this.hasResourceBundle(lng, ns)) {
|
|
4571
|
+
delete this.data[lng][ns];
|
|
4572
|
+
}
|
|
4573
|
+
this.removeNamespaces(ns);
|
|
4574
|
+
this.emit("removed", lng, ns);
|
|
4575
|
+
}
|
|
4576
|
+
hasResourceBundle(lng, ns) {
|
|
4577
|
+
return this.getResource(lng, ns) !== void 0;
|
|
4578
|
+
}
|
|
4579
|
+
getResourceBundle(lng, ns) {
|
|
4580
|
+
if (!ns) ns = this.options.defaultNS;
|
|
4581
|
+
return this.getResource(lng, ns);
|
|
4582
|
+
}
|
|
4583
|
+
getDataByLanguage(lng) {
|
|
4584
|
+
return this.data[lng];
|
|
4585
|
+
}
|
|
4586
|
+
hasLanguageSomeTranslations(lng) {
|
|
4587
|
+
const data = this.getDataByLanguage(lng);
|
|
4588
|
+
const n = data && Object.keys(data) || [];
|
|
4589
|
+
return !!n.find((v) => data[v] && Object.keys(data[v]).length > 0);
|
|
4590
|
+
}
|
|
4591
|
+
toJSON() {
|
|
4592
|
+
return this.data;
|
|
4593
|
+
}
|
|
4594
|
+
};
|
|
4595
|
+
var postProcessor = {
|
|
4596
|
+
processors: {},
|
|
4597
|
+
addPostProcessor(module) {
|
|
4598
|
+
this.processors[module.name] = module;
|
|
4599
|
+
},
|
|
4600
|
+
handle(processors, value, key, options, translator) {
|
|
4601
|
+
processors.forEach((processor) => {
|
|
4602
|
+
value = this.processors[processor]?.process(value, key, options, translator) ?? value;
|
|
4603
|
+
});
|
|
4604
|
+
return value;
|
|
4605
|
+
}
|
|
4606
|
+
};
|
|
4607
|
+
var checkedLoadedFor = {};
|
|
4608
|
+
var shouldHandleAsObject = (res) => !isString2(res) && typeof res !== "boolean" && typeof res !== "number";
|
|
4609
|
+
var Translator = class _Translator extends EventEmitter {
|
|
4610
|
+
constructor(services) {
|
|
4611
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
4612
|
+
super();
|
|
4613
|
+
copy(["resourceStore", "languageUtils", "pluralResolver", "interpolator", "backendConnector", "i18nFormat", "utils"], services, this);
|
|
4614
|
+
this.options = options;
|
|
4615
|
+
if (this.options.keySeparator === void 0) {
|
|
4616
|
+
this.options.keySeparator = ".";
|
|
4617
|
+
}
|
|
4618
|
+
this.logger = baseLogger.create("translator");
|
|
4619
|
+
}
|
|
4620
|
+
changeLanguage(lng) {
|
|
4621
|
+
if (lng) this.language = lng;
|
|
4622
|
+
}
|
|
4623
|
+
exists(key) {
|
|
4624
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
|
|
4625
|
+
interpolation: {}
|
|
4626
|
+
};
|
|
4627
|
+
if (key == null) {
|
|
4628
|
+
return false;
|
|
4629
|
+
}
|
|
4630
|
+
const resolved = this.resolve(key, options);
|
|
4631
|
+
return resolved?.res !== void 0;
|
|
4632
|
+
}
|
|
4633
|
+
extractFromKey(key, options) {
|
|
4634
|
+
let nsSeparator = options.nsSeparator !== void 0 ? options.nsSeparator : this.options.nsSeparator;
|
|
4635
|
+
if (nsSeparator === void 0) nsSeparator = ":";
|
|
4636
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
4637
|
+
let namespaces = options.ns || this.options.defaultNS || [];
|
|
4638
|
+
const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
|
|
4639
|
+
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
4640
|
+
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
4641
|
+
const m = key.match(this.interpolator.nestingRegexp);
|
|
4642
|
+
if (m && m.length > 0) {
|
|
4643
|
+
return {
|
|
4644
|
+
key,
|
|
4645
|
+
namespaces: isString2(namespaces) ? [namespaces] : namespaces
|
|
4646
|
+
};
|
|
4647
|
+
}
|
|
4648
|
+
const parts = key.split(nsSeparator);
|
|
4649
|
+
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
|
|
4650
|
+
key = parts.join(keySeparator);
|
|
4651
|
+
}
|
|
4652
|
+
return {
|
|
4653
|
+
key,
|
|
4654
|
+
namespaces: isString2(namespaces) ? [namespaces] : namespaces
|
|
4655
|
+
};
|
|
4656
|
+
}
|
|
4657
|
+
translate(keys, options, lastKey) {
|
|
4658
|
+
if (typeof options !== "object" && this.options.overloadTranslationOptionHandler) {
|
|
4659
|
+
options = this.options.overloadTranslationOptionHandler(arguments);
|
|
4660
|
+
}
|
|
4661
|
+
if (typeof options === "object") options = {
|
|
4662
|
+
...options
|
|
4663
|
+
};
|
|
4664
|
+
if (!options) options = {};
|
|
4665
|
+
if (keys == null) return "";
|
|
4666
|
+
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
4667
|
+
const returnDetails = options.returnDetails !== void 0 ? options.returnDetails : this.options.returnDetails;
|
|
4668
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
4669
|
+
const {
|
|
4670
|
+
key,
|
|
4671
|
+
namespaces
|
|
4672
|
+
} = this.extractFromKey(keys[keys.length - 1], options);
|
|
4673
|
+
const namespace = namespaces[namespaces.length - 1];
|
|
4674
|
+
const lng = options.lng || this.language;
|
|
4675
|
+
const appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
4676
|
+
if (lng?.toLowerCase() === "cimode") {
|
|
4677
|
+
if (appendNamespaceToCIMode) {
|
|
4678
|
+
const nsSeparator = options.nsSeparator || this.options.nsSeparator;
|
|
4679
|
+
if (returnDetails) {
|
|
4680
|
+
return {
|
|
4681
|
+
res: `${namespace}${nsSeparator}${key}`,
|
|
4682
|
+
usedKey: key,
|
|
4683
|
+
exactUsedKey: key,
|
|
4684
|
+
usedLng: lng,
|
|
4685
|
+
usedNS: namespace,
|
|
4686
|
+
usedParams: this.getUsedParamsDetails(options)
|
|
4687
|
+
};
|
|
4688
|
+
}
|
|
4689
|
+
return `${namespace}${nsSeparator}${key}`;
|
|
4690
|
+
}
|
|
4691
|
+
if (returnDetails) {
|
|
4692
|
+
return {
|
|
4693
|
+
res: key,
|
|
4694
|
+
usedKey: key,
|
|
4695
|
+
exactUsedKey: key,
|
|
4696
|
+
usedLng: lng,
|
|
4697
|
+
usedNS: namespace,
|
|
4698
|
+
usedParams: this.getUsedParamsDetails(options)
|
|
4699
|
+
};
|
|
4700
|
+
}
|
|
4701
|
+
return key;
|
|
4702
|
+
}
|
|
4703
|
+
const resolved = this.resolve(keys, options);
|
|
4704
|
+
let res = resolved?.res;
|
|
4705
|
+
const resUsedKey = resolved?.usedKey || key;
|
|
4706
|
+
const resExactUsedKey = resolved?.exactUsedKey || key;
|
|
4707
|
+
const noObject = ["[object Number]", "[object Function]", "[object RegExp]"];
|
|
4708
|
+
const joinArrays = options.joinArrays !== void 0 ? options.joinArrays : this.options.joinArrays;
|
|
4709
|
+
const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
4710
|
+
const needsPluralHandling = options.count !== void 0 && !isString2(options.count);
|
|
4711
|
+
const hasDefaultValue = _Translator.hasDefaultValue(options);
|
|
4712
|
+
const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : "";
|
|
4713
|
+
const defaultValueSuffixOrdinalFallback = options.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, {
|
|
4714
|
+
ordinal: false
|
|
4715
|
+
}) : "";
|
|
4716
|
+
const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0;
|
|
4717
|
+
const defaultValue = needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] || options[`defaultValue${defaultValueSuffix}`] || options[`defaultValue${defaultValueSuffixOrdinalFallback}`] || options.defaultValue;
|
|
4718
|
+
let resForObjHndl = res;
|
|
4719
|
+
if (handleAsObjectInI18nFormat && !res && hasDefaultValue) {
|
|
4720
|
+
resForObjHndl = defaultValue;
|
|
4721
|
+
}
|
|
4722
|
+
const handleAsObject = shouldHandleAsObject(resForObjHndl);
|
|
4723
|
+
const resType = Object.prototype.toString.apply(resForObjHndl);
|
|
4724
|
+
if (handleAsObjectInI18nFormat && resForObjHndl && handleAsObject && noObject.indexOf(resType) < 0 && !(isString2(joinArrays) && Array.isArray(resForObjHndl))) {
|
|
4725
|
+
if (!options.returnObjects && !this.options.returnObjects) {
|
|
4726
|
+
if (!this.options.returnedObjectHandler) {
|
|
4727
|
+
this.logger.warn("accessing an object - but returnObjects options is not enabled!");
|
|
4728
|
+
}
|
|
4729
|
+
const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, resForObjHndl, {
|
|
4730
|
+
...options,
|
|
4731
|
+
ns: namespaces
|
|
4732
|
+
}) : `key '${key} (${this.language})' returned an object instead of string.`;
|
|
4733
|
+
if (returnDetails) {
|
|
4734
|
+
resolved.res = r;
|
|
4735
|
+
resolved.usedParams = this.getUsedParamsDetails(options);
|
|
4736
|
+
return resolved;
|
|
4737
|
+
}
|
|
4738
|
+
return r;
|
|
4739
|
+
}
|
|
4740
|
+
if (keySeparator) {
|
|
4741
|
+
const resTypeIsArray = Array.isArray(resForObjHndl);
|
|
4742
|
+
const copy2 = resTypeIsArray ? [] : {};
|
|
4743
|
+
const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
4744
|
+
for (const m in resForObjHndl) {
|
|
4745
|
+
if (Object.prototype.hasOwnProperty.call(resForObjHndl, m)) {
|
|
4746
|
+
const deepKey = `${newKeyToUse}${keySeparator}${m}`;
|
|
4747
|
+
if (hasDefaultValue && !res) {
|
|
4748
|
+
copy2[m] = this.translate(deepKey, {
|
|
4749
|
+
...options,
|
|
4750
|
+
defaultValue: shouldHandleAsObject(defaultValue) ? defaultValue[m] : void 0,
|
|
4751
|
+
...{
|
|
4752
|
+
joinArrays: false,
|
|
4753
|
+
ns: namespaces
|
|
4754
|
+
}
|
|
4755
|
+
});
|
|
4756
|
+
} else {
|
|
4757
|
+
copy2[m] = this.translate(deepKey, {
|
|
4758
|
+
...options,
|
|
4759
|
+
...{
|
|
4760
|
+
joinArrays: false,
|
|
4761
|
+
ns: namespaces
|
|
4762
|
+
}
|
|
4763
|
+
});
|
|
4764
|
+
}
|
|
4765
|
+
if (copy2[m] === deepKey) copy2[m] = resForObjHndl[m];
|
|
4766
|
+
}
|
|
4767
|
+
}
|
|
4768
|
+
res = copy2;
|
|
4769
|
+
}
|
|
4770
|
+
} else if (handleAsObjectInI18nFormat && isString2(joinArrays) && Array.isArray(res)) {
|
|
4771
|
+
res = res.join(joinArrays);
|
|
4772
|
+
if (res) res = this.extendTranslation(res, keys, options, lastKey);
|
|
4773
|
+
} else {
|
|
4774
|
+
let usedDefault = false;
|
|
4775
|
+
let usedKey = false;
|
|
4776
|
+
if (!this.isValidLookup(res) && hasDefaultValue) {
|
|
4777
|
+
usedDefault = true;
|
|
4778
|
+
res = defaultValue;
|
|
4779
|
+
}
|
|
4780
|
+
if (!this.isValidLookup(res)) {
|
|
4781
|
+
usedKey = true;
|
|
4782
|
+
res = key;
|
|
4783
|
+
}
|
|
4784
|
+
const missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
|
|
4785
|
+
const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? void 0 : res;
|
|
4786
|
+
const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
4787
|
+
if (usedKey || usedDefault || updateMissing) {
|
|
4788
|
+
this.logger.log(updateMissing ? "updateKey" : "missingKey", lng, namespace, key, updateMissing ? defaultValue : res);
|
|
4789
|
+
if (keySeparator) {
|
|
4790
|
+
const fk = this.resolve(key, {
|
|
4791
|
+
...options,
|
|
4792
|
+
keySeparator: false
|
|
4793
|
+
});
|
|
4794
|
+
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.");
|
|
4795
|
+
}
|
|
4796
|
+
let lngs = [];
|
|
4797
|
+
const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
|
|
4798
|
+
if (this.options.saveMissingTo === "fallback" && fallbackLngs && fallbackLngs[0]) {
|
|
4799
|
+
for (let i = 0; i < fallbackLngs.length; i++) {
|
|
4800
|
+
lngs.push(fallbackLngs[i]);
|
|
4801
|
+
}
|
|
4802
|
+
} else if (this.options.saveMissingTo === "all") {
|
|
4803
|
+
lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
|
|
4804
|
+
} else {
|
|
4805
|
+
lngs.push(options.lng || this.language);
|
|
4806
|
+
}
|
|
4807
|
+
const send = (l, k, specificDefaultValue) => {
|
|
4808
|
+
const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
4809
|
+
if (this.options.missingKeyHandler) {
|
|
4810
|
+
this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
4811
|
+
} else if (this.backendConnector?.saveMissing) {
|
|
4812
|
+
this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
4813
|
+
}
|
|
4814
|
+
this.emit("missingKey", l, namespace, k, res);
|
|
4815
|
+
};
|
|
4816
|
+
if (this.options.saveMissing) {
|
|
4817
|
+
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
4818
|
+
lngs.forEach((language) => {
|
|
4819
|
+
const suffixes = this.pluralResolver.getSuffixes(language, options);
|
|
4820
|
+
if (needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.indexOf(`${this.options.pluralSeparator}zero`) < 0) {
|
|
4821
|
+
suffixes.push(`${this.options.pluralSeparator}zero`);
|
|
4822
|
+
}
|
|
4823
|
+
suffixes.forEach((suffix) => {
|
|
4824
|
+
send([language], key + suffix, options[`defaultValue${suffix}`] || defaultValue);
|
|
4825
|
+
});
|
|
4826
|
+
});
|
|
4827
|
+
} else {
|
|
4828
|
+
send(lngs, key, defaultValue);
|
|
4829
|
+
}
|
|
4830
|
+
}
|
|
4831
|
+
}
|
|
4832
|
+
res = this.extendTranslation(res, keys, options, resolved, lastKey);
|
|
4833
|
+
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
|
|
4834
|
+
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
|
|
4835
|
+
res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : void 0);
|
|
4836
|
+
}
|
|
4837
|
+
}
|
|
4838
|
+
if (returnDetails) {
|
|
4839
|
+
resolved.res = res;
|
|
4840
|
+
resolved.usedParams = this.getUsedParamsDetails(options);
|
|
4841
|
+
return resolved;
|
|
4842
|
+
}
|
|
4843
|
+
return res;
|
|
4844
|
+
}
|
|
4845
|
+
extendTranslation(res, key, options, resolved, lastKey) {
|
|
4846
|
+
var _this = this;
|
|
4847
|
+
if (this.i18nFormat?.parse) {
|
|
4848
|
+
res = this.i18nFormat.parse(res, {
|
|
4849
|
+
...this.options.interpolation.defaultVariables,
|
|
4850
|
+
...options
|
|
4851
|
+
}, options.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
|
|
4852
|
+
resolved
|
|
4853
|
+
});
|
|
4854
|
+
} else if (!options.skipInterpolation) {
|
|
4855
|
+
if (options.interpolation) this.interpolator.init({
|
|
4856
|
+
...options,
|
|
4857
|
+
...{
|
|
4858
|
+
interpolation: {
|
|
4859
|
+
...this.options.interpolation,
|
|
4860
|
+
...options.interpolation
|
|
4861
|
+
}
|
|
4862
|
+
}
|
|
4863
|
+
});
|
|
4864
|
+
const skipOnVariables = isString2(res) && (options?.interpolation?.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
4865
|
+
let nestBef;
|
|
4866
|
+
if (skipOnVariables) {
|
|
4867
|
+
const nb = res.match(this.interpolator.nestingRegexp);
|
|
4868
|
+
nestBef = nb && nb.length;
|
|
4869
|
+
}
|
|
4870
|
+
let data = options.replace && !isString2(options.replace) ? options.replace : options;
|
|
4871
|
+
if (this.options.interpolation.defaultVariables) data = {
|
|
4872
|
+
...this.options.interpolation.defaultVariables,
|
|
4873
|
+
...data
|
|
4874
|
+
};
|
|
4875
|
+
res = this.interpolator.interpolate(res, data, options.lng || this.language || resolved.usedLng, options);
|
|
4876
|
+
if (skipOnVariables) {
|
|
4877
|
+
const na = res.match(this.interpolator.nestingRegexp);
|
|
4878
|
+
const nestAft = na && na.length;
|
|
4879
|
+
if (nestBef < nestAft) options.nest = false;
|
|
4880
|
+
}
|
|
4881
|
+
if (!options.lng && resolved && resolved.res) options.lng = this.language || resolved.usedLng;
|
|
4882
|
+
if (options.nest !== false) res = this.interpolator.nest(res, function() {
|
|
4883
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4884
|
+
args[_key] = arguments[_key];
|
|
4885
|
+
}
|
|
4886
|
+
if (lastKey?.[0] === args[0] && !options.context) {
|
|
4887
|
+
_this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
|
|
4888
|
+
return null;
|
|
4889
|
+
}
|
|
4890
|
+
return _this.translate(...args, key);
|
|
4891
|
+
}, options);
|
|
4892
|
+
if (options.interpolation) this.interpolator.reset();
|
|
4893
|
+
}
|
|
4894
|
+
const postProcess = options.postProcess || this.options.postProcess;
|
|
4895
|
+
const postProcessorNames = isString2(postProcess) ? [postProcess] : postProcess;
|
|
4896
|
+
if (res != null && postProcessorNames?.length && options.applyPostProcessor !== false) {
|
|
4897
|
+
res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
|
|
4898
|
+
i18nResolved: {
|
|
4899
|
+
...resolved,
|
|
4900
|
+
usedParams: this.getUsedParamsDetails(options)
|
|
4901
|
+
},
|
|
4902
|
+
...options
|
|
4903
|
+
} : options, this);
|
|
4904
|
+
}
|
|
4905
|
+
return res;
|
|
4906
|
+
}
|
|
4907
|
+
resolve(keys) {
|
|
4908
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
4909
|
+
let found;
|
|
4910
|
+
let usedKey;
|
|
4911
|
+
let exactUsedKey;
|
|
4912
|
+
let usedLng;
|
|
4913
|
+
let usedNS;
|
|
4914
|
+
if (isString2(keys)) keys = [keys];
|
|
4915
|
+
keys.forEach((k) => {
|
|
4916
|
+
if (this.isValidLookup(found)) return;
|
|
4917
|
+
const extracted = this.extractFromKey(k, options);
|
|
4918
|
+
const key = extracted.key;
|
|
4919
|
+
usedKey = key;
|
|
4920
|
+
let namespaces = extracted.namespaces;
|
|
4921
|
+
if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
|
|
4922
|
+
const needsPluralHandling = options.count !== void 0 && !isString2(options.count);
|
|
4923
|
+
const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0;
|
|
4924
|
+
const needsContextHandling = options.context !== void 0 && (isString2(options.context) || typeof options.context === "number") && options.context !== "";
|
|
4925
|
+
const codes = options.lngs ? options.lngs : this.languageUtils.toResolveHierarchy(options.lng || this.language, options.fallbackLng);
|
|
4926
|
+
namespaces.forEach((ns) => {
|
|
4927
|
+
if (this.isValidLookup(found)) return;
|
|
4928
|
+
usedNS = ns;
|
|
4929
|
+
if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils?.hasLoadedNamespace && !this.utils?.hasLoadedNamespace(usedNS)) {
|
|
4930
|
+
checkedLoadedFor[`${codes[0]}-${ns}`] = true;
|
|
4931
|
+
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!!!");
|
|
4932
|
+
}
|
|
4933
|
+
codes.forEach((code) => {
|
|
4934
|
+
if (this.isValidLookup(found)) return;
|
|
4935
|
+
usedLng = code;
|
|
4936
|
+
const finalKeys = [key];
|
|
4937
|
+
if (this.i18nFormat?.addLookupKeys) {
|
|
4938
|
+
this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
|
|
4939
|
+
} else {
|
|
4940
|
+
let pluralSuffix;
|
|
4941
|
+
if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, options.count, options);
|
|
4942
|
+
const zeroSuffix = `${this.options.pluralSeparator}zero`;
|
|
4943
|
+
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
|
|
4944
|
+
if (needsPluralHandling) {
|
|
4945
|
+
finalKeys.push(key + pluralSuffix);
|
|
4946
|
+
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
4947
|
+
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
4948
|
+
}
|
|
4949
|
+
if (needsZeroSuffixLookup) {
|
|
4950
|
+
finalKeys.push(key + zeroSuffix);
|
|
4951
|
+
}
|
|
4952
|
+
}
|
|
4953
|
+
if (needsContextHandling) {
|
|
4954
|
+
const contextKey = `${key}${this.options.contextSeparator}${options.context}`;
|
|
4955
|
+
finalKeys.push(contextKey);
|
|
4956
|
+
if (needsPluralHandling) {
|
|
4957
|
+
finalKeys.push(contextKey + pluralSuffix);
|
|
4958
|
+
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
4959
|
+
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
4960
|
+
}
|
|
4961
|
+
if (needsZeroSuffixLookup) {
|
|
4962
|
+
finalKeys.push(contextKey + zeroSuffix);
|
|
4963
|
+
}
|
|
4964
|
+
}
|
|
4965
|
+
}
|
|
4966
|
+
}
|
|
4967
|
+
let possibleKey;
|
|
4968
|
+
while (possibleKey = finalKeys.pop()) {
|
|
4969
|
+
if (!this.isValidLookup(found)) {
|
|
4970
|
+
exactUsedKey = possibleKey;
|
|
4971
|
+
found = this.getResource(code, ns, possibleKey, options);
|
|
4972
|
+
}
|
|
4973
|
+
}
|
|
4974
|
+
});
|
|
4975
|
+
});
|
|
4976
|
+
});
|
|
4977
|
+
return {
|
|
4978
|
+
res: found,
|
|
4979
|
+
usedKey,
|
|
4980
|
+
exactUsedKey,
|
|
4981
|
+
usedLng,
|
|
4982
|
+
usedNS
|
|
4983
|
+
};
|
|
4984
|
+
}
|
|
4985
|
+
isValidLookup(res) {
|
|
4986
|
+
return res !== void 0 && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === "");
|
|
4987
|
+
}
|
|
4988
|
+
getResource(code, ns, key) {
|
|
4989
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
4990
|
+
if (this.i18nFormat?.getResource) return this.i18nFormat.getResource(code, ns, key, options);
|
|
4991
|
+
return this.resourceStore.getResource(code, ns, key, options);
|
|
4992
|
+
}
|
|
4993
|
+
getUsedParamsDetails() {
|
|
4994
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
4995
|
+
const optionsKeys = ["defaultValue", "ordinal", "context", "replace", "lng", "lngs", "fallbackLng", "ns", "keySeparator", "nsSeparator", "returnObjects", "returnDetails", "joinArrays", "postProcess", "interpolation"];
|
|
4996
|
+
const useOptionsReplaceForData = options.replace && !isString2(options.replace);
|
|
4997
|
+
let data = useOptionsReplaceForData ? options.replace : options;
|
|
4998
|
+
if (useOptionsReplaceForData && typeof options.count !== "undefined") {
|
|
4999
|
+
data.count = options.count;
|
|
5000
|
+
}
|
|
5001
|
+
if (this.options.interpolation.defaultVariables) {
|
|
5002
|
+
data = {
|
|
5003
|
+
...this.options.interpolation.defaultVariables,
|
|
5004
|
+
...data
|
|
5005
|
+
};
|
|
5006
|
+
}
|
|
5007
|
+
if (!useOptionsReplaceForData) {
|
|
5008
|
+
data = {
|
|
5009
|
+
...data
|
|
5010
|
+
};
|
|
5011
|
+
for (const key of optionsKeys) {
|
|
5012
|
+
delete data[key];
|
|
5013
|
+
}
|
|
5014
|
+
}
|
|
5015
|
+
return data;
|
|
5016
|
+
}
|
|
5017
|
+
static hasDefaultValue(options) {
|
|
5018
|
+
const prefix = "defaultValue";
|
|
5019
|
+
for (const option in options) {
|
|
5020
|
+
if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && void 0 !== options[option]) {
|
|
5021
|
+
return true;
|
|
5022
|
+
}
|
|
5023
|
+
}
|
|
5024
|
+
return false;
|
|
5025
|
+
}
|
|
5026
|
+
};
|
|
5027
|
+
var LanguageUtil = class {
|
|
5028
|
+
constructor(options) {
|
|
5029
|
+
this.options = options;
|
|
5030
|
+
this.supportedLngs = this.options.supportedLngs || false;
|
|
5031
|
+
this.logger = baseLogger.create("languageUtils");
|
|
5032
|
+
}
|
|
5033
|
+
getScriptPartFromCode(code) {
|
|
5034
|
+
code = getCleanedCode(code);
|
|
5035
|
+
if (!code || code.indexOf("-") < 0) return null;
|
|
5036
|
+
const p = code.split("-");
|
|
5037
|
+
if (p.length === 2) return null;
|
|
5038
|
+
p.pop();
|
|
5039
|
+
if (p[p.length - 1].toLowerCase() === "x") return null;
|
|
5040
|
+
return this.formatLanguageCode(p.join("-"));
|
|
5041
|
+
}
|
|
5042
|
+
getLanguagePartFromCode(code) {
|
|
5043
|
+
code = getCleanedCode(code);
|
|
5044
|
+
if (!code || code.indexOf("-") < 0) return code;
|
|
5045
|
+
const p = code.split("-");
|
|
5046
|
+
return this.formatLanguageCode(p[0]);
|
|
5047
|
+
}
|
|
5048
|
+
formatLanguageCode(code) {
|
|
5049
|
+
if (isString2(code) && code.indexOf("-") > -1) {
|
|
5050
|
+
let formattedCode;
|
|
5051
|
+
try {
|
|
5052
|
+
formattedCode = Intl.getCanonicalLocales(code)[0];
|
|
5053
|
+
} catch (e2) {
|
|
5054
|
+
}
|
|
5055
|
+
if (formattedCode && this.options.lowerCaseLng) {
|
|
5056
|
+
formattedCode = formattedCode.toLowerCase();
|
|
5057
|
+
}
|
|
5058
|
+
if (formattedCode) return formattedCode;
|
|
5059
|
+
if (this.options.lowerCaseLng) {
|
|
5060
|
+
return code.toLowerCase();
|
|
5061
|
+
}
|
|
5062
|
+
return code;
|
|
5063
|
+
}
|
|
5064
|
+
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
|
|
5065
|
+
}
|
|
5066
|
+
isSupportedCode(code) {
|
|
5067
|
+
if (this.options.load === "languageOnly" || this.options.nonExplicitSupportedLngs) {
|
|
5068
|
+
code = this.getLanguagePartFromCode(code);
|
|
5069
|
+
}
|
|
5070
|
+
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
|
|
5071
|
+
}
|
|
5072
|
+
getBestMatchFromCodes(codes) {
|
|
5073
|
+
if (!codes) return null;
|
|
5074
|
+
let found;
|
|
5075
|
+
codes.forEach((code) => {
|
|
5076
|
+
if (found) return;
|
|
5077
|
+
const cleanedLng = this.formatLanguageCode(code);
|
|
5078
|
+
if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
|
|
5079
|
+
});
|
|
5080
|
+
if (!found && this.options.supportedLngs) {
|
|
5081
|
+
codes.forEach((code) => {
|
|
5082
|
+
if (found) return;
|
|
5083
|
+
const lngOnly = this.getLanguagePartFromCode(code);
|
|
5084
|
+
if (this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
5085
|
+
found = this.options.supportedLngs.find((supportedLng) => {
|
|
5086
|
+
if (supportedLng === lngOnly) return supportedLng;
|
|
5087
|
+
if (supportedLng.indexOf("-") < 0 && lngOnly.indexOf("-") < 0) return;
|
|
5088
|
+
if (supportedLng.indexOf("-") > 0 && lngOnly.indexOf("-") < 0 && supportedLng.substring(0, supportedLng.indexOf("-")) === lngOnly) return supportedLng;
|
|
5089
|
+
if (supportedLng.indexOf(lngOnly) === 0 && lngOnly.length > 1) return supportedLng;
|
|
5090
|
+
});
|
|
5091
|
+
});
|
|
5092
|
+
}
|
|
5093
|
+
if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
|
|
5094
|
+
return found;
|
|
5095
|
+
}
|
|
5096
|
+
getFallbackCodes(fallbacks, code) {
|
|
5097
|
+
if (!fallbacks) return [];
|
|
5098
|
+
if (typeof fallbacks === "function") fallbacks = fallbacks(code);
|
|
5099
|
+
if (isString2(fallbacks)) fallbacks = [fallbacks];
|
|
5100
|
+
if (Array.isArray(fallbacks)) return fallbacks;
|
|
5101
|
+
if (!code) return fallbacks.default || [];
|
|
5102
|
+
let found = fallbacks[code];
|
|
5103
|
+
if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
|
|
5104
|
+
if (!found) found = fallbacks[this.formatLanguageCode(code)];
|
|
5105
|
+
if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
5106
|
+
if (!found) found = fallbacks.default;
|
|
5107
|
+
return found || [];
|
|
5108
|
+
}
|
|
5109
|
+
toResolveHierarchy(code, fallbackCode) {
|
|
5110
|
+
const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
|
|
5111
|
+
const codes = [];
|
|
5112
|
+
const addCode = (c) => {
|
|
5113
|
+
if (!c) return;
|
|
5114
|
+
if (this.isSupportedCode(c)) {
|
|
5115
|
+
codes.push(c);
|
|
5116
|
+
} else {
|
|
5117
|
+
this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
|
|
5118
|
+
}
|
|
5119
|
+
};
|
|
5120
|
+
if (isString2(code) && (code.indexOf("-") > -1 || code.indexOf("_") > -1)) {
|
|
5121
|
+
if (this.options.load !== "languageOnly") addCode(this.formatLanguageCode(code));
|
|
5122
|
+
if (this.options.load !== "languageOnly" && this.options.load !== "currentOnly") addCode(this.getScriptPartFromCode(code));
|
|
5123
|
+
if (this.options.load !== "currentOnly") addCode(this.getLanguagePartFromCode(code));
|
|
5124
|
+
} else if (isString2(code)) {
|
|
5125
|
+
addCode(this.formatLanguageCode(code));
|
|
5126
|
+
}
|
|
5127
|
+
fallbackCodes.forEach((fc) => {
|
|
5128
|
+
if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
|
|
5129
|
+
});
|
|
5130
|
+
return codes;
|
|
5131
|
+
}
|
|
5132
|
+
};
|
|
5133
|
+
var suffixesOrder = {
|
|
5134
|
+
zero: 0,
|
|
5135
|
+
one: 1,
|
|
5136
|
+
two: 2,
|
|
5137
|
+
few: 3,
|
|
5138
|
+
many: 4,
|
|
5139
|
+
other: 5
|
|
5140
|
+
};
|
|
5141
|
+
var dummyRule = {
|
|
5142
|
+
select: (count) => count === 1 ? "one" : "other",
|
|
5143
|
+
resolvedOptions: () => ({
|
|
5144
|
+
pluralCategories: ["one", "other"]
|
|
5145
|
+
})
|
|
5146
|
+
};
|
|
5147
|
+
var PluralResolver = class {
|
|
5148
|
+
constructor(languageUtils) {
|
|
5149
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
5150
|
+
this.languageUtils = languageUtils;
|
|
5151
|
+
this.options = options;
|
|
5152
|
+
this.logger = baseLogger.create("pluralResolver");
|
|
5153
|
+
this.pluralRulesCache = {};
|
|
5154
|
+
}
|
|
5155
|
+
addRule(lng, obj) {
|
|
5156
|
+
this.rules[lng] = obj;
|
|
5157
|
+
}
|
|
5158
|
+
clearCache() {
|
|
5159
|
+
this.pluralRulesCache = {};
|
|
5160
|
+
}
|
|
5161
|
+
getRule(code) {
|
|
5162
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
5163
|
+
const cleanedCode = getCleanedCode(code === "dev" ? "en" : code);
|
|
5164
|
+
const type = options.ordinal ? "ordinal" : "cardinal";
|
|
5165
|
+
const cacheKey = JSON.stringify({
|
|
5166
|
+
cleanedCode,
|
|
5167
|
+
type
|
|
5168
|
+
});
|
|
5169
|
+
if (cacheKey in this.pluralRulesCache) {
|
|
5170
|
+
return this.pluralRulesCache[cacheKey];
|
|
5171
|
+
}
|
|
5172
|
+
let rule;
|
|
5173
|
+
try {
|
|
5174
|
+
rule = new Intl.PluralRules(cleanedCode, {
|
|
5175
|
+
type
|
|
5176
|
+
});
|
|
5177
|
+
} catch (err) {
|
|
5178
|
+
if (!Intl) {
|
|
5179
|
+
this.logger.error("No Intl support, please use an Intl polyfill!");
|
|
5180
|
+
return dummyRule;
|
|
5181
|
+
}
|
|
5182
|
+
if (!code.match(/-|_/)) return dummyRule;
|
|
5183
|
+
const lngPart = this.languageUtils.getLanguagePartFromCode(code);
|
|
5184
|
+
rule = this.getRule(lngPart, options);
|
|
5185
|
+
}
|
|
5186
|
+
this.pluralRulesCache[cacheKey] = rule;
|
|
5187
|
+
return rule;
|
|
5188
|
+
}
|
|
5189
|
+
needsPlural(code) {
|
|
5190
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
5191
|
+
let rule = this.getRule(code, options);
|
|
5192
|
+
if (!rule) rule = this.getRule("dev", options);
|
|
5193
|
+
return rule?.resolvedOptions().pluralCategories.length > 1;
|
|
5194
|
+
}
|
|
5195
|
+
getPluralFormsOfKey(code, key) {
|
|
5196
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
5197
|
+
return this.getSuffixes(code, options).map((suffix) => `${key}${suffix}`);
|
|
5198
|
+
}
|
|
5199
|
+
getSuffixes(code) {
|
|
5200
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
5201
|
+
let rule = this.getRule(code, options);
|
|
5202
|
+
if (!rule) rule = this.getRule("dev", options);
|
|
5203
|
+
if (!rule) return [];
|
|
5204
|
+
return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map((pluralCategory) => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${pluralCategory}`);
|
|
5205
|
+
}
|
|
5206
|
+
getSuffix(code, count) {
|
|
5207
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
5208
|
+
const rule = this.getRule(code, options);
|
|
5209
|
+
if (rule) {
|
|
5210
|
+
return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${rule.select(count)}`;
|
|
5211
|
+
}
|
|
5212
|
+
this.logger.warn(`no plural rule found for: ${code}`);
|
|
5213
|
+
return this.getSuffix("dev", count, options);
|
|
5214
|
+
}
|
|
5215
|
+
};
|
|
5216
|
+
var deepFindWithDefaults = function(data, defaultData, key) {
|
|
5217
|
+
let keySeparator = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : ".";
|
|
5218
|
+
let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : true;
|
|
5219
|
+
let path2 = getPathWithDefaults(data, defaultData, key);
|
|
5220
|
+
if (!path2 && ignoreJSONStructure && isString2(key)) {
|
|
5221
|
+
path2 = deepFind(data, key, keySeparator);
|
|
5222
|
+
if (path2 === void 0) path2 = deepFind(defaultData, key, keySeparator);
|
|
5223
|
+
}
|
|
5224
|
+
return path2;
|
|
5225
|
+
};
|
|
5226
|
+
var regexSafe = (val) => val.replace(/\$/g, "$$$$");
|
|
5227
|
+
var Interpolator = class {
|
|
5228
|
+
constructor() {
|
|
5229
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
5230
|
+
this.logger = baseLogger.create("interpolator");
|
|
5231
|
+
this.options = options;
|
|
5232
|
+
this.format = options?.interpolation?.format || ((value) => value);
|
|
5233
|
+
this.init(options);
|
|
5234
|
+
}
|
|
5235
|
+
init() {
|
|
5236
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
5237
|
+
if (!options.interpolation) options.interpolation = {
|
|
5238
|
+
escapeValue: true
|
|
5239
|
+
};
|
|
5240
|
+
const {
|
|
5241
|
+
escape: escape$1,
|
|
5242
|
+
escapeValue,
|
|
5243
|
+
useRawValueToEscape,
|
|
5244
|
+
prefix,
|
|
5245
|
+
prefixEscaped,
|
|
5246
|
+
suffix,
|
|
5247
|
+
suffixEscaped,
|
|
5248
|
+
formatSeparator,
|
|
5249
|
+
unescapeSuffix,
|
|
5250
|
+
unescapePrefix,
|
|
5251
|
+
nestingPrefix,
|
|
5252
|
+
nestingPrefixEscaped,
|
|
5253
|
+
nestingSuffix,
|
|
5254
|
+
nestingSuffixEscaped,
|
|
5255
|
+
nestingOptionsSeparator,
|
|
5256
|
+
maxReplaces,
|
|
5257
|
+
alwaysFormat
|
|
5258
|
+
} = options.interpolation;
|
|
5259
|
+
this.escape = escape$1 !== void 0 ? escape$1 : escape;
|
|
5260
|
+
this.escapeValue = escapeValue !== void 0 ? escapeValue : true;
|
|
5261
|
+
this.useRawValueToEscape = useRawValueToEscape !== void 0 ? useRawValueToEscape : false;
|
|
5262
|
+
this.prefix = prefix ? regexEscape(prefix) : prefixEscaped || "{{";
|
|
5263
|
+
this.suffix = suffix ? regexEscape(suffix) : suffixEscaped || "}}";
|
|
5264
|
+
this.formatSeparator = formatSeparator || ",";
|
|
5265
|
+
this.unescapePrefix = unescapeSuffix ? "" : unescapePrefix || "-";
|
|
5266
|
+
this.unescapeSuffix = this.unescapePrefix ? "" : unescapeSuffix || "";
|
|
5267
|
+
this.nestingPrefix = nestingPrefix ? regexEscape(nestingPrefix) : nestingPrefixEscaped || regexEscape("$t(");
|
|
5268
|
+
this.nestingSuffix = nestingSuffix ? regexEscape(nestingSuffix) : nestingSuffixEscaped || regexEscape(")");
|
|
5269
|
+
this.nestingOptionsSeparator = nestingOptionsSeparator || ",";
|
|
5270
|
+
this.maxReplaces = maxReplaces || 1e3;
|
|
5271
|
+
this.alwaysFormat = alwaysFormat !== void 0 ? alwaysFormat : false;
|
|
5272
|
+
this.resetRegExp();
|
|
5273
|
+
}
|
|
5274
|
+
reset() {
|
|
5275
|
+
if (this.options) this.init(this.options);
|
|
5276
|
+
}
|
|
5277
|
+
resetRegExp() {
|
|
5278
|
+
const getOrResetRegExp = (existingRegExp, pattern) => {
|
|
5279
|
+
if (existingRegExp?.source === pattern) {
|
|
5280
|
+
existingRegExp.lastIndex = 0;
|
|
5281
|
+
return existingRegExp;
|
|
5282
|
+
}
|
|
5283
|
+
return new RegExp(pattern, "g");
|
|
5284
|
+
};
|
|
5285
|
+
this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
|
|
5286
|
+
this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
|
|
5287
|
+
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}(.+?)${this.nestingSuffix}`);
|
|
5288
|
+
}
|
|
5289
|
+
interpolate(str, data, lng, options) {
|
|
5290
|
+
let match;
|
|
5291
|
+
let value;
|
|
5292
|
+
let replaces;
|
|
5293
|
+
const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
5294
|
+
const handleFormat = (key) => {
|
|
5295
|
+
if (key.indexOf(this.formatSeparator) < 0) {
|
|
5296
|
+
const path2 = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
|
|
5297
|
+
return this.alwaysFormat ? this.format(path2, void 0, lng, {
|
|
5298
|
+
...options,
|
|
5299
|
+
...data,
|
|
5300
|
+
interpolationkey: key
|
|
5301
|
+
}) : path2;
|
|
5302
|
+
}
|
|
5303
|
+
const p = key.split(this.formatSeparator);
|
|
5304
|
+
const k = p.shift().trim();
|
|
5305
|
+
const f = p.join(this.formatSeparator).trim();
|
|
5306
|
+
return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
|
|
5307
|
+
...options,
|
|
5308
|
+
...data,
|
|
5309
|
+
interpolationkey: k
|
|
5310
|
+
});
|
|
5311
|
+
};
|
|
5312
|
+
this.resetRegExp();
|
|
5313
|
+
const missingInterpolationHandler = options?.missingInterpolationHandler || this.options.missingInterpolationHandler;
|
|
5314
|
+
const skipOnVariables = options?.interpolation?.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
|
|
5315
|
+
const todos = [{
|
|
5316
|
+
regex: this.regexpUnescape,
|
|
5317
|
+
safeValue: (val) => regexSafe(val)
|
|
5318
|
+
}, {
|
|
5319
|
+
regex: this.regexp,
|
|
5320
|
+
safeValue: (val) => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
|
|
5321
|
+
}];
|
|
5322
|
+
todos.forEach((todo) => {
|
|
5323
|
+
replaces = 0;
|
|
5324
|
+
while (match = todo.regex.exec(str)) {
|
|
5325
|
+
const matchedVar = match[1].trim();
|
|
5326
|
+
value = handleFormat(matchedVar);
|
|
5327
|
+
if (value === void 0) {
|
|
5328
|
+
if (typeof missingInterpolationHandler === "function") {
|
|
5329
|
+
const temp = missingInterpolationHandler(str, match, options);
|
|
5330
|
+
value = isString2(temp) ? temp : "";
|
|
5331
|
+
} else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
|
|
5332
|
+
value = "";
|
|
5333
|
+
} else if (skipOnVariables) {
|
|
5334
|
+
value = match[0];
|
|
5335
|
+
continue;
|
|
5336
|
+
} else {
|
|
5337
|
+
this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
|
|
5338
|
+
value = "";
|
|
5339
|
+
}
|
|
5340
|
+
} else if (!isString2(value) && !this.useRawValueToEscape) {
|
|
5341
|
+
value = makeString(value);
|
|
5342
|
+
}
|
|
5343
|
+
const safeValue = todo.safeValue(value);
|
|
5344
|
+
str = str.replace(match[0], safeValue);
|
|
5345
|
+
if (skipOnVariables) {
|
|
5346
|
+
todo.regex.lastIndex += value.length;
|
|
5347
|
+
todo.regex.lastIndex -= match[0].length;
|
|
5348
|
+
} else {
|
|
5349
|
+
todo.regex.lastIndex = 0;
|
|
5350
|
+
}
|
|
5351
|
+
replaces++;
|
|
5352
|
+
if (replaces >= this.maxReplaces) {
|
|
5353
|
+
break;
|
|
5354
|
+
}
|
|
5355
|
+
}
|
|
5356
|
+
});
|
|
5357
|
+
return str;
|
|
5358
|
+
}
|
|
5359
|
+
nest(str, fc) {
|
|
5360
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
5361
|
+
let match;
|
|
5362
|
+
let value;
|
|
5363
|
+
let clonedOptions;
|
|
5364
|
+
const handleHasOptions = (key, inheritedOptions) => {
|
|
5365
|
+
const sep = this.nestingOptionsSeparator;
|
|
5366
|
+
if (key.indexOf(sep) < 0) return key;
|
|
5367
|
+
const c = key.split(new RegExp(`${sep}[ ]*{`));
|
|
5368
|
+
let optionsString = `{${c[1]}`;
|
|
5369
|
+
key = c[0];
|
|
5370
|
+
optionsString = this.interpolate(optionsString, clonedOptions);
|
|
5371
|
+
const matchedSingleQuotes = optionsString.match(/'/g);
|
|
5372
|
+
const matchedDoubleQuotes = optionsString.match(/"/g);
|
|
5373
|
+
if ((matchedSingleQuotes?.length ?? 0) % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
|
|
5374
|
+
optionsString = optionsString.replace(/'/g, '"');
|
|
5375
|
+
}
|
|
5376
|
+
try {
|
|
5377
|
+
clonedOptions = JSON.parse(optionsString);
|
|
5378
|
+
if (inheritedOptions) clonedOptions = {
|
|
5379
|
+
...inheritedOptions,
|
|
5380
|
+
...clonedOptions
|
|
5381
|
+
};
|
|
5382
|
+
} catch (e2) {
|
|
5383
|
+
this.logger.warn(`failed parsing options string in nesting for key ${key}`, e2);
|
|
5384
|
+
return `${key}${sep}${optionsString}`;
|
|
5385
|
+
}
|
|
5386
|
+
if (clonedOptions.defaultValue && clonedOptions.defaultValue.indexOf(this.prefix) > -1) delete clonedOptions.defaultValue;
|
|
5387
|
+
return key;
|
|
5388
|
+
};
|
|
5389
|
+
while (match = this.nestingRegexp.exec(str)) {
|
|
5390
|
+
let formatters = [];
|
|
5391
|
+
clonedOptions = {
|
|
5392
|
+
...options
|
|
5393
|
+
};
|
|
5394
|
+
clonedOptions = clonedOptions.replace && !isString2(clonedOptions.replace) ? clonedOptions.replace : clonedOptions;
|
|
5395
|
+
clonedOptions.applyPostProcessor = false;
|
|
5396
|
+
delete clonedOptions.defaultValue;
|
|
5397
|
+
let doReduce = false;
|
|
5398
|
+
if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
|
|
5399
|
+
const r = match[1].split(this.formatSeparator).map((elem) => elem.trim());
|
|
5400
|
+
match[1] = r.shift();
|
|
5401
|
+
formatters = r;
|
|
5402
|
+
doReduce = true;
|
|
5403
|
+
}
|
|
5404
|
+
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
5405
|
+
if (value && match[0] === str && !isString2(value)) return value;
|
|
5406
|
+
if (!isString2(value)) value = makeString(value);
|
|
5407
|
+
if (!value) {
|
|
5408
|
+
this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
|
|
5409
|
+
value = "";
|
|
5410
|
+
}
|
|
5411
|
+
if (doReduce) {
|
|
5412
|
+
value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
|
|
5413
|
+
...options,
|
|
5414
|
+
interpolationkey: match[1].trim()
|
|
5415
|
+
}), value.trim());
|
|
5416
|
+
}
|
|
5417
|
+
str = str.replace(match[0], value);
|
|
5418
|
+
this.regexp.lastIndex = 0;
|
|
5419
|
+
}
|
|
5420
|
+
return str;
|
|
5421
|
+
}
|
|
5422
|
+
};
|
|
5423
|
+
var parseFormatStr = (formatStr) => {
|
|
5424
|
+
let formatName = formatStr.toLowerCase().trim();
|
|
5425
|
+
const formatOptions = {};
|
|
5426
|
+
if (formatStr.indexOf("(") > -1) {
|
|
5427
|
+
const p = formatStr.split("(");
|
|
5428
|
+
formatName = p[0].toLowerCase().trim();
|
|
5429
|
+
const optStr = p[1].substring(0, p[1].length - 1);
|
|
5430
|
+
if (formatName === "currency" && optStr.indexOf(":") < 0) {
|
|
5431
|
+
if (!formatOptions.currency) formatOptions.currency = optStr.trim();
|
|
5432
|
+
} else if (formatName === "relativetime" && optStr.indexOf(":") < 0) {
|
|
5433
|
+
if (!formatOptions.range) formatOptions.range = optStr.trim();
|
|
5434
|
+
} else {
|
|
5435
|
+
const opts = optStr.split(";");
|
|
5436
|
+
opts.forEach((opt) => {
|
|
5437
|
+
if (opt) {
|
|
5438
|
+
const [key, ...rest] = opt.split(":");
|
|
5439
|
+
const val = rest.join(":").trim().replace(/^'+|'+$/g, "");
|
|
5440
|
+
const trimmedKey = key.trim();
|
|
5441
|
+
if (!formatOptions[trimmedKey]) formatOptions[trimmedKey] = val;
|
|
5442
|
+
if (val === "false") formatOptions[trimmedKey] = false;
|
|
5443
|
+
if (val === "true") formatOptions[trimmedKey] = true;
|
|
5444
|
+
if (!isNaN(val)) formatOptions[trimmedKey] = parseInt(val, 10);
|
|
5445
|
+
}
|
|
5446
|
+
});
|
|
5447
|
+
}
|
|
5448
|
+
}
|
|
5449
|
+
return {
|
|
5450
|
+
formatName,
|
|
5451
|
+
formatOptions
|
|
5452
|
+
};
|
|
5453
|
+
};
|
|
5454
|
+
var createCachedFormatter = (fn) => {
|
|
5455
|
+
const cache = {};
|
|
5456
|
+
return (val, lng, options) => {
|
|
5457
|
+
let optForCache = options;
|
|
5458
|
+
if (options && options.interpolationkey && options.formatParams && options.formatParams[options.interpolationkey] && options[options.interpolationkey]) {
|
|
5459
|
+
optForCache = {
|
|
5460
|
+
...optForCache,
|
|
5461
|
+
[options.interpolationkey]: void 0
|
|
5462
|
+
};
|
|
5463
|
+
}
|
|
5464
|
+
const key = lng + JSON.stringify(optForCache);
|
|
5465
|
+
let formatter = cache[key];
|
|
5466
|
+
if (!formatter) {
|
|
5467
|
+
formatter = fn(getCleanedCode(lng), options);
|
|
5468
|
+
cache[key] = formatter;
|
|
5469
|
+
}
|
|
5470
|
+
return formatter(val);
|
|
5471
|
+
};
|
|
5472
|
+
};
|
|
5473
|
+
var Formatter = class {
|
|
5474
|
+
constructor() {
|
|
5475
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
5476
|
+
this.logger = baseLogger.create("formatter");
|
|
5477
|
+
this.options = options;
|
|
5478
|
+
this.formats = {
|
|
5479
|
+
number: createCachedFormatter((lng, opt) => {
|
|
5480
|
+
const formatter = new Intl.NumberFormat(lng, {
|
|
5481
|
+
...opt
|
|
5482
|
+
});
|
|
5483
|
+
return (val) => formatter.format(val);
|
|
5484
|
+
}),
|
|
5485
|
+
currency: createCachedFormatter((lng, opt) => {
|
|
5486
|
+
const formatter = new Intl.NumberFormat(lng, {
|
|
5487
|
+
...opt,
|
|
5488
|
+
style: "currency"
|
|
5489
|
+
});
|
|
5490
|
+
return (val) => formatter.format(val);
|
|
5491
|
+
}),
|
|
5492
|
+
datetime: createCachedFormatter((lng, opt) => {
|
|
5493
|
+
const formatter = new Intl.DateTimeFormat(lng, {
|
|
5494
|
+
...opt
|
|
5495
|
+
});
|
|
5496
|
+
return (val) => formatter.format(val);
|
|
5497
|
+
}),
|
|
5498
|
+
relativetime: createCachedFormatter((lng, opt) => {
|
|
5499
|
+
const formatter = new Intl.RelativeTimeFormat(lng, {
|
|
5500
|
+
...opt
|
|
5501
|
+
});
|
|
5502
|
+
return (val) => formatter.format(val, opt.range || "day");
|
|
5503
|
+
}),
|
|
5504
|
+
list: createCachedFormatter((lng, opt) => {
|
|
5505
|
+
const formatter = new Intl.ListFormat(lng, {
|
|
5506
|
+
...opt
|
|
5507
|
+
});
|
|
5508
|
+
return (val) => formatter.format(val);
|
|
5509
|
+
})
|
|
5510
|
+
};
|
|
5511
|
+
this.init(options);
|
|
5512
|
+
}
|
|
5513
|
+
init(services) {
|
|
5514
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
|
|
5515
|
+
interpolation: {}
|
|
5516
|
+
};
|
|
5517
|
+
this.formatSeparator = options.interpolation.formatSeparator || ",";
|
|
5518
|
+
}
|
|
5519
|
+
add(name, fc) {
|
|
5520
|
+
this.formats[name.toLowerCase().trim()] = fc;
|
|
5521
|
+
}
|
|
5522
|
+
addCached(name, fc) {
|
|
5523
|
+
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
5524
|
+
}
|
|
5525
|
+
format(value, format, lng) {
|
|
5526
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
5527
|
+
const formats = format.split(this.formatSeparator);
|
|
5528
|
+
if (formats.length > 1 && formats[0].indexOf("(") > 1 && formats[0].indexOf(")") < 0 && formats.find((f) => f.indexOf(")") > -1)) {
|
|
5529
|
+
const lastIndex = formats.findIndex((f) => f.indexOf(")") > -1);
|
|
5530
|
+
formats[0] = [formats[0], ...formats.splice(1, lastIndex)].join(this.formatSeparator);
|
|
5531
|
+
}
|
|
5532
|
+
const result = formats.reduce((mem, f) => {
|
|
5533
|
+
const {
|
|
5534
|
+
formatName,
|
|
5535
|
+
formatOptions
|
|
5536
|
+
} = parseFormatStr(f);
|
|
5537
|
+
if (this.formats[formatName]) {
|
|
5538
|
+
let formatted = mem;
|
|
5539
|
+
try {
|
|
5540
|
+
const valOptions = options?.formatParams?.[options.interpolationkey] || {};
|
|
5541
|
+
const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
|
|
5542
|
+
formatted = this.formats[formatName](mem, l, {
|
|
5543
|
+
...formatOptions,
|
|
5544
|
+
...options,
|
|
5545
|
+
...valOptions
|
|
5546
|
+
});
|
|
5547
|
+
} catch (error) {
|
|
5548
|
+
this.logger.warn(error);
|
|
5549
|
+
}
|
|
5550
|
+
return formatted;
|
|
5551
|
+
} else {
|
|
5552
|
+
this.logger.warn(`there was no format function for ${formatName}`);
|
|
5553
|
+
}
|
|
5554
|
+
return mem;
|
|
5555
|
+
}, value);
|
|
5556
|
+
return result;
|
|
5557
|
+
}
|
|
5558
|
+
};
|
|
5559
|
+
var removePending = (q, name) => {
|
|
5560
|
+
if (q.pending[name] !== void 0) {
|
|
5561
|
+
delete q.pending[name];
|
|
5562
|
+
q.pendingCount--;
|
|
5563
|
+
}
|
|
5564
|
+
};
|
|
5565
|
+
var Connector = class extends EventEmitter {
|
|
5566
|
+
constructor(backend, store, services) {
|
|
5567
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
5568
|
+
super();
|
|
5569
|
+
this.backend = backend;
|
|
5570
|
+
this.store = store;
|
|
5571
|
+
this.services = services;
|
|
5572
|
+
this.languageUtils = services.languageUtils;
|
|
5573
|
+
this.options = options;
|
|
5574
|
+
this.logger = baseLogger.create("backendConnector");
|
|
5575
|
+
this.waitingReads = [];
|
|
5576
|
+
this.maxParallelReads = options.maxParallelReads || 10;
|
|
5577
|
+
this.readingCalls = 0;
|
|
5578
|
+
this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
|
|
5579
|
+
this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
|
|
5580
|
+
this.state = {};
|
|
5581
|
+
this.queue = [];
|
|
5582
|
+
this.backend?.init?.(services, options.backend, options);
|
|
5583
|
+
}
|
|
5584
|
+
queueLoad(languages, namespaces, options, callback) {
|
|
5585
|
+
const toLoad = {};
|
|
5586
|
+
const pending = {};
|
|
5587
|
+
const toLoadLanguages = {};
|
|
5588
|
+
const toLoadNamespaces = {};
|
|
5589
|
+
languages.forEach((lng) => {
|
|
5590
|
+
let hasAllNamespaces = true;
|
|
5591
|
+
namespaces.forEach((ns) => {
|
|
5592
|
+
const name = `${lng}|${ns}`;
|
|
5593
|
+
if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
|
|
5594
|
+
this.state[name] = 2;
|
|
5595
|
+
} else if (this.state[name] < 0) ;
|
|
5596
|
+
else if (this.state[name] === 1) {
|
|
5597
|
+
if (pending[name] === void 0) pending[name] = true;
|
|
5598
|
+
} else {
|
|
5599
|
+
this.state[name] = 1;
|
|
5600
|
+
hasAllNamespaces = false;
|
|
5601
|
+
if (pending[name] === void 0) pending[name] = true;
|
|
5602
|
+
if (toLoad[name] === void 0) toLoad[name] = true;
|
|
5603
|
+
if (toLoadNamespaces[ns] === void 0) toLoadNamespaces[ns] = true;
|
|
5604
|
+
}
|
|
5605
|
+
});
|
|
5606
|
+
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
5607
|
+
});
|
|
5608
|
+
if (Object.keys(toLoad).length || Object.keys(pending).length) {
|
|
5609
|
+
this.queue.push({
|
|
5610
|
+
pending,
|
|
5611
|
+
pendingCount: Object.keys(pending).length,
|
|
5612
|
+
loaded: {},
|
|
5613
|
+
errors: [],
|
|
5614
|
+
callback
|
|
5615
|
+
});
|
|
5616
|
+
}
|
|
5617
|
+
return {
|
|
5618
|
+
toLoad: Object.keys(toLoad),
|
|
5619
|
+
pending: Object.keys(pending),
|
|
5620
|
+
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
5621
|
+
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
5622
|
+
};
|
|
5623
|
+
}
|
|
5624
|
+
loaded(name, err, data) {
|
|
5625
|
+
const s = name.split("|");
|
|
5626
|
+
const lng = s[0];
|
|
5627
|
+
const ns = s[1];
|
|
5628
|
+
if (err) this.emit("failedLoading", lng, ns, err);
|
|
5629
|
+
if (!err && data) {
|
|
5630
|
+
this.store.addResourceBundle(lng, ns, data, void 0, void 0, {
|
|
5631
|
+
skipCopy: true
|
|
5632
|
+
});
|
|
5633
|
+
}
|
|
5634
|
+
this.state[name] = err ? -1 : 2;
|
|
5635
|
+
if (err && data) this.state[name] = 0;
|
|
5636
|
+
const loaded = {};
|
|
5637
|
+
this.queue.forEach((q) => {
|
|
5638
|
+
pushPath(q.loaded, [lng], ns);
|
|
5639
|
+
removePending(q, name);
|
|
5640
|
+
if (err) q.errors.push(err);
|
|
5641
|
+
if (q.pendingCount === 0 && !q.done) {
|
|
5642
|
+
Object.keys(q.loaded).forEach((l) => {
|
|
5643
|
+
if (!loaded[l]) loaded[l] = {};
|
|
5644
|
+
const loadedKeys = q.loaded[l];
|
|
5645
|
+
if (loadedKeys.length) {
|
|
5646
|
+
loadedKeys.forEach((n) => {
|
|
5647
|
+
if (loaded[l][n] === void 0) loaded[l][n] = true;
|
|
5648
|
+
});
|
|
5649
|
+
}
|
|
5650
|
+
});
|
|
5651
|
+
q.done = true;
|
|
5652
|
+
if (q.errors.length) {
|
|
5653
|
+
q.callback(q.errors);
|
|
5654
|
+
} else {
|
|
5655
|
+
q.callback();
|
|
5656
|
+
}
|
|
5657
|
+
}
|
|
5658
|
+
});
|
|
5659
|
+
this.emit("loaded", loaded);
|
|
5660
|
+
this.queue = this.queue.filter((q) => !q.done);
|
|
5661
|
+
}
|
|
5662
|
+
read(lng, ns, fcName) {
|
|
5663
|
+
let tried = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0;
|
|
5664
|
+
let wait = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : this.retryTimeout;
|
|
5665
|
+
let callback = arguments.length > 5 ? arguments[5] : void 0;
|
|
5666
|
+
if (!lng.length) return callback(null, {});
|
|
5667
|
+
if (this.readingCalls >= this.maxParallelReads) {
|
|
5668
|
+
this.waitingReads.push({
|
|
5669
|
+
lng,
|
|
5670
|
+
ns,
|
|
5671
|
+
fcName,
|
|
5672
|
+
tried,
|
|
5673
|
+
wait,
|
|
5674
|
+
callback
|
|
5675
|
+
});
|
|
5676
|
+
return;
|
|
5677
|
+
}
|
|
5678
|
+
this.readingCalls++;
|
|
5679
|
+
const resolver = (err, data) => {
|
|
5680
|
+
this.readingCalls--;
|
|
5681
|
+
if (this.waitingReads.length > 0) {
|
|
5682
|
+
const next = this.waitingReads.shift();
|
|
5683
|
+
this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
5684
|
+
}
|
|
5685
|
+
if (err && data && tried < this.maxRetries) {
|
|
5686
|
+
setTimeout(() => {
|
|
5687
|
+
this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
5688
|
+
}, wait);
|
|
5689
|
+
return;
|
|
5690
|
+
}
|
|
5691
|
+
callback(err, data);
|
|
5692
|
+
};
|
|
5693
|
+
const fc = this.backend[fcName].bind(this.backend);
|
|
5694
|
+
if (fc.length === 2) {
|
|
5695
|
+
try {
|
|
5696
|
+
const r = fc(lng, ns);
|
|
5697
|
+
if (r && typeof r.then === "function") {
|
|
5698
|
+
r.then((data) => resolver(null, data)).catch(resolver);
|
|
5699
|
+
} else {
|
|
5700
|
+
resolver(null, r);
|
|
5701
|
+
}
|
|
5702
|
+
} catch (err) {
|
|
5703
|
+
resolver(err);
|
|
5704
|
+
}
|
|
5705
|
+
return;
|
|
5706
|
+
}
|
|
5707
|
+
return fc(lng, ns, resolver);
|
|
5708
|
+
}
|
|
5709
|
+
prepareLoading(languages, namespaces) {
|
|
5710
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
5711
|
+
let callback = arguments.length > 3 ? arguments[3] : void 0;
|
|
5712
|
+
if (!this.backend) {
|
|
5713
|
+
this.logger.warn("No backend was added via i18next.use. Will not load resources.");
|
|
5714
|
+
return callback && callback();
|
|
5715
|
+
}
|
|
5716
|
+
if (isString2(languages)) languages = this.languageUtils.toResolveHierarchy(languages);
|
|
5717
|
+
if (isString2(namespaces)) namespaces = [namespaces];
|
|
5718
|
+
const toLoad = this.queueLoad(languages, namespaces, options, callback);
|
|
5719
|
+
if (!toLoad.toLoad.length) {
|
|
5720
|
+
if (!toLoad.pending.length) callback();
|
|
5721
|
+
return null;
|
|
5722
|
+
}
|
|
5723
|
+
toLoad.toLoad.forEach((name) => {
|
|
5724
|
+
this.loadOne(name);
|
|
5725
|
+
});
|
|
5726
|
+
}
|
|
5727
|
+
load(languages, namespaces, callback) {
|
|
5728
|
+
this.prepareLoading(languages, namespaces, {}, callback);
|
|
5729
|
+
}
|
|
5730
|
+
reload(languages, namespaces, callback) {
|
|
5731
|
+
this.prepareLoading(languages, namespaces, {
|
|
5732
|
+
reload: true
|
|
5733
|
+
}, callback);
|
|
5734
|
+
}
|
|
5735
|
+
loadOne(name) {
|
|
5736
|
+
let prefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
|
|
5737
|
+
const s = name.split("|");
|
|
5738
|
+
const lng = s[0];
|
|
5739
|
+
const ns = s[1];
|
|
5740
|
+
this.read(lng, ns, "read", void 0, void 0, (err, data) => {
|
|
5741
|
+
if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
|
|
5742
|
+
if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
|
|
5743
|
+
this.loaded(name, err, data);
|
|
5744
|
+
});
|
|
5745
|
+
}
|
|
5746
|
+
saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
|
|
5747
|
+
let options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {};
|
|
5748
|
+
let clb = arguments.length > 6 && arguments[6] !== void 0 ? arguments[6] : () => {
|
|
5749
|
+
};
|
|
5750
|
+
if (this.services?.utils?.hasLoadedNamespace && !this.services?.utils?.hasLoadedNamespace(namespace)) {
|
|
5751
|
+
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!!!");
|
|
5752
|
+
return;
|
|
5753
|
+
}
|
|
5754
|
+
if (key === void 0 || key === null || key === "") return;
|
|
5755
|
+
if (this.backend?.create) {
|
|
5756
|
+
const opts = {
|
|
5757
|
+
...options,
|
|
5758
|
+
isUpdate
|
|
5759
|
+
};
|
|
5760
|
+
const fc = this.backend.create.bind(this.backend);
|
|
5761
|
+
if (fc.length < 6) {
|
|
5762
|
+
try {
|
|
5763
|
+
let r;
|
|
5764
|
+
if (fc.length === 5) {
|
|
5765
|
+
r = fc(languages, namespace, key, fallbackValue, opts);
|
|
5766
|
+
} else {
|
|
5767
|
+
r = fc(languages, namespace, key, fallbackValue);
|
|
5768
|
+
}
|
|
5769
|
+
if (r && typeof r.then === "function") {
|
|
5770
|
+
r.then((data) => clb(null, data)).catch(clb);
|
|
5771
|
+
} else {
|
|
5772
|
+
clb(null, r);
|
|
5773
|
+
}
|
|
5774
|
+
} catch (err) {
|
|
5775
|
+
clb(err);
|
|
5776
|
+
}
|
|
5777
|
+
} else {
|
|
5778
|
+
fc(languages, namespace, key, fallbackValue, clb, opts);
|
|
5779
|
+
}
|
|
5780
|
+
}
|
|
5781
|
+
if (!languages || !languages[0]) return;
|
|
5782
|
+
this.store.addResource(languages[0], namespace, key, fallbackValue);
|
|
5783
|
+
}
|
|
5784
|
+
};
|
|
5785
|
+
var get = () => ({
|
|
5786
|
+
debug: false,
|
|
5787
|
+
initAsync: true,
|
|
5788
|
+
ns: ["translation"],
|
|
5789
|
+
defaultNS: ["translation"],
|
|
5790
|
+
fallbackLng: ["dev"],
|
|
5791
|
+
fallbackNS: false,
|
|
5792
|
+
supportedLngs: false,
|
|
5793
|
+
nonExplicitSupportedLngs: false,
|
|
5794
|
+
load: "all",
|
|
5795
|
+
preload: false,
|
|
5796
|
+
simplifyPluralSuffix: true,
|
|
5797
|
+
keySeparator: ".",
|
|
5798
|
+
nsSeparator: ":",
|
|
5799
|
+
pluralSeparator: "_",
|
|
5800
|
+
contextSeparator: "_",
|
|
5801
|
+
partialBundledLanguages: false,
|
|
5802
|
+
saveMissing: false,
|
|
5803
|
+
updateMissing: false,
|
|
5804
|
+
saveMissingTo: "fallback",
|
|
5805
|
+
saveMissingPlurals: true,
|
|
5806
|
+
missingKeyHandler: false,
|
|
5807
|
+
missingInterpolationHandler: false,
|
|
5808
|
+
postProcess: false,
|
|
5809
|
+
postProcessPassResolved: false,
|
|
5810
|
+
returnNull: false,
|
|
5811
|
+
returnEmptyString: true,
|
|
5812
|
+
returnObjects: false,
|
|
5813
|
+
joinArrays: false,
|
|
5814
|
+
returnedObjectHandler: false,
|
|
5815
|
+
parseMissingKeyHandler: false,
|
|
5816
|
+
appendNamespaceToMissingKey: false,
|
|
5817
|
+
appendNamespaceToCIMode: false,
|
|
5818
|
+
overloadTranslationOptionHandler: (args) => {
|
|
5819
|
+
let ret = {};
|
|
5820
|
+
if (typeof args[1] === "object") ret = args[1];
|
|
5821
|
+
if (isString2(args[1])) ret.defaultValue = args[1];
|
|
5822
|
+
if (isString2(args[2])) ret.tDescription = args[2];
|
|
5823
|
+
if (typeof args[2] === "object" || typeof args[3] === "object") {
|
|
5824
|
+
const options = args[3] || args[2];
|
|
5825
|
+
Object.keys(options).forEach((key) => {
|
|
5826
|
+
ret[key] = options[key];
|
|
5827
|
+
});
|
|
5828
|
+
}
|
|
5829
|
+
return ret;
|
|
5830
|
+
},
|
|
5831
|
+
interpolation: {
|
|
5832
|
+
escapeValue: true,
|
|
5833
|
+
format: (value) => value,
|
|
5834
|
+
prefix: "{{",
|
|
5835
|
+
suffix: "}}",
|
|
5836
|
+
formatSeparator: ",",
|
|
5837
|
+
unescapePrefix: "-",
|
|
5838
|
+
nestingPrefix: "$t(",
|
|
5839
|
+
nestingSuffix: ")",
|
|
5840
|
+
nestingOptionsSeparator: ",",
|
|
5841
|
+
maxReplaces: 1e3,
|
|
5842
|
+
skipOnVariables: true
|
|
5843
|
+
}
|
|
5844
|
+
});
|
|
5845
|
+
var transformOptions = (options) => {
|
|
5846
|
+
if (isString2(options.ns)) options.ns = [options.ns];
|
|
5847
|
+
if (isString2(options.fallbackLng)) options.fallbackLng = [options.fallbackLng];
|
|
5848
|
+
if (isString2(options.fallbackNS)) options.fallbackNS = [options.fallbackNS];
|
|
5849
|
+
if (options.supportedLngs?.indexOf?.("cimode") < 0) {
|
|
5850
|
+
options.supportedLngs = options.supportedLngs.concat(["cimode"]);
|
|
5851
|
+
}
|
|
5852
|
+
if (typeof options.initImmediate === "boolean") options.initAsync = options.initImmediate;
|
|
5853
|
+
return options;
|
|
5854
|
+
};
|
|
5855
|
+
var noop = () => {
|
|
5856
|
+
};
|
|
5857
|
+
var bindMemberFunctions = (inst) => {
|
|
5858
|
+
const mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
|
|
5859
|
+
mems.forEach((mem) => {
|
|
5860
|
+
if (typeof inst[mem] === "function") {
|
|
5861
|
+
inst[mem] = inst[mem].bind(inst);
|
|
5862
|
+
}
|
|
5863
|
+
});
|
|
5864
|
+
};
|
|
5865
|
+
var I18n = class _I18n extends EventEmitter {
|
|
5866
|
+
constructor() {
|
|
5867
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
5868
|
+
let callback = arguments.length > 1 ? arguments[1] : void 0;
|
|
5869
|
+
super();
|
|
5870
|
+
this.options = transformOptions(options);
|
|
5871
|
+
this.services = {};
|
|
5872
|
+
this.logger = baseLogger;
|
|
5873
|
+
this.modules = {
|
|
5874
|
+
external: []
|
|
5875
|
+
};
|
|
5876
|
+
bindMemberFunctions(this);
|
|
5877
|
+
if (callback && !this.isInitialized && !options.isClone) {
|
|
5878
|
+
if (!this.options.initAsync) {
|
|
5879
|
+
this.init(options, callback);
|
|
5880
|
+
return this;
|
|
5881
|
+
}
|
|
5882
|
+
setTimeout(() => {
|
|
5883
|
+
this.init(options, callback);
|
|
5884
|
+
}, 0);
|
|
5885
|
+
}
|
|
5886
|
+
}
|
|
5887
|
+
init() {
|
|
5888
|
+
var _this = this;
|
|
5889
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
5890
|
+
let callback = arguments.length > 1 ? arguments[1] : void 0;
|
|
5891
|
+
this.isInitializing = true;
|
|
5892
|
+
if (typeof options === "function") {
|
|
5893
|
+
callback = options;
|
|
5894
|
+
options = {};
|
|
5895
|
+
}
|
|
5896
|
+
if (options.defaultNS == null && options.ns) {
|
|
5897
|
+
if (isString2(options.ns)) {
|
|
5898
|
+
options.defaultNS = options.ns;
|
|
5899
|
+
} else if (options.ns.indexOf("translation") < 0) {
|
|
5900
|
+
options.defaultNS = options.ns[0];
|
|
5901
|
+
}
|
|
5902
|
+
}
|
|
5903
|
+
const defOpts = get();
|
|
5904
|
+
this.options = {
|
|
5905
|
+
...defOpts,
|
|
5906
|
+
...this.options,
|
|
5907
|
+
...transformOptions(options)
|
|
5908
|
+
};
|
|
5909
|
+
this.options.interpolation = {
|
|
5910
|
+
...defOpts.interpolation,
|
|
5911
|
+
...this.options.interpolation
|
|
5912
|
+
};
|
|
5913
|
+
if (options.keySeparator !== void 0) {
|
|
5914
|
+
this.options.userDefinedKeySeparator = options.keySeparator;
|
|
5915
|
+
}
|
|
5916
|
+
if (options.nsSeparator !== void 0) {
|
|
5917
|
+
this.options.userDefinedNsSeparator = options.nsSeparator;
|
|
5918
|
+
}
|
|
5919
|
+
const createClassOnDemand = (ClassOrObject) => {
|
|
5920
|
+
if (!ClassOrObject) return null;
|
|
5921
|
+
if (typeof ClassOrObject === "function") return new ClassOrObject();
|
|
5922
|
+
return ClassOrObject;
|
|
5923
|
+
};
|
|
5924
|
+
if (!this.options.isClone) {
|
|
5925
|
+
if (this.modules.logger) {
|
|
5926
|
+
baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
|
|
5927
|
+
} else {
|
|
5928
|
+
baseLogger.init(null, this.options);
|
|
5929
|
+
}
|
|
5930
|
+
let formatter;
|
|
5931
|
+
if (this.modules.formatter) {
|
|
5932
|
+
formatter = this.modules.formatter;
|
|
5933
|
+
} else {
|
|
5934
|
+
formatter = Formatter;
|
|
5935
|
+
}
|
|
5936
|
+
const lu = new LanguageUtil(this.options);
|
|
5937
|
+
this.store = new ResourceStore(this.options.resources, this.options);
|
|
5938
|
+
const s = this.services;
|
|
5939
|
+
s.logger = baseLogger;
|
|
5940
|
+
s.resourceStore = this.store;
|
|
5941
|
+
s.languageUtils = lu;
|
|
5942
|
+
s.pluralResolver = new PluralResolver(lu, {
|
|
5943
|
+
prepend: this.options.pluralSeparator,
|
|
5944
|
+
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
5945
|
+
});
|
|
5946
|
+
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
|
|
5947
|
+
s.formatter = createClassOnDemand(formatter);
|
|
5948
|
+
s.formatter.init(s, this.options);
|
|
5949
|
+
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
5950
|
+
}
|
|
5951
|
+
s.interpolator = new Interpolator(this.options);
|
|
5952
|
+
s.utils = {
|
|
5953
|
+
hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
|
|
5954
|
+
};
|
|
5955
|
+
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
5956
|
+
s.backendConnector.on("*", function(event) {
|
|
5957
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
5958
|
+
args[_key - 1] = arguments[_key];
|
|
5959
|
+
}
|
|
5960
|
+
_this.emit(event, ...args);
|
|
5961
|
+
});
|
|
5962
|
+
if (this.modules.languageDetector) {
|
|
5963
|
+
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
5964
|
+
if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
|
|
5965
|
+
}
|
|
5966
|
+
if (this.modules.i18nFormat) {
|
|
5967
|
+
s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
|
|
5968
|
+
if (s.i18nFormat.init) s.i18nFormat.init(this);
|
|
5969
|
+
}
|
|
5970
|
+
this.translator = new Translator(this.services, this.options);
|
|
5971
|
+
this.translator.on("*", function(event) {
|
|
5972
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
5973
|
+
args[_key2 - 1] = arguments[_key2];
|
|
5974
|
+
}
|
|
5975
|
+
_this.emit(event, ...args);
|
|
5976
|
+
});
|
|
5977
|
+
this.modules.external.forEach((m) => {
|
|
5978
|
+
if (m.init) m.init(this);
|
|
5979
|
+
});
|
|
5980
|
+
}
|
|
5981
|
+
this.format = this.options.interpolation.format;
|
|
5982
|
+
if (!callback) callback = noop;
|
|
5983
|
+
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
5984
|
+
const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
5985
|
+
if (codes.length > 0 && codes[0] !== "dev") this.options.lng = codes[0];
|
|
5986
|
+
}
|
|
5987
|
+
if (!this.services.languageDetector && !this.options.lng) {
|
|
5988
|
+
this.logger.warn("init: no languageDetector is used and no lng is defined");
|
|
5989
|
+
}
|
|
5990
|
+
const storeApi = ["getResource", "hasResourceBundle", "getResourceBundle", "getDataByLanguage"];
|
|
5991
|
+
storeApi.forEach((fcName) => {
|
|
5992
|
+
this[fcName] = function() {
|
|
5993
|
+
return _this.store[fcName](...arguments);
|
|
5994
|
+
};
|
|
5995
|
+
});
|
|
5996
|
+
const storeApiChained = ["addResource", "addResources", "addResourceBundle", "removeResourceBundle"];
|
|
5997
|
+
storeApiChained.forEach((fcName) => {
|
|
5998
|
+
this[fcName] = function() {
|
|
5999
|
+
_this.store[fcName](...arguments);
|
|
6000
|
+
return _this;
|
|
6001
|
+
};
|
|
6002
|
+
});
|
|
6003
|
+
const deferred = defer();
|
|
6004
|
+
const load = () => {
|
|
6005
|
+
const finish = (err, t2) => {
|
|
6006
|
+
this.isInitializing = false;
|
|
6007
|
+
if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn("init: i18next is already initialized. You should call init just once!");
|
|
6008
|
+
this.isInitialized = true;
|
|
6009
|
+
if (!this.options.isClone) this.logger.log("initialized", this.options);
|
|
6010
|
+
this.emit("initialized", this.options);
|
|
6011
|
+
deferred.resolve(t2);
|
|
6012
|
+
callback(err, t2);
|
|
6013
|
+
};
|
|
6014
|
+
if (this.languages && !this.isInitialized) return finish(null, this.t.bind(this));
|
|
6015
|
+
this.changeLanguage(this.options.lng, finish);
|
|
6016
|
+
};
|
|
6017
|
+
if (this.options.resources || !this.options.initAsync) {
|
|
6018
|
+
load();
|
|
6019
|
+
} else {
|
|
6020
|
+
setTimeout(load, 0);
|
|
6021
|
+
}
|
|
6022
|
+
return deferred;
|
|
6023
|
+
}
|
|
6024
|
+
loadResources(language) {
|
|
6025
|
+
let callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
6026
|
+
let usedCallback = callback;
|
|
6027
|
+
const usedLng = isString2(language) ? language : this.language;
|
|
6028
|
+
if (typeof language === "function") usedCallback = language;
|
|
6029
|
+
if (!this.options.resources || this.options.partialBundledLanguages) {
|
|
6030
|
+
if (usedLng?.toLowerCase() === "cimode" && (!this.options.preload || this.options.preload.length === 0)) return usedCallback();
|
|
6031
|
+
const toLoad = [];
|
|
6032
|
+
const append = (lng) => {
|
|
6033
|
+
if (!lng) return;
|
|
6034
|
+
if (lng === "cimode") return;
|
|
6035
|
+
const lngs = this.services.languageUtils.toResolveHierarchy(lng);
|
|
6036
|
+
lngs.forEach((l) => {
|
|
6037
|
+
if (l === "cimode") return;
|
|
6038
|
+
if (toLoad.indexOf(l) < 0) toLoad.push(l);
|
|
6039
|
+
});
|
|
6040
|
+
};
|
|
6041
|
+
if (!usedLng) {
|
|
6042
|
+
const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
6043
|
+
fallbacks.forEach((l) => append(l));
|
|
6044
|
+
} else {
|
|
6045
|
+
append(usedLng);
|
|
6046
|
+
}
|
|
6047
|
+
this.options.preload?.forEach?.((l) => append(l));
|
|
6048
|
+
this.services.backendConnector.load(toLoad, this.options.ns, (e2) => {
|
|
6049
|
+
if (!e2 && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
|
|
6050
|
+
usedCallback(e2);
|
|
6051
|
+
});
|
|
6052
|
+
} else {
|
|
6053
|
+
usedCallback(null);
|
|
6054
|
+
}
|
|
6055
|
+
}
|
|
6056
|
+
reloadResources(lngs, ns, callback) {
|
|
6057
|
+
const deferred = defer();
|
|
6058
|
+
if (typeof lngs === "function") {
|
|
6059
|
+
callback = lngs;
|
|
6060
|
+
lngs = void 0;
|
|
6061
|
+
}
|
|
6062
|
+
if (typeof ns === "function") {
|
|
6063
|
+
callback = ns;
|
|
6064
|
+
ns = void 0;
|
|
6065
|
+
}
|
|
6066
|
+
if (!lngs) lngs = this.languages;
|
|
6067
|
+
if (!ns) ns = this.options.ns;
|
|
6068
|
+
if (!callback) callback = noop;
|
|
6069
|
+
this.services.backendConnector.reload(lngs, ns, (err) => {
|
|
6070
|
+
deferred.resolve();
|
|
6071
|
+
callback(err);
|
|
6072
|
+
});
|
|
6073
|
+
return deferred;
|
|
6074
|
+
}
|
|
6075
|
+
use(module) {
|
|
6076
|
+
if (!module) throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");
|
|
6077
|
+
if (!module.type) throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");
|
|
6078
|
+
if (module.type === "backend") {
|
|
6079
|
+
this.modules.backend = module;
|
|
6080
|
+
}
|
|
6081
|
+
if (module.type === "logger" || module.log && module.warn && module.error) {
|
|
6082
|
+
this.modules.logger = module;
|
|
6083
|
+
}
|
|
6084
|
+
if (module.type === "languageDetector") {
|
|
6085
|
+
this.modules.languageDetector = module;
|
|
6086
|
+
}
|
|
6087
|
+
if (module.type === "i18nFormat") {
|
|
6088
|
+
this.modules.i18nFormat = module;
|
|
6089
|
+
}
|
|
6090
|
+
if (module.type === "postProcessor") {
|
|
6091
|
+
postProcessor.addPostProcessor(module);
|
|
6092
|
+
}
|
|
6093
|
+
if (module.type === "formatter") {
|
|
6094
|
+
this.modules.formatter = module;
|
|
6095
|
+
}
|
|
6096
|
+
if (module.type === "3rdParty") {
|
|
6097
|
+
this.modules.external.push(module);
|
|
6098
|
+
}
|
|
6099
|
+
return this;
|
|
6100
|
+
}
|
|
6101
|
+
setResolvedLanguage(l) {
|
|
6102
|
+
if (!l || !this.languages) return;
|
|
6103
|
+
if (["cimode", "dev"].indexOf(l) > -1) return;
|
|
6104
|
+
for (let li = 0; li < this.languages.length; li++) {
|
|
6105
|
+
const lngInLngs = this.languages[li];
|
|
6106
|
+
if (["cimode", "dev"].indexOf(lngInLngs) > -1) continue;
|
|
6107
|
+
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
6108
|
+
this.resolvedLanguage = lngInLngs;
|
|
6109
|
+
break;
|
|
6110
|
+
}
|
|
6111
|
+
}
|
|
6112
|
+
}
|
|
6113
|
+
changeLanguage(lng, callback) {
|
|
6114
|
+
var _this2 = this;
|
|
6115
|
+
this.isLanguageChangingTo = lng;
|
|
6116
|
+
const deferred = defer();
|
|
6117
|
+
this.emit("languageChanging", lng);
|
|
6118
|
+
const setLngProps = (l) => {
|
|
6119
|
+
this.language = l;
|
|
6120
|
+
this.languages = this.services.languageUtils.toResolveHierarchy(l);
|
|
6121
|
+
this.resolvedLanguage = void 0;
|
|
6122
|
+
this.setResolvedLanguage(l);
|
|
6123
|
+
};
|
|
6124
|
+
const done = (err, l) => {
|
|
6125
|
+
if (l) {
|
|
6126
|
+
setLngProps(l);
|
|
6127
|
+
this.translator.changeLanguage(l);
|
|
6128
|
+
this.isLanguageChangingTo = void 0;
|
|
6129
|
+
this.emit("languageChanged", l);
|
|
6130
|
+
this.logger.log("languageChanged", l);
|
|
6131
|
+
} else {
|
|
6132
|
+
this.isLanguageChangingTo = void 0;
|
|
6133
|
+
}
|
|
6134
|
+
deferred.resolve(function() {
|
|
6135
|
+
return _this2.t(...arguments);
|
|
6136
|
+
});
|
|
6137
|
+
if (callback) callback(err, function() {
|
|
6138
|
+
return _this2.t(...arguments);
|
|
6139
|
+
});
|
|
6140
|
+
};
|
|
6141
|
+
const setLng = (lngs) => {
|
|
6142
|
+
if (!lng && !lngs && this.services.languageDetector) lngs = [];
|
|
6143
|
+
const l = isString2(lngs) ? lngs : this.services.languageUtils.getBestMatchFromCodes(lngs);
|
|
6144
|
+
if (l) {
|
|
6145
|
+
if (!this.language) {
|
|
6146
|
+
setLngProps(l);
|
|
6147
|
+
}
|
|
6148
|
+
if (!this.translator.language) this.translator.changeLanguage(l);
|
|
6149
|
+
this.services.languageDetector?.cacheUserLanguage?.(l);
|
|
6150
|
+
}
|
|
6151
|
+
this.loadResources(l, (err) => {
|
|
6152
|
+
done(err, l);
|
|
6153
|
+
});
|
|
6154
|
+
};
|
|
6155
|
+
if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
|
|
6156
|
+
setLng(this.services.languageDetector.detect());
|
|
6157
|
+
} else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
|
|
6158
|
+
if (this.services.languageDetector.detect.length === 0) {
|
|
6159
|
+
this.services.languageDetector.detect().then(setLng);
|
|
6160
|
+
} else {
|
|
6161
|
+
this.services.languageDetector.detect(setLng);
|
|
6162
|
+
}
|
|
6163
|
+
} else {
|
|
6164
|
+
setLng(lng);
|
|
6165
|
+
}
|
|
6166
|
+
return deferred;
|
|
6167
|
+
}
|
|
6168
|
+
getFixedT(lng, ns, keyPrefix) {
|
|
6169
|
+
var _this3 = this;
|
|
6170
|
+
const fixedT = function(key, opts) {
|
|
6171
|
+
let options;
|
|
6172
|
+
if (typeof opts !== "object") {
|
|
6173
|
+
for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
6174
|
+
rest[_key3 - 2] = arguments[_key3];
|
|
6175
|
+
}
|
|
6176
|
+
options = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
6177
|
+
} else {
|
|
6178
|
+
options = {
|
|
6179
|
+
...opts
|
|
6180
|
+
};
|
|
6181
|
+
}
|
|
6182
|
+
options.lng = options.lng || fixedT.lng;
|
|
6183
|
+
options.lngs = options.lngs || fixedT.lngs;
|
|
6184
|
+
options.ns = options.ns || fixedT.ns;
|
|
6185
|
+
if (options.keyPrefix !== "") options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
|
|
6186
|
+
const keySeparator = _this3.options.keySeparator || ".";
|
|
6187
|
+
let resultKey;
|
|
6188
|
+
if (options.keyPrefix && Array.isArray(key)) {
|
|
6189
|
+
resultKey = key.map((k) => `${options.keyPrefix}${keySeparator}${k}`);
|
|
6190
|
+
} else {
|
|
6191
|
+
resultKey = options.keyPrefix ? `${options.keyPrefix}${keySeparator}${key}` : key;
|
|
6192
|
+
}
|
|
6193
|
+
return _this3.t(resultKey, options);
|
|
6194
|
+
};
|
|
6195
|
+
if (isString2(lng)) {
|
|
6196
|
+
fixedT.lng = lng;
|
|
6197
|
+
} else {
|
|
6198
|
+
fixedT.lngs = lng;
|
|
6199
|
+
}
|
|
6200
|
+
fixedT.ns = ns;
|
|
6201
|
+
fixedT.keyPrefix = keyPrefix;
|
|
6202
|
+
return fixedT;
|
|
6203
|
+
}
|
|
6204
|
+
t() {
|
|
6205
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
6206
|
+
args[_key4] = arguments[_key4];
|
|
6207
|
+
}
|
|
6208
|
+
return this.translator?.translate(...args);
|
|
6209
|
+
}
|
|
6210
|
+
exists() {
|
|
6211
|
+
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
6212
|
+
args[_key5] = arguments[_key5];
|
|
6213
|
+
}
|
|
6214
|
+
return this.translator?.exists(...args);
|
|
6215
|
+
}
|
|
6216
|
+
setDefaultNamespace(ns) {
|
|
6217
|
+
this.options.defaultNS = ns;
|
|
6218
|
+
}
|
|
6219
|
+
hasLoadedNamespace(ns) {
|
|
6220
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
6221
|
+
if (!this.isInitialized) {
|
|
6222
|
+
this.logger.warn("hasLoadedNamespace: i18next was not initialized", this.languages);
|
|
6223
|
+
return false;
|
|
6224
|
+
}
|
|
6225
|
+
if (!this.languages || !this.languages.length) {
|
|
6226
|
+
this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty", this.languages);
|
|
6227
|
+
return false;
|
|
6228
|
+
}
|
|
6229
|
+
const lng = options.lng || this.resolvedLanguage || this.languages[0];
|
|
6230
|
+
const fallbackLng = this.options ? this.options.fallbackLng : false;
|
|
6231
|
+
const lastLng = this.languages[this.languages.length - 1];
|
|
6232
|
+
if (lng.toLowerCase() === "cimode") return true;
|
|
6233
|
+
const loadNotPending = (l, n) => {
|
|
6234
|
+
const loadState = this.services.backendConnector.state[`${l}|${n}`];
|
|
6235
|
+
return loadState === -1 || loadState === 0 || loadState === 2;
|
|
6236
|
+
};
|
|
6237
|
+
if (options.precheck) {
|
|
6238
|
+
const preResult = options.precheck(this, loadNotPending);
|
|
6239
|
+
if (preResult !== void 0) return preResult;
|
|
6240
|
+
}
|
|
6241
|
+
if (this.hasResourceBundle(lng, ns)) return true;
|
|
6242
|
+
if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
|
|
6243
|
+
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
6244
|
+
return false;
|
|
6245
|
+
}
|
|
6246
|
+
loadNamespaces(ns, callback) {
|
|
6247
|
+
const deferred = defer();
|
|
6248
|
+
if (!this.options.ns) {
|
|
6249
|
+
if (callback) callback();
|
|
6250
|
+
return Promise.resolve();
|
|
6251
|
+
}
|
|
6252
|
+
if (isString2(ns)) ns = [ns];
|
|
6253
|
+
ns.forEach((n) => {
|
|
6254
|
+
if (this.options.ns.indexOf(n) < 0) this.options.ns.push(n);
|
|
6255
|
+
});
|
|
6256
|
+
this.loadResources((err) => {
|
|
6257
|
+
deferred.resolve();
|
|
6258
|
+
if (callback) callback(err);
|
|
6259
|
+
});
|
|
6260
|
+
return deferred;
|
|
6261
|
+
}
|
|
6262
|
+
loadLanguages(lngs, callback) {
|
|
6263
|
+
const deferred = defer();
|
|
6264
|
+
if (isString2(lngs)) lngs = [lngs];
|
|
6265
|
+
const preloaded = this.options.preload || [];
|
|
6266
|
+
const newLngs = lngs.filter((lng) => preloaded.indexOf(lng) < 0 && this.services.languageUtils.isSupportedCode(lng));
|
|
6267
|
+
if (!newLngs.length) {
|
|
6268
|
+
if (callback) callback();
|
|
6269
|
+
return Promise.resolve();
|
|
6270
|
+
}
|
|
6271
|
+
this.options.preload = preloaded.concat(newLngs);
|
|
6272
|
+
this.loadResources((err) => {
|
|
6273
|
+
deferred.resolve();
|
|
6274
|
+
if (callback) callback(err);
|
|
6275
|
+
});
|
|
6276
|
+
return deferred;
|
|
6277
|
+
}
|
|
6278
|
+
dir(lng) {
|
|
6279
|
+
if (!lng) lng = this.resolvedLanguage || (this.languages?.length > 0 ? this.languages[0] : this.language);
|
|
6280
|
+
if (!lng) return "rtl";
|
|
6281
|
+
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"];
|
|
6282
|
+
const languageUtils = this.services?.languageUtils || new LanguageUtil(get());
|
|
6283
|
+
return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf("-arab") > 1 ? "rtl" : "ltr";
|
|
6284
|
+
}
|
|
6285
|
+
static createInstance() {
|
|
6286
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
6287
|
+
let callback = arguments.length > 1 ? arguments[1] : void 0;
|
|
6288
|
+
return new _I18n(options, callback);
|
|
6289
|
+
}
|
|
6290
|
+
cloneInstance() {
|
|
6291
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
6292
|
+
let callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
6293
|
+
const forkResourceStore = options.forkResourceStore;
|
|
6294
|
+
if (forkResourceStore) delete options.forkResourceStore;
|
|
6295
|
+
const mergedOptions = {
|
|
6296
|
+
...this.options,
|
|
6297
|
+
...options,
|
|
6298
|
+
...{
|
|
6299
|
+
isClone: true
|
|
6300
|
+
}
|
|
6301
|
+
};
|
|
6302
|
+
const clone = new _I18n(mergedOptions);
|
|
6303
|
+
if (options.debug !== void 0 || options.prefix !== void 0) {
|
|
6304
|
+
clone.logger = clone.logger.clone(options);
|
|
6305
|
+
}
|
|
6306
|
+
const membersToCopy = ["store", "services", "language"];
|
|
6307
|
+
membersToCopy.forEach((m) => {
|
|
6308
|
+
clone[m] = this[m];
|
|
6309
|
+
});
|
|
6310
|
+
clone.services = {
|
|
6311
|
+
...this.services
|
|
6312
|
+
};
|
|
6313
|
+
clone.services.utils = {
|
|
6314
|
+
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
6315
|
+
};
|
|
6316
|
+
if (forkResourceStore) {
|
|
6317
|
+
const clonedData = Object.keys(this.store.data).reduce((prev, l) => {
|
|
6318
|
+
prev[l] = {
|
|
6319
|
+
...this.store.data[l]
|
|
6320
|
+
};
|
|
6321
|
+
return Object.keys(prev[l]).reduce((acc, n) => {
|
|
6322
|
+
acc[n] = {
|
|
6323
|
+
...prev[l][n]
|
|
6324
|
+
};
|
|
6325
|
+
return acc;
|
|
6326
|
+
}, {});
|
|
6327
|
+
}, {});
|
|
6328
|
+
clone.store = new ResourceStore(clonedData, mergedOptions);
|
|
6329
|
+
clone.services.resourceStore = clone.store;
|
|
6330
|
+
}
|
|
6331
|
+
clone.translator = new Translator(clone.services, mergedOptions);
|
|
6332
|
+
clone.translator.on("*", function(event) {
|
|
6333
|
+
for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
|
|
6334
|
+
args[_key6 - 1] = arguments[_key6];
|
|
6335
|
+
}
|
|
6336
|
+
clone.emit(event, ...args);
|
|
6337
|
+
});
|
|
6338
|
+
clone.init(mergedOptions, callback);
|
|
6339
|
+
clone.translator.options = mergedOptions;
|
|
6340
|
+
clone.translator.backendConnector.services.utils = {
|
|
6341
|
+
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
6342
|
+
};
|
|
6343
|
+
return clone;
|
|
6344
|
+
}
|
|
6345
|
+
toJSON() {
|
|
6346
|
+
return {
|
|
6347
|
+
options: this.options,
|
|
6348
|
+
store: this.store,
|
|
6349
|
+
language: this.language,
|
|
6350
|
+
languages: this.languages,
|
|
6351
|
+
resolvedLanguage: this.resolvedLanguage
|
|
6352
|
+
};
|
|
6353
|
+
}
|
|
6354
|
+
};
|
|
6355
|
+
var instance = I18n.createInstance();
|
|
6356
|
+
instance.createInstance = I18n.createInstance;
|
|
6357
|
+
var createInstance = instance.createInstance;
|
|
6358
|
+
var dir = instance.dir;
|
|
6359
|
+
var init = instance.init;
|
|
6360
|
+
var loadResources = instance.loadResources;
|
|
6361
|
+
var reloadResources = instance.reloadResources;
|
|
6362
|
+
var use = instance.use;
|
|
6363
|
+
var changeLanguage = instance.changeLanguage;
|
|
6364
|
+
var getFixedT = instance.getFixedT;
|
|
6365
|
+
var t = instance.t;
|
|
6366
|
+
var exists = instance.exists;
|
|
6367
|
+
var setDefaultNamespace = instance.setDefaultNamespace;
|
|
6368
|
+
var hasLoadedNamespace2 = instance.hasLoadedNamespace;
|
|
6369
|
+
var loadNamespaces2 = instance.loadNamespaces;
|
|
6370
|
+
var loadLanguages2 = instance.loadLanguages;
|
|
6371
|
+
|
|
6372
|
+
// node_modules/i18next-browser-languagedetector/dist/esm/i18nextBrowserLanguageDetector.js
|
|
6373
|
+
var {
|
|
6374
|
+
slice,
|
|
6375
|
+
forEach
|
|
6376
|
+
} = [];
|
|
6377
|
+
function defaults(obj) {
|
|
6378
|
+
forEach.call(slice.call(arguments, 1), (source) => {
|
|
6379
|
+
if (source) {
|
|
6380
|
+
for (const prop in source) {
|
|
6381
|
+
if (obj[prop] === void 0) obj[prop] = source[prop];
|
|
6382
|
+
}
|
|
6383
|
+
}
|
|
6384
|
+
});
|
|
6385
|
+
return obj;
|
|
6386
|
+
}
|
|
6387
|
+
function hasXSS(input) {
|
|
6388
|
+
if (typeof input !== "string") return false;
|
|
6389
|
+
const xssPatterns = [/<\s*script.*?>/i, /<\s*\/\s*script\s*>/i, /<\s*img.*?on\w+\s*=/i, /<\s*\w+\s*on\w+\s*=.*?>/i, /javascript\s*:/i, /vbscript\s*:/i, /expression\s*\(/i, /eval\s*\(/i, /alert\s*\(/i, /document\.cookie/i, /document\.write\s*\(/i, /window\.location/i, /innerHTML/i];
|
|
6390
|
+
return xssPatterns.some((pattern) => pattern.test(input));
|
|
6391
|
+
}
|
|
6392
|
+
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
6393
|
+
var serializeCookie = function(name, val) {
|
|
6394
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {
|
|
6395
|
+
path: "/"
|
|
6396
|
+
};
|
|
6397
|
+
const opt = options;
|
|
6398
|
+
const value = encodeURIComponent(val);
|
|
6399
|
+
let str = `${name}=${value}`;
|
|
6400
|
+
if (opt.maxAge > 0) {
|
|
6401
|
+
const maxAge = opt.maxAge - 0;
|
|
6402
|
+
if (Number.isNaN(maxAge)) throw new Error("maxAge should be a Number");
|
|
6403
|
+
str += `; Max-Age=${Math.floor(maxAge)}`;
|
|
6404
|
+
}
|
|
6405
|
+
if (opt.domain) {
|
|
6406
|
+
if (!fieldContentRegExp.test(opt.domain)) {
|
|
6407
|
+
throw new TypeError("option domain is invalid");
|
|
6408
|
+
}
|
|
6409
|
+
str += `; Domain=${opt.domain}`;
|
|
6410
|
+
}
|
|
6411
|
+
if (opt.path) {
|
|
6412
|
+
if (!fieldContentRegExp.test(opt.path)) {
|
|
6413
|
+
throw new TypeError("option path is invalid");
|
|
6414
|
+
}
|
|
6415
|
+
str += `; Path=${opt.path}`;
|
|
6416
|
+
}
|
|
6417
|
+
if (opt.expires) {
|
|
6418
|
+
if (typeof opt.expires.toUTCString !== "function") {
|
|
6419
|
+
throw new TypeError("option expires is invalid");
|
|
6420
|
+
}
|
|
6421
|
+
str += `; Expires=${opt.expires.toUTCString()}`;
|
|
6422
|
+
}
|
|
6423
|
+
if (opt.httpOnly) str += "; HttpOnly";
|
|
6424
|
+
if (opt.secure) str += "; Secure";
|
|
6425
|
+
if (opt.sameSite) {
|
|
6426
|
+
const sameSite = typeof opt.sameSite === "string" ? opt.sameSite.toLowerCase() : opt.sameSite;
|
|
6427
|
+
switch (sameSite) {
|
|
6428
|
+
case true:
|
|
6429
|
+
str += "; SameSite=Strict";
|
|
6430
|
+
break;
|
|
6431
|
+
case "lax":
|
|
6432
|
+
str += "; SameSite=Lax";
|
|
6433
|
+
break;
|
|
6434
|
+
case "strict":
|
|
6435
|
+
str += "; SameSite=Strict";
|
|
6436
|
+
break;
|
|
6437
|
+
case "none":
|
|
6438
|
+
str += "; SameSite=None";
|
|
6439
|
+
break;
|
|
6440
|
+
default:
|
|
6441
|
+
throw new TypeError("option sameSite is invalid");
|
|
6442
|
+
}
|
|
6443
|
+
}
|
|
6444
|
+
if (opt.partitioned) str += "; Partitioned";
|
|
6445
|
+
return str;
|
|
6446
|
+
};
|
|
6447
|
+
var cookie = {
|
|
6448
|
+
create(name, value, minutes, domain) {
|
|
6449
|
+
let cookieOptions = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : {
|
|
6450
|
+
path: "/",
|
|
6451
|
+
sameSite: "strict"
|
|
6452
|
+
};
|
|
6453
|
+
if (minutes) {
|
|
6454
|
+
cookieOptions.expires = /* @__PURE__ */ new Date();
|
|
6455
|
+
cookieOptions.expires.setTime(cookieOptions.expires.getTime() + minutes * 60 * 1e3);
|
|
6456
|
+
}
|
|
6457
|
+
if (domain) cookieOptions.domain = domain;
|
|
6458
|
+
document.cookie = serializeCookie(name, value, cookieOptions);
|
|
6459
|
+
},
|
|
6460
|
+
read(name) {
|
|
6461
|
+
const nameEQ = `${name}=`;
|
|
6462
|
+
const ca = document.cookie.split(";");
|
|
6463
|
+
for (let i = 0; i < ca.length; i++) {
|
|
6464
|
+
let c = ca[i];
|
|
6465
|
+
while (c.charAt(0) === " ") c = c.substring(1, c.length);
|
|
6466
|
+
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
|
|
6467
|
+
}
|
|
6468
|
+
return null;
|
|
6469
|
+
},
|
|
6470
|
+
remove(name, domain) {
|
|
6471
|
+
this.create(name, "", -1, domain);
|
|
6472
|
+
}
|
|
6473
|
+
};
|
|
6474
|
+
var cookie$1 = {
|
|
6475
|
+
name: "cookie",
|
|
6476
|
+
// Deconstruct the options object and extract the lookupCookie property
|
|
6477
|
+
lookup(_ref) {
|
|
6478
|
+
let {
|
|
6479
|
+
lookupCookie
|
|
6480
|
+
} = _ref;
|
|
6481
|
+
if (lookupCookie && typeof document !== "undefined") {
|
|
6482
|
+
return cookie.read(lookupCookie) || void 0;
|
|
6483
|
+
}
|
|
6484
|
+
return void 0;
|
|
6485
|
+
},
|
|
6486
|
+
// Deconstruct the options object and extract the lookupCookie, cookieMinutes, cookieDomain, and cookieOptions properties
|
|
6487
|
+
cacheUserLanguage(lng, _ref2) {
|
|
6488
|
+
let {
|
|
6489
|
+
lookupCookie,
|
|
6490
|
+
cookieMinutes,
|
|
6491
|
+
cookieDomain,
|
|
6492
|
+
cookieOptions
|
|
6493
|
+
} = _ref2;
|
|
6494
|
+
if (lookupCookie && typeof document !== "undefined") {
|
|
6495
|
+
cookie.create(lookupCookie, lng, cookieMinutes, cookieDomain, cookieOptions);
|
|
6496
|
+
}
|
|
6497
|
+
}
|
|
6498
|
+
};
|
|
6499
|
+
var querystring = {
|
|
6500
|
+
name: "querystring",
|
|
6501
|
+
// Deconstruct the options object and extract the lookupQuerystring property
|
|
6502
|
+
lookup(_ref) {
|
|
6503
|
+
let {
|
|
6504
|
+
lookupQuerystring
|
|
6505
|
+
} = _ref;
|
|
6506
|
+
let found;
|
|
6507
|
+
if (typeof window !== "undefined") {
|
|
6508
|
+
let {
|
|
6509
|
+
search
|
|
6510
|
+
} = window.location;
|
|
6511
|
+
if (!window.location.search && window.location.hash?.indexOf("?") > -1) {
|
|
6512
|
+
search = window.location.hash.substring(window.location.hash.indexOf("?"));
|
|
6513
|
+
}
|
|
6514
|
+
const query = search.substring(1);
|
|
6515
|
+
const params = query.split("&");
|
|
6516
|
+
for (let i = 0; i < params.length; i++) {
|
|
6517
|
+
const pos = params[i].indexOf("=");
|
|
6518
|
+
if (pos > 0) {
|
|
6519
|
+
const key = params[i].substring(0, pos);
|
|
6520
|
+
if (key === lookupQuerystring) {
|
|
6521
|
+
found = params[i].substring(pos + 1);
|
|
6522
|
+
}
|
|
6523
|
+
}
|
|
6524
|
+
}
|
|
6525
|
+
}
|
|
6526
|
+
return found;
|
|
6527
|
+
}
|
|
6528
|
+
};
|
|
6529
|
+
var hash = {
|
|
6530
|
+
name: "hash",
|
|
6531
|
+
// Deconstruct the options object and extract the lookupHash property and the lookupFromHashIndex property
|
|
6532
|
+
lookup(_ref) {
|
|
6533
|
+
let {
|
|
6534
|
+
lookupHash,
|
|
6535
|
+
lookupFromHashIndex
|
|
6536
|
+
} = _ref;
|
|
6537
|
+
let found;
|
|
6538
|
+
if (typeof window !== "undefined") {
|
|
6539
|
+
const {
|
|
6540
|
+
hash: hash2
|
|
6541
|
+
} = window.location;
|
|
6542
|
+
if (hash2 && hash2.length > 2) {
|
|
6543
|
+
const query = hash2.substring(1);
|
|
6544
|
+
if (lookupHash) {
|
|
6545
|
+
const params = query.split("&");
|
|
6546
|
+
for (let i = 0; i < params.length; i++) {
|
|
6547
|
+
const pos = params[i].indexOf("=");
|
|
6548
|
+
if (pos > 0) {
|
|
6549
|
+
const key = params[i].substring(0, pos);
|
|
6550
|
+
if (key === lookupHash) {
|
|
6551
|
+
found = params[i].substring(pos + 1);
|
|
6552
|
+
}
|
|
6553
|
+
}
|
|
6554
|
+
}
|
|
6555
|
+
}
|
|
6556
|
+
if (found) return found;
|
|
6557
|
+
if (!found && lookupFromHashIndex > -1) {
|
|
6558
|
+
const language = hash2.match(/\/([a-zA-Z-]*)/g);
|
|
6559
|
+
if (!Array.isArray(language)) return void 0;
|
|
6560
|
+
const index = typeof lookupFromHashIndex === "number" ? lookupFromHashIndex : 0;
|
|
6561
|
+
return language[index]?.replace("/", "");
|
|
6562
|
+
}
|
|
6563
|
+
}
|
|
6564
|
+
}
|
|
6565
|
+
return found;
|
|
6566
|
+
}
|
|
6567
|
+
};
|
|
6568
|
+
var hasLocalStorageSupport = null;
|
|
6569
|
+
var localStorageAvailable = () => {
|
|
6570
|
+
if (hasLocalStorageSupport !== null) return hasLocalStorageSupport;
|
|
6571
|
+
try {
|
|
6572
|
+
hasLocalStorageSupport = typeof window !== "undefined" && window.localStorage !== null;
|
|
6573
|
+
if (!hasLocalStorageSupport) {
|
|
6574
|
+
return false;
|
|
6575
|
+
}
|
|
6576
|
+
const testKey = "i18next.translate.boo";
|
|
6577
|
+
window.localStorage.setItem(testKey, "foo");
|
|
6578
|
+
window.localStorage.removeItem(testKey);
|
|
6579
|
+
} catch (e2) {
|
|
6580
|
+
hasLocalStorageSupport = false;
|
|
6581
|
+
}
|
|
6582
|
+
return hasLocalStorageSupport;
|
|
6583
|
+
};
|
|
6584
|
+
var localStorage = {
|
|
6585
|
+
name: "localStorage",
|
|
6586
|
+
// Deconstruct the options object and extract the lookupLocalStorage property
|
|
6587
|
+
lookup(_ref) {
|
|
6588
|
+
let {
|
|
6589
|
+
lookupLocalStorage
|
|
6590
|
+
} = _ref;
|
|
6591
|
+
if (lookupLocalStorage && localStorageAvailable()) {
|
|
6592
|
+
return window.localStorage.getItem(lookupLocalStorage) || void 0;
|
|
6593
|
+
}
|
|
6594
|
+
return void 0;
|
|
6595
|
+
},
|
|
6596
|
+
// Deconstruct the options object and extract the lookupLocalStorage property
|
|
6597
|
+
cacheUserLanguage(lng, _ref2) {
|
|
6598
|
+
let {
|
|
6599
|
+
lookupLocalStorage
|
|
6600
|
+
} = _ref2;
|
|
6601
|
+
if (lookupLocalStorage && localStorageAvailable()) {
|
|
6602
|
+
window.localStorage.setItem(lookupLocalStorage, lng);
|
|
6603
|
+
}
|
|
6604
|
+
}
|
|
6605
|
+
};
|
|
6606
|
+
var hasSessionStorageSupport = null;
|
|
6607
|
+
var sessionStorageAvailable = () => {
|
|
6608
|
+
if (hasSessionStorageSupport !== null) return hasSessionStorageSupport;
|
|
6609
|
+
try {
|
|
6610
|
+
hasSessionStorageSupport = typeof window !== "undefined" && window.sessionStorage !== null;
|
|
6611
|
+
if (!hasSessionStorageSupport) {
|
|
6612
|
+
return false;
|
|
6613
|
+
}
|
|
6614
|
+
const testKey = "i18next.translate.boo";
|
|
6615
|
+
window.sessionStorage.setItem(testKey, "foo");
|
|
6616
|
+
window.sessionStorage.removeItem(testKey);
|
|
6617
|
+
} catch (e2) {
|
|
6618
|
+
hasSessionStorageSupport = false;
|
|
6619
|
+
}
|
|
6620
|
+
return hasSessionStorageSupport;
|
|
6621
|
+
};
|
|
6622
|
+
var sessionStorage = {
|
|
6623
|
+
name: "sessionStorage",
|
|
6624
|
+
lookup(_ref) {
|
|
6625
|
+
let {
|
|
6626
|
+
lookupSessionStorage
|
|
6627
|
+
} = _ref;
|
|
6628
|
+
if (lookupSessionStorage && sessionStorageAvailable()) {
|
|
6629
|
+
return window.sessionStorage.getItem(lookupSessionStorage) || void 0;
|
|
6630
|
+
}
|
|
6631
|
+
return void 0;
|
|
6632
|
+
},
|
|
6633
|
+
cacheUserLanguage(lng, _ref2) {
|
|
6634
|
+
let {
|
|
6635
|
+
lookupSessionStorage
|
|
6636
|
+
} = _ref2;
|
|
6637
|
+
if (lookupSessionStorage && sessionStorageAvailable()) {
|
|
6638
|
+
window.sessionStorage.setItem(lookupSessionStorage, lng);
|
|
6639
|
+
}
|
|
6640
|
+
}
|
|
6641
|
+
};
|
|
6642
|
+
var navigator$1 = {
|
|
6643
|
+
name: "navigator",
|
|
6644
|
+
lookup(options) {
|
|
6645
|
+
const found = [];
|
|
6646
|
+
if (typeof navigator !== "undefined") {
|
|
6647
|
+
const {
|
|
6648
|
+
languages,
|
|
6649
|
+
userLanguage,
|
|
6650
|
+
language
|
|
6651
|
+
} = navigator;
|
|
6652
|
+
if (languages) {
|
|
6653
|
+
for (let i = 0; i < languages.length; i++) {
|
|
6654
|
+
found.push(languages[i]);
|
|
6655
|
+
}
|
|
6656
|
+
}
|
|
6657
|
+
if (userLanguage) {
|
|
6658
|
+
found.push(userLanguage);
|
|
6659
|
+
}
|
|
6660
|
+
if (language) {
|
|
6661
|
+
found.push(language);
|
|
6662
|
+
}
|
|
6663
|
+
}
|
|
6664
|
+
return found.length > 0 ? found : void 0;
|
|
6665
|
+
}
|
|
6666
|
+
};
|
|
6667
|
+
var htmlTag = {
|
|
6668
|
+
name: "htmlTag",
|
|
6669
|
+
// Deconstruct the options object and extract the htmlTag property
|
|
6670
|
+
lookup(_ref) {
|
|
6671
|
+
let {
|
|
6672
|
+
htmlTag: htmlTag2
|
|
6673
|
+
} = _ref;
|
|
6674
|
+
let found;
|
|
6675
|
+
const internalHtmlTag = htmlTag2 || (typeof document !== "undefined" ? document.documentElement : null);
|
|
6676
|
+
if (internalHtmlTag && typeof internalHtmlTag.getAttribute === "function") {
|
|
6677
|
+
found = internalHtmlTag.getAttribute("lang");
|
|
6678
|
+
}
|
|
6679
|
+
return found;
|
|
6680
|
+
}
|
|
6681
|
+
};
|
|
6682
|
+
var path = {
|
|
6683
|
+
name: "path",
|
|
6684
|
+
// Deconstruct the options object and extract the lookupFromPathIndex property
|
|
6685
|
+
lookup(_ref) {
|
|
6686
|
+
let {
|
|
6687
|
+
lookupFromPathIndex
|
|
6688
|
+
} = _ref;
|
|
6689
|
+
if (typeof window === "undefined") return void 0;
|
|
6690
|
+
const language = window.location.pathname.match(/\/([a-zA-Z-]*)/g);
|
|
6691
|
+
if (!Array.isArray(language)) return void 0;
|
|
6692
|
+
const index = typeof lookupFromPathIndex === "number" ? lookupFromPathIndex : 0;
|
|
6693
|
+
return language[index]?.replace("/", "");
|
|
6694
|
+
}
|
|
6695
|
+
};
|
|
6696
|
+
var subdomain = {
|
|
6697
|
+
name: "subdomain",
|
|
6698
|
+
lookup(_ref) {
|
|
6699
|
+
let {
|
|
6700
|
+
lookupFromSubdomainIndex
|
|
6701
|
+
} = _ref;
|
|
6702
|
+
const internalLookupFromSubdomainIndex = typeof lookupFromSubdomainIndex === "number" ? lookupFromSubdomainIndex + 1 : 1;
|
|
6703
|
+
const language = typeof window !== "undefined" && window.location?.hostname?.match(/^(\w{2,5})\.(([a-z0-9-]{1,63}\.[a-z]{2,6})|localhost)/i);
|
|
6704
|
+
if (!language) return void 0;
|
|
6705
|
+
return language[internalLookupFromSubdomainIndex];
|
|
6706
|
+
}
|
|
6707
|
+
};
|
|
6708
|
+
var canCookies = false;
|
|
6709
|
+
try {
|
|
6710
|
+
document.cookie;
|
|
6711
|
+
canCookies = true;
|
|
6712
|
+
} catch (e2) {
|
|
6713
|
+
}
|
|
6714
|
+
var order = ["querystring", "cookie", "localStorage", "sessionStorage", "navigator", "htmlTag"];
|
|
6715
|
+
if (!canCookies) order.splice(1, 1);
|
|
6716
|
+
var getDefaults2 = () => ({
|
|
6717
|
+
order,
|
|
6718
|
+
lookupQuerystring: "lng",
|
|
6719
|
+
lookupCookie: "i18next",
|
|
6720
|
+
lookupLocalStorage: "i18nextLng",
|
|
6721
|
+
lookupSessionStorage: "i18nextLng",
|
|
6722
|
+
// cache user language
|
|
6723
|
+
caches: ["localStorage"],
|
|
6724
|
+
excludeCacheFor: ["cimode"],
|
|
6725
|
+
// cookieMinutes: 10,
|
|
6726
|
+
// cookieDomain: 'myDomain'
|
|
6727
|
+
convertDetectedLanguage: (l) => l
|
|
6728
|
+
});
|
|
6729
|
+
var Browser = class {
|
|
6730
|
+
constructor(services) {
|
|
6731
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
6732
|
+
this.type = "languageDetector";
|
|
6733
|
+
this.detectors = {};
|
|
6734
|
+
this.init(services, options);
|
|
6735
|
+
}
|
|
6736
|
+
init() {
|
|
6737
|
+
let services = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
|
|
6738
|
+
languageUtils: {}
|
|
6739
|
+
};
|
|
6740
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
6741
|
+
let i18nOptions = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
6742
|
+
this.services = services;
|
|
6743
|
+
this.options = defaults(options, this.options || {}, getDefaults2());
|
|
6744
|
+
if (typeof this.options.convertDetectedLanguage === "string" && this.options.convertDetectedLanguage.indexOf("15897") > -1) {
|
|
6745
|
+
this.options.convertDetectedLanguage = (l) => l.replace("-", "_");
|
|
6746
|
+
}
|
|
6747
|
+
if (this.options.lookupFromUrlIndex) this.options.lookupFromPathIndex = this.options.lookupFromUrlIndex;
|
|
6748
|
+
this.i18nOptions = i18nOptions;
|
|
6749
|
+
this.addDetector(cookie$1);
|
|
6750
|
+
this.addDetector(querystring);
|
|
6751
|
+
this.addDetector(localStorage);
|
|
6752
|
+
this.addDetector(sessionStorage);
|
|
6753
|
+
this.addDetector(navigator$1);
|
|
6754
|
+
this.addDetector(htmlTag);
|
|
6755
|
+
this.addDetector(path);
|
|
6756
|
+
this.addDetector(subdomain);
|
|
6757
|
+
this.addDetector(hash);
|
|
6758
|
+
}
|
|
6759
|
+
addDetector(detector) {
|
|
6760
|
+
this.detectors[detector.name] = detector;
|
|
6761
|
+
return this;
|
|
6762
|
+
}
|
|
6763
|
+
detect() {
|
|
6764
|
+
let detectionOrder = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.options.order;
|
|
6765
|
+
let detected = [];
|
|
6766
|
+
detectionOrder.forEach((detectorName) => {
|
|
6767
|
+
if (this.detectors[detectorName]) {
|
|
6768
|
+
let lookup = this.detectors[detectorName].lookup(this.options);
|
|
6769
|
+
if (lookup && typeof lookup === "string") lookup = [lookup];
|
|
6770
|
+
if (lookup) detected = detected.concat(lookup);
|
|
6771
|
+
}
|
|
6772
|
+
});
|
|
6773
|
+
detected = detected.filter((d) => d !== void 0 && d !== null && !hasXSS(d)).map((d) => this.options.convertDetectedLanguage(d));
|
|
6774
|
+
if (this.services && this.services.languageUtils && this.services.languageUtils.getBestMatchFromCodes) return detected;
|
|
6775
|
+
return detected.length > 0 ? detected[0] : null;
|
|
6776
|
+
}
|
|
6777
|
+
cacheUserLanguage(lng) {
|
|
6778
|
+
let caches = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : this.options.caches;
|
|
6779
|
+
if (!caches) return;
|
|
6780
|
+
if (this.options.excludeCacheFor && this.options.excludeCacheFor.indexOf(lng) > -1) return;
|
|
6781
|
+
caches.forEach((cacheName) => {
|
|
6782
|
+
if (this.detectors[cacheName]) this.detectors[cacheName].cacheUserLanguage(lng, this.options);
|
|
6783
|
+
});
|
|
6784
|
+
}
|
|
6785
|
+
};
|
|
6786
|
+
Browser.type = "languageDetector";
|
|
6787
|
+
|
|
6788
|
+
// src/locales/vi.json
|
|
6789
|
+
var vi_default = {
|
|
6790
|
+
"search...": "T\xECm ki\u1EBFm...",
|
|
6791
|
+
search: "T\xECm ki\u1EBFm",
|
|
6792
|
+
search_more: "T\xECm ki\u1EBFm th\xEAm",
|
|
6793
|
+
for: "cho",
|
|
6794
|
+
cancel: "H\u1EE7y",
|
|
6795
|
+
empty_data: "D\u1EEF li\u1EC7u tr\u1ED1ng",
|
|
6796
|
+
detail_button: "Chi ti\u1EBFt",
|
|
6797
|
+
cancel_button: "H\u1EE7y",
|
|
6798
|
+
choose: "Ch\u1ECDn",
|
|
6799
|
+
total: "T\u1ED5ng ti\u1EC1n",
|
|
6800
|
+
no: "Kh\xF4ng",
|
|
6801
|
+
loading: "\u0110ang t\u1EA3i",
|
|
6802
|
+
active: "Ho\u1EA1t \u0111\u1ED9ng",
|
|
6803
|
+
in_active: "Ng\u01B0ng ho\u1EA1t \u0111\u1ED9ng",
|
|
6804
|
+
new: "M\u1EDBi",
|
|
6805
|
+
add_line: "Th\xEAm d\xF2ng",
|
|
6806
|
+
choose_place: "Vui l\xF2ng ch\u1ECDn",
|
|
6807
|
+
filter_by: "B\u1ED9 l\u1ECDc",
|
|
6808
|
+
group_by: "Nh\xF3m theo",
|
|
6809
|
+
or: "ho\u1EB7c",
|
|
6810
|
+
now: "B\xE2y gi\u1EDD",
|
|
6811
|
+
download_file: "T\u1EA3i xu\u1ED1ng t\u1EC7p n\xE0y",
|
|
6812
|
+
upload_success: "T\u1EA3i t\u1EC7p l\xEAn th\xE0nh c\xF4ng",
|
|
6813
|
+
upload_failure: "T\u1EA3i t\u1EC7p l\xEAn th\u1EA5t b\u1EA1i",
|
|
6814
|
+
file_accept_single: "Ch\u1EC9 ch\u1EA5p nh\u1EADn c\xE1c \u0111\u1ECBnh d\u1EA1ng JPEG, PNG, PDF, MP4, XLS, XLXS, ZIP v\xE0 m\u1ED7i t\u1EC7p c\xF3 dung l\u01B0\u1EE3ng t\u1ED1i \u0111a l\xE0 10MB.",
|
|
6815
|
+
file_accept_total: "Ch\u1EC9 ch\u1EA5p nh\u1EADn c\xE1c \u0111\u1ECBnh d\u1EA1ng JPEG, PNG, PDF, MP4, XLS, XLXS, ZIP v\xE0 t\u1ED5ng dung l\u01B0\u1EE3ng t\u1ED1i \u0111a l\xE0 50MB.",
|
|
6816
|
+
must_required: "l\xE0 b\u1EAFt bu\u1ED9c.",
|
|
6817
|
+
"none-validated": "Gi\xE1 tr\u1ECB kh\xF4ng h\u1EE3p l\u1EC7",
|
|
6818
|
+
invalid_number: "\u0110\u1ECBnh d\u1EA1ng s\u1ED1 kh\xF4ng h\u1EE3p l\u1EC7",
|
|
6819
|
+
upload_file_placeholder: "T\u1EA3i t\u1EC7p c\u1EE7a b\u1EA1n",
|
|
6820
|
+
"no-available": "Kh\xF4ng c\xF3 l\u1EF1a ch\u1ECDn n\xE0o",
|
|
6821
|
+
paid_amount: "S\u1ED1 ti\u1EC1n \u0111\xE3 \u0111\xF3ng",
|
|
6822
|
+
remanining_amount: "S\u1ED1 ti\u1EC1n c\xF2n l\u1EA1i"
|
|
6823
|
+
};
|
|
6824
|
+
|
|
6825
|
+
// src/locales/en.json
|
|
6826
|
+
var en_default = {
|
|
6827
|
+
"none-validated": "Invalid value",
|
|
6828
|
+
"search...": "Search...",
|
|
6829
|
+
search: "Search",
|
|
6830
|
+
search_more: "Search more",
|
|
6831
|
+
for: "for",
|
|
6832
|
+
cancel: "Cancel",
|
|
6833
|
+
choose: "Choose",
|
|
6834
|
+
total: "Total",
|
|
6835
|
+
no: "No",
|
|
6836
|
+
loading: "Loading",
|
|
6837
|
+
detail_button: "Detail",
|
|
6838
|
+
cancel_button: "Cancel",
|
|
6839
|
+
empty_data: "No data",
|
|
6840
|
+
new: "New",
|
|
6841
|
+
add_line: "Add a line",
|
|
6842
|
+
choose_place: "Please choose",
|
|
6843
|
+
filter_by: "Filter",
|
|
6844
|
+
group_by: "Group By",
|
|
6845
|
+
or: "or",
|
|
6846
|
+
now: "Now",
|
|
6847
|
+
download_file: "Download this file",
|
|
6848
|
+
upload_success: "Upload file success",
|
|
6849
|
+
upload_failure: "Upload file failure",
|
|
6850
|
+
file_accept_single: "Only JPEG, PNG, PDF, MP4, XLS, XLXS, ZIP formats are allowed, and each file should be up to 10MB.",
|
|
6851
|
+
file_accept_total: "Only JPEG, PNG, PDF, MP4, XLS, XLXS, ZIP formats are allowed, and total should be up to 50MB.",
|
|
6852
|
+
must_required: "is required",
|
|
6853
|
+
invalid_number: "Invalid number",
|
|
6854
|
+
active: "Active",
|
|
6855
|
+
in_active: "Inactive",
|
|
6856
|
+
upload_file_placeholder: "Upload your file",
|
|
6857
|
+
"no-available": "No options available",
|
|
6858
|
+
paid_amount: "Amount Paid",
|
|
6859
|
+
remanining_amount: "Amount Remaining"
|
|
6860
|
+
};
|
|
6861
|
+
|
|
6862
|
+
// src/utils/i18n.ts
|
|
6863
|
+
instance.use(Browser).use(initReactI18next).init({
|
|
6864
|
+
resources: {
|
|
6865
|
+
vi: { translation: vi_default },
|
|
6866
|
+
en: { translation: en_default }
|
|
6867
|
+
},
|
|
6868
|
+
fallbackLng: "vi",
|
|
6869
|
+
lng: "vi_VN",
|
|
6870
|
+
debug: false,
|
|
6871
|
+
nonExplicitSupportedLngs: true,
|
|
6872
|
+
interpolation: {
|
|
6873
|
+
escapeValue: false
|
|
6874
|
+
},
|
|
6875
|
+
detection: {
|
|
6876
|
+
caches: ["cookie"]
|
|
6877
|
+
}
|
|
6878
|
+
});
|
|
6879
|
+
|
|
6880
|
+
// src/provider/index.tsx
|
|
6881
|
+
import { jsx } from "react/jsx-runtime";
|
|
6882
|
+
var I18nContext2 = createContext2(null);
|
|
6883
|
+
var useI18n = () => {
|
|
6884
|
+
const context = useContext4(I18nContext2);
|
|
6885
|
+
if (!context) {
|
|
6886
|
+
throw new Error("useI18n must be used within I18nProvider");
|
|
6887
|
+
}
|
|
6888
|
+
return context;
|
|
4298
6889
|
};
|
|
4299
|
-
|
|
4300
|
-
// node_modules/react-i18next/dist/es/withTranslation.js
|
|
4301
|
-
import { createElement as createElement2, forwardRef as forwardRefReact } from "react";
|
|
4302
|
-
|
|
4303
|
-
// node_modules/react-i18next/dist/es/I18nextProvider.js
|
|
4304
|
-
import { createElement as createElement3, useMemo } from "react";
|
|
4305
|
-
|
|
4306
|
-
// node_modules/react-i18next/dist/es/withSSR.js
|
|
4307
|
-
import { createElement as createElement4 } from "react";
|
|
4308
|
-
|
|
4309
|
-
// node_modules/react-i18next/dist/es/useSSR.js
|
|
4310
|
-
import { useContext as useContext3 } from "react";
|
|
4311
6890
|
|
|
4312
6891
|
// src/utils/function.ts
|
|
4313
6892
|
var useFormatDate = () => {
|
|
4314
|
-
const { t } =
|
|
6893
|
+
const { t: t2 } = useI18n();
|
|
4315
6894
|
const getRelativeTime = (dateString) => {
|
|
4316
6895
|
const units = [
|
|
4317
6896
|
{
|
|
@@ -4375,10 +6954,10 @@ var useFormatDate = () => {
|
|
|
4375
6954
|
let diff = absoluteDiff / seconds2;
|
|
4376
6955
|
if (diff >= 1) {
|
|
4377
6956
|
diff = isFuture ? Math.ceil(diff) : Math.floor(diff);
|
|
4378
|
-
return isFuture ? `${diff} ${
|
|
6957
|
+
return isFuture ? `${diff} ${t2(keyFuture, { count: diff })}` : `${diff} ${t2(keyPast, { count: diff })}`;
|
|
4379
6958
|
}
|
|
4380
6959
|
}
|
|
4381
|
-
return
|
|
6960
|
+
return t2("now");
|
|
4382
6961
|
};
|
|
4383
6962
|
return { getRelativeTime };
|
|
4384
6963
|
};
|