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