@thanh01.pmt/interactive-quiz-kit 1.0.89 → 1.1.0
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/i18n.cjs +5 -2374
- package/dist/i18n.mjs +4 -2374
- package/dist/index.cjs +438 -2508
- package/dist/index.mjs +437 -2508
- package/dist/player.cjs +1263 -3292
- package/dist/player.mjs +1262 -3290
- package/dist/react-ui.cjs +427 -84
- package/dist/react-ui.mjs +427 -82
- package/package.json +5 -3
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var i18n = require('i18next');
|
|
3
4
|
var reactI18next = require('react-i18next');
|
|
4
5
|
var LanguageDetector = require('i18next-browser-languagedetector');
|
|
5
6
|
var generativeAi = require('@google/generative-ai');
|
|
6
7
|
|
|
7
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
9
|
|
|
10
|
+
var i18n__default = /*#__PURE__*/_interopDefault(i18n);
|
|
9
11
|
var LanguageDetector__default = /*#__PURE__*/_interopDefault(LanguageDetector);
|
|
10
12
|
|
|
11
13
|
var __create = Object.create;
|
|
@@ -188,10 +190,10 @@ var require_util = __commonJS({
|
|
|
188
190
|
return typeof arg === "number";
|
|
189
191
|
}
|
|
190
192
|
exports$1.isNumber = isNumber2;
|
|
191
|
-
function
|
|
193
|
+
function isString(arg) {
|
|
192
194
|
return typeof arg === "string";
|
|
193
195
|
}
|
|
194
|
-
exports$1.isString =
|
|
196
|
+
exports$1.isString = isString;
|
|
195
197
|
function isSymbol(arg) {
|
|
196
198
|
return typeof arg === "symbol";
|
|
197
199
|
}
|
|
@@ -281,8 +283,8 @@ var require_inherits = __commonJS({
|
|
|
281
283
|
// ../../node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/internal/streams/BufferList.js
|
|
282
284
|
var require_BufferList = __commonJS({
|
|
283
285
|
"../../node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/internal/streams/BufferList.js"(exports$1, module) {
|
|
284
|
-
function _classCallCheck(
|
|
285
|
-
if (!(
|
|
286
|
+
function _classCallCheck(instance, Constructor) {
|
|
287
|
+
if (!(instance instanceof Constructor)) {
|
|
286
288
|
throw new TypeError("Cannot call a class as a function");
|
|
287
289
|
}
|
|
288
290
|
}
|
|
@@ -3751,18 +3753,18 @@ var require_crc32 = __commonJS({
|
|
|
3751
3753
|
}
|
|
3752
3754
|
var crcTable = makeTable();
|
|
3753
3755
|
function crc32(crc, buf, len, pos) {
|
|
3754
|
-
var
|
|
3756
|
+
var t = crcTable, end = pos + len;
|
|
3755
3757
|
crc = crc ^ -1;
|
|
3756
3758
|
for (var i = pos; i < end; i++) {
|
|
3757
|
-
crc = crc >>> 8 ^
|
|
3759
|
+
crc = crc >>> 8 ^ t[(crc ^ buf[i]) & 255];
|
|
3758
3760
|
}
|
|
3759
3761
|
return crc ^ -1;
|
|
3760
3762
|
}
|
|
3761
3763
|
function crc32str(crc, str, len, pos) {
|
|
3762
|
-
var
|
|
3764
|
+
var t = crcTable, end = pos + len;
|
|
3763
3765
|
crc = crc ^ -1;
|
|
3764
3766
|
for (var i = pos; i < end; i++) {
|
|
3765
|
-
crc = crc >>> 8 ^
|
|
3767
|
+
crc = crc >>> 8 ^ t[(crc ^ str.charCodeAt(i)) & 255];
|
|
3766
3768
|
}
|
|
3767
3769
|
return crc ^ -1;
|
|
3768
3770
|
}
|
|
@@ -4749,10 +4751,10 @@ var require_crc322 = __commonJS({
|
|
|
4749
4751
|
}
|
|
4750
4752
|
var crcTable = makeTable();
|
|
4751
4753
|
function crc32(crc, buf, len, pos) {
|
|
4752
|
-
var
|
|
4754
|
+
var t = crcTable, end = pos + len;
|
|
4753
4755
|
crc ^= -1;
|
|
4754
4756
|
for (var i = pos; i < end; i++) {
|
|
4755
|
-
crc = crc >>> 8 ^
|
|
4757
|
+
crc = crc >>> 8 ^ t[(crc ^ buf[i]) & 255];
|
|
4756
4758
|
}
|
|
4757
4759
|
return crc ^ -1;
|
|
4758
4760
|
}
|
|
@@ -6910,7 +6912,7 @@ var require_inflate = __commonJS({
|
|
|
6910
6912
|
state.distcode = distfix;
|
|
6911
6913
|
state.distbits = 5;
|
|
6912
6914
|
}
|
|
6913
|
-
function updatewindow(strm, src, end,
|
|
6915
|
+
function updatewindow(strm, src, end, copy) {
|
|
6914
6916
|
var dist;
|
|
6915
6917
|
var state = strm.state;
|
|
6916
6918
|
if (state.window === null) {
|
|
@@ -6919,20 +6921,20 @@ var require_inflate = __commonJS({
|
|
|
6919
6921
|
state.whave = 0;
|
|
6920
6922
|
state.window = new utils.Buf8(state.wsize);
|
|
6921
6923
|
}
|
|
6922
|
-
if (
|
|
6924
|
+
if (copy >= state.wsize) {
|
|
6923
6925
|
utils.arraySet(state.window, src, end - state.wsize, state.wsize, 0);
|
|
6924
6926
|
state.wnext = 0;
|
|
6925
6927
|
state.whave = state.wsize;
|
|
6926
6928
|
} else {
|
|
6927
6929
|
dist = state.wsize - state.wnext;
|
|
6928
|
-
if (dist >
|
|
6929
|
-
dist =
|
|
6930
|
-
}
|
|
6931
|
-
utils.arraySet(state.window, src, end -
|
|
6932
|
-
|
|
6933
|
-
if (
|
|
6934
|
-
utils.arraySet(state.window, src, end -
|
|
6935
|
-
state.wnext =
|
|
6930
|
+
if (dist > copy) {
|
|
6931
|
+
dist = copy;
|
|
6932
|
+
}
|
|
6933
|
+
utils.arraySet(state.window, src, end - copy, dist, state.wnext);
|
|
6934
|
+
copy -= dist;
|
|
6935
|
+
if (copy) {
|
|
6936
|
+
utils.arraySet(state.window, src, end - copy, copy, 0);
|
|
6937
|
+
state.wnext = copy;
|
|
6936
6938
|
state.whave = state.wsize;
|
|
6937
6939
|
} else {
|
|
6938
6940
|
state.wnext += dist;
|
|
@@ -6955,7 +6957,7 @@ var require_inflate = __commonJS({
|
|
|
6955
6957
|
var hold;
|
|
6956
6958
|
var bits;
|
|
6957
6959
|
var _in, _out;
|
|
6958
|
-
var
|
|
6960
|
+
var copy;
|
|
6959
6961
|
var from;
|
|
6960
6962
|
var from_source;
|
|
6961
6963
|
var here = 0;
|
|
@@ -7150,11 +7152,11 @@ var require_inflate = __commonJS({
|
|
|
7150
7152
|
/* falls through */
|
|
7151
7153
|
case EXTRA:
|
|
7152
7154
|
if (state.flags & 1024) {
|
|
7153
|
-
|
|
7154
|
-
if (
|
|
7155
|
-
|
|
7155
|
+
copy = state.length;
|
|
7156
|
+
if (copy > have) {
|
|
7157
|
+
copy = have;
|
|
7156
7158
|
}
|
|
7157
|
-
if (
|
|
7159
|
+
if (copy) {
|
|
7158
7160
|
if (state.head) {
|
|
7159
7161
|
len = state.head.extra_len - state.length;
|
|
7160
7162
|
if (!state.head.extra) {
|
|
@@ -7166,17 +7168,17 @@ var require_inflate = __commonJS({
|
|
|
7166
7168
|
next,
|
|
7167
7169
|
// extra field is limited to 65536 bytes
|
|
7168
7170
|
// - no need for additional size check
|
|
7169
|
-
|
|
7171
|
+
copy,
|
|
7170
7172
|
/*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/
|
|
7171
7173
|
len
|
|
7172
7174
|
);
|
|
7173
7175
|
}
|
|
7174
7176
|
if (state.flags & 512) {
|
|
7175
|
-
state.check = crc32(state.check, input,
|
|
7177
|
+
state.check = crc32(state.check, input, copy, next);
|
|
7176
7178
|
}
|
|
7177
|
-
have -=
|
|
7178
|
-
next +=
|
|
7179
|
-
state.length -=
|
|
7179
|
+
have -= copy;
|
|
7180
|
+
next += copy;
|
|
7181
|
+
state.length -= copy;
|
|
7180
7182
|
}
|
|
7181
7183
|
if (state.length) {
|
|
7182
7184
|
break inf_leave;
|
|
@@ -7190,18 +7192,18 @@ var require_inflate = __commonJS({
|
|
|
7190
7192
|
if (have === 0) {
|
|
7191
7193
|
break inf_leave;
|
|
7192
7194
|
}
|
|
7193
|
-
|
|
7195
|
+
copy = 0;
|
|
7194
7196
|
do {
|
|
7195
|
-
len = input[next +
|
|
7197
|
+
len = input[next + copy++];
|
|
7196
7198
|
if (state.head && len && state.length < 65536) {
|
|
7197
7199
|
state.head.name += String.fromCharCode(len);
|
|
7198
7200
|
}
|
|
7199
|
-
} while (len &&
|
|
7201
|
+
} while (len && copy < have);
|
|
7200
7202
|
if (state.flags & 512) {
|
|
7201
|
-
state.check = crc32(state.check, input,
|
|
7203
|
+
state.check = crc32(state.check, input, copy, next);
|
|
7202
7204
|
}
|
|
7203
|
-
have -=
|
|
7204
|
-
next +=
|
|
7205
|
+
have -= copy;
|
|
7206
|
+
next += copy;
|
|
7205
7207
|
if (len) {
|
|
7206
7208
|
break inf_leave;
|
|
7207
7209
|
}
|
|
@@ -7216,18 +7218,18 @@ var require_inflate = __commonJS({
|
|
|
7216
7218
|
if (have === 0) {
|
|
7217
7219
|
break inf_leave;
|
|
7218
7220
|
}
|
|
7219
|
-
|
|
7221
|
+
copy = 0;
|
|
7220
7222
|
do {
|
|
7221
|
-
len = input[next +
|
|
7223
|
+
len = input[next + copy++];
|
|
7222
7224
|
if (state.head && len && state.length < 65536) {
|
|
7223
7225
|
state.head.comment += String.fromCharCode(len);
|
|
7224
7226
|
}
|
|
7225
|
-
} while (len &&
|
|
7227
|
+
} while (len && copy < have);
|
|
7226
7228
|
if (state.flags & 512) {
|
|
7227
|
-
state.check = crc32(state.check, input,
|
|
7229
|
+
state.check = crc32(state.check, input, copy, next);
|
|
7228
7230
|
}
|
|
7229
|
-
have -=
|
|
7230
|
-
next +=
|
|
7231
|
+
have -= copy;
|
|
7232
|
+
next += copy;
|
|
7231
7233
|
if (len) {
|
|
7232
7234
|
break inf_leave;
|
|
7233
7235
|
}
|
|
@@ -7362,23 +7364,23 @@ var require_inflate = __commonJS({
|
|
|
7362
7364
|
state.mode = COPY;
|
|
7363
7365
|
/* falls through */
|
|
7364
7366
|
case COPY:
|
|
7365
|
-
|
|
7366
|
-
if (
|
|
7367
|
-
if (
|
|
7368
|
-
|
|
7367
|
+
copy = state.length;
|
|
7368
|
+
if (copy) {
|
|
7369
|
+
if (copy > have) {
|
|
7370
|
+
copy = have;
|
|
7369
7371
|
}
|
|
7370
|
-
if (
|
|
7371
|
-
|
|
7372
|
+
if (copy > left) {
|
|
7373
|
+
copy = left;
|
|
7372
7374
|
}
|
|
7373
|
-
if (
|
|
7375
|
+
if (copy === 0) {
|
|
7374
7376
|
break inf_leave;
|
|
7375
7377
|
}
|
|
7376
|
-
utils.arraySet(output, input, next,
|
|
7377
|
-
have -=
|
|
7378
|
-
next +=
|
|
7379
|
-
left -=
|
|
7380
|
-
put +=
|
|
7381
|
-
state.length -=
|
|
7378
|
+
utils.arraySet(output, input, next, copy, put);
|
|
7379
|
+
have -= copy;
|
|
7380
|
+
next += copy;
|
|
7381
|
+
left -= copy;
|
|
7382
|
+
put += copy;
|
|
7383
|
+
state.length -= copy;
|
|
7382
7384
|
break;
|
|
7383
7385
|
}
|
|
7384
7386
|
state.mode = TYPE;
|
|
@@ -7479,7 +7481,7 @@ var require_inflate = __commonJS({
|
|
|
7479
7481
|
break;
|
|
7480
7482
|
}
|
|
7481
7483
|
len = state.lens[state.have - 1];
|
|
7482
|
-
|
|
7484
|
+
copy = 3 + (hold & 3);
|
|
7483
7485
|
hold >>>= 2;
|
|
7484
7486
|
bits -= 2;
|
|
7485
7487
|
} else if (here_val === 17) {
|
|
@@ -7495,7 +7497,7 @@ var require_inflate = __commonJS({
|
|
|
7495
7497
|
hold >>>= here_bits;
|
|
7496
7498
|
bits -= here_bits;
|
|
7497
7499
|
len = 0;
|
|
7498
|
-
|
|
7500
|
+
copy = 3 + (hold & 7);
|
|
7499
7501
|
hold >>>= 3;
|
|
7500
7502
|
bits -= 3;
|
|
7501
7503
|
} else {
|
|
@@ -7511,16 +7513,16 @@ var require_inflate = __commonJS({
|
|
|
7511
7513
|
hold >>>= here_bits;
|
|
7512
7514
|
bits -= here_bits;
|
|
7513
7515
|
len = 0;
|
|
7514
|
-
|
|
7516
|
+
copy = 11 + (hold & 127);
|
|
7515
7517
|
hold >>>= 7;
|
|
7516
7518
|
bits -= 7;
|
|
7517
7519
|
}
|
|
7518
|
-
if (state.have +
|
|
7520
|
+
if (state.have + copy > state.nlen + state.ndist) {
|
|
7519
7521
|
strm.msg = "invalid bit length repeat";
|
|
7520
7522
|
state.mode = BAD;
|
|
7521
7523
|
break;
|
|
7522
7524
|
}
|
|
7523
|
-
while (
|
|
7525
|
+
while (copy--) {
|
|
7524
7526
|
state.lens[state.have++] = len;
|
|
7525
7527
|
}
|
|
7526
7528
|
}
|
|
@@ -7739,39 +7741,39 @@ var require_inflate = __commonJS({
|
|
|
7739
7741
|
if (left === 0) {
|
|
7740
7742
|
break inf_leave;
|
|
7741
7743
|
}
|
|
7742
|
-
|
|
7743
|
-
if (state.offset >
|
|
7744
|
-
|
|
7745
|
-
if (
|
|
7744
|
+
copy = _out - left;
|
|
7745
|
+
if (state.offset > copy) {
|
|
7746
|
+
copy = state.offset - copy;
|
|
7747
|
+
if (copy > state.whave) {
|
|
7746
7748
|
if (state.sane) {
|
|
7747
7749
|
strm.msg = "invalid distance too far back";
|
|
7748
7750
|
state.mode = BAD;
|
|
7749
7751
|
break;
|
|
7750
7752
|
}
|
|
7751
7753
|
}
|
|
7752
|
-
if (
|
|
7753
|
-
|
|
7754
|
-
from = state.wsize -
|
|
7754
|
+
if (copy > state.wnext) {
|
|
7755
|
+
copy -= state.wnext;
|
|
7756
|
+
from = state.wsize - copy;
|
|
7755
7757
|
} else {
|
|
7756
|
-
from = state.wnext -
|
|
7758
|
+
from = state.wnext - copy;
|
|
7757
7759
|
}
|
|
7758
|
-
if (
|
|
7759
|
-
|
|
7760
|
+
if (copy > state.length) {
|
|
7761
|
+
copy = state.length;
|
|
7760
7762
|
}
|
|
7761
7763
|
from_source = state.window;
|
|
7762
7764
|
} else {
|
|
7763
7765
|
from_source = output;
|
|
7764
7766
|
from = put - state.offset;
|
|
7765
|
-
|
|
7767
|
+
copy = state.length;
|
|
7766
7768
|
}
|
|
7767
|
-
if (
|
|
7768
|
-
|
|
7769
|
+
if (copy > left) {
|
|
7770
|
+
copy = left;
|
|
7769
7771
|
}
|
|
7770
|
-
left -=
|
|
7771
|
-
state.length -=
|
|
7772
|
+
left -= copy;
|
|
7773
|
+
state.length -= copy;
|
|
7772
7774
|
do {
|
|
7773
7775
|
output[put++] = from_source[from++];
|
|
7774
|
-
} while (--
|
|
7776
|
+
} while (--copy);
|
|
7775
7777
|
if (state.length === 0) {
|
|
7776
7778
|
state.mode = LEN;
|
|
7777
7779
|
}
|
|
@@ -8299,7 +8301,7 @@ var require_ZipFileWorker = __commonJS({
|
|
|
8299
8301
|
return (dosPermissions || 0) & 63;
|
|
8300
8302
|
};
|
|
8301
8303
|
var generateZipParts = function(streamInfo, streamedContent, streamingEnded, offset, platform, encodeFileName) {
|
|
8302
|
-
var file = streamInfo["file"], compression = streamInfo["compression"], useCustomEncoding = encodeFileName !== utf8.utf8encode, encodedFileName = utils.transformTo("string", encodeFileName(file.name)), utfEncodedFileName = utils.transformTo("string", utf8.utf8encode(file.name)), comment = file.comment, encodedComment = utils.transformTo("string", encodeFileName(comment)), utfEncodedComment = utils.transformTo("string", utf8.utf8encode(comment)), useUTF8ForFileName = utfEncodedFileName.length !== file.name.length, useUTF8ForComment = utfEncodedComment.length !== comment.length, dosTime, dosDate, extraFields = "", unicodePathExtraField = "", unicodeCommentExtraField = "",
|
|
8304
|
+
var file = streamInfo["file"], compression = streamInfo["compression"], useCustomEncoding = encodeFileName !== utf8.utf8encode, encodedFileName = utils.transformTo("string", encodeFileName(file.name)), utfEncodedFileName = utils.transformTo("string", utf8.utf8encode(file.name)), comment = file.comment, encodedComment = utils.transformTo("string", encodeFileName(comment)), utfEncodedComment = utils.transformTo("string", utf8.utf8encode(comment)), useUTF8ForFileName = utfEncodedFileName.length !== file.name.length, useUTF8ForComment = utfEncodedComment.length !== comment.length, dosTime, dosDate, extraFields = "", unicodePathExtraField = "", unicodeCommentExtraField = "", dir = file.dir, date = file.date;
|
|
8303
8305
|
var dataInfo = {
|
|
8304
8306
|
crc32: 0,
|
|
8305
8307
|
compressedSize: 0,
|
|
@@ -8319,12 +8321,12 @@ var require_ZipFileWorker = __commonJS({
|
|
|
8319
8321
|
}
|
|
8320
8322
|
var extFileAttr = 0;
|
|
8321
8323
|
var versionMadeBy = 0;
|
|
8322
|
-
if (
|
|
8324
|
+
if (dir) {
|
|
8323
8325
|
extFileAttr |= 16;
|
|
8324
8326
|
}
|
|
8325
8327
|
if (platform === "UNIX") {
|
|
8326
8328
|
versionMadeBy = 798;
|
|
8327
|
-
extFileAttr |= generateUnixExternalFileAttr(file.unixPermissions,
|
|
8329
|
+
extFileAttr |= generateUnixExternalFileAttr(file.unixPermissions, dir);
|
|
8328
8330
|
} else {
|
|
8329
8331
|
versionMadeBy = 20;
|
|
8330
8332
|
extFileAttr |= generateDosExternalFileAttr(file.dosPermissions);
|
|
@@ -8576,10 +8578,10 @@ var require_generate = __commonJS({
|
|
|
8576
8578
|
entriesCount++;
|
|
8577
8579
|
var compression = getCompression(file.options.compression, options.compression);
|
|
8578
8580
|
var compressionOptions = file.options.compressionOptions || options.compressionOptions || {};
|
|
8579
|
-
var
|
|
8581
|
+
var dir = file.dir, date = file.date;
|
|
8580
8582
|
file._compressWorker(compression, compressionOptions).withStreamInfo("file", {
|
|
8581
8583
|
name: relativePath,
|
|
8582
|
-
dir
|
|
8584
|
+
dir,
|
|
8583
8585
|
date,
|
|
8584
8586
|
comment: file.comment || "",
|
|
8585
8587
|
unixPermissions: file.unixPermissions,
|
|
@@ -9914,8 +9916,8 @@ var ZodParsedType = util.arrayToEnum([
|
|
|
9914
9916
|
"set"
|
|
9915
9917
|
]);
|
|
9916
9918
|
var getParsedType = (data) => {
|
|
9917
|
-
const
|
|
9918
|
-
switch (
|
|
9919
|
+
const t = typeof data;
|
|
9920
|
+
switch (t) {
|
|
9919
9921
|
case "undefined":
|
|
9920
9922
|
return ZodParsedType.undefined;
|
|
9921
9923
|
case "string":
|
|
@@ -14245,2379 +14247,6 @@ var TrueFalseQuestionSchema2 = external_exports.object({
|
|
|
14245
14247
|
topic: external_exports.string().optional().describe("Specific topic within the category.")
|
|
14246
14248
|
});
|
|
14247
14249
|
|
|
14248
|
-
// ../../node_modules/.pnpm/i18next@23.16.8/node_modules/i18next/dist/esm/i18next.js
|
|
14249
|
-
var isString = (obj) => typeof obj === "string";
|
|
14250
|
-
var defer = () => {
|
|
14251
|
-
let res;
|
|
14252
|
-
let rej;
|
|
14253
|
-
const promise = new Promise((resolve, reject) => {
|
|
14254
|
-
res = resolve;
|
|
14255
|
-
rej = reject;
|
|
14256
|
-
});
|
|
14257
|
-
promise.resolve = res;
|
|
14258
|
-
promise.reject = rej;
|
|
14259
|
-
return promise;
|
|
14260
|
-
};
|
|
14261
|
-
var makeString = (object) => {
|
|
14262
|
-
if (object == null) return "";
|
|
14263
|
-
return "" + object;
|
|
14264
|
-
};
|
|
14265
|
-
var copy = (a, s, t2) => {
|
|
14266
|
-
a.forEach((m) => {
|
|
14267
|
-
if (s[m]) t2[m] = s[m];
|
|
14268
|
-
});
|
|
14269
|
-
};
|
|
14270
|
-
var lastOfPathSeparatorRegExp = /###/g;
|
|
14271
|
-
var cleanKey = (key) => key && key.indexOf("###") > -1 ? key.replace(lastOfPathSeparatorRegExp, ".") : key;
|
|
14272
|
-
var canNotTraverseDeeper = (object) => !object || isString(object);
|
|
14273
|
-
var getLastOfPath = (object, path, Empty) => {
|
|
14274
|
-
const stack = !isString(path) ? path : path.split(".");
|
|
14275
|
-
let stackIndex = 0;
|
|
14276
|
-
while (stackIndex < stack.length - 1) {
|
|
14277
|
-
if (canNotTraverseDeeper(object)) return {};
|
|
14278
|
-
const key = cleanKey(stack[stackIndex]);
|
|
14279
|
-
if (!object[key] && Empty) object[key] = new Empty();
|
|
14280
|
-
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
14281
|
-
object = object[key];
|
|
14282
|
-
} else {
|
|
14283
|
-
object = {};
|
|
14284
|
-
}
|
|
14285
|
-
++stackIndex;
|
|
14286
|
-
}
|
|
14287
|
-
if (canNotTraverseDeeper(object)) return {};
|
|
14288
|
-
return {
|
|
14289
|
-
obj: object,
|
|
14290
|
-
k: cleanKey(stack[stackIndex])
|
|
14291
|
-
};
|
|
14292
|
-
};
|
|
14293
|
-
var setPath = (object, path, newValue) => {
|
|
14294
|
-
const {
|
|
14295
|
-
obj,
|
|
14296
|
-
k
|
|
14297
|
-
} = getLastOfPath(object, path, Object);
|
|
14298
|
-
if (obj !== void 0 || path.length === 1) {
|
|
14299
|
-
obj[k] = newValue;
|
|
14300
|
-
return;
|
|
14301
|
-
}
|
|
14302
|
-
let e = path[path.length - 1];
|
|
14303
|
-
let p = path.slice(0, path.length - 1);
|
|
14304
|
-
let last = getLastOfPath(object, p, Object);
|
|
14305
|
-
while (last.obj === void 0 && p.length) {
|
|
14306
|
-
e = `${p[p.length - 1]}.${e}`;
|
|
14307
|
-
p = p.slice(0, p.length - 1);
|
|
14308
|
-
last = getLastOfPath(object, p, Object);
|
|
14309
|
-
if (last && last.obj && typeof last.obj[`${last.k}.${e}`] !== "undefined") {
|
|
14310
|
-
last.obj = void 0;
|
|
14311
|
-
}
|
|
14312
|
-
}
|
|
14313
|
-
last.obj[`${last.k}.${e}`] = newValue;
|
|
14314
|
-
};
|
|
14315
|
-
var pushPath = (object, path, newValue, concat) => {
|
|
14316
|
-
const {
|
|
14317
|
-
obj,
|
|
14318
|
-
k
|
|
14319
|
-
} = getLastOfPath(object, path, Object);
|
|
14320
|
-
obj[k] = obj[k] || [];
|
|
14321
|
-
obj[k].push(newValue);
|
|
14322
|
-
};
|
|
14323
|
-
var getPath = (object, path) => {
|
|
14324
|
-
const {
|
|
14325
|
-
obj,
|
|
14326
|
-
k
|
|
14327
|
-
} = getLastOfPath(object, path);
|
|
14328
|
-
if (!obj) return void 0;
|
|
14329
|
-
return obj[k];
|
|
14330
|
-
};
|
|
14331
|
-
var getPathWithDefaults = (data, defaultData, key) => {
|
|
14332
|
-
const value = getPath(data, key);
|
|
14333
|
-
if (value !== void 0) {
|
|
14334
|
-
return value;
|
|
14335
|
-
}
|
|
14336
|
-
return getPath(defaultData, key);
|
|
14337
|
-
};
|
|
14338
|
-
var deepExtend = (target, source, overwrite) => {
|
|
14339
|
-
for (const prop in source) {
|
|
14340
|
-
if (prop !== "__proto__" && prop !== "constructor") {
|
|
14341
|
-
if (prop in target) {
|
|
14342
|
-
if (isString(target[prop]) || target[prop] instanceof String || isString(source[prop]) || source[prop] instanceof String) {
|
|
14343
|
-
if (overwrite) target[prop] = source[prop];
|
|
14344
|
-
} else {
|
|
14345
|
-
deepExtend(target[prop], source[prop], overwrite);
|
|
14346
|
-
}
|
|
14347
|
-
} else {
|
|
14348
|
-
target[prop] = source[prop];
|
|
14349
|
-
}
|
|
14350
|
-
}
|
|
14351
|
-
}
|
|
14352
|
-
return target;
|
|
14353
|
-
};
|
|
14354
|
-
var regexEscape = (str) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
|
14355
|
-
var _entityMap = {
|
|
14356
|
-
"&": "&",
|
|
14357
|
-
"<": "<",
|
|
14358
|
-
">": ">",
|
|
14359
|
-
'"': """,
|
|
14360
|
-
"'": "'",
|
|
14361
|
-
"/": "/"
|
|
14362
|
-
};
|
|
14363
|
-
var escape = (data) => {
|
|
14364
|
-
if (isString(data)) {
|
|
14365
|
-
return data.replace(/[&<>"'\/]/g, (s) => _entityMap[s]);
|
|
14366
|
-
}
|
|
14367
|
-
return data;
|
|
14368
|
-
};
|
|
14369
|
-
var RegExpCache = class {
|
|
14370
|
-
constructor(capacity) {
|
|
14371
|
-
this.capacity = capacity;
|
|
14372
|
-
this.regExpMap = /* @__PURE__ */ new Map();
|
|
14373
|
-
this.regExpQueue = [];
|
|
14374
|
-
}
|
|
14375
|
-
getRegExp(pattern) {
|
|
14376
|
-
const regExpFromCache = this.regExpMap.get(pattern);
|
|
14377
|
-
if (regExpFromCache !== void 0) {
|
|
14378
|
-
return regExpFromCache;
|
|
14379
|
-
}
|
|
14380
|
-
const regExpNew = new RegExp(pattern);
|
|
14381
|
-
if (this.regExpQueue.length === this.capacity) {
|
|
14382
|
-
this.regExpMap.delete(this.regExpQueue.shift());
|
|
14383
|
-
}
|
|
14384
|
-
this.regExpMap.set(pattern, regExpNew);
|
|
14385
|
-
this.regExpQueue.push(pattern);
|
|
14386
|
-
return regExpNew;
|
|
14387
|
-
}
|
|
14388
|
-
};
|
|
14389
|
-
var chars = [" ", ",", "?", "!", ";"];
|
|
14390
|
-
var looksLikeObjectPathRegExpCache = new RegExpCache(20);
|
|
14391
|
-
var looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
|
|
14392
|
-
nsSeparator = nsSeparator || "";
|
|
14393
|
-
keySeparator = keySeparator || "";
|
|
14394
|
-
const possibleChars = chars.filter((c) => nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0);
|
|
14395
|
-
if (possibleChars.length === 0) return true;
|
|
14396
|
-
const r2 = looksLikeObjectPathRegExpCache.getRegExp(`(${possibleChars.map((c) => c === "?" ? "\\?" : c).join("|")})`);
|
|
14397
|
-
let matched = !r2.test(key);
|
|
14398
|
-
if (!matched) {
|
|
14399
|
-
const ki = key.indexOf(keySeparator);
|
|
14400
|
-
if (ki > 0 && !r2.test(key.substring(0, ki))) {
|
|
14401
|
-
matched = true;
|
|
14402
|
-
}
|
|
14403
|
-
}
|
|
14404
|
-
return matched;
|
|
14405
|
-
};
|
|
14406
|
-
var deepFind = function(obj, path) {
|
|
14407
|
-
let keySeparator = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : ".";
|
|
14408
|
-
if (!obj) return void 0;
|
|
14409
|
-
if (obj[path]) return obj[path];
|
|
14410
|
-
const tokens = path.split(keySeparator);
|
|
14411
|
-
let current = obj;
|
|
14412
|
-
for (let i = 0; i < tokens.length; ) {
|
|
14413
|
-
if (!current || typeof current !== "object") {
|
|
14414
|
-
return void 0;
|
|
14415
|
-
}
|
|
14416
|
-
let next;
|
|
14417
|
-
let nextPath = "";
|
|
14418
|
-
for (let j = i; j < tokens.length; ++j) {
|
|
14419
|
-
if (j !== i) {
|
|
14420
|
-
nextPath += keySeparator;
|
|
14421
|
-
}
|
|
14422
|
-
nextPath += tokens[j];
|
|
14423
|
-
next = current[nextPath];
|
|
14424
|
-
if (next !== void 0) {
|
|
14425
|
-
if (["string", "number", "boolean"].indexOf(typeof next) > -1 && j < tokens.length - 1) {
|
|
14426
|
-
continue;
|
|
14427
|
-
}
|
|
14428
|
-
i += j - i + 1;
|
|
14429
|
-
break;
|
|
14430
|
-
}
|
|
14431
|
-
}
|
|
14432
|
-
current = next;
|
|
14433
|
-
}
|
|
14434
|
-
return current;
|
|
14435
|
-
};
|
|
14436
|
-
var getCleanedCode = (code) => code && code.replace("_", "-");
|
|
14437
|
-
var consoleLogger = {
|
|
14438
|
-
type: "logger",
|
|
14439
|
-
log(args) {
|
|
14440
|
-
this.output("log", args);
|
|
14441
|
-
},
|
|
14442
|
-
warn(args) {
|
|
14443
|
-
this.output("warn", args);
|
|
14444
|
-
},
|
|
14445
|
-
error(args) {
|
|
14446
|
-
this.output("error", args);
|
|
14447
|
-
},
|
|
14448
|
-
output(type, args) {
|
|
14449
|
-
if (console && console[type]) console[type].apply(console, args);
|
|
14450
|
-
}
|
|
14451
|
-
};
|
|
14452
|
-
var Logger = class _Logger {
|
|
14453
|
-
constructor(concreteLogger) {
|
|
14454
|
-
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
14455
|
-
this.init(concreteLogger, options);
|
|
14456
|
-
}
|
|
14457
|
-
init(concreteLogger) {
|
|
14458
|
-
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
14459
|
-
this.prefix = options.prefix || "i18next:";
|
|
14460
|
-
this.logger = concreteLogger || consoleLogger;
|
|
14461
|
-
this.options = options;
|
|
14462
|
-
this.debug = options.debug;
|
|
14463
|
-
}
|
|
14464
|
-
log() {
|
|
14465
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
14466
|
-
args[_key] = arguments[_key];
|
|
14467
|
-
}
|
|
14468
|
-
return this.forward(args, "log", "", true);
|
|
14469
|
-
}
|
|
14470
|
-
warn() {
|
|
14471
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
14472
|
-
args[_key2] = arguments[_key2];
|
|
14473
|
-
}
|
|
14474
|
-
return this.forward(args, "warn", "", true);
|
|
14475
|
-
}
|
|
14476
|
-
error() {
|
|
14477
|
-
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
14478
|
-
args[_key3] = arguments[_key3];
|
|
14479
|
-
}
|
|
14480
|
-
return this.forward(args, "error", "");
|
|
14481
|
-
}
|
|
14482
|
-
deprecate() {
|
|
14483
|
-
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
14484
|
-
args[_key4] = arguments[_key4];
|
|
14485
|
-
}
|
|
14486
|
-
return this.forward(args, "warn", "WARNING DEPRECATED: ", true);
|
|
14487
|
-
}
|
|
14488
|
-
forward(args, lvl, prefix, debugOnly) {
|
|
14489
|
-
if (debugOnly && !this.debug) return null;
|
|
14490
|
-
if (isString(args[0])) args[0] = `${prefix}${this.prefix} ${args[0]}`;
|
|
14491
|
-
return this.logger[lvl](args);
|
|
14492
|
-
}
|
|
14493
|
-
create(moduleName) {
|
|
14494
|
-
return new _Logger(this.logger, {
|
|
14495
|
-
...{
|
|
14496
|
-
prefix: `${this.prefix}:${moduleName}:`
|
|
14497
|
-
},
|
|
14498
|
-
...this.options
|
|
14499
|
-
});
|
|
14500
|
-
}
|
|
14501
|
-
clone(options) {
|
|
14502
|
-
options = options || this.options;
|
|
14503
|
-
options.prefix = options.prefix || this.prefix;
|
|
14504
|
-
return new _Logger(this.logger, options);
|
|
14505
|
-
}
|
|
14506
|
-
};
|
|
14507
|
-
var baseLogger = new Logger();
|
|
14508
|
-
var EventEmitter = class {
|
|
14509
|
-
constructor() {
|
|
14510
|
-
this.observers = {};
|
|
14511
|
-
}
|
|
14512
|
-
on(events, listener) {
|
|
14513
|
-
events.split(" ").forEach((event) => {
|
|
14514
|
-
if (!this.observers[event]) this.observers[event] = /* @__PURE__ */ new Map();
|
|
14515
|
-
const numListeners = this.observers[event].get(listener) || 0;
|
|
14516
|
-
this.observers[event].set(listener, numListeners + 1);
|
|
14517
|
-
});
|
|
14518
|
-
return this;
|
|
14519
|
-
}
|
|
14520
|
-
off(event, listener) {
|
|
14521
|
-
if (!this.observers[event]) return;
|
|
14522
|
-
if (!listener) {
|
|
14523
|
-
delete this.observers[event];
|
|
14524
|
-
return;
|
|
14525
|
-
}
|
|
14526
|
-
this.observers[event].delete(listener);
|
|
14527
|
-
}
|
|
14528
|
-
emit(event) {
|
|
14529
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
14530
|
-
args[_key - 1] = arguments[_key];
|
|
14531
|
-
}
|
|
14532
|
-
if (this.observers[event]) {
|
|
14533
|
-
const cloned = Array.from(this.observers[event].entries());
|
|
14534
|
-
cloned.forEach((_ref) => {
|
|
14535
|
-
let [observer, numTimesAdded] = _ref;
|
|
14536
|
-
for (let i = 0; i < numTimesAdded; i++) {
|
|
14537
|
-
observer(...args);
|
|
14538
|
-
}
|
|
14539
|
-
});
|
|
14540
|
-
}
|
|
14541
|
-
if (this.observers["*"]) {
|
|
14542
|
-
const cloned = Array.from(this.observers["*"].entries());
|
|
14543
|
-
cloned.forEach((_ref2) => {
|
|
14544
|
-
let [observer, numTimesAdded] = _ref2;
|
|
14545
|
-
for (let i = 0; i < numTimesAdded; i++) {
|
|
14546
|
-
observer.apply(observer, [event, ...args]);
|
|
14547
|
-
}
|
|
14548
|
-
});
|
|
14549
|
-
}
|
|
14550
|
-
}
|
|
14551
|
-
};
|
|
14552
|
-
var ResourceStore = class extends EventEmitter {
|
|
14553
|
-
constructor(data) {
|
|
14554
|
-
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
|
|
14555
|
-
ns: ["translation"],
|
|
14556
|
-
defaultNS: "translation"
|
|
14557
|
-
};
|
|
14558
|
-
super();
|
|
14559
|
-
this.data = data || {};
|
|
14560
|
-
this.options = options;
|
|
14561
|
-
if (this.options.keySeparator === void 0) {
|
|
14562
|
-
this.options.keySeparator = ".";
|
|
14563
|
-
}
|
|
14564
|
-
if (this.options.ignoreJSONStructure === void 0) {
|
|
14565
|
-
this.options.ignoreJSONStructure = true;
|
|
14566
|
-
}
|
|
14567
|
-
}
|
|
14568
|
-
addNamespaces(ns) {
|
|
14569
|
-
if (this.options.ns.indexOf(ns) < 0) {
|
|
14570
|
-
this.options.ns.push(ns);
|
|
14571
|
-
}
|
|
14572
|
-
}
|
|
14573
|
-
removeNamespaces(ns) {
|
|
14574
|
-
const index = this.options.ns.indexOf(ns);
|
|
14575
|
-
if (index > -1) {
|
|
14576
|
-
this.options.ns.splice(index, 1);
|
|
14577
|
-
}
|
|
14578
|
-
}
|
|
14579
|
-
getResource(lng, ns, key) {
|
|
14580
|
-
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
14581
|
-
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
14582
|
-
const ignoreJSONStructure = options.ignoreJSONStructure !== void 0 ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
14583
|
-
let path;
|
|
14584
|
-
if (lng.indexOf(".") > -1) {
|
|
14585
|
-
path = lng.split(".");
|
|
14586
|
-
} else {
|
|
14587
|
-
path = [lng, ns];
|
|
14588
|
-
if (key) {
|
|
14589
|
-
if (Array.isArray(key)) {
|
|
14590
|
-
path.push(...key);
|
|
14591
|
-
} else if (isString(key) && keySeparator) {
|
|
14592
|
-
path.push(...key.split(keySeparator));
|
|
14593
|
-
} else {
|
|
14594
|
-
path.push(key);
|
|
14595
|
-
}
|
|
14596
|
-
}
|
|
14597
|
-
}
|
|
14598
|
-
const result = getPath(this.data, path);
|
|
14599
|
-
if (!result && !ns && !key && lng.indexOf(".") > -1) {
|
|
14600
|
-
lng = path[0];
|
|
14601
|
-
ns = path[1];
|
|
14602
|
-
key = path.slice(2).join(".");
|
|
14603
|
-
}
|
|
14604
|
-
if (result || !ignoreJSONStructure || !isString(key)) return result;
|
|
14605
|
-
return deepFind(this.data && this.data[lng] && this.data[lng][ns], key, keySeparator);
|
|
14606
|
-
}
|
|
14607
|
-
addResource(lng, ns, key, value) {
|
|
14608
|
-
let options = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : {
|
|
14609
|
-
silent: false
|
|
14610
|
-
};
|
|
14611
|
-
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
14612
|
-
let path = [lng, ns];
|
|
14613
|
-
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
14614
|
-
if (lng.indexOf(".") > -1) {
|
|
14615
|
-
path = lng.split(".");
|
|
14616
|
-
value = ns;
|
|
14617
|
-
ns = path[1];
|
|
14618
|
-
}
|
|
14619
|
-
this.addNamespaces(ns);
|
|
14620
|
-
setPath(this.data, path, value);
|
|
14621
|
-
if (!options.silent) this.emit("added", lng, ns, key, value);
|
|
14622
|
-
}
|
|
14623
|
-
addResources(lng, ns, resources2) {
|
|
14624
|
-
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {
|
|
14625
|
-
silent: false
|
|
14626
|
-
};
|
|
14627
|
-
for (const m in resources2) {
|
|
14628
|
-
if (isString(resources2[m]) || Array.isArray(resources2[m])) this.addResource(lng, ns, m, resources2[m], {
|
|
14629
|
-
silent: true
|
|
14630
|
-
});
|
|
14631
|
-
}
|
|
14632
|
-
if (!options.silent) this.emit("added", lng, ns, resources2);
|
|
14633
|
-
}
|
|
14634
|
-
addResourceBundle(lng, ns, resources2, deep, overwrite) {
|
|
14635
|
-
let options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {
|
|
14636
|
-
silent: false,
|
|
14637
|
-
skipCopy: false
|
|
14638
|
-
};
|
|
14639
|
-
let path = [lng, ns];
|
|
14640
|
-
if (lng.indexOf(".") > -1) {
|
|
14641
|
-
path = lng.split(".");
|
|
14642
|
-
deep = resources2;
|
|
14643
|
-
resources2 = ns;
|
|
14644
|
-
ns = path[1];
|
|
14645
|
-
}
|
|
14646
|
-
this.addNamespaces(ns);
|
|
14647
|
-
let pack = getPath(this.data, path) || {};
|
|
14648
|
-
if (!options.skipCopy) resources2 = JSON.parse(JSON.stringify(resources2));
|
|
14649
|
-
if (deep) {
|
|
14650
|
-
deepExtend(pack, resources2, overwrite);
|
|
14651
|
-
} else {
|
|
14652
|
-
pack = {
|
|
14653
|
-
...pack,
|
|
14654
|
-
...resources2
|
|
14655
|
-
};
|
|
14656
|
-
}
|
|
14657
|
-
setPath(this.data, path, pack);
|
|
14658
|
-
if (!options.silent) this.emit("added", lng, ns, resources2);
|
|
14659
|
-
}
|
|
14660
|
-
removeResourceBundle(lng, ns) {
|
|
14661
|
-
if (this.hasResourceBundle(lng, ns)) {
|
|
14662
|
-
delete this.data[lng][ns];
|
|
14663
|
-
}
|
|
14664
|
-
this.removeNamespaces(ns);
|
|
14665
|
-
this.emit("removed", lng, ns);
|
|
14666
|
-
}
|
|
14667
|
-
hasResourceBundle(lng, ns) {
|
|
14668
|
-
return this.getResource(lng, ns) !== void 0;
|
|
14669
|
-
}
|
|
14670
|
-
getResourceBundle(lng, ns) {
|
|
14671
|
-
if (!ns) ns = this.options.defaultNS;
|
|
14672
|
-
if (this.options.compatibilityAPI === "v1") return {
|
|
14673
|
-
...{},
|
|
14674
|
-
...this.getResource(lng, ns)
|
|
14675
|
-
};
|
|
14676
|
-
return this.getResource(lng, ns);
|
|
14677
|
-
}
|
|
14678
|
-
getDataByLanguage(lng) {
|
|
14679
|
-
return this.data[lng];
|
|
14680
|
-
}
|
|
14681
|
-
hasLanguageSomeTranslations(lng) {
|
|
14682
|
-
const data = this.getDataByLanguage(lng);
|
|
14683
|
-
const n = data && Object.keys(data) || [];
|
|
14684
|
-
return !!n.find((v) => data[v] && Object.keys(data[v]).length > 0);
|
|
14685
|
-
}
|
|
14686
|
-
toJSON() {
|
|
14687
|
-
return this.data;
|
|
14688
|
-
}
|
|
14689
|
-
};
|
|
14690
|
-
var postProcessor = {
|
|
14691
|
-
processors: {},
|
|
14692
|
-
addPostProcessor(module) {
|
|
14693
|
-
this.processors[module.name] = module;
|
|
14694
|
-
},
|
|
14695
|
-
handle(processors, value, key, options, translator) {
|
|
14696
|
-
processors.forEach((processor) => {
|
|
14697
|
-
if (this.processors[processor]) value = this.processors[processor].process(value, key, options, translator);
|
|
14698
|
-
});
|
|
14699
|
-
return value;
|
|
14700
|
-
}
|
|
14701
|
-
};
|
|
14702
|
-
var checkedLoadedFor = {};
|
|
14703
|
-
var Translator = class _Translator extends EventEmitter {
|
|
14704
|
-
constructor(services) {
|
|
14705
|
-
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
14706
|
-
super();
|
|
14707
|
-
copy(["resourceStore", "languageUtils", "pluralResolver", "interpolator", "backendConnector", "i18nFormat", "utils"], services, this);
|
|
14708
|
-
this.options = options;
|
|
14709
|
-
if (this.options.keySeparator === void 0) {
|
|
14710
|
-
this.options.keySeparator = ".";
|
|
14711
|
-
}
|
|
14712
|
-
this.logger = baseLogger.create("translator");
|
|
14713
|
-
}
|
|
14714
|
-
changeLanguage(lng) {
|
|
14715
|
-
if (lng) this.language = lng;
|
|
14716
|
-
}
|
|
14717
|
-
exists(key) {
|
|
14718
|
-
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
|
|
14719
|
-
interpolation: {}
|
|
14720
|
-
};
|
|
14721
|
-
if (key === void 0 || key === null) {
|
|
14722
|
-
return false;
|
|
14723
|
-
}
|
|
14724
|
-
const resolved = this.resolve(key, options);
|
|
14725
|
-
return resolved && resolved.res !== void 0;
|
|
14726
|
-
}
|
|
14727
|
-
extractFromKey(key, options) {
|
|
14728
|
-
let nsSeparator = options.nsSeparator !== void 0 ? options.nsSeparator : this.options.nsSeparator;
|
|
14729
|
-
if (nsSeparator === void 0) nsSeparator = ":";
|
|
14730
|
-
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
14731
|
-
let namespaces = options.ns || this.options.defaultNS || [];
|
|
14732
|
-
const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
|
|
14733
|
-
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
14734
|
-
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
14735
|
-
const m = key.match(this.interpolator.nestingRegexp);
|
|
14736
|
-
if (m && m.length > 0) {
|
|
14737
|
-
return {
|
|
14738
|
-
key,
|
|
14739
|
-
namespaces: isString(namespaces) ? [namespaces] : namespaces
|
|
14740
|
-
};
|
|
14741
|
-
}
|
|
14742
|
-
const parts = key.split(nsSeparator);
|
|
14743
|
-
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
|
|
14744
|
-
key = parts.join(keySeparator);
|
|
14745
|
-
}
|
|
14746
|
-
return {
|
|
14747
|
-
key,
|
|
14748
|
-
namespaces: isString(namespaces) ? [namespaces] : namespaces
|
|
14749
|
-
};
|
|
14750
|
-
}
|
|
14751
|
-
translate(keys, options, lastKey) {
|
|
14752
|
-
if (typeof options !== "object" && this.options.overloadTranslationOptionHandler) {
|
|
14753
|
-
options = this.options.overloadTranslationOptionHandler(arguments);
|
|
14754
|
-
}
|
|
14755
|
-
if (typeof options === "object") options = {
|
|
14756
|
-
...options
|
|
14757
|
-
};
|
|
14758
|
-
if (!options) options = {};
|
|
14759
|
-
if (keys === void 0 || keys === null) return "";
|
|
14760
|
-
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
14761
|
-
const returnDetails = options.returnDetails !== void 0 ? options.returnDetails : this.options.returnDetails;
|
|
14762
|
-
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
14763
|
-
const {
|
|
14764
|
-
key,
|
|
14765
|
-
namespaces
|
|
14766
|
-
} = this.extractFromKey(keys[keys.length - 1], options);
|
|
14767
|
-
const namespace = namespaces[namespaces.length - 1];
|
|
14768
|
-
const lng = options.lng || this.language;
|
|
14769
|
-
const appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
14770
|
-
if (lng && lng.toLowerCase() === "cimode") {
|
|
14771
|
-
if (appendNamespaceToCIMode) {
|
|
14772
|
-
const nsSeparator = options.nsSeparator || this.options.nsSeparator;
|
|
14773
|
-
if (returnDetails) {
|
|
14774
|
-
return {
|
|
14775
|
-
res: `${namespace}${nsSeparator}${key}`,
|
|
14776
|
-
usedKey: key,
|
|
14777
|
-
exactUsedKey: key,
|
|
14778
|
-
usedLng: lng,
|
|
14779
|
-
usedNS: namespace,
|
|
14780
|
-
usedParams: this.getUsedParamsDetails(options)
|
|
14781
|
-
};
|
|
14782
|
-
}
|
|
14783
|
-
return `${namespace}${nsSeparator}${key}`;
|
|
14784
|
-
}
|
|
14785
|
-
if (returnDetails) {
|
|
14786
|
-
return {
|
|
14787
|
-
res: key,
|
|
14788
|
-
usedKey: key,
|
|
14789
|
-
exactUsedKey: key,
|
|
14790
|
-
usedLng: lng,
|
|
14791
|
-
usedNS: namespace,
|
|
14792
|
-
usedParams: this.getUsedParamsDetails(options)
|
|
14793
|
-
};
|
|
14794
|
-
}
|
|
14795
|
-
return key;
|
|
14796
|
-
}
|
|
14797
|
-
const resolved = this.resolve(keys, options);
|
|
14798
|
-
let res = resolved && resolved.res;
|
|
14799
|
-
const resUsedKey = resolved && resolved.usedKey || key;
|
|
14800
|
-
const resExactUsedKey = resolved && resolved.exactUsedKey || key;
|
|
14801
|
-
const resType = Object.prototype.toString.apply(res);
|
|
14802
|
-
const noObject = ["[object Number]", "[object Function]", "[object RegExp]"];
|
|
14803
|
-
const joinArrays = options.joinArrays !== void 0 ? options.joinArrays : this.options.joinArrays;
|
|
14804
|
-
const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
14805
|
-
const handleAsObject = !isString(res) && typeof res !== "boolean" && typeof res !== "number";
|
|
14806
|
-
if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(isString(joinArrays) && Array.isArray(res))) {
|
|
14807
|
-
if (!options.returnObjects && !this.options.returnObjects) {
|
|
14808
|
-
if (!this.options.returnedObjectHandler) {
|
|
14809
|
-
this.logger.warn("accessing an object - but returnObjects options is not enabled!");
|
|
14810
|
-
}
|
|
14811
|
-
const r2 = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, {
|
|
14812
|
-
...options,
|
|
14813
|
-
ns: namespaces
|
|
14814
|
-
}) : `key '${key} (${this.language})' returned an object instead of string.`;
|
|
14815
|
-
if (returnDetails) {
|
|
14816
|
-
resolved.res = r2;
|
|
14817
|
-
resolved.usedParams = this.getUsedParamsDetails(options);
|
|
14818
|
-
return resolved;
|
|
14819
|
-
}
|
|
14820
|
-
return r2;
|
|
14821
|
-
}
|
|
14822
|
-
if (keySeparator) {
|
|
14823
|
-
const resTypeIsArray = Array.isArray(res);
|
|
14824
|
-
const copy2 = resTypeIsArray ? [] : {};
|
|
14825
|
-
const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
14826
|
-
for (const m in res) {
|
|
14827
|
-
if (Object.prototype.hasOwnProperty.call(res, m)) {
|
|
14828
|
-
const deepKey = `${newKeyToUse}${keySeparator}${m}`;
|
|
14829
|
-
copy2[m] = this.translate(deepKey, {
|
|
14830
|
-
...options,
|
|
14831
|
-
...{
|
|
14832
|
-
joinArrays: false,
|
|
14833
|
-
ns: namespaces
|
|
14834
|
-
}
|
|
14835
|
-
});
|
|
14836
|
-
if (copy2[m] === deepKey) copy2[m] = res[m];
|
|
14837
|
-
}
|
|
14838
|
-
}
|
|
14839
|
-
res = copy2;
|
|
14840
|
-
}
|
|
14841
|
-
} else if (handleAsObjectInI18nFormat && isString(joinArrays) && Array.isArray(res)) {
|
|
14842
|
-
res = res.join(joinArrays);
|
|
14843
|
-
if (res) res = this.extendTranslation(res, keys, options, lastKey);
|
|
14844
|
-
} else {
|
|
14845
|
-
let usedDefault = false;
|
|
14846
|
-
let usedKey = false;
|
|
14847
|
-
const needsPluralHandling = options.count !== void 0 && !isString(options.count);
|
|
14848
|
-
const hasDefaultValue = _Translator.hasDefaultValue(options);
|
|
14849
|
-
const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : "";
|
|
14850
|
-
const defaultValueSuffixOrdinalFallback = options.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, {
|
|
14851
|
-
ordinal: false
|
|
14852
|
-
}) : "";
|
|
14853
|
-
const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
|
|
14854
|
-
const defaultValue = needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] || options[`defaultValue${defaultValueSuffix}`] || options[`defaultValue${defaultValueSuffixOrdinalFallback}`] || options.defaultValue;
|
|
14855
|
-
if (!this.isValidLookup(res) && hasDefaultValue) {
|
|
14856
|
-
usedDefault = true;
|
|
14857
|
-
res = defaultValue;
|
|
14858
|
-
}
|
|
14859
|
-
if (!this.isValidLookup(res)) {
|
|
14860
|
-
usedKey = true;
|
|
14861
|
-
res = key;
|
|
14862
|
-
}
|
|
14863
|
-
const missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
|
|
14864
|
-
const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? void 0 : res;
|
|
14865
|
-
const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
14866
|
-
if (usedKey || usedDefault || updateMissing) {
|
|
14867
|
-
this.logger.log(updateMissing ? "updateKey" : "missingKey", lng, namespace, key, updateMissing ? defaultValue : res);
|
|
14868
|
-
if (keySeparator) {
|
|
14869
|
-
const fk = this.resolve(key, {
|
|
14870
|
-
...options,
|
|
14871
|
-
keySeparator: false
|
|
14872
|
-
});
|
|
14873
|
-
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.");
|
|
14874
|
-
}
|
|
14875
|
-
let lngs = [];
|
|
14876
|
-
const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
|
|
14877
|
-
if (this.options.saveMissingTo === "fallback" && fallbackLngs && fallbackLngs[0]) {
|
|
14878
|
-
for (let i = 0; i < fallbackLngs.length; i++) {
|
|
14879
|
-
lngs.push(fallbackLngs[i]);
|
|
14880
|
-
}
|
|
14881
|
-
} else if (this.options.saveMissingTo === "all") {
|
|
14882
|
-
lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
|
|
14883
|
-
} else {
|
|
14884
|
-
lngs.push(options.lng || this.language);
|
|
14885
|
-
}
|
|
14886
|
-
const send = (l, k, specificDefaultValue) => {
|
|
14887
|
-
const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
14888
|
-
if (this.options.missingKeyHandler) {
|
|
14889
|
-
this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
14890
|
-
} else if (this.backendConnector && this.backendConnector.saveMissing) {
|
|
14891
|
-
this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
14892
|
-
}
|
|
14893
|
-
this.emit("missingKey", l, namespace, k, res);
|
|
14894
|
-
};
|
|
14895
|
-
if (this.options.saveMissing) {
|
|
14896
|
-
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
14897
|
-
lngs.forEach((language) => {
|
|
14898
|
-
const suffixes = this.pluralResolver.getSuffixes(language, options);
|
|
14899
|
-
if (needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.indexOf(`${this.options.pluralSeparator}zero`) < 0) {
|
|
14900
|
-
suffixes.push(`${this.options.pluralSeparator}zero`);
|
|
14901
|
-
}
|
|
14902
|
-
suffixes.forEach((suffix) => {
|
|
14903
|
-
send([language], key + suffix, options[`defaultValue${suffix}`] || defaultValue);
|
|
14904
|
-
});
|
|
14905
|
-
});
|
|
14906
|
-
} else {
|
|
14907
|
-
send(lngs, key, defaultValue);
|
|
14908
|
-
}
|
|
14909
|
-
}
|
|
14910
|
-
}
|
|
14911
|
-
res = this.extendTranslation(res, keys, options, resolved, lastKey);
|
|
14912
|
-
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
|
|
14913
|
-
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
|
|
14914
|
-
if (this.options.compatibilityAPI !== "v1") {
|
|
14915
|
-
res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : void 0);
|
|
14916
|
-
} else {
|
|
14917
|
-
res = this.options.parseMissingKeyHandler(res);
|
|
14918
|
-
}
|
|
14919
|
-
}
|
|
14920
|
-
}
|
|
14921
|
-
if (returnDetails) {
|
|
14922
|
-
resolved.res = res;
|
|
14923
|
-
resolved.usedParams = this.getUsedParamsDetails(options);
|
|
14924
|
-
return resolved;
|
|
14925
|
-
}
|
|
14926
|
-
return res;
|
|
14927
|
-
}
|
|
14928
|
-
extendTranslation(res, key, options, resolved, lastKey) {
|
|
14929
|
-
var _this = this;
|
|
14930
|
-
if (this.i18nFormat && this.i18nFormat.parse) {
|
|
14931
|
-
res = this.i18nFormat.parse(res, {
|
|
14932
|
-
...this.options.interpolation.defaultVariables,
|
|
14933
|
-
...options
|
|
14934
|
-
}, options.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
|
|
14935
|
-
resolved
|
|
14936
|
-
});
|
|
14937
|
-
} else if (!options.skipInterpolation) {
|
|
14938
|
-
if (options.interpolation) this.interpolator.init({
|
|
14939
|
-
...options,
|
|
14940
|
-
...{
|
|
14941
|
-
interpolation: {
|
|
14942
|
-
...this.options.interpolation,
|
|
14943
|
-
...options.interpolation
|
|
14944
|
-
}
|
|
14945
|
-
}
|
|
14946
|
-
});
|
|
14947
|
-
const skipOnVariables = isString(res) && (options && options.interpolation && options.interpolation.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
14948
|
-
let nestBef;
|
|
14949
|
-
if (skipOnVariables) {
|
|
14950
|
-
const nb = res.match(this.interpolator.nestingRegexp);
|
|
14951
|
-
nestBef = nb && nb.length;
|
|
14952
|
-
}
|
|
14953
|
-
let data = options.replace && !isString(options.replace) ? options.replace : options;
|
|
14954
|
-
if (this.options.interpolation.defaultVariables) data = {
|
|
14955
|
-
...this.options.interpolation.defaultVariables,
|
|
14956
|
-
...data
|
|
14957
|
-
};
|
|
14958
|
-
res = this.interpolator.interpolate(res, data, options.lng || this.language || resolved.usedLng, options);
|
|
14959
|
-
if (skipOnVariables) {
|
|
14960
|
-
const na = res.match(this.interpolator.nestingRegexp);
|
|
14961
|
-
const nestAft = na && na.length;
|
|
14962
|
-
if (nestBef < nestAft) options.nest = false;
|
|
14963
|
-
}
|
|
14964
|
-
if (!options.lng && this.options.compatibilityAPI !== "v1" && resolved && resolved.res) options.lng = this.language || resolved.usedLng;
|
|
14965
|
-
if (options.nest !== false) res = this.interpolator.nest(res, function() {
|
|
14966
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
14967
|
-
args[_key] = arguments[_key];
|
|
14968
|
-
}
|
|
14969
|
-
if (lastKey && lastKey[0] === args[0] && !options.context) {
|
|
14970
|
-
_this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
|
|
14971
|
-
return null;
|
|
14972
|
-
}
|
|
14973
|
-
return _this.translate(...args, key);
|
|
14974
|
-
}, options);
|
|
14975
|
-
if (options.interpolation) this.interpolator.reset();
|
|
14976
|
-
}
|
|
14977
|
-
const postProcess = options.postProcess || this.options.postProcess;
|
|
14978
|
-
const postProcessorNames = isString(postProcess) ? [postProcess] : postProcess;
|
|
14979
|
-
if (res !== void 0 && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) {
|
|
14980
|
-
res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
|
|
14981
|
-
i18nResolved: {
|
|
14982
|
-
...resolved,
|
|
14983
|
-
usedParams: this.getUsedParamsDetails(options)
|
|
14984
|
-
},
|
|
14985
|
-
...options
|
|
14986
|
-
} : options, this);
|
|
14987
|
-
}
|
|
14988
|
-
return res;
|
|
14989
|
-
}
|
|
14990
|
-
resolve(keys) {
|
|
14991
|
-
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
14992
|
-
let found;
|
|
14993
|
-
let usedKey;
|
|
14994
|
-
let exactUsedKey;
|
|
14995
|
-
let usedLng;
|
|
14996
|
-
let usedNS;
|
|
14997
|
-
if (isString(keys)) keys = [keys];
|
|
14998
|
-
keys.forEach((k) => {
|
|
14999
|
-
if (this.isValidLookup(found)) return;
|
|
15000
|
-
const extracted = this.extractFromKey(k, options);
|
|
15001
|
-
const key = extracted.key;
|
|
15002
|
-
usedKey = key;
|
|
15003
|
-
let namespaces = extracted.namespaces;
|
|
15004
|
-
if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
|
|
15005
|
-
const needsPluralHandling = options.count !== void 0 && !isString(options.count);
|
|
15006
|
-
const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
|
|
15007
|
-
const needsContextHandling = options.context !== void 0 && (isString(options.context) || typeof options.context === "number") && options.context !== "";
|
|
15008
|
-
const codes = options.lngs ? options.lngs : this.languageUtils.toResolveHierarchy(options.lng || this.language, options.fallbackLng);
|
|
15009
|
-
namespaces.forEach((ns) => {
|
|
15010
|
-
if (this.isValidLookup(found)) return;
|
|
15011
|
-
usedNS = ns;
|
|
15012
|
-
if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils && this.utils.hasLoadedNamespace && !this.utils.hasLoadedNamespace(usedNS)) {
|
|
15013
|
-
checkedLoadedFor[`${codes[0]}-${ns}`] = true;
|
|
15014
|
-
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!!!");
|
|
15015
|
-
}
|
|
15016
|
-
codes.forEach((code) => {
|
|
15017
|
-
if (this.isValidLookup(found)) return;
|
|
15018
|
-
usedLng = code;
|
|
15019
|
-
const finalKeys = [key];
|
|
15020
|
-
if (this.i18nFormat && this.i18nFormat.addLookupKeys) {
|
|
15021
|
-
this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
|
|
15022
|
-
} else {
|
|
15023
|
-
let pluralSuffix;
|
|
15024
|
-
if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, options.count, options);
|
|
15025
|
-
const zeroSuffix = `${this.options.pluralSeparator}zero`;
|
|
15026
|
-
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
|
|
15027
|
-
if (needsPluralHandling) {
|
|
15028
|
-
finalKeys.push(key + pluralSuffix);
|
|
15029
|
-
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
15030
|
-
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
15031
|
-
}
|
|
15032
|
-
if (needsZeroSuffixLookup) {
|
|
15033
|
-
finalKeys.push(key + zeroSuffix);
|
|
15034
|
-
}
|
|
15035
|
-
}
|
|
15036
|
-
if (needsContextHandling) {
|
|
15037
|
-
const contextKey = `${key}${this.options.contextSeparator}${options.context}`;
|
|
15038
|
-
finalKeys.push(contextKey);
|
|
15039
|
-
if (needsPluralHandling) {
|
|
15040
|
-
finalKeys.push(contextKey + pluralSuffix);
|
|
15041
|
-
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
15042
|
-
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
15043
|
-
}
|
|
15044
|
-
if (needsZeroSuffixLookup) {
|
|
15045
|
-
finalKeys.push(contextKey + zeroSuffix);
|
|
15046
|
-
}
|
|
15047
|
-
}
|
|
15048
|
-
}
|
|
15049
|
-
}
|
|
15050
|
-
let possibleKey;
|
|
15051
|
-
while (possibleKey = finalKeys.pop()) {
|
|
15052
|
-
if (!this.isValidLookup(found)) {
|
|
15053
|
-
exactUsedKey = possibleKey;
|
|
15054
|
-
found = this.getResource(code, ns, possibleKey, options);
|
|
15055
|
-
}
|
|
15056
|
-
}
|
|
15057
|
-
});
|
|
15058
|
-
});
|
|
15059
|
-
});
|
|
15060
|
-
return {
|
|
15061
|
-
res: found,
|
|
15062
|
-
usedKey,
|
|
15063
|
-
exactUsedKey,
|
|
15064
|
-
usedLng,
|
|
15065
|
-
usedNS
|
|
15066
|
-
};
|
|
15067
|
-
}
|
|
15068
|
-
isValidLookup(res) {
|
|
15069
|
-
return res !== void 0 && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === "");
|
|
15070
|
-
}
|
|
15071
|
-
getResource(code, ns, key) {
|
|
15072
|
-
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
15073
|
-
if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options);
|
|
15074
|
-
return this.resourceStore.getResource(code, ns, key, options);
|
|
15075
|
-
}
|
|
15076
|
-
getUsedParamsDetails() {
|
|
15077
|
-
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
15078
|
-
const optionsKeys = ["defaultValue", "ordinal", "context", "replace", "lng", "lngs", "fallbackLng", "ns", "keySeparator", "nsSeparator", "returnObjects", "returnDetails", "joinArrays", "postProcess", "interpolation"];
|
|
15079
|
-
const useOptionsReplaceForData = options.replace && !isString(options.replace);
|
|
15080
|
-
let data = useOptionsReplaceForData ? options.replace : options;
|
|
15081
|
-
if (useOptionsReplaceForData && typeof options.count !== "undefined") {
|
|
15082
|
-
data.count = options.count;
|
|
15083
|
-
}
|
|
15084
|
-
if (this.options.interpolation.defaultVariables) {
|
|
15085
|
-
data = {
|
|
15086
|
-
...this.options.interpolation.defaultVariables,
|
|
15087
|
-
...data
|
|
15088
|
-
};
|
|
15089
|
-
}
|
|
15090
|
-
if (!useOptionsReplaceForData) {
|
|
15091
|
-
data = {
|
|
15092
|
-
...data
|
|
15093
|
-
};
|
|
15094
|
-
for (const key of optionsKeys) {
|
|
15095
|
-
delete data[key];
|
|
15096
|
-
}
|
|
15097
|
-
}
|
|
15098
|
-
return data;
|
|
15099
|
-
}
|
|
15100
|
-
static hasDefaultValue(options) {
|
|
15101
|
-
const prefix = "defaultValue";
|
|
15102
|
-
for (const option in options) {
|
|
15103
|
-
if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && void 0 !== options[option]) {
|
|
15104
|
-
return true;
|
|
15105
|
-
}
|
|
15106
|
-
}
|
|
15107
|
-
return false;
|
|
15108
|
-
}
|
|
15109
|
-
};
|
|
15110
|
-
var capitalize = (string) => string.charAt(0).toUpperCase() + string.slice(1);
|
|
15111
|
-
var LanguageUtil = class {
|
|
15112
|
-
constructor(options) {
|
|
15113
|
-
this.options = options;
|
|
15114
|
-
this.supportedLngs = this.options.supportedLngs || false;
|
|
15115
|
-
this.logger = baseLogger.create("languageUtils");
|
|
15116
|
-
}
|
|
15117
|
-
getScriptPartFromCode(code) {
|
|
15118
|
-
code = getCleanedCode(code);
|
|
15119
|
-
if (!code || code.indexOf("-") < 0) return null;
|
|
15120
|
-
const p = code.split("-");
|
|
15121
|
-
if (p.length === 2) return null;
|
|
15122
|
-
p.pop();
|
|
15123
|
-
if (p[p.length - 1].toLowerCase() === "x") return null;
|
|
15124
|
-
return this.formatLanguageCode(p.join("-"));
|
|
15125
|
-
}
|
|
15126
|
-
getLanguagePartFromCode(code) {
|
|
15127
|
-
code = getCleanedCode(code);
|
|
15128
|
-
if (!code || code.indexOf("-") < 0) return code;
|
|
15129
|
-
const p = code.split("-");
|
|
15130
|
-
return this.formatLanguageCode(p[0]);
|
|
15131
|
-
}
|
|
15132
|
-
formatLanguageCode(code) {
|
|
15133
|
-
if (isString(code) && code.indexOf("-") > -1) {
|
|
15134
|
-
if (typeof Intl !== "undefined" && typeof Intl.getCanonicalLocales !== "undefined") {
|
|
15135
|
-
try {
|
|
15136
|
-
let formattedCode = Intl.getCanonicalLocales(code)[0];
|
|
15137
|
-
if (formattedCode && this.options.lowerCaseLng) {
|
|
15138
|
-
formattedCode = formattedCode.toLowerCase();
|
|
15139
|
-
}
|
|
15140
|
-
if (formattedCode) return formattedCode;
|
|
15141
|
-
} catch (e) {
|
|
15142
|
-
}
|
|
15143
|
-
}
|
|
15144
|
-
const specialCases = ["hans", "hant", "latn", "cyrl", "cans", "mong", "arab"];
|
|
15145
|
-
let p = code.split("-");
|
|
15146
|
-
if (this.options.lowerCaseLng) {
|
|
15147
|
-
p = p.map((part) => part.toLowerCase());
|
|
15148
|
-
} else if (p.length === 2) {
|
|
15149
|
-
p[0] = p[0].toLowerCase();
|
|
15150
|
-
p[1] = p[1].toUpperCase();
|
|
15151
|
-
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
|
|
15152
|
-
} else if (p.length === 3) {
|
|
15153
|
-
p[0] = p[0].toLowerCase();
|
|
15154
|
-
if (p[1].length === 2) p[1] = p[1].toUpperCase();
|
|
15155
|
-
if (p[0] !== "sgn" && p[2].length === 2) p[2] = p[2].toUpperCase();
|
|
15156
|
-
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
|
|
15157
|
-
if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize(p[2].toLowerCase());
|
|
15158
|
-
}
|
|
15159
|
-
return p.join("-");
|
|
15160
|
-
}
|
|
15161
|
-
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
|
|
15162
|
-
}
|
|
15163
|
-
isSupportedCode(code) {
|
|
15164
|
-
if (this.options.load === "languageOnly" || this.options.nonExplicitSupportedLngs) {
|
|
15165
|
-
code = this.getLanguagePartFromCode(code);
|
|
15166
|
-
}
|
|
15167
|
-
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
|
|
15168
|
-
}
|
|
15169
|
-
getBestMatchFromCodes(codes) {
|
|
15170
|
-
if (!codes) return null;
|
|
15171
|
-
let found;
|
|
15172
|
-
codes.forEach((code) => {
|
|
15173
|
-
if (found) return;
|
|
15174
|
-
const cleanedLng = this.formatLanguageCode(code);
|
|
15175
|
-
if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
|
|
15176
|
-
});
|
|
15177
|
-
if (!found && this.options.supportedLngs) {
|
|
15178
|
-
codes.forEach((code) => {
|
|
15179
|
-
if (found) return;
|
|
15180
|
-
const lngOnly = this.getLanguagePartFromCode(code);
|
|
15181
|
-
if (this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
15182
|
-
found = this.options.supportedLngs.find((supportedLng) => {
|
|
15183
|
-
if (supportedLng === lngOnly) return supportedLng;
|
|
15184
|
-
if (supportedLng.indexOf("-") < 0 && lngOnly.indexOf("-") < 0) return;
|
|
15185
|
-
if (supportedLng.indexOf("-") > 0 && lngOnly.indexOf("-") < 0 && supportedLng.substring(0, supportedLng.indexOf("-")) === lngOnly) return supportedLng;
|
|
15186
|
-
if (supportedLng.indexOf(lngOnly) === 0 && lngOnly.length > 1) return supportedLng;
|
|
15187
|
-
});
|
|
15188
|
-
});
|
|
15189
|
-
}
|
|
15190
|
-
if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
|
|
15191
|
-
return found;
|
|
15192
|
-
}
|
|
15193
|
-
getFallbackCodes(fallbacks, code) {
|
|
15194
|
-
if (!fallbacks) return [];
|
|
15195
|
-
if (typeof fallbacks === "function") fallbacks = fallbacks(code);
|
|
15196
|
-
if (isString(fallbacks)) fallbacks = [fallbacks];
|
|
15197
|
-
if (Array.isArray(fallbacks)) return fallbacks;
|
|
15198
|
-
if (!code) return fallbacks.default || [];
|
|
15199
|
-
let found = fallbacks[code];
|
|
15200
|
-
if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
|
|
15201
|
-
if (!found) found = fallbacks[this.formatLanguageCode(code)];
|
|
15202
|
-
if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
15203
|
-
if (!found) found = fallbacks.default;
|
|
15204
|
-
return found || [];
|
|
15205
|
-
}
|
|
15206
|
-
toResolveHierarchy(code, fallbackCode) {
|
|
15207
|
-
const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
|
|
15208
|
-
const codes = [];
|
|
15209
|
-
const addCode = (c) => {
|
|
15210
|
-
if (!c) return;
|
|
15211
|
-
if (this.isSupportedCode(c)) {
|
|
15212
|
-
codes.push(c);
|
|
15213
|
-
} else {
|
|
15214
|
-
this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
|
|
15215
|
-
}
|
|
15216
|
-
};
|
|
15217
|
-
if (isString(code) && (code.indexOf("-") > -1 || code.indexOf("_") > -1)) {
|
|
15218
|
-
if (this.options.load !== "languageOnly") addCode(this.formatLanguageCode(code));
|
|
15219
|
-
if (this.options.load !== "languageOnly" && this.options.load !== "currentOnly") addCode(this.getScriptPartFromCode(code));
|
|
15220
|
-
if (this.options.load !== "currentOnly") addCode(this.getLanguagePartFromCode(code));
|
|
15221
|
-
} else if (isString(code)) {
|
|
15222
|
-
addCode(this.formatLanguageCode(code));
|
|
15223
|
-
}
|
|
15224
|
-
fallbackCodes.forEach((fc) => {
|
|
15225
|
-
if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
|
|
15226
|
-
});
|
|
15227
|
-
return codes;
|
|
15228
|
-
}
|
|
15229
|
-
};
|
|
15230
|
-
var sets = [{
|
|
15231
|
-
lngs: ["ach", "ak", "am", "arn", "br", "fil", "gun", "ln", "mfe", "mg", "mi", "oc", "pt", "pt-BR", "tg", "tl", "ti", "tr", "uz", "wa"],
|
|
15232
|
-
nr: [1, 2],
|
|
15233
|
-
fc: 1
|
|
15234
|
-
}, {
|
|
15235
|
-
lngs: ["af", "an", "ast", "az", "bg", "bn", "ca", "da", "de", "dev", "el", "en", "eo", "es", "et", "eu", "fi", "fo", "fur", "fy", "gl", "gu", "ha", "hi", "hu", "hy", "ia", "it", "kk", "kn", "ku", "lb", "mai", "ml", "mn", "mr", "nah", "nap", "nb", "ne", "nl", "nn", "no", "nso", "pa", "pap", "pms", "ps", "pt-PT", "rm", "sco", "se", "si", "so", "son", "sq", "sv", "sw", "ta", "te", "tk", "ur", "yo"],
|
|
15236
|
-
nr: [1, 2],
|
|
15237
|
-
fc: 2
|
|
15238
|
-
}, {
|
|
15239
|
-
lngs: ["ay", "bo", "cgg", "fa", "ht", "id", "ja", "jbo", "ka", "km", "ko", "ky", "lo", "ms", "sah", "su", "th", "tt", "ug", "vi", "wo", "zh"],
|
|
15240
|
-
nr: [1],
|
|
15241
|
-
fc: 3
|
|
15242
|
-
}, {
|
|
15243
|
-
lngs: ["be", "bs", "cnr", "dz", "hr", "ru", "sr", "uk"],
|
|
15244
|
-
nr: [1, 2, 5],
|
|
15245
|
-
fc: 4
|
|
15246
|
-
}, {
|
|
15247
|
-
lngs: ["ar"],
|
|
15248
|
-
nr: [0, 1, 2, 3, 11, 100],
|
|
15249
|
-
fc: 5
|
|
15250
|
-
}, {
|
|
15251
|
-
lngs: ["cs", "sk"],
|
|
15252
|
-
nr: [1, 2, 5],
|
|
15253
|
-
fc: 6
|
|
15254
|
-
}, {
|
|
15255
|
-
lngs: ["csb", "pl"],
|
|
15256
|
-
nr: [1, 2, 5],
|
|
15257
|
-
fc: 7
|
|
15258
|
-
}, {
|
|
15259
|
-
lngs: ["cy"],
|
|
15260
|
-
nr: [1, 2, 3, 8],
|
|
15261
|
-
fc: 8
|
|
15262
|
-
}, {
|
|
15263
|
-
lngs: ["fr"],
|
|
15264
|
-
nr: [1, 2],
|
|
15265
|
-
fc: 9
|
|
15266
|
-
}, {
|
|
15267
|
-
lngs: ["ga"],
|
|
15268
|
-
nr: [1, 2, 3, 7, 11],
|
|
15269
|
-
fc: 10
|
|
15270
|
-
}, {
|
|
15271
|
-
lngs: ["gd"],
|
|
15272
|
-
nr: [1, 2, 3, 20],
|
|
15273
|
-
fc: 11
|
|
15274
|
-
}, {
|
|
15275
|
-
lngs: ["is"],
|
|
15276
|
-
nr: [1, 2],
|
|
15277
|
-
fc: 12
|
|
15278
|
-
}, {
|
|
15279
|
-
lngs: ["jv"],
|
|
15280
|
-
nr: [0, 1],
|
|
15281
|
-
fc: 13
|
|
15282
|
-
}, {
|
|
15283
|
-
lngs: ["kw"],
|
|
15284
|
-
nr: [1, 2, 3, 4],
|
|
15285
|
-
fc: 14
|
|
15286
|
-
}, {
|
|
15287
|
-
lngs: ["lt"],
|
|
15288
|
-
nr: [1, 2, 10],
|
|
15289
|
-
fc: 15
|
|
15290
|
-
}, {
|
|
15291
|
-
lngs: ["lv"],
|
|
15292
|
-
nr: [1, 2, 0],
|
|
15293
|
-
fc: 16
|
|
15294
|
-
}, {
|
|
15295
|
-
lngs: ["mk"],
|
|
15296
|
-
nr: [1, 2],
|
|
15297
|
-
fc: 17
|
|
15298
|
-
}, {
|
|
15299
|
-
lngs: ["mnk"],
|
|
15300
|
-
nr: [0, 1, 2],
|
|
15301
|
-
fc: 18
|
|
15302
|
-
}, {
|
|
15303
|
-
lngs: ["mt"],
|
|
15304
|
-
nr: [1, 2, 11, 20],
|
|
15305
|
-
fc: 19
|
|
15306
|
-
}, {
|
|
15307
|
-
lngs: ["or"],
|
|
15308
|
-
nr: [2, 1],
|
|
15309
|
-
fc: 2
|
|
15310
|
-
}, {
|
|
15311
|
-
lngs: ["ro"],
|
|
15312
|
-
nr: [1, 2, 20],
|
|
15313
|
-
fc: 20
|
|
15314
|
-
}, {
|
|
15315
|
-
lngs: ["sl"],
|
|
15316
|
-
nr: [5, 1, 2, 3],
|
|
15317
|
-
fc: 21
|
|
15318
|
-
}, {
|
|
15319
|
-
lngs: ["he", "iw"],
|
|
15320
|
-
nr: [1, 2, 20, 21],
|
|
15321
|
-
fc: 22
|
|
15322
|
-
}];
|
|
15323
|
-
var _rulesPluralsTypes = {
|
|
15324
|
-
1: (n) => Number(n > 1),
|
|
15325
|
-
2: (n) => Number(n != 1),
|
|
15326
|
-
3: (n) => 0,
|
|
15327
|
-
4: (n) => Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2),
|
|
15328
|
-
5: (n) => Number(n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5),
|
|
15329
|
-
6: (n) => Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2),
|
|
15330
|
-
7: (n) => Number(n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2),
|
|
15331
|
-
8: (n) => Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3),
|
|
15332
|
-
9: (n) => Number(n >= 2),
|
|
15333
|
-
10: (n) => Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4),
|
|
15334
|
-
11: (n) => Number(n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3),
|
|
15335
|
-
12: (n) => Number(n % 10 != 1 || n % 100 == 11),
|
|
15336
|
-
13: (n) => Number(n !== 0),
|
|
15337
|
-
14: (n) => Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3),
|
|
15338
|
-
15: (n) => Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2),
|
|
15339
|
-
16: (n) => Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2),
|
|
15340
|
-
17: (n) => Number(n == 1 || n % 10 == 1 && n % 100 != 11 ? 0 : 1),
|
|
15341
|
-
18: (n) => Number(n == 0 ? 0 : n == 1 ? 1 : 2),
|
|
15342
|
-
19: (n) => Number(n == 1 ? 0 : n == 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3),
|
|
15343
|
-
20: (n) => Number(n == 1 ? 0 : n == 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2),
|
|
15344
|
-
21: (n) => Number(n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0),
|
|
15345
|
-
22: (n) => Number(n == 1 ? 0 : n == 2 ? 1 : (n < 0 || n > 10) && n % 10 == 0 ? 2 : 3)
|
|
15346
|
-
};
|
|
15347
|
-
var nonIntlVersions = ["v1", "v2", "v3"];
|
|
15348
|
-
var intlVersions = ["v4"];
|
|
15349
|
-
var suffixesOrder = {
|
|
15350
|
-
zero: 0,
|
|
15351
|
-
one: 1,
|
|
15352
|
-
two: 2,
|
|
15353
|
-
few: 3,
|
|
15354
|
-
many: 4,
|
|
15355
|
-
other: 5
|
|
15356
|
-
};
|
|
15357
|
-
var createRules = () => {
|
|
15358
|
-
const rules = {};
|
|
15359
|
-
sets.forEach((set) => {
|
|
15360
|
-
set.lngs.forEach((l) => {
|
|
15361
|
-
rules[l] = {
|
|
15362
|
-
numbers: set.nr,
|
|
15363
|
-
plurals: _rulesPluralsTypes[set.fc]
|
|
15364
|
-
};
|
|
15365
|
-
});
|
|
15366
|
-
});
|
|
15367
|
-
return rules;
|
|
15368
|
-
};
|
|
15369
|
-
var PluralResolver = class {
|
|
15370
|
-
constructor(languageUtils) {
|
|
15371
|
-
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
15372
|
-
this.languageUtils = languageUtils;
|
|
15373
|
-
this.options = options;
|
|
15374
|
-
this.logger = baseLogger.create("pluralResolver");
|
|
15375
|
-
if ((!this.options.compatibilityJSON || intlVersions.includes(this.options.compatibilityJSON)) && (typeof Intl === "undefined" || !Intl.PluralRules)) {
|
|
15376
|
-
this.options.compatibilityJSON = "v3";
|
|
15377
|
-
this.logger.error("Your environment seems not to be Intl API compatible, use an Intl.PluralRules polyfill. Will fallback to the compatibilityJSON v3 format handling.");
|
|
15378
|
-
}
|
|
15379
|
-
this.rules = createRules();
|
|
15380
|
-
this.pluralRulesCache = {};
|
|
15381
|
-
}
|
|
15382
|
-
addRule(lng, obj) {
|
|
15383
|
-
this.rules[lng] = obj;
|
|
15384
|
-
}
|
|
15385
|
-
clearCache() {
|
|
15386
|
-
this.pluralRulesCache = {};
|
|
15387
|
-
}
|
|
15388
|
-
getRule(code) {
|
|
15389
|
-
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
15390
|
-
if (this.shouldUseIntlApi()) {
|
|
15391
|
-
const cleanedCode = getCleanedCode(code === "dev" ? "en" : code);
|
|
15392
|
-
const type = options.ordinal ? "ordinal" : "cardinal";
|
|
15393
|
-
const cacheKey = JSON.stringify({
|
|
15394
|
-
cleanedCode,
|
|
15395
|
-
type
|
|
15396
|
-
});
|
|
15397
|
-
if (cacheKey in this.pluralRulesCache) {
|
|
15398
|
-
return this.pluralRulesCache[cacheKey];
|
|
15399
|
-
}
|
|
15400
|
-
let rule;
|
|
15401
|
-
try {
|
|
15402
|
-
rule = new Intl.PluralRules(cleanedCode, {
|
|
15403
|
-
type
|
|
15404
|
-
});
|
|
15405
|
-
} catch (err) {
|
|
15406
|
-
if (!code.match(/-|_/)) return;
|
|
15407
|
-
const lngPart = this.languageUtils.getLanguagePartFromCode(code);
|
|
15408
|
-
rule = this.getRule(lngPart, options);
|
|
15409
|
-
}
|
|
15410
|
-
this.pluralRulesCache[cacheKey] = rule;
|
|
15411
|
-
return rule;
|
|
15412
|
-
}
|
|
15413
|
-
return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
|
|
15414
|
-
}
|
|
15415
|
-
needsPlural(code) {
|
|
15416
|
-
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
15417
|
-
const rule = this.getRule(code, options);
|
|
15418
|
-
if (this.shouldUseIntlApi()) {
|
|
15419
|
-
return rule && rule.resolvedOptions().pluralCategories.length > 1;
|
|
15420
|
-
}
|
|
15421
|
-
return rule && rule.numbers.length > 1;
|
|
15422
|
-
}
|
|
15423
|
-
getPluralFormsOfKey(code, key) {
|
|
15424
|
-
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
15425
|
-
return this.getSuffixes(code, options).map((suffix) => `${key}${suffix}`);
|
|
15426
|
-
}
|
|
15427
|
-
getSuffixes(code) {
|
|
15428
|
-
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
15429
|
-
const rule = this.getRule(code, options);
|
|
15430
|
-
if (!rule) {
|
|
15431
|
-
return [];
|
|
15432
|
-
}
|
|
15433
|
-
if (this.shouldUseIntlApi()) {
|
|
15434
|
-
return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map((pluralCategory) => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${pluralCategory}`);
|
|
15435
|
-
}
|
|
15436
|
-
return rule.numbers.map((number) => this.getSuffix(code, number, options));
|
|
15437
|
-
}
|
|
15438
|
-
getSuffix(code, count) {
|
|
15439
|
-
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
15440
|
-
const rule = this.getRule(code, options);
|
|
15441
|
-
if (rule) {
|
|
15442
|
-
if (this.shouldUseIntlApi()) {
|
|
15443
|
-
return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${rule.select(count)}`;
|
|
15444
|
-
}
|
|
15445
|
-
return this.getSuffixRetroCompatible(rule, count);
|
|
15446
|
-
}
|
|
15447
|
-
this.logger.warn(`no plural rule found for: ${code}`);
|
|
15448
|
-
return "";
|
|
15449
|
-
}
|
|
15450
|
-
getSuffixRetroCompatible(rule, count) {
|
|
15451
|
-
const idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
|
|
15452
|
-
let suffix = rule.numbers[idx];
|
|
15453
|
-
if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
15454
|
-
if (suffix === 2) {
|
|
15455
|
-
suffix = "plural";
|
|
15456
|
-
} else if (suffix === 1) {
|
|
15457
|
-
suffix = "";
|
|
15458
|
-
}
|
|
15459
|
-
}
|
|
15460
|
-
const returnSuffix = () => this.options.prepend && suffix.toString() ? this.options.prepend + suffix.toString() : suffix.toString();
|
|
15461
|
-
if (this.options.compatibilityJSON === "v1") {
|
|
15462
|
-
if (suffix === 1) return "";
|
|
15463
|
-
if (typeof suffix === "number") return `_plural_${suffix.toString()}`;
|
|
15464
|
-
return returnSuffix();
|
|
15465
|
-
} else if (this.options.compatibilityJSON === "v2") {
|
|
15466
|
-
return returnSuffix();
|
|
15467
|
-
} else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
15468
|
-
return returnSuffix();
|
|
15469
|
-
}
|
|
15470
|
-
return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
|
|
15471
|
-
}
|
|
15472
|
-
shouldUseIntlApi() {
|
|
15473
|
-
return !nonIntlVersions.includes(this.options.compatibilityJSON);
|
|
15474
|
-
}
|
|
15475
|
-
};
|
|
15476
|
-
var deepFindWithDefaults = function(data, defaultData, key) {
|
|
15477
|
-
let keySeparator = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : ".";
|
|
15478
|
-
let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : true;
|
|
15479
|
-
let path = getPathWithDefaults(data, defaultData, key);
|
|
15480
|
-
if (!path && ignoreJSONStructure && isString(key)) {
|
|
15481
|
-
path = deepFind(data, key, keySeparator);
|
|
15482
|
-
if (path === void 0) path = deepFind(defaultData, key, keySeparator);
|
|
15483
|
-
}
|
|
15484
|
-
return path;
|
|
15485
|
-
};
|
|
15486
|
-
var regexSafe = (val) => val.replace(/\$/g, "$$$$");
|
|
15487
|
-
var Interpolator = class {
|
|
15488
|
-
constructor() {
|
|
15489
|
-
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
15490
|
-
this.logger = baseLogger.create("interpolator");
|
|
15491
|
-
this.options = options;
|
|
15492
|
-
this.format = options.interpolation && options.interpolation.format || ((value) => value);
|
|
15493
|
-
this.init(options);
|
|
15494
|
-
}
|
|
15495
|
-
init() {
|
|
15496
|
-
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
15497
|
-
if (!options.interpolation) options.interpolation = {
|
|
15498
|
-
escapeValue: true
|
|
15499
|
-
};
|
|
15500
|
-
const {
|
|
15501
|
-
escape: escape$1,
|
|
15502
|
-
escapeValue,
|
|
15503
|
-
useRawValueToEscape,
|
|
15504
|
-
prefix,
|
|
15505
|
-
prefixEscaped,
|
|
15506
|
-
suffix,
|
|
15507
|
-
suffixEscaped,
|
|
15508
|
-
formatSeparator,
|
|
15509
|
-
unescapeSuffix,
|
|
15510
|
-
unescapePrefix,
|
|
15511
|
-
nestingPrefix,
|
|
15512
|
-
nestingPrefixEscaped,
|
|
15513
|
-
nestingSuffix,
|
|
15514
|
-
nestingSuffixEscaped,
|
|
15515
|
-
nestingOptionsSeparator,
|
|
15516
|
-
maxReplaces,
|
|
15517
|
-
alwaysFormat
|
|
15518
|
-
} = options.interpolation;
|
|
15519
|
-
this.escape = escape$1 !== void 0 ? escape$1 : escape;
|
|
15520
|
-
this.escapeValue = escapeValue !== void 0 ? escapeValue : true;
|
|
15521
|
-
this.useRawValueToEscape = useRawValueToEscape !== void 0 ? useRawValueToEscape : false;
|
|
15522
|
-
this.prefix = prefix ? regexEscape(prefix) : prefixEscaped || "{{";
|
|
15523
|
-
this.suffix = suffix ? regexEscape(suffix) : suffixEscaped || "}}";
|
|
15524
|
-
this.formatSeparator = formatSeparator || ",";
|
|
15525
|
-
this.unescapePrefix = unescapeSuffix ? "" : unescapePrefix || "-";
|
|
15526
|
-
this.unescapeSuffix = this.unescapePrefix ? "" : unescapeSuffix || "";
|
|
15527
|
-
this.nestingPrefix = nestingPrefix ? regexEscape(nestingPrefix) : nestingPrefixEscaped || regexEscape("$t(");
|
|
15528
|
-
this.nestingSuffix = nestingSuffix ? regexEscape(nestingSuffix) : nestingSuffixEscaped || regexEscape(")");
|
|
15529
|
-
this.nestingOptionsSeparator = nestingOptionsSeparator || ",";
|
|
15530
|
-
this.maxReplaces = maxReplaces || 1e3;
|
|
15531
|
-
this.alwaysFormat = alwaysFormat !== void 0 ? alwaysFormat : false;
|
|
15532
|
-
this.resetRegExp();
|
|
15533
|
-
}
|
|
15534
|
-
reset() {
|
|
15535
|
-
if (this.options) this.init(this.options);
|
|
15536
|
-
}
|
|
15537
|
-
resetRegExp() {
|
|
15538
|
-
const getOrResetRegExp = (existingRegExp, pattern) => {
|
|
15539
|
-
if (existingRegExp && existingRegExp.source === pattern) {
|
|
15540
|
-
existingRegExp.lastIndex = 0;
|
|
15541
|
-
return existingRegExp;
|
|
15542
|
-
}
|
|
15543
|
-
return new RegExp(pattern, "g");
|
|
15544
|
-
};
|
|
15545
|
-
this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
|
|
15546
|
-
this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
|
|
15547
|
-
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}(.+?)${this.nestingSuffix}`);
|
|
15548
|
-
}
|
|
15549
|
-
interpolate(str, data, lng, options) {
|
|
15550
|
-
let match;
|
|
15551
|
-
let value;
|
|
15552
|
-
let replaces;
|
|
15553
|
-
const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
15554
|
-
const handleFormat = (key) => {
|
|
15555
|
-
if (key.indexOf(this.formatSeparator) < 0) {
|
|
15556
|
-
const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
|
|
15557
|
-
return this.alwaysFormat ? this.format(path, void 0, lng, {
|
|
15558
|
-
...options,
|
|
15559
|
-
...data,
|
|
15560
|
-
interpolationkey: key
|
|
15561
|
-
}) : path;
|
|
15562
|
-
}
|
|
15563
|
-
const p = key.split(this.formatSeparator);
|
|
15564
|
-
const k = p.shift().trim();
|
|
15565
|
-
const f = p.join(this.formatSeparator).trim();
|
|
15566
|
-
return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
|
|
15567
|
-
...options,
|
|
15568
|
-
...data,
|
|
15569
|
-
interpolationkey: k
|
|
15570
|
-
});
|
|
15571
|
-
};
|
|
15572
|
-
this.resetRegExp();
|
|
15573
|
-
const missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler;
|
|
15574
|
-
const skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
|
|
15575
|
-
const todos = [{
|
|
15576
|
-
regex: this.regexpUnescape,
|
|
15577
|
-
safeValue: (val) => regexSafe(val)
|
|
15578
|
-
}, {
|
|
15579
|
-
regex: this.regexp,
|
|
15580
|
-
safeValue: (val) => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
|
|
15581
|
-
}];
|
|
15582
|
-
todos.forEach((todo) => {
|
|
15583
|
-
replaces = 0;
|
|
15584
|
-
while (match = todo.regex.exec(str)) {
|
|
15585
|
-
const matchedVar = match[1].trim();
|
|
15586
|
-
value = handleFormat(matchedVar);
|
|
15587
|
-
if (value === void 0) {
|
|
15588
|
-
if (typeof missingInterpolationHandler === "function") {
|
|
15589
|
-
const temp = missingInterpolationHandler(str, match, options);
|
|
15590
|
-
value = isString(temp) ? temp : "";
|
|
15591
|
-
} else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
|
|
15592
|
-
value = "";
|
|
15593
|
-
} else if (skipOnVariables) {
|
|
15594
|
-
value = match[0];
|
|
15595
|
-
continue;
|
|
15596
|
-
} else {
|
|
15597
|
-
this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
|
|
15598
|
-
value = "";
|
|
15599
|
-
}
|
|
15600
|
-
} else if (!isString(value) && !this.useRawValueToEscape) {
|
|
15601
|
-
value = makeString(value);
|
|
15602
|
-
}
|
|
15603
|
-
const safeValue = todo.safeValue(value);
|
|
15604
|
-
str = str.replace(match[0], safeValue);
|
|
15605
|
-
if (skipOnVariables) {
|
|
15606
|
-
todo.regex.lastIndex += value.length;
|
|
15607
|
-
todo.regex.lastIndex -= match[0].length;
|
|
15608
|
-
} else {
|
|
15609
|
-
todo.regex.lastIndex = 0;
|
|
15610
|
-
}
|
|
15611
|
-
replaces++;
|
|
15612
|
-
if (replaces >= this.maxReplaces) {
|
|
15613
|
-
break;
|
|
15614
|
-
}
|
|
15615
|
-
}
|
|
15616
|
-
});
|
|
15617
|
-
return str;
|
|
15618
|
-
}
|
|
15619
|
-
nest(str, fc) {
|
|
15620
|
-
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
15621
|
-
let match;
|
|
15622
|
-
let value;
|
|
15623
|
-
let clonedOptions;
|
|
15624
|
-
const handleHasOptions = (key, inheritedOptions) => {
|
|
15625
|
-
const sep = this.nestingOptionsSeparator;
|
|
15626
|
-
if (key.indexOf(sep) < 0) return key;
|
|
15627
|
-
const c = key.split(new RegExp(`${sep}[ ]*{`));
|
|
15628
|
-
let optionsString = `{${c[1]}`;
|
|
15629
|
-
key = c[0];
|
|
15630
|
-
optionsString = this.interpolate(optionsString, clonedOptions);
|
|
15631
|
-
const matchedSingleQuotes = optionsString.match(/'/g);
|
|
15632
|
-
const matchedDoubleQuotes = optionsString.match(/"/g);
|
|
15633
|
-
if (matchedSingleQuotes && matchedSingleQuotes.length % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
|
|
15634
|
-
optionsString = optionsString.replace(/'/g, '"');
|
|
15635
|
-
}
|
|
15636
|
-
try {
|
|
15637
|
-
clonedOptions = JSON.parse(optionsString);
|
|
15638
|
-
if (inheritedOptions) clonedOptions = {
|
|
15639
|
-
...inheritedOptions,
|
|
15640
|
-
...clonedOptions
|
|
15641
|
-
};
|
|
15642
|
-
} catch (e) {
|
|
15643
|
-
this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
|
|
15644
|
-
return `${key}${sep}${optionsString}`;
|
|
15645
|
-
}
|
|
15646
|
-
if (clonedOptions.defaultValue && clonedOptions.defaultValue.indexOf(this.prefix) > -1) delete clonedOptions.defaultValue;
|
|
15647
|
-
return key;
|
|
15648
|
-
};
|
|
15649
|
-
while (match = this.nestingRegexp.exec(str)) {
|
|
15650
|
-
let formatters = [];
|
|
15651
|
-
clonedOptions = {
|
|
15652
|
-
...options
|
|
15653
|
-
};
|
|
15654
|
-
clonedOptions = clonedOptions.replace && !isString(clonedOptions.replace) ? clonedOptions.replace : clonedOptions;
|
|
15655
|
-
clonedOptions.applyPostProcessor = false;
|
|
15656
|
-
delete clonedOptions.defaultValue;
|
|
15657
|
-
let doReduce = false;
|
|
15658
|
-
if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
|
|
15659
|
-
const r2 = match[1].split(this.formatSeparator).map((elem) => elem.trim());
|
|
15660
|
-
match[1] = r2.shift();
|
|
15661
|
-
formatters = r2;
|
|
15662
|
-
doReduce = true;
|
|
15663
|
-
}
|
|
15664
|
-
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
15665
|
-
if (value && match[0] === str && !isString(value)) return value;
|
|
15666
|
-
if (!isString(value)) value = makeString(value);
|
|
15667
|
-
if (!value) {
|
|
15668
|
-
this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
|
|
15669
|
-
value = "";
|
|
15670
|
-
}
|
|
15671
|
-
if (doReduce) {
|
|
15672
|
-
value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
|
|
15673
|
-
...options,
|
|
15674
|
-
interpolationkey: match[1].trim()
|
|
15675
|
-
}), value.trim());
|
|
15676
|
-
}
|
|
15677
|
-
str = str.replace(match[0], value);
|
|
15678
|
-
this.regexp.lastIndex = 0;
|
|
15679
|
-
}
|
|
15680
|
-
return str;
|
|
15681
|
-
}
|
|
15682
|
-
};
|
|
15683
|
-
var parseFormatStr = (formatStr) => {
|
|
15684
|
-
let formatName = formatStr.toLowerCase().trim();
|
|
15685
|
-
const formatOptions = {};
|
|
15686
|
-
if (formatStr.indexOf("(") > -1) {
|
|
15687
|
-
const p = formatStr.split("(");
|
|
15688
|
-
formatName = p[0].toLowerCase().trim();
|
|
15689
|
-
const optStr = p[1].substring(0, p[1].length - 1);
|
|
15690
|
-
if (formatName === "currency" && optStr.indexOf(":") < 0) {
|
|
15691
|
-
if (!formatOptions.currency) formatOptions.currency = optStr.trim();
|
|
15692
|
-
} else if (formatName === "relativetime" && optStr.indexOf(":") < 0) {
|
|
15693
|
-
if (!formatOptions.range) formatOptions.range = optStr.trim();
|
|
15694
|
-
} else {
|
|
15695
|
-
const opts = optStr.split(";");
|
|
15696
|
-
opts.forEach((opt) => {
|
|
15697
|
-
if (opt) {
|
|
15698
|
-
const [key, ...rest] = opt.split(":");
|
|
15699
|
-
const val = rest.join(":").trim().replace(/^'+|'+$/g, "");
|
|
15700
|
-
const trimmedKey = key.trim();
|
|
15701
|
-
if (!formatOptions[trimmedKey]) formatOptions[trimmedKey] = val;
|
|
15702
|
-
if (val === "false") formatOptions[trimmedKey] = false;
|
|
15703
|
-
if (val === "true") formatOptions[trimmedKey] = true;
|
|
15704
|
-
if (!isNaN(val)) formatOptions[trimmedKey] = parseInt(val, 10);
|
|
15705
|
-
}
|
|
15706
|
-
});
|
|
15707
|
-
}
|
|
15708
|
-
}
|
|
15709
|
-
return {
|
|
15710
|
-
formatName,
|
|
15711
|
-
formatOptions
|
|
15712
|
-
};
|
|
15713
|
-
};
|
|
15714
|
-
var createCachedFormatter = (fn) => {
|
|
15715
|
-
const cache = {};
|
|
15716
|
-
return (val, lng, options) => {
|
|
15717
|
-
let optForCache = options;
|
|
15718
|
-
if (options && options.interpolationkey && options.formatParams && options.formatParams[options.interpolationkey] && options[options.interpolationkey]) {
|
|
15719
|
-
optForCache = {
|
|
15720
|
-
...optForCache,
|
|
15721
|
-
[options.interpolationkey]: void 0
|
|
15722
|
-
};
|
|
15723
|
-
}
|
|
15724
|
-
const key = lng + JSON.stringify(optForCache);
|
|
15725
|
-
let formatter = cache[key];
|
|
15726
|
-
if (!formatter) {
|
|
15727
|
-
formatter = fn(getCleanedCode(lng), options);
|
|
15728
|
-
cache[key] = formatter;
|
|
15729
|
-
}
|
|
15730
|
-
return formatter(val);
|
|
15731
|
-
};
|
|
15732
|
-
};
|
|
15733
|
-
var Formatter = class {
|
|
15734
|
-
constructor() {
|
|
15735
|
-
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
15736
|
-
this.logger = baseLogger.create("formatter");
|
|
15737
|
-
this.options = options;
|
|
15738
|
-
this.formats = {
|
|
15739
|
-
number: createCachedFormatter((lng, opt) => {
|
|
15740
|
-
const formatter = new Intl.NumberFormat(lng, {
|
|
15741
|
-
...opt
|
|
15742
|
-
});
|
|
15743
|
-
return (val) => formatter.format(val);
|
|
15744
|
-
}),
|
|
15745
|
-
currency: createCachedFormatter((lng, opt) => {
|
|
15746
|
-
const formatter = new Intl.NumberFormat(lng, {
|
|
15747
|
-
...opt,
|
|
15748
|
-
style: "currency"
|
|
15749
|
-
});
|
|
15750
|
-
return (val) => formatter.format(val);
|
|
15751
|
-
}),
|
|
15752
|
-
datetime: createCachedFormatter((lng, opt) => {
|
|
15753
|
-
const formatter = new Intl.DateTimeFormat(lng, {
|
|
15754
|
-
...opt
|
|
15755
|
-
});
|
|
15756
|
-
return (val) => formatter.format(val);
|
|
15757
|
-
}),
|
|
15758
|
-
relativetime: createCachedFormatter((lng, opt) => {
|
|
15759
|
-
const formatter = new Intl.RelativeTimeFormat(lng, {
|
|
15760
|
-
...opt
|
|
15761
|
-
});
|
|
15762
|
-
return (val) => formatter.format(val, opt.range || "day");
|
|
15763
|
-
}),
|
|
15764
|
-
list: createCachedFormatter((lng, opt) => {
|
|
15765
|
-
const formatter = new Intl.ListFormat(lng, {
|
|
15766
|
-
...opt
|
|
15767
|
-
});
|
|
15768
|
-
return (val) => formatter.format(val);
|
|
15769
|
-
})
|
|
15770
|
-
};
|
|
15771
|
-
this.init(options);
|
|
15772
|
-
}
|
|
15773
|
-
init(services) {
|
|
15774
|
-
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
|
|
15775
|
-
interpolation: {}
|
|
15776
|
-
};
|
|
15777
|
-
this.formatSeparator = options.interpolation.formatSeparator || ",";
|
|
15778
|
-
}
|
|
15779
|
-
add(name, fc) {
|
|
15780
|
-
this.formats[name.toLowerCase().trim()] = fc;
|
|
15781
|
-
}
|
|
15782
|
-
addCached(name, fc) {
|
|
15783
|
-
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
15784
|
-
}
|
|
15785
|
-
format(value, format, lng) {
|
|
15786
|
-
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
15787
|
-
const formats = format.split(this.formatSeparator);
|
|
15788
|
-
if (formats.length > 1 && formats[0].indexOf("(") > 1 && formats[0].indexOf(")") < 0 && formats.find((f) => f.indexOf(")") > -1)) {
|
|
15789
|
-
const lastIndex = formats.findIndex((f) => f.indexOf(")") > -1);
|
|
15790
|
-
formats[0] = [formats[0], ...formats.splice(1, lastIndex)].join(this.formatSeparator);
|
|
15791
|
-
}
|
|
15792
|
-
const result = formats.reduce((mem, f) => {
|
|
15793
|
-
const {
|
|
15794
|
-
formatName,
|
|
15795
|
-
formatOptions
|
|
15796
|
-
} = parseFormatStr(f);
|
|
15797
|
-
if (this.formats[formatName]) {
|
|
15798
|
-
let formatted = mem;
|
|
15799
|
-
try {
|
|
15800
|
-
const valOptions = options && options.formatParams && options.formatParams[options.interpolationkey] || {};
|
|
15801
|
-
const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
|
|
15802
|
-
formatted = this.formats[formatName](mem, l, {
|
|
15803
|
-
...formatOptions,
|
|
15804
|
-
...options,
|
|
15805
|
-
...valOptions
|
|
15806
|
-
});
|
|
15807
|
-
} catch (error) {
|
|
15808
|
-
this.logger.warn(error);
|
|
15809
|
-
}
|
|
15810
|
-
return formatted;
|
|
15811
|
-
} else {
|
|
15812
|
-
this.logger.warn(`there was no format function for ${formatName}`);
|
|
15813
|
-
}
|
|
15814
|
-
return mem;
|
|
15815
|
-
}, value);
|
|
15816
|
-
return result;
|
|
15817
|
-
}
|
|
15818
|
-
};
|
|
15819
|
-
var removePending = (q, name) => {
|
|
15820
|
-
if (q.pending[name] !== void 0) {
|
|
15821
|
-
delete q.pending[name];
|
|
15822
|
-
q.pendingCount--;
|
|
15823
|
-
}
|
|
15824
|
-
};
|
|
15825
|
-
var Connector = class extends EventEmitter {
|
|
15826
|
-
constructor(backend, store, services) {
|
|
15827
|
-
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
15828
|
-
super();
|
|
15829
|
-
this.backend = backend;
|
|
15830
|
-
this.store = store;
|
|
15831
|
-
this.services = services;
|
|
15832
|
-
this.languageUtils = services.languageUtils;
|
|
15833
|
-
this.options = options;
|
|
15834
|
-
this.logger = baseLogger.create("backendConnector");
|
|
15835
|
-
this.waitingReads = [];
|
|
15836
|
-
this.maxParallelReads = options.maxParallelReads || 10;
|
|
15837
|
-
this.readingCalls = 0;
|
|
15838
|
-
this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
|
|
15839
|
-
this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
|
|
15840
|
-
this.state = {};
|
|
15841
|
-
this.queue = [];
|
|
15842
|
-
if (this.backend && this.backend.init) {
|
|
15843
|
-
this.backend.init(services, options.backend, options);
|
|
15844
|
-
}
|
|
15845
|
-
}
|
|
15846
|
-
queueLoad(languages, namespaces, options, callback) {
|
|
15847
|
-
const toLoad = {};
|
|
15848
|
-
const pending = {};
|
|
15849
|
-
const toLoadLanguages = {};
|
|
15850
|
-
const toLoadNamespaces = {};
|
|
15851
|
-
languages.forEach((lng) => {
|
|
15852
|
-
let hasAllNamespaces = true;
|
|
15853
|
-
namespaces.forEach((ns) => {
|
|
15854
|
-
const name = `${lng}|${ns}`;
|
|
15855
|
-
if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
|
|
15856
|
-
this.state[name] = 2;
|
|
15857
|
-
} else if (this.state[name] < 0) ;
|
|
15858
|
-
else if (this.state[name] === 1) {
|
|
15859
|
-
if (pending[name] === void 0) pending[name] = true;
|
|
15860
|
-
} else {
|
|
15861
|
-
this.state[name] = 1;
|
|
15862
|
-
hasAllNamespaces = false;
|
|
15863
|
-
if (pending[name] === void 0) pending[name] = true;
|
|
15864
|
-
if (toLoad[name] === void 0) toLoad[name] = true;
|
|
15865
|
-
if (toLoadNamespaces[ns] === void 0) toLoadNamespaces[ns] = true;
|
|
15866
|
-
}
|
|
15867
|
-
});
|
|
15868
|
-
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
15869
|
-
});
|
|
15870
|
-
if (Object.keys(toLoad).length || Object.keys(pending).length) {
|
|
15871
|
-
this.queue.push({
|
|
15872
|
-
pending,
|
|
15873
|
-
pendingCount: Object.keys(pending).length,
|
|
15874
|
-
loaded: {},
|
|
15875
|
-
errors: [],
|
|
15876
|
-
callback
|
|
15877
|
-
});
|
|
15878
|
-
}
|
|
15879
|
-
return {
|
|
15880
|
-
toLoad: Object.keys(toLoad),
|
|
15881
|
-
pending: Object.keys(pending),
|
|
15882
|
-
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
15883
|
-
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
15884
|
-
};
|
|
15885
|
-
}
|
|
15886
|
-
loaded(name, err, data) {
|
|
15887
|
-
const s = name.split("|");
|
|
15888
|
-
const lng = s[0];
|
|
15889
|
-
const ns = s[1];
|
|
15890
|
-
if (err) this.emit("failedLoading", lng, ns, err);
|
|
15891
|
-
if (!err && data) {
|
|
15892
|
-
this.store.addResourceBundle(lng, ns, data, void 0, void 0, {
|
|
15893
|
-
skipCopy: true
|
|
15894
|
-
});
|
|
15895
|
-
}
|
|
15896
|
-
this.state[name] = err ? -1 : 2;
|
|
15897
|
-
if (err && data) this.state[name] = 0;
|
|
15898
|
-
const loaded = {};
|
|
15899
|
-
this.queue.forEach((q) => {
|
|
15900
|
-
pushPath(q.loaded, [lng], ns);
|
|
15901
|
-
removePending(q, name);
|
|
15902
|
-
if (err) q.errors.push(err);
|
|
15903
|
-
if (q.pendingCount === 0 && !q.done) {
|
|
15904
|
-
Object.keys(q.loaded).forEach((l) => {
|
|
15905
|
-
if (!loaded[l]) loaded[l] = {};
|
|
15906
|
-
const loadedKeys = q.loaded[l];
|
|
15907
|
-
if (loadedKeys.length) {
|
|
15908
|
-
loadedKeys.forEach((n) => {
|
|
15909
|
-
if (loaded[l][n] === void 0) loaded[l][n] = true;
|
|
15910
|
-
});
|
|
15911
|
-
}
|
|
15912
|
-
});
|
|
15913
|
-
q.done = true;
|
|
15914
|
-
if (q.errors.length) {
|
|
15915
|
-
q.callback(q.errors);
|
|
15916
|
-
} else {
|
|
15917
|
-
q.callback();
|
|
15918
|
-
}
|
|
15919
|
-
}
|
|
15920
|
-
});
|
|
15921
|
-
this.emit("loaded", loaded);
|
|
15922
|
-
this.queue = this.queue.filter((q) => !q.done);
|
|
15923
|
-
}
|
|
15924
|
-
read(lng, ns, fcName) {
|
|
15925
|
-
let tried = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0;
|
|
15926
|
-
let wait = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : this.retryTimeout;
|
|
15927
|
-
let callback = arguments.length > 5 ? arguments[5] : void 0;
|
|
15928
|
-
if (!lng.length) return callback(null, {});
|
|
15929
|
-
if (this.readingCalls >= this.maxParallelReads) {
|
|
15930
|
-
this.waitingReads.push({
|
|
15931
|
-
lng,
|
|
15932
|
-
ns,
|
|
15933
|
-
fcName,
|
|
15934
|
-
tried,
|
|
15935
|
-
wait,
|
|
15936
|
-
callback
|
|
15937
|
-
});
|
|
15938
|
-
return;
|
|
15939
|
-
}
|
|
15940
|
-
this.readingCalls++;
|
|
15941
|
-
const resolver = (err, data) => {
|
|
15942
|
-
this.readingCalls--;
|
|
15943
|
-
if (this.waitingReads.length > 0) {
|
|
15944
|
-
const next = this.waitingReads.shift();
|
|
15945
|
-
this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
15946
|
-
}
|
|
15947
|
-
if (err && data && tried < this.maxRetries) {
|
|
15948
|
-
setTimeout(() => {
|
|
15949
|
-
this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
15950
|
-
}, wait);
|
|
15951
|
-
return;
|
|
15952
|
-
}
|
|
15953
|
-
callback(err, data);
|
|
15954
|
-
};
|
|
15955
|
-
const fc = this.backend[fcName].bind(this.backend);
|
|
15956
|
-
if (fc.length === 2) {
|
|
15957
|
-
try {
|
|
15958
|
-
const r2 = fc(lng, ns);
|
|
15959
|
-
if (r2 && typeof r2.then === "function") {
|
|
15960
|
-
r2.then((data) => resolver(null, data)).catch(resolver);
|
|
15961
|
-
} else {
|
|
15962
|
-
resolver(null, r2);
|
|
15963
|
-
}
|
|
15964
|
-
} catch (err) {
|
|
15965
|
-
resolver(err);
|
|
15966
|
-
}
|
|
15967
|
-
return;
|
|
15968
|
-
}
|
|
15969
|
-
return fc(lng, ns, resolver);
|
|
15970
|
-
}
|
|
15971
|
-
prepareLoading(languages, namespaces) {
|
|
15972
|
-
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
15973
|
-
let callback = arguments.length > 3 ? arguments[3] : void 0;
|
|
15974
|
-
if (!this.backend) {
|
|
15975
|
-
this.logger.warn("No backend was added via i18next.use. Will not load resources.");
|
|
15976
|
-
return callback && callback();
|
|
15977
|
-
}
|
|
15978
|
-
if (isString(languages)) languages = this.languageUtils.toResolveHierarchy(languages);
|
|
15979
|
-
if (isString(namespaces)) namespaces = [namespaces];
|
|
15980
|
-
const toLoad = this.queueLoad(languages, namespaces, options, callback);
|
|
15981
|
-
if (!toLoad.toLoad.length) {
|
|
15982
|
-
if (!toLoad.pending.length) callback();
|
|
15983
|
-
return null;
|
|
15984
|
-
}
|
|
15985
|
-
toLoad.toLoad.forEach((name) => {
|
|
15986
|
-
this.loadOne(name);
|
|
15987
|
-
});
|
|
15988
|
-
}
|
|
15989
|
-
load(languages, namespaces, callback) {
|
|
15990
|
-
this.prepareLoading(languages, namespaces, {}, callback);
|
|
15991
|
-
}
|
|
15992
|
-
reload(languages, namespaces, callback) {
|
|
15993
|
-
this.prepareLoading(languages, namespaces, {
|
|
15994
|
-
reload: true
|
|
15995
|
-
}, callback);
|
|
15996
|
-
}
|
|
15997
|
-
loadOne(name) {
|
|
15998
|
-
let prefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
|
|
15999
|
-
const s = name.split("|");
|
|
16000
|
-
const lng = s[0];
|
|
16001
|
-
const ns = s[1];
|
|
16002
|
-
this.read(lng, ns, "read", void 0, void 0, (err, data) => {
|
|
16003
|
-
if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
|
|
16004
|
-
if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
|
|
16005
|
-
this.loaded(name, err, data);
|
|
16006
|
-
});
|
|
16007
|
-
}
|
|
16008
|
-
saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
|
|
16009
|
-
let options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {};
|
|
16010
|
-
let clb = arguments.length > 6 && arguments[6] !== void 0 ? arguments[6] : () => {
|
|
16011
|
-
};
|
|
16012
|
-
if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
|
|
16013
|
-
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!!!");
|
|
16014
|
-
return;
|
|
16015
|
-
}
|
|
16016
|
-
if (key === void 0 || key === null || key === "") return;
|
|
16017
|
-
if (this.backend && this.backend.create) {
|
|
16018
|
-
const opts = {
|
|
16019
|
-
...options,
|
|
16020
|
-
isUpdate
|
|
16021
|
-
};
|
|
16022
|
-
const fc = this.backend.create.bind(this.backend);
|
|
16023
|
-
if (fc.length < 6) {
|
|
16024
|
-
try {
|
|
16025
|
-
let r2;
|
|
16026
|
-
if (fc.length === 5) {
|
|
16027
|
-
r2 = fc(languages, namespace, key, fallbackValue, opts);
|
|
16028
|
-
} else {
|
|
16029
|
-
r2 = fc(languages, namespace, key, fallbackValue);
|
|
16030
|
-
}
|
|
16031
|
-
if (r2 && typeof r2.then === "function") {
|
|
16032
|
-
r2.then((data) => clb(null, data)).catch(clb);
|
|
16033
|
-
} else {
|
|
16034
|
-
clb(null, r2);
|
|
16035
|
-
}
|
|
16036
|
-
} catch (err) {
|
|
16037
|
-
clb(err);
|
|
16038
|
-
}
|
|
16039
|
-
} else {
|
|
16040
|
-
fc(languages, namespace, key, fallbackValue, clb, opts);
|
|
16041
|
-
}
|
|
16042
|
-
}
|
|
16043
|
-
if (!languages || !languages[0]) return;
|
|
16044
|
-
this.store.addResource(languages[0], namespace, key, fallbackValue);
|
|
16045
|
-
}
|
|
16046
|
-
};
|
|
16047
|
-
var get = () => ({
|
|
16048
|
-
debug: false,
|
|
16049
|
-
initImmediate: true,
|
|
16050
|
-
ns: ["translation"],
|
|
16051
|
-
defaultNS: ["translation"],
|
|
16052
|
-
fallbackLng: ["dev"],
|
|
16053
|
-
fallbackNS: false,
|
|
16054
|
-
supportedLngs: false,
|
|
16055
|
-
nonExplicitSupportedLngs: false,
|
|
16056
|
-
load: "all",
|
|
16057
|
-
preload: false,
|
|
16058
|
-
simplifyPluralSuffix: true,
|
|
16059
|
-
keySeparator: ".",
|
|
16060
|
-
nsSeparator: ":",
|
|
16061
|
-
pluralSeparator: "_",
|
|
16062
|
-
contextSeparator: "_",
|
|
16063
|
-
partialBundledLanguages: false,
|
|
16064
|
-
saveMissing: false,
|
|
16065
|
-
updateMissing: false,
|
|
16066
|
-
saveMissingTo: "fallback",
|
|
16067
|
-
saveMissingPlurals: true,
|
|
16068
|
-
missingKeyHandler: false,
|
|
16069
|
-
missingInterpolationHandler: false,
|
|
16070
|
-
postProcess: false,
|
|
16071
|
-
postProcessPassResolved: false,
|
|
16072
|
-
returnNull: false,
|
|
16073
|
-
returnEmptyString: true,
|
|
16074
|
-
returnObjects: false,
|
|
16075
|
-
joinArrays: false,
|
|
16076
|
-
returnedObjectHandler: false,
|
|
16077
|
-
parseMissingKeyHandler: false,
|
|
16078
|
-
appendNamespaceToMissingKey: false,
|
|
16079
|
-
appendNamespaceToCIMode: false,
|
|
16080
|
-
overloadTranslationOptionHandler: (args) => {
|
|
16081
|
-
let ret = {};
|
|
16082
|
-
if (typeof args[1] === "object") ret = args[1];
|
|
16083
|
-
if (isString(args[1])) ret.defaultValue = args[1];
|
|
16084
|
-
if (isString(args[2])) ret.tDescription = args[2];
|
|
16085
|
-
if (typeof args[2] === "object" || typeof args[3] === "object") {
|
|
16086
|
-
const options = args[3] || args[2];
|
|
16087
|
-
Object.keys(options).forEach((key) => {
|
|
16088
|
-
ret[key] = options[key];
|
|
16089
|
-
});
|
|
16090
|
-
}
|
|
16091
|
-
return ret;
|
|
16092
|
-
},
|
|
16093
|
-
interpolation: {
|
|
16094
|
-
escapeValue: true,
|
|
16095
|
-
format: (value) => value,
|
|
16096
|
-
prefix: "{{",
|
|
16097
|
-
suffix: "}}",
|
|
16098
|
-
formatSeparator: ",",
|
|
16099
|
-
unescapePrefix: "-",
|
|
16100
|
-
nestingPrefix: "$t(",
|
|
16101
|
-
nestingSuffix: ")",
|
|
16102
|
-
nestingOptionsSeparator: ",",
|
|
16103
|
-
maxReplaces: 1e3,
|
|
16104
|
-
skipOnVariables: true
|
|
16105
|
-
}
|
|
16106
|
-
});
|
|
16107
|
-
var transformOptions = (options) => {
|
|
16108
|
-
if (isString(options.ns)) options.ns = [options.ns];
|
|
16109
|
-
if (isString(options.fallbackLng)) options.fallbackLng = [options.fallbackLng];
|
|
16110
|
-
if (isString(options.fallbackNS)) options.fallbackNS = [options.fallbackNS];
|
|
16111
|
-
if (options.supportedLngs && options.supportedLngs.indexOf("cimode") < 0) {
|
|
16112
|
-
options.supportedLngs = options.supportedLngs.concat(["cimode"]);
|
|
16113
|
-
}
|
|
16114
|
-
return options;
|
|
16115
|
-
};
|
|
16116
|
-
var noop = () => {
|
|
16117
|
-
};
|
|
16118
|
-
var bindMemberFunctions = (inst) => {
|
|
16119
|
-
const mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
|
|
16120
|
-
mems.forEach((mem) => {
|
|
16121
|
-
if (typeof inst[mem] === "function") {
|
|
16122
|
-
inst[mem] = inst[mem].bind(inst);
|
|
16123
|
-
}
|
|
16124
|
-
});
|
|
16125
|
-
};
|
|
16126
|
-
var I18n = class _I18n extends EventEmitter {
|
|
16127
|
-
constructor() {
|
|
16128
|
-
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
16129
|
-
let callback = arguments.length > 1 ? arguments[1] : void 0;
|
|
16130
|
-
super();
|
|
16131
|
-
this.options = transformOptions(options);
|
|
16132
|
-
this.services = {};
|
|
16133
|
-
this.logger = baseLogger;
|
|
16134
|
-
this.modules = {
|
|
16135
|
-
external: []
|
|
16136
|
-
};
|
|
16137
|
-
bindMemberFunctions(this);
|
|
16138
|
-
if (callback && !this.isInitialized && !options.isClone) {
|
|
16139
|
-
if (!this.options.initImmediate) {
|
|
16140
|
-
this.init(options, callback);
|
|
16141
|
-
return this;
|
|
16142
|
-
}
|
|
16143
|
-
setTimeout(() => {
|
|
16144
|
-
this.init(options, callback);
|
|
16145
|
-
}, 0);
|
|
16146
|
-
}
|
|
16147
|
-
}
|
|
16148
|
-
init() {
|
|
16149
|
-
var _this = this;
|
|
16150
|
-
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
16151
|
-
let callback = arguments.length > 1 ? arguments[1] : void 0;
|
|
16152
|
-
this.isInitializing = true;
|
|
16153
|
-
if (typeof options === "function") {
|
|
16154
|
-
callback = options;
|
|
16155
|
-
options = {};
|
|
16156
|
-
}
|
|
16157
|
-
if (!options.defaultNS && options.defaultNS !== false && options.ns) {
|
|
16158
|
-
if (isString(options.ns)) {
|
|
16159
|
-
options.defaultNS = options.ns;
|
|
16160
|
-
} else if (options.ns.indexOf("translation") < 0) {
|
|
16161
|
-
options.defaultNS = options.ns[0];
|
|
16162
|
-
}
|
|
16163
|
-
}
|
|
16164
|
-
const defOpts = get();
|
|
16165
|
-
this.options = {
|
|
16166
|
-
...defOpts,
|
|
16167
|
-
...this.options,
|
|
16168
|
-
...transformOptions(options)
|
|
16169
|
-
};
|
|
16170
|
-
if (this.options.compatibilityAPI !== "v1") {
|
|
16171
|
-
this.options.interpolation = {
|
|
16172
|
-
...defOpts.interpolation,
|
|
16173
|
-
...this.options.interpolation
|
|
16174
|
-
};
|
|
16175
|
-
}
|
|
16176
|
-
if (options.keySeparator !== void 0) {
|
|
16177
|
-
this.options.userDefinedKeySeparator = options.keySeparator;
|
|
16178
|
-
}
|
|
16179
|
-
if (options.nsSeparator !== void 0) {
|
|
16180
|
-
this.options.userDefinedNsSeparator = options.nsSeparator;
|
|
16181
|
-
}
|
|
16182
|
-
const createClassOnDemand = (ClassOrObject) => {
|
|
16183
|
-
if (!ClassOrObject) return null;
|
|
16184
|
-
if (typeof ClassOrObject === "function") return new ClassOrObject();
|
|
16185
|
-
return ClassOrObject;
|
|
16186
|
-
};
|
|
16187
|
-
if (!this.options.isClone) {
|
|
16188
|
-
if (this.modules.logger) {
|
|
16189
|
-
baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
|
|
16190
|
-
} else {
|
|
16191
|
-
baseLogger.init(null, this.options);
|
|
16192
|
-
}
|
|
16193
|
-
let formatter;
|
|
16194
|
-
if (this.modules.formatter) {
|
|
16195
|
-
formatter = this.modules.formatter;
|
|
16196
|
-
} else if (typeof Intl !== "undefined") {
|
|
16197
|
-
formatter = Formatter;
|
|
16198
|
-
}
|
|
16199
|
-
const lu = new LanguageUtil(this.options);
|
|
16200
|
-
this.store = new ResourceStore(this.options.resources, this.options);
|
|
16201
|
-
const s = this.services;
|
|
16202
|
-
s.logger = baseLogger;
|
|
16203
|
-
s.resourceStore = this.store;
|
|
16204
|
-
s.languageUtils = lu;
|
|
16205
|
-
s.pluralResolver = new PluralResolver(lu, {
|
|
16206
|
-
prepend: this.options.pluralSeparator,
|
|
16207
|
-
compatibilityJSON: this.options.compatibilityJSON,
|
|
16208
|
-
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
16209
|
-
});
|
|
16210
|
-
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
|
|
16211
|
-
s.formatter = createClassOnDemand(formatter);
|
|
16212
|
-
s.formatter.init(s, this.options);
|
|
16213
|
-
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
16214
|
-
}
|
|
16215
|
-
s.interpolator = new Interpolator(this.options);
|
|
16216
|
-
s.utils = {
|
|
16217
|
-
hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
|
|
16218
|
-
};
|
|
16219
|
-
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
16220
|
-
s.backendConnector.on("*", function(event) {
|
|
16221
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
16222
|
-
args[_key - 1] = arguments[_key];
|
|
16223
|
-
}
|
|
16224
|
-
_this.emit(event, ...args);
|
|
16225
|
-
});
|
|
16226
|
-
if (this.modules.languageDetector) {
|
|
16227
|
-
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
16228
|
-
if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
|
|
16229
|
-
}
|
|
16230
|
-
if (this.modules.i18nFormat) {
|
|
16231
|
-
s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
|
|
16232
|
-
if (s.i18nFormat.init) s.i18nFormat.init(this);
|
|
16233
|
-
}
|
|
16234
|
-
this.translator = new Translator(this.services, this.options);
|
|
16235
|
-
this.translator.on("*", function(event) {
|
|
16236
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
16237
|
-
args[_key2 - 1] = arguments[_key2];
|
|
16238
|
-
}
|
|
16239
|
-
_this.emit(event, ...args);
|
|
16240
|
-
});
|
|
16241
|
-
this.modules.external.forEach((m) => {
|
|
16242
|
-
if (m.init) m.init(this);
|
|
16243
|
-
});
|
|
16244
|
-
}
|
|
16245
|
-
this.format = this.options.interpolation.format;
|
|
16246
|
-
if (!callback) callback = noop;
|
|
16247
|
-
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
16248
|
-
const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
16249
|
-
if (codes.length > 0 && codes[0] !== "dev") this.options.lng = codes[0];
|
|
16250
|
-
}
|
|
16251
|
-
if (!this.services.languageDetector && !this.options.lng) {
|
|
16252
|
-
this.logger.warn("init: no languageDetector is used and no lng is defined");
|
|
16253
|
-
}
|
|
16254
|
-
const storeApi = ["getResource", "hasResourceBundle", "getResourceBundle", "getDataByLanguage"];
|
|
16255
|
-
storeApi.forEach((fcName) => {
|
|
16256
|
-
this[fcName] = function() {
|
|
16257
|
-
return _this.store[fcName](...arguments);
|
|
16258
|
-
};
|
|
16259
|
-
});
|
|
16260
|
-
const storeApiChained = ["addResource", "addResources", "addResourceBundle", "removeResourceBundle"];
|
|
16261
|
-
storeApiChained.forEach((fcName) => {
|
|
16262
|
-
this[fcName] = function() {
|
|
16263
|
-
_this.store[fcName](...arguments);
|
|
16264
|
-
return _this;
|
|
16265
|
-
};
|
|
16266
|
-
});
|
|
16267
|
-
const deferred = defer();
|
|
16268
|
-
const load = () => {
|
|
16269
|
-
const finish = (err, t2) => {
|
|
16270
|
-
this.isInitializing = false;
|
|
16271
|
-
if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn("init: i18next is already initialized. You should call init just once!");
|
|
16272
|
-
this.isInitialized = true;
|
|
16273
|
-
if (!this.options.isClone) this.logger.log("initialized", this.options);
|
|
16274
|
-
this.emit("initialized", this.options);
|
|
16275
|
-
deferred.resolve(t2);
|
|
16276
|
-
callback(err, t2);
|
|
16277
|
-
};
|
|
16278
|
-
if (this.languages && this.options.compatibilityAPI !== "v1" && !this.isInitialized) return finish(null, this.t.bind(this));
|
|
16279
|
-
this.changeLanguage(this.options.lng, finish);
|
|
16280
|
-
};
|
|
16281
|
-
if (this.options.resources || !this.options.initImmediate) {
|
|
16282
|
-
load();
|
|
16283
|
-
} else {
|
|
16284
|
-
setTimeout(load, 0);
|
|
16285
|
-
}
|
|
16286
|
-
return deferred;
|
|
16287
|
-
}
|
|
16288
|
-
loadResources(language) {
|
|
16289
|
-
let callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
16290
|
-
let usedCallback = callback;
|
|
16291
|
-
const usedLng = isString(language) ? language : this.language;
|
|
16292
|
-
if (typeof language === "function") usedCallback = language;
|
|
16293
|
-
if (!this.options.resources || this.options.partialBundledLanguages) {
|
|
16294
|
-
if (usedLng && usedLng.toLowerCase() === "cimode" && (!this.options.preload || this.options.preload.length === 0)) return usedCallback();
|
|
16295
|
-
const toLoad = [];
|
|
16296
|
-
const append = (lng) => {
|
|
16297
|
-
if (!lng) return;
|
|
16298
|
-
if (lng === "cimode") return;
|
|
16299
|
-
const lngs = this.services.languageUtils.toResolveHierarchy(lng);
|
|
16300
|
-
lngs.forEach((l) => {
|
|
16301
|
-
if (l === "cimode") return;
|
|
16302
|
-
if (toLoad.indexOf(l) < 0) toLoad.push(l);
|
|
16303
|
-
});
|
|
16304
|
-
};
|
|
16305
|
-
if (!usedLng) {
|
|
16306
|
-
const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
16307
|
-
fallbacks.forEach((l) => append(l));
|
|
16308
|
-
} else {
|
|
16309
|
-
append(usedLng);
|
|
16310
|
-
}
|
|
16311
|
-
if (this.options.preload) {
|
|
16312
|
-
this.options.preload.forEach((l) => append(l));
|
|
16313
|
-
}
|
|
16314
|
-
this.services.backendConnector.load(toLoad, this.options.ns, (e) => {
|
|
16315
|
-
if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
|
|
16316
|
-
usedCallback(e);
|
|
16317
|
-
});
|
|
16318
|
-
} else {
|
|
16319
|
-
usedCallback(null);
|
|
16320
|
-
}
|
|
16321
|
-
}
|
|
16322
|
-
reloadResources(lngs, ns, callback) {
|
|
16323
|
-
const deferred = defer();
|
|
16324
|
-
if (typeof lngs === "function") {
|
|
16325
|
-
callback = lngs;
|
|
16326
|
-
lngs = void 0;
|
|
16327
|
-
}
|
|
16328
|
-
if (typeof ns === "function") {
|
|
16329
|
-
callback = ns;
|
|
16330
|
-
ns = void 0;
|
|
16331
|
-
}
|
|
16332
|
-
if (!lngs) lngs = this.languages;
|
|
16333
|
-
if (!ns) ns = this.options.ns;
|
|
16334
|
-
if (!callback) callback = noop;
|
|
16335
|
-
this.services.backendConnector.reload(lngs, ns, (err) => {
|
|
16336
|
-
deferred.resolve();
|
|
16337
|
-
callback(err);
|
|
16338
|
-
});
|
|
16339
|
-
return deferred;
|
|
16340
|
-
}
|
|
16341
|
-
use(module) {
|
|
16342
|
-
if (!module) throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");
|
|
16343
|
-
if (!module.type) throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");
|
|
16344
|
-
if (module.type === "backend") {
|
|
16345
|
-
this.modules.backend = module;
|
|
16346
|
-
}
|
|
16347
|
-
if (module.type === "logger" || module.log && module.warn && module.error) {
|
|
16348
|
-
this.modules.logger = module;
|
|
16349
|
-
}
|
|
16350
|
-
if (module.type === "languageDetector") {
|
|
16351
|
-
this.modules.languageDetector = module;
|
|
16352
|
-
}
|
|
16353
|
-
if (module.type === "i18nFormat") {
|
|
16354
|
-
this.modules.i18nFormat = module;
|
|
16355
|
-
}
|
|
16356
|
-
if (module.type === "postProcessor") {
|
|
16357
|
-
postProcessor.addPostProcessor(module);
|
|
16358
|
-
}
|
|
16359
|
-
if (module.type === "formatter") {
|
|
16360
|
-
this.modules.formatter = module;
|
|
16361
|
-
}
|
|
16362
|
-
if (module.type === "3rdParty") {
|
|
16363
|
-
this.modules.external.push(module);
|
|
16364
|
-
}
|
|
16365
|
-
return this;
|
|
16366
|
-
}
|
|
16367
|
-
setResolvedLanguage(l) {
|
|
16368
|
-
if (!l || !this.languages) return;
|
|
16369
|
-
if (["cimode", "dev"].indexOf(l) > -1) return;
|
|
16370
|
-
for (let li = 0; li < this.languages.length; li++) {
|
|
16371
|
-
const lngInLngs = this.languages[li];
|
|
16372
|
-
if (["cimode", "dev"].indexOf(lngInLngs) > -1) continue;
|
|
16373
|
-
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
16374
|
-
this.resolvedLanguage = lngInLngs;
|
|
16375
|
-
break;
|
|
16376
|
-
}
|
|
16377
|
-
}
|
|
16378
|
-
}
|
|
16379
|
-
changeLanguage(lng, callback) {
|
|
16380
|
-
var _this2 = this;
|
|
16381
|
-
this.isLanguageChangingTo = lng;
|
|
16382
|
-
const deferred = defer();
|
|
16383
|
-
this.emit("languageChanging", lng);
|
|
16384
|
-
const setLngProps = (l) => {
|
|
16385
|
-
this.language = l;
|
|
16386
|
-
this.languages = this.services.languageUtils.toResolveHierarchy(l);
|
|
16387
|
-
this.resolvedLanguage = void 0;
|
|
16388
|
-
this.setResolvedLanguage(l);
|
|
16389
|
-
};
|
|
16390
|
-
const done = (err, l) => {
|
|
16391
|
-
if (l) {
|
|
16392
|
-
setLngProps(l);
|
|
16393
|
-
this.translator.changeLanguage(l);
|
|
16394
|
-
this.isLanguageChangingTo = void 0;
|
|
16395
|
-
this.emit("languageChanged", l);
|
|
16396
|
-
this.logger.log("languageChanged", l);
|
|
16397
|
-
} else {
|
|
16398
|
-
this.isLanguageChangingTo = void 0;
|
|
16399
|
-
}
|
|
16400
|
-
deferred.resolve(function() {
|
|
16401
|
-
return _this2.t(...arguments);
|
|
16402
|
-
});
|
|
16403
|
-
if (callback) callback(err, function() {
|
|
16404
|
-
return _this2.t(...arguments);
|
|
16405
|
-
});
|
|
16406
|
-
};
|
|
16407
|
-
const setLng = (lngs) => {
|
|
16408
|
-
if (!lng && !lngs && this.services.languageDetector) lngs = [];
|
|
16409
|
-
const l = isString(lngs) ? lngs : this.services.languageUtils.getBestMatchFromCodes(lngs);
|
|
16410
|
-
if (l) {
|
|
16411
|
-
if (!this.language) {
|
|
16412
|
-
setLngProps(l);
|
|
16413
|
-
}
|
|
16414
|
-
if (!this.translator.language) this.translator.changeLanguage(l);
|
|
16415
|
-
if (this.services.languageDetector && this.services.languageDetector.cacheUserLanguage) this.services.languageDetector.cacheUserLanguage(l);
|
|
16416
|
-
}
|
|
16417
|
-
this.loadResources(l, (err) => {
|
|
16418
|
-
done(err, l);
|
|
16419
|
-
});
|
|
16420
|
-
};
|
|
16421
|
-
if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
|
|
16422
|
-
setLng(this.services.languageDetector.detect());
|
|
16423
|
-
} else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
|
|
16424
|
-
if (this.services.languageDetector.detect.length === 0) {
|
|
16425
|
-
this.services.languageDetector.detect().then(setLng);
|
|
16426
|
-
} else {
|
|
16427
|
-
this.services.languageDetector.detect(setLng);
|
|
16428
|
-
}
|
|
16429
|
-
} else {
|
|
16430
|
-
setLng(lng);
|
|
16431
|
-
}
|
|
16432
|
-
return deferred;
|
|
16433
|
-
}
|
|
16434
|
-
getFixedT(lng, ns, keyPrefix) {
|
|
16435
|
-
var _this3 = this;
|
|
16436
|
-
const fixedT = function(key, opts) {
|
|
16437
|
-
let options;
|
|
16438
|
-
if (typeof opts !== "object") {
|
|
16439
|
-
for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
16440
|
-
rest[_key3 - 2] = arguments[_key3];
|
|
16441
|
-
}
|
|
16442
|
-
options = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
16443
|
-
} else {
|
|
16444
|
-
options = {
|
|
16445
|
-
...opts
|
|
16446
|
-
};
|
|
16447
|
-
}
|
|
16448
|
-
options.lng = options.lng || fixedT.lng;
|
|
16449
|
-
options.lngs = options.lngs || fixedT.lngs;
|
|
16450
|
-
options.ns = options.ns || fixedT.ns;
|
|
16451
|
-
if (options.keyPrefix !== "") options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
|
|
16452
|
-
const keySeparator = _this3.options.keySeparator || ".";
|
|
16453
|
-
let resultKey;
|
|
16454
|
-
if (options.keyPrefix && Array.isArray(key)) {
|
|
16455
|
-
resultKey = key.map((k) => `${options.keyPrefix}${keySeparator}${k}`);
|
|
16456
|
-
} else {
|
|
16457
|
-
resultKey = options.keyPrefix ? `${options.keyPrefix}${keySeparator}${key}` : key;
|
|
16458
|
-
}
|
|
16459
|
-
return _this3.t(resultKey, options);
|
|
16460
|
-
};
|
|
16461
|
-
if (isString(lng)) {
|
|
16462
|
-
fixedT.lng = lng;
|
|
16463
|
-
} else {
|
|
16464
|
-
fixedT.lngs = lng;
|
|
16465
|
-
}
|
|
16466
|
-
fixedT.ns = ns;
|
|
16467
|
-
fixedT.keyPrefix = keyPrefix;
|
|
16468
|
-
return fixedT;
|
|
16469
|
-
}
|
|
16470
|
-
t() {
|
|
16471
|
-
return this.translator && this.translator.translate(...arguments);
|
|
16472
|
-
}
|
|
16473
|
-
exists() {
|
|
16474
|
-
return this.translator && this.translator.exists(...arguments);
|
|
16475
|
-
}
|
|
16476
|
-
setDefaultNamespace(ns) {
|
|
16477
|
-
this.options.defaultNS = ns;
|
|
16478
|
-
}
|
|
16479
|
-
hasLoadedNamespace(ns) {
|
|
16480
|
-
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
16481
|
-
if (!this.isInitialized) {
|
|
16482
|
-
this.logger.warn("hasLoadedNamespace: i18next was not initialized", this.languages);
|
|
16483
|
-
return false;
|
|
16484
|
-
}
|
|
16485
|
-
if (!this.languages || !this.languages.length) {
|
|
16486
|
-
this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty", this.languages);
|
|
16487
|
-
return false;
|
|
16488
|
-
}
|
|
16489
|
-
const lng = options.lng || this.resolvedLanguage || this.languages[0];
|
|
16490
|
-
const fallbackLng = this.options ? this.options.fallbackLng : false;
|
|
16491
|
-
const lastLng = this.languages[this.languages.length - 1];
|
|
16492
|
-
if (lng.toLowerCase() === "cimode") return true;
|
|
16493
|
-
const loadNotPending = (l, n) => {
|
|
16494
|
-
const loadState = this.services.backendConnector.state[`${l}|${n}`];
|
|
16495
|
-
return loadState === -1 || loadState === 0 || loadState === 2;
|
|
16496
|
-
};
|
|
16497
|
-
if (options.precheck) {
|
|
16498
|
-
const preResult = options.precheck(this, loadNotPending);
|
|
16499
|
-
if (preResult !== void 0) return preResult;
|
|
16500
|
-
}
|
|
16501
|
-
if (this.hasResourceBundle(lng, ns)) return true;
|
|
16502
|
-
if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
|
|
16503
|
-
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
16504
|
-
return false;
|
|
16505
|
-
}
|
|
16506
|
-
loadNamespaces(ns, callback) {
|
|
16507
|
-
const deferred = defer();
|
|
16508
|
-
if (!this.options.ns) {
|
|
16509
|
-
if (callback) callback();
|
|
16510
|
-
return Promise.resolve();
|
|
16511
|
-
}
|
|
16512
|
-
if (isString(ns)) ns = [ns];
|
|
16513
|
-
ns.forEach((n) => {
|
|
16514
|
-
if (this.options.ns.indexOf(n) < 0) this.options.ns.push(n);
|
|
16515
|
-
});
|
|
16516
|
-
this.loadResources((err) => {
|
|
16517
|
-
deferred.resolve();
|
|
16518
|
-
if (callback) callback(err);
|
|
16519
|
-
});
|
|
16520
|
-
return deferred;
|
|
16521
|
-
}
|
|
16522
|
-
loadLanguages(lngs, callback) {
|
|
16523
|
-
const deferred = defer();
|
|
16524
|
-
if (isString(lngs)) lngs = [lngs];
|
|
16525
|
-
const preloaded = this.options.preload || [];
|
|
16526
|
-
const newLngs = lngs.filter((lng) => preloaded.indexOf(lng) < 0 && this.services.languageUtils.isSupportedCode(lng));
|
|
16527
|
-
if (!newLngs.length) {
|
|
16528
|
-
if (callback) callback();
|
|
16529
|
-
return Promise.resolve();
|
|
16530
|
-
}
|
|
16531
|
-
this.options.preload = preloaded.concat(newLngs);
|
|
16532
|
-
this.loadResources((err) => {
|
|
16533
|
-
deferred.resolve();
|
|
16534
|
-
if (callback) callback(err);
|
|
16535
|
-
});
|
|
16536
|
-
return deferred;
|
|
16537
|
-
}
|
|
16538
|
-
dir(lng) {
|
|
16539
|
-
if (!lng) lng = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language);
|
|
16540
|
-
if (!lng) return "rtl";
|
|
16541
|
-
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"];
|
|
16542
|
-
const languageUtils = this.services && this.services.languageUtils || new LanguageUtil(get());
|
|
16543
|
-
return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf("-arab") > 1 ? "rtl" : "ltr";
|
|
16544
|
-
}
|
|
16545
|
-
static createInstance() {
|
|
16546
|
-
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
16547
|
-
let callback = arguments.length > 1 ? arguments[1] : void 0;
|
|
16548
|
-
return new _I18n(options, callback);
|
|
16549
|
-
}
|
|
16550
|
-
cloneInstance() {
|
|
16551
|
-
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
16552
|
-
let callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
16553
|
-
const forkResourceStore = options.forkResourceStore;
|
|
16554
|
-
if (forkResourceStore) delete options.forkResourceStore;
|
|
16555
|
-
const mergedOptions = {
|
|
16556
|
-
...this.options,
|
|
16557
|
-
...options,
|
|
16558
|
-
...{
|
|
16559
|
-
isClone: true
|
|
16560
|
-
}
|
|
16561
|
-
};
|
|
16562
|
-
const clone = new _I18n(mergedOptions);
|
|
16563
|
-
if (options.debug !== void 0 || options.prefix !== void 0) {
|
|
16564
|
-
clone.logger = clone.logger.clone(options);
|
|
16565
|
-
}
|
|
16566
|
-
const membersToCopy = ["store", "services", "language"];
|
|
16567
|
-
membersToCopy.forEach((m) => {
|
|
16568
|
-
clone[m] = this[m];
|
|
16569
|
-
});
|
|
16570
|
-
clone.services = {
|
|
16571
|
-
...this.services
|
|
16572
|
-
};
|
|
16573
|
-
clone.services.utils = {
|
|
16574
|
-
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
16575
|
-
};
|
|
16576
|
-
if (forkResourceStore) {
|
|
16577
|
-
clone.store = new ResourceStore(this.store.data, mergedOptions);
|
|
16578
|
-
clone.services.resourceStore = clone.store;
|
|
16579
|
-
}
|
|
16580
|
-
clone.translator = new Translator(clone.services, mergedOptions);
|
|
16581
|
-
clone.translator.on("*", function(event) {
|
|
16582
|
-
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
16583
|
-
args[_key4 - 1] = arguments[_key4];
|
|
16584
|
-
}
|
|
16585
|
-
clone.emit(event, ...args);
|
|
16586
|
-
});
|
|
16587
|
-
clone.init(mergedOptions, callback);
|
|
16588
|
-
clone.translator.options = mergedOptions;
|
|
16589
|
-
clone.translator.backendConnector.services.utils = {
|
|
16590
|
-
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
16591
|
-
};
|
|
16592
|
-
return clone;
|
|
16593
|
-
}
|
|
16594
|
-
toJSON() {
|
|
16595
|
-
return {
|
|
16596
|
-
options: this.options,
|
|
16597
|
-
store: this.store,
|
|
16598
|
-
language: this.language,
|
|
16599
|
-
languages: this.languages,
|
|
16600
|
-
resolvedLanguage: this.resolvedLanguage
|
|
16601
|
-
};
|
|
16602
|
-
}
|
|
16603
|
-
};
|
|
16604
|
-
var instance = I18n.createInstance();
|
|
16605
|
-
instance.createInstance = I18n.createInstance;
|
|
16606
|
-
instance.createInstance;
|
|
16607
|
-
instance.dir;
|
|
16608
|
-
instance.init;
|
|
16609
|
-
instance.loadResources;
|
|
16610
|
-
instance.reloadResources;
|
|
16611
|
-
instance.use;
|
|
16612
|
-
instance.changeLanguage;
|
|
16613
|
-
instance.getFixedT;
|
|
16614
|
-
instance.t;
|
|
16615
|
-
instance.exists;
|
|
16616
|
-
instance.setDefaultNamespace;
|
|
16617
|
-
instance.hasLoadedNamespace;
|
|
16618
|
-
instance.loadNamespaces;
|
|
16619
|
-
instance.loadLanguages;
|
|
16620
|
-
|
|
16621
14250
|
// src/locales/en/translation.ts
|
|
16622
14251
|
var translationEN = {
|
|
16623
14252
|
common: {
|
|
@@ -18230,7 +15859,7 @@ var resources = {
|
|
|
18230
15859
|
translation: translationVI
|
|
18231
15860
|
}
|
|
18232
15861
|
};
|
|
18233
|
-
|
|
15862
|
+
i18n__default.default.use(LanguageDetector__default.default).use(reactI18next.initReactI18next).init({
|
|
18234
15863
|
resources,
|
|
18235
15864
|
fallbackLng: "en",
|
|
18236
15865
|
// Use English if the detected language is not available
|
|
@@ -20604,7 +18233,7 @@ async function generateQuizPlan(clientInput, apiKey, imageContexts = []) {
|
|
|
20604
18233
|
topicCount: clientInput.topics.length,
|
|
20605
18234
|
bloomLevelCount: clientInput.bloomLevels.length
|
|
20606
18235
|
});
|
|
20607
|
-
const totalTopicRatio = clientInput.topics.reduce((sum,
|
|
18236
|
+
const totalTopicRatio = clientInput.topics.reduce((sum, t) => sum + t.ratio, 0);
|
|
20608
18237
|
if (Math.abs(totalTopicRatio - 100) > 1) {
|
|
20609
18238
|
throw new Error(`Total topic ratio must be 100%. Current sum: ${totalTopicRatio.toFixed(1)}%`);
|
|
20610
18239
|
}
|
|
@@ -20629,11 +18258,11 @@ async function generateQuizPlan(clientInput, apiKey, imageContexts = []) {
|
|
|
20629
18258
|
logger.log("AI_INITIALIZATION", { model: modelName }, Date.now() - aiStartTime);
|
|
20630
18259
|
const { language, totalQuestions, numCodingQuestions = 0 } = clientInput;
|
|
20631
18260
|
const promptStartTime = Date.now();
|
|
20632
|
-
const topicsDistribution = clientInput.topics.map((
|
|
20633
|
-
let topicString = `- Topic Context: "${
|
|
20634
|
-
if (
|
|
18261
|
+
const topicsDistribution = clientInput.topics.map((t) => {
|
|
18262
|
+
let topicString = `- Topic Context: "${t.topic}", LoId: "${t.originalLoId || "nil"}", Subject: "${t.originalSubject || "nil"}", Category: "${t.originalCategory || "nil"}", Topic: "${t.originalTopic || "nil"}", Ratio: ${t.ratio}%`;
|
|
18263
|
+
if (t.commonMisconceptions && t.commonMisconceptions.length > 0) {
|
|
20635
18264
|
topicString += `
|
|
20636
|
-
- Common Misconceptions: [${
|
|
18265
|
+
- Common Misconceptions: [${t.commonMisconceptions.join(", ")}]`;
|
|
20637
18266
|
}
|
|
20638
18267
|
return topicString;
|
|
20639
18268
|
}).join("\n ");
|
|
@@ -20646,7 +18275,7 @@ async function generateQuizPlan(clientInput, apiKey, imageContexts = []) {
|
|
|
20646
18275
|
(type) => type !== "SHORT_ANSWER" && type !== "CODING"
|
|
20647
18276
|
);
|
|
20648
18277
|
}
|
|
20649
|
-
const allowedQuestionTypes = questionTypesForPrompt.map((
|
|
18278
|
+
const allowedQuestionTypes = questionTypesForPrompt.map((t) => `'${t}'`).join(", ");
|
|
20650
18279
|
const codingRequirement = numCodingQuestions > 0 ? `
|
|
20651
18280
|
**CRITICAL CODING REQUIREMENT**: Exactly ${numCodingQuestions} questions in the plan MUST be of type 'CODING'. These should typically be at 'APPLY' or higher Bloom levels and focus on implementation, debugging, or algorithm design.` : "";
|
|
20652
18281
|
const imageContextSection = imageContexts && imageContexts.length > 0 ? `
|
|
@@ -20729,7 +18358,7 @@ Execute this plan with pedagogical precision. The quiz should feel like a carefu
|
|
|
20729
18358
|
logger.log("PROMPT_PREPARATION", {
|
|
20730
18359
|
promptLength: enhancedPromptText.length,
|
|
20731
18360
|
topicCount: clientInput.topics.length,
|
|
20732
|
-
misconceptionCount: clientInput.topics.reduce((sum,
|
|
18361
|
+
misconceptionCount: clientInput.topics.reduce((sum, t) => sum + (t.commonMisconceptions?.length || 0), 0)
|
|
20733
18362
|
}, Date.now() - promptStartTime);
|
|
20734
18363
|
const generationStartTime = Date.now();
|
|
20735
18364
|
const contents = [
|
|
@@ -21776,6 +19405,12 @@ var ExecutionService = class _ExecutionService {
|
|
|
21776
19405
|
}
|
|
21777
19406
|
return _ExecutionService.instance;
|
|
21778
19407
|
}
|
|
19408
|
+
/**
|
|
19409
|
+
* Clear all registered providers.
|
|
19410
|
+
*/
|
|
19411
|
+
clearProviders() {
|
|
19412
|
+
this.providers.clear();
|
|
19413
|
+
}
|
|
21779
19414
|
/**
|
|
21780
19415
|
* Register a provider.
|
|
21781
19416
|
*/
|
|
@@ -21792,20 +19427,25 @@ var ExecutionService = class _ExecutionService {
|
|
|
21792
19427
|
* Get the best provider for a language based on priority and availability.
|
|
21793
19428
|
*/
|
|
21794
19429
|
async getBestProvider(language) {
|
|
21795
|
-
const
|
|
19430
|
+
const lang = language.toLowerCase();
|
|
19431
|
+
const sortedProviders = Array.from(this.providers.values()).filter((p) => p.getSupportedLanguages().map((l) => l.toLowerCase()).includes(lang)).sort((a, b) => b.getPriority(lang) - a.getPriority(lang));
|
|
19432
|
+
console.log(`[ExecutionService] Finding best provider for '${language}' (normalized: '${lang}'). Found ${sortedProviders.length} potential providers.`);
|
|
21796
19433
|
for (const provider of sortedProviders) {
|
|
21797
19434
|
if (await provider.isAvailable()) {
|
|
19435
|
+
console.log(`[ExecutionService] Selected provider: ${provider.name} (ID: ${provider.id})`);
|
|
21798
19436
|
return provider;
|
|
21799
19437
|
}
|
|
21800
19438
|
}
|
|
21801
19439
|
return null;
|
|
21802
19440
|
}
|
|
21803
19441
|
/**
|
|
21804
|
-
* Execute code using the best available provider.
|
|
19442
|
+
* Execute code using the best available provider with automatic fallback.
|
|
21805
19443
|
*/
|
|
21806
19444
|
async execute(code, language, stdin) {
|
|
21807
|
-
const
|
|
21808
|
-
|
|
19445
|
+
const lang = language.toLowerCase();
|
|
19446
|
+
const providers = Array.from(this.providers.values()).filter((p) => p.getSupportedLanguages().map((l) => l.toLowerCase()).includes(lang)).sort((a, b) => b.getPriority(lang) - a.getPriority(lang));
|
|
19447
|
+
console.log(`[ExecutionService] Executing for '${language}'. Providers in order:`, providers.map((p) => `${p.name} (${p.id})`));
|
|
19448
|
+
if (providers.length === 0) {
|
|
21809
19449
|
return {
|
|
21810
19450
|
stdout: "",
|
|
21811
19451
|
stderr: `No execution provider available for language: ${language}`,
|
|
@@ -21813,25 +19453,35 @@ var ExecutionService = class _ExecutionService {
|
|
|
21813
19453
|
message: "EXECUTION_ERROR_NO_PROVIDER"
|
|
21814
19454
|
};
|
|
21815
19455
|
}
|
|
21816
|
-
|
|
21817
|
-
|
|
21818
|
-
|
|
21819
|
-
|
|
21820
|
-
|
|
21821
|
-
|
|
21822
|
-
exitCode
|
|
21823
|
-
|
|
21824
|
-
|
|
19456
|
+
let lastError = null;
|
|
19457
|
+
for (const provider of providers) {
|
|
19458
|
+
try {
|
|
19459
|
+
if (!await provider.isAvailable()) continue;
|
|
19460
|
+
const result = await provider.execute(code, language, stdin);
|
|
19461
|
+
const isRecoverable = result.message === "RATE_LIMIT_EXCEEDED" || result.message === "AUTH_FAILED" || result.message === "UNSUPPORTED_LANGUAGE" || result.message === "EXECUTION_ERROR" || result.status?.id === 13 || // Internal Error
|
|
19462
|
+
result.exitCode === 1 && !result.stderr;
|
|
19463
|
+
if (isRecoverable && providers.indexOf(provider) < providers.length - 1) {
|
|
19464
|
+
lastError = result;
|
|
19465
|
+
continue;
|
|
19466
|
+
}
|
|
19467
|
+
return result;
|
|
19468
|
+
} catch (error) {
|
|
19469
|
+
lastError = error;
|
|
19470
|
+
}
|
|
21825
19471
|
}
|
|
19472
|
+
return {
|
|
19473
|
+
stdout: "",
|
|
19474
|
+
stderr: lastError?.stderr || lastError?.message || "All execution providers failed",
|
|
19475
|
+
exitCode: 1,
|
|
19476
|
+
message: "EXECUTION_ERROR_ALL_FAILED"
|
|
19477
|
+
};
|
|
21826
19478
|
}
|
|
21827
19479
|
};
|
|
21828
19480
|
var executionService = ExecutionService.getInstance();
|
|
21829
19481
|
|
|
21830
19482
|
// src/lib/execution/providers/Judge0Provider.ts
|
|
21831
19483
|
var Judge0Provider = class {
|
|
21832
|
-
constructor(apiUrl, apiKey) {
|
|
21833
|
-
this.id = "judge0";
|
|
21834
|
-
this.name = "Judge0 Professional";
|
|
19484
|
+
constructor(apiUrl, apiKey, options) {
|
|
21835
19485
|
this.languageMap = {
|
|
21836
19486
|
"python": 71,
|
|
21837
19487
|
"javascript": 63,
|
|
@@ -21844,6 +19494,9 @@ var Judge0Provider = class {
|
|
|
21844
19494
|
};
|
|
21845
19495
|
this.apiUrl = apiUrl;
|
|
21846
19496
|
this.apiKey = apiKey;
|
|
19497
|
+
this.id = options?.id || "judge0";
|
|
19498
|
+
this.name = options?.name || "Judge0 Professional";
|
|
19499
|
+
this.customPriority = options?.priority;
|
|
21847
19500
|
}
|
|
21848
19501
|
async isAvailable() {
|
|
21849
19502
|
return !!this.apiUrl;
|
|
@@ -21879,11 +19532,15 @@ var Judge0Provider = class {
|
|
|
21879
19532
|
};
|
|
21880
19533
|
}
|
|
21881
19534
|
try {
|
|
19535
|
+
console.log(`[Judge0Provider] Calling ${this.name} at ${this.apiUrl}...`);
|
|
21882
19536
|
const response = await fetch(`${this.apiUrl}/submissions?base64_encoded=true&wait=true`, {
|
|
21883
19537
|
method: "POST",
|
|
21884
19538
|
headers: {
|
|
21885
19539
|
"Content-Type": "application/json",
|
|
21886
|
-
...this.apiKey &&
|
|
19540
|
+
...this.apiKey && (this.apiUrl.includes("rapidapi.com") ? {
|
|
19541
|
+
"x-rapidapi-key": this.apiKey,
|
|
19542
|
+
"x-rapidapi-host": new URL(this.apiUrl).hostname
|
|
19543
|
+
} : { "X-Auth-Token": this.apiKey })
|
|
21887
19544
|
},
|
|
21888
19545
|
body: JSON.stringify({
|
|
21889
19546
|
source_code: this.toBase64(code),
|
|
@@ -21892,9 +19549,45 @@ var Judge0Provider = class {
|
|
|
21892
19549
|
})
|
|
21893
19550
|
});
|
|
21894
19551
|
if (!response.ok) {
|
|
21895
|
-
|
|
19552
|
+
const errorText = await response.text();
|
|
19553
|
+
console.error(`[Judge0Provider] ${this.name} HTTP Error ${response.status}:`, errorText);
|
|
19554
|
+
throw new Error(`PROVIDER_HTTP_ERROR: ${response.status} - ${errorText}`);
|
|
19555
|
+
}
|
|
19556
|
+
let result = await response.json();
|
|
19557
|
+
console.log(`[Judge0Provider] ${this.name} initial result:`, result);
|
|
19558
|
+
if (result.message) {
|
|
19559
|
+
if (result.message.includes("not subscribed")) {
|
|
19560
|
+
console.warn(`[Judge0Provider] ${this.name} auth failed, triggering fallback...`);
|
|
19561
|
+
throw new Error("AUTH_FAILED: Not subscribed");
|
|
19562
|
+
}
|
|
19563
|
+
if (result.message.includes("rate limit")) {
|
|
19564
|
+
console.warn(`[Judge0Provider] ${this.name} rate limited, triggering fallback...`);
|
|
19565
|
+
throw new Error("RATE_LIMIT_EXCEEDED");
|
|
19566
|
+
}
|
|
19567
|
+
}
|
|
19568
|
+
let attempts = 0;
|
|
19569
|
+
const maxAttempts = 10;
|
|
19570
|
+
while ((result.status?.id === 1 || result.status?.id === 2) && attempts < maxAttempts) {
|
|
19571
|
+
console.log(`[Judge0Provider] ${this.name} polling... (status: ${result.status?.description})`);
|
|
19572
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
19573
|
+
const pollResponse = await fetch(`${this.apiUrl}/submissions/${result.token}?base64_encoded=true`, {
|
|
19574
|
+
headers: {
|
|
19575
|
+
"Content-Type": "application/json",
|
|
19576
|
+
...this.apiKey && (this.apiUrl.includes("rapidapi.com") ? {
|
|
19577
|
+
"x-rapidapi-key": this.apiKey,
|
|
19578
|
+
"x-rapidapi-host": new URL(this.apiUrl).hostname
|
|
19579
|
+
} : { "X-Auth-Token": this.apiKey })
|
|
19580
|
+
}
|
|
19581
|
+
});
|
|
19582
|
+
if (pollResponse.ok) {
|
|
19583
|
+
result = await pollResponse.json();
|
|
19584
|
+
console.log(`[Judge0Provider] ${this.name} poll result (attempt ${attempts + 1}):`, result);
|
|
19585
|
+
} else {
|
|
19586
|
+
console.error(`[Judge0Provider] Poll failed: ${pollResponse.status}`);
|
|
19587
|
+
break;
|
|
19588
|
+
}
|
|
19589
|
+
attempts++;
|
|
21896
19590
|
}
|
|
21897
|
-
const result = await response.json();
|
|
21898
19591
|
return {
|
|
21899
19592
|
stdout: this.fromBase64(result.stdout),
|
|
21900
19593
|
stderr: this.fromBase64(result.stderr),
|
|
@@ -21904,18 +19597,16 @@ var Judge0Provider = class {
|
|
|
21904
19597
|
time: result.time ? parseFloat(result.time) * 1e3 : void 0,
|
|
21905
19598
|
memory: result.memory ? parseInt(result.memory) : void 0,
|
|
21906
19599
|
message: result.status?.description,
|
|
19600
|
+
status: result.status,
|
|
21907
19601
|
token: result.token
|
|
21908
19602
|
};
|
|
21909
19603
|
} catch (error) {
|
|
21910
|
-
|
|
21911
|
-
|
|
21912
|
-
stderr: error instanceof Error ? error.message : String(error),
|
|
21913
|
-
exitCode: 1,
|
|
21914
|
-
message: "EXECUTION_ERROR"
|
|
21915
|
-
};
|
|
19604
|
+
console.error(`[Judge0Provider] ${this.name} execution error:`, error);
|
|
19605
|
+
throw error;
|
|
21916
19606
|
}
|
|
21917
19607
|
}
|
|
21918
19608
|
getPriority(language) {
|
|
19609
|
+
if (this.customPriority !== void 0) return this.customPriority;
|
|
21919
19610
|
const compiled = ["cpp", "c", "java", "csharp"];
|
|
21920
19611
|
return compiled.includes(language.toLowerCase()) ? 10 : 5;
|
|
21921
19612
|
}
|
|
@@ -21924,6 +19615,103 @@ var Judge0Provider = class {
|
|
|
21924
19615
|
}
|
|
21925
19616
|
};
|
|
21926
19617
|
|
|
19618
|
+
// src/lib/execution/providers/PistonProvider.ts
|
|
19619
|
+
var PistonProvider = class {
|
|
19620
|
+
constructor(apiUrl, apiKey, options) {
|
|
19621
|
+
this.cachedRuntimes = null;
|
|
19622
|
+
this.apiUrl = apiUrl.endsWith("/") ? apiUrl.slice(0, -1) : apiUrl;
|
|
19623
|
+
this.apiKey = apiKey;
|
|
19624
|
+
this.id = options?.id || "piston";
|
|
19625
|
+
this.name = options?.name || "Piston Engine";
|
|
19626
|
+
this.customPriority = options?.priority;
|
|
19627
|
+
}
|
|
19628
|
+
async isAvailable() {
|
|
19629
|
+
try {
|
|
19630
|
+
const response = await fetch(`${this.apiUrl}/runtimes`);
|
|
19631
|
+
if (response.ok) {
|
|
19632
|
+
this.cachedRuntimes = await response.json();
|
|
19633
|
+
return true;
|
|
19634
|
+
}
|
|
19635
|
+
return false;
|
|
19636
|
+
} catch (e) {
|
|
19637
|
+
return false;
|
|
19638
|
+
}
|
|
19639
|
+
}
|
|
19640
|
+
async execute(code, language, stdin) {
|
|
19641
|
+
try {
|
|
19642
|
+
if (!this.cachedRuntimes) {
|
|
19643
|
+
const response2 = await fetch(`${this.apiUrl}/runtimes`);
|
|
19644
|
+
if (response2.ok) {
|
|
19645
|
+
this.cachedRuntimes = await response2.json();
|
|
19646
|
+
} else {
|
|
19647
|
+
throw new Error("Could not fetch Piston runtimes");
|
|
19648
|
+
}
|
|
19649
|
+
}
|
|
19650
|
+
const lowerLang = language.toLowerCase();
|
|
19651
|
+
let targetLang = lowerLang;
|
|
19652
|
+
if (lowerLang === "js") targetLang = "javascript";
|
|
19653
|
+
if (lowerLang === "c" || lowerLang === "cpp") targetLang = "gcc";
|
|
19654
|
+
const runtime = this.cachedRuntimes.find(
|
|
19655
|
+
(r2) => r2.language === targetLang || r2.aliases && r2.aliases.includes(targetLang)
|
|
19656
|
+
);
|
|
19657
|
+
if (!runtime) {
|
|
19658
|
+
return {
|
|
19659
|
+
stdout: "",
|
|
19660
|
+
stderr: `Language '${language}' (mapped to '${targetLang}') is not supported by this Piston instance.`,
|
|
19661
|
+
exitCode: 1,
|
|
19662
|
+
message: "UNSUPPORTED_LANGUAGE"
|
|
19663
|
+
};
|
|
19664
|
+
}
|
|
19665
|
+
console.log(`[PistonProvider] Calling ${this.name} (${runtime.language} ${runtime.version}) at ${this.apiUrl}...`);
|
|
19666
|
+
const headers = {
|
|
19667
|
+
"Content-Type": "application/json"
|
|
19668
|
+
};
|
|
19669
|
+
if (this.apiKey) {
|
|
19670
|
+
headers["X-API-Key"] = this.apiKey;
|
|
19671
|
+
}
|
|
19672
|
+
const response = await fetch(`${this.apiUrl}/execute`, {
|
|
19673
|
+
method: "POST",
|
|
19674
|
+
headers,
|
|
19675
|
+
body: JSON.stringify({
|
|
19676
|
+
language: runtime.language,
|
|
19677
|
+
version: runtime.version,
|
|
19678
|
+
files: [{ content: code }],
|
|
19679
|
+
stdin: stdin || ""
|
|
19680
|
+
})
|
|
19681
|
+
});
|
|
19682
|
+
if (!response.ok) {
|
|
19683
|
+
const errorText = await response.text();
|
|
19684
|
+
console.error(`[PistonProvider] HTTP Error ${response.status}:`, errorText);
|
|
19685
|
+
throw new Error(`PISTON_HTTP_ERROR: ${response.status} - ${errorText}`);
|
|
19686
|
+
}
|
|
19687
|
+
const result = await response.json();
|
|
19688
|
+
console.log(`[PistonProvider] result:`, result);
|
|
19689
|
+
if (result.message) {
|
|
19690
|
+
throw new Error(`PISTON_ERROR: ${result.message}`);
|
|
19691
|
+
}
|
|
19692
|
+
const run = result.run || {};
|
|
19693
|
+
const compile = result.compile || {};
|
|
19694
|
+
return {
|
|
19695
|
+
stdout: run.stdout || "",
|
|
19696
|
+
stderr: (compile.stderr || "") + (run.stderr || ""),
|
|
19697
|
+
compileOutput: compile.stdout || "",
|
|
19698
|
+
exitCode: run.code === 0 ? 0 : 1,
|
|
19699
|
+
message: run.signal ? `Terminated by signal: ${run.signal}` : void 0
|
|
19700
|
+
};
|
|
19701
|
+
} catch (error) {
|
|
19702
|
+
console.error(`[PistonProvider] execution error:`, error);
|
|
19703
|
+
throw error;
|
|
19704
|
+
}
|
|
19705
|
+
}
|
|
19706
|
+
getPriority(language) {
|
|
19707
|
+
if (this.customPriority !== void 0) return this.customPriority;
|
|
19708
|
+
return 20;
|
|
19709
|
+
}
|
|
19710
|
+
getSupportedLanguages() {
|
|
19711
|
+
return ["python", "javascript", "js", "lua", "c", "cpp", "csharp"];
|
|
19712
|
+
}
|
|
19713
|
+
};
|
|
19714
|
+
|
|
21927
19715
|
// src/lib/execution/providers/LiteProvider.ts
|
|
21928
19716
|
var LiteProvider = class {
|
|
21929
19717
|
constructor() {
|
|
@@ -22135,9 +19923,40 @@ var AIProvider = class {
|
|
|
22135
19923
|
|
|
22136
19924
|
// src/lib/execution/index.ts
|
|
22137
19925
|
function initExecutionSystem(config) {
|
|
19926
|
+
executionService.clearProviders();
|
|
22138
19927
|
executionService.registerProvider(new LiteProvider());
|
|
22139
|
-
if (config?.
|
|
22140
|
-
executionService.registerProvider(new Judge0Provider(
|
|
19928
|
+
if (config?.judge0Fallback?.url) {
|
|
19929
|
+
executionService.registerProvider(new Judge0Provider(
|
|
19930
|
+
config.judge0Fallback.url,
|
|
19931
|
+
config.judge0Fallback.key,
|
|
19932
|
+
{
|
|
19933
|
+
id: "judge0-fallback",
|
|
19934
|
+
name: config.judge0Fallback.name || "Judge0 Fallback (RapidAPI)",
|
|
19935
|
+
priority: config.judge0Fallback.priority || 8
|
|
19936
|
+
}
|
|
19937
|
+
));
|
|
19938
|
+
}
|
|
19939
|
+
if (config?.pistonPrimary?.url) {
|
|
19940
|
+
executionService.registerProvider(new PistonProvider(
|
|
19941
|
+
config.pistonPrimary.url,
|
|
19942
|
+
config.pistonPrimary.key,
|
|
19943
|
+
{
|
|
19944
|
+
id: "piston-primary",
|
|
19945
|
+
name: config.pistonPrimary.name || "Piston Primary (Self-hosted)",
|
|
19946
|
+
priority: config.pistonPrimary.priority || 20
|
|
19947
|
+
}
|
|
19948
|
+
));
|
|
19949
|
+
}
|
|
19950
|
+
if (config?.judge0Primary?.url) {
|
|
19951
|
+
executionService.registerProvider(new Judge0Provider(
|
|
19952
|
+
config.judge0Primary.url,
|
|
19953
|
+
config.judge0Primary.key,
|
|
19954
|
+
{
|
|
19955
|
+
id: "judge0-primary",
|
|
19956
|
+
name: config.judge0Primary.name || "Judge0 Primary (Self-hosted)",
|
|
19957
|
+
priority: config.judge0Primary.priority || 15
|
|
19958
|
+
}
|
|
19959
|
+
));
|
|
22141
19960
|
}
|
|
22142
19961
|
if (config?.geminiKey) {
|
|
22143
19962
|
executionService.registerProvider(new AIProvider(config.geminiKey));
|
|
@@ -22146,8 +19965,11 @@ function initExecutionSystem(config) {
|
|
|
22146
19965
|
|
|
22147
19966
|
// src/services/APIKeyService.ts
|
|
22148
19967
|
var GEMINI_API_KEY_SERVICE_NAME = "gemini";
|
|
22149
|
-
var
|
|
22150
|
-
var
|
|
19968
|
+
var JUDGE0_PRIMARY_API_KEY_SERVICE_NAME = "judge0_primary";
|
|
19969
|
+
var JUDGE0_PRIMARY_API_URL_SERVICE_NAME = "judge0_primary_url";
|
|
19970
|
+
var JUDGE0_FALLBACK_API_KEY_SERVICE_NAME = "judge0_fallback";
|
|
19971
|
+
var JUDGE0_FALLBACK_API_URL_SERVICE_NAME = "judge0_fallback_url";
|
|
19972
|
+
var PISTON_PRIMARY_API_URL_SERVICE_NAME = "piston_primary_url";
|
|
22151
19973
|
var LOCAL_STORAGE_PREFIX = "iqk_api_keys_";
|
|
22152
19974
|
function _encode(data) {
|
|
22153
19975
|
if (typeof window !== "undefined" && typeof window.btoa === "function") {
|
|
@@ -22233,6 +20055,95 @@ var APIKeyService = class {
|
|
|
22233
20055
|
}
|
|
22234
20056
|
};
|
|
22235
20057
|
|
|
20058
|
+
// src/lib/execution/CodeWrapper.ts
|
|
20059
|
+
var CodeWrapper = class {
|
|
20060
|
+
/**
|
|
20061
|
+
* Wraps code with necessary boilerplate for the given language.
|
|
20062
|
+
*/
|
|
20063
|
+
static wrap(code, language, options = {}) {
|
|
20064
|
+
const lang = language.toLowerCase();
|
|
20065
|
+
if (lang === "c" || lang === "cpp") {
|
|
20066
|
+
return this.wrapC(code, options.testCaseInput || [], options.functionSignature);
|
|
20067
|
+
}
|
|
20068
|
+
return code;
|
|
20069
|
+
}
|
|
20070
|
+
static wrapC(code, input, signature) {
|
|
20071
|
+
if (code.includes("int main") || code.includes("void main")) {
|
|
20072
|
+
return code;
|
|
20073
|
+
}
|
|
20074
|
+
if (!signature) {
|
|
20075
|
+
return `
|
|
20076
|
+
#include <stdio.h>
|
|
20077
|
+
#include <stdlib.h>
|
|
20078
|
+
#include <stdbool.h>
|
|
20079
|
+
#include <string.h>
|
|
20080
|
+
|
|
20081
|
+
${code}
|
|
20082
|
+
|
|
20083
|
+
int main() {
|
|
20084
|
+
// No signature provided, assuming competitive programming style if stdin is used
|
|
20085
|
+
return 0;
|
|
20086
|
+
}
|
|
20087
|
+
`;
|
|
20088
|
+
}
|
|
20089
|
+
const sig = signature?.trim();
|
|
20090
|
+
const match = sig?.match(/(\w+)\s+(\w+)\s*\((.*)\)/);
|
|
20091
|
+
if (!match) {
|
|
20092
|
+
if (input.length === 2) {
|
|
20093
|
+
return `
|
|
20094
|
+
#include <stdio.h>
|
|
20095
|
+
#include <stdlib.h>
|
|
20096
|
+
#include <stdbool.h>
|
|
20097
|
+
#include <string.h>
|
|
20098
|
+
|
|
20099
|
+
${code}
|
|
20100
|
+
|
|
20101
|
+
int main() {
|
|
20102
|
+
int v0, v1;
|
|
20103
|
+
if (scanf("%d %d", &v0, &v1) == 2) {
|
|
20104
|
+
// Try to call 'add' if it exists in the code
|
|
20105
|
+
${code.includes("add") ? 'printf("%d", add(v0, v1));' : "// Function not found"}
|
|
20106
|
+
}
|
|
20107
|
+
return 0;
|
|
20108
|
+
}
|
|
20109
|
+
`;
|
|
20110
|
+
}
|
|
20111
|
+
return code;
|
|
20112
|
+
}
|
|
20113
|
+
const [, , funcName, paramsStr] = match;
|
|
20114
|
+
const params = paramsStr.split(",").map((p) => p.trim()).filter((p) => p.length > 0);
|
|
20115
|
+
let scanfFormat = "";
|
|
20116
|
+
let scanfArgs = "";
|
|
20117
|
+
let callArgs = "";
|
|
20118
|
+
params.forEach((p, i) => {
|
|
20119
|
+
const parts = p.split(/\s+/);
|
|
20120
|
+
const type = parts[0];
|
|
20121
|
+
parts[parts.length - 1];
|
|
20122
|
+
let fmt = "%d";
|
|
20123
|
+
if (type === "float" || type === "double") fmt = "%lf";
|
|
20124
|
+
if (type === "char*") fmt = "%s";
|
|
20125
|
+
scanfFormat += (i === 0 ? "" : " ") + fmt;
|
|
20126
|
+
scanfArgs += `, &v${i}`;
|
|
20127
|
+
callArgs += (i === 0 ? "" : ", ") + `v${i}`;
|
|
20128
|
+
});
|
|
20129
|
+
return `
|
|
20130
|
+
#include <stdio.h>
|
|
20131
|
+
#include <stdlib.h>
|
|
20132
|
+
#include <stdbool.h>
|
|
20133
|
+
#include <string.h>
|
|
20134
|
+
|
|
20135
|
+
${code}
|
|
20136
|
+
|
|
20137
|
+
int main() {
|
|
20138
|
+
${params.map((p, i) => `${p.split(/\s+/)[0]} v${i};`).join("\n ")}
|
|
20139
|
+
if (scanf("${scanfFormat}"${scanfArgs}) != ${params.length}) return 1;
|
|
20140
|
+
printf("%d", ${funcName}(${callArgs}));
|
|
20141
|
+
return 0;
|
|
20142
|
+
}
|
|
20143
|
+
`;
|
|
20144
|
+
}
|
|
20145
|
+
};
|
|
20146
|
+
|
|
22236
20147
|
// src/services/CodeEvaluationService.ts
|
|
22237
20148
|
var CodeEvaluationService = class {
|
|
22238
20149
|
constructor() {
|
|
@@ -22240,27 +20151,46 @@ var CodeEvaluationService = class {
|
|
|
22240
20151
|
}
|
|
22241
20152
|
/**
|
|
22242
20153
|
* Ensure execution system is initialized with latest keys.
|
|
20154
|
+
* Order of precedence: LocalStorage (User choice) > Environment Variables (System default)
|
|
22243
20155
|
*/
|
|
22244
20156
|
ensureInitialized() {
|
|
22245
20157
|
if (typeof window === "undefined") return;
|
|
22246
|
-
const geminiKey = APIKeyService.getAPIKey(GEMINI_API_KEY_SERVICE_NAME) ||
|
|
22247
|
-
const
|
|
22248
|
-
const
|
|
20158
|
+
const geminiKey = APIKeyService.getAPIKey(GEMINI_API_KEY_SERVICE_NAME) || "";
|
|
20159
|
+
const judge0PrimaryUrl = APIKeyService.getAPIKey(JUDGE0_PRIMARY_API_URL_SERVICE_NAME) || "/api/judge0";
|
|
20160
|
+
const judge0PrimaryKey = APIKeyService.getAPIKey(JUDGE0_PRIMARY_API_KEY_SERVICE_NAME) || "Code@Orchable";
|
|
20161
|
+
const judge0FallbackUrl = APIKeyService.getAPIKey(JUDGE0_FALLBACK_API_URL_SERVICE_NAME) || "https://judge0-ce.p.rapidapi.com";
|
|
20162
|
+
const judge0FallbackKey = APIKeyService.getAPIKey(JUDGE0_FALLBACK_API_KEY_SERVICE_NAME) || "9343426db9mshd122142ba1d0927p1259d6jsne24390a88e67";
|
|
20163
|
+
const pistonPrimaryUrl = APIKeyService.getAPIKey(PISTON_PRIMARY_API_URL_SERVICE_NAME) || "/api/piston";
|
|
20164
|
+
const pistonPrimaryKey = "Piston@Orchable";
|
|
22249
20165
|
initExecutionSystem({
|
|
22250
|
-
geminiKey,
|
|
22251
|
-
|
|
22252
|
-
|
|
20166
|
+
geminiKey: geminiKey || void 0,
|
|
20167
|
+
pistonPrimary: {
|
|
20168
|
+
url: pistonPrimaryUrl,
|
|
20169
|
+
key: pistonPrimaryKey
|
|
20170
|
+
} ,
|
|
20171
|
+
judge0Primary: {
|
|
20172
|
+
url: judge0PrimaryUrl,
|
|
20173
|
+
key: judge0PrimaryKey
|
|
20174
|
+
} ,
|
|
20175
|
+
judge0Fallback: {
|
|
20176
|
+
url: judge0FallbackUrl,
|
|
20177
|
+
key: judge0FallbackKey
|
|
20178
|
+
}
|
|
22253
20179
|
});
|
|
22254
20180
|
}
|
|
22255
20181
|
async evaluateSingleTestCase(question, userCode, testCase) {
|
|
22256
20182
|
try {
|
|
20183
|
+
const wrappedCode = CodeWrapper.wrap(userCode, question.codingLanguage, {
|
|
20184
|
+
functionSignature: question.functionSignature,
|
|
20185
|
+
testCaseInput: testCase.input
|
|
20186
|
+
});
|
|
22257
20187
|
const result = await executionService.execute(
|
|
22258
|
-
|
|
20188
|
+
wrappedCode,
|
|
22259
20189
|
question.codingLanguage,
|
|
22260
20190
|
Array.isArray(testCase.input) ? testCase.input.join("\n") : String(testCase.input || "")
|
|
22261
20191
|
);
|
|
22262
|
-
const actual = (result.stdout || "").trim();
|
|
22263
|
-
const expected = (testCase.expectedOutput || "").trim();
|
|
20192
|
+
const actual = String(result.stdout || "").trim();
|
|
20193
|
+
const expected = String(testCase.expectedOutput || "").trim();
|
|
22264
20194
|
const statusPassed = result.exitCode === 0;
|
|
22265
20195
|
const outputMatches = actual === expected;
|
|
22266
20196
|
const passed = statusPassed && outputMatches;
|
|
@@ -22423,9 +20353,9 @@ var QuizEngine = class {
|
|
|
22423
20353
|
let s = seed >>> 0;
|
|
22424
20354
|
const next = () => {
|
|
22425
20355
|
s += 1831565813;
|
|
22426
|
-
let
|
|
22427
|
-
|
|
22428
|
-
return ((
|
|
20356
|
+
let t = Math.imul(s ^ s >>> 15, 1 | s);
|
|
20357
|
+
t ^= t + Math.imul(t ^ t >>> 7, 61 | t);
|
|
20358
|
+
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
22429
20359
|
};
|
|
22430
20360
|
for (let i = arr.length - 1; i > 0; i--) {
|
|
22431
20361
|
const j = Math.floor(next() * (i + 1));
|
|
@@ -24267,16 +22197,16 @@ var emptyQuiz = {
|
|
|
24267
22197
|
|
|
24268
22198
|
// ../../node_modules/.pnpm/clsx@2.1.1/node_modules/clsx/dist/clsx.mjs
|
|
24269
22199
|
function r(e) {
|
|
24270
|
-
var
|
|
22200
|
+
var t, f, n = "";
|
|
24271
22201
|
if ("string" == typeof e || "number" == typeof e) n += e;
|
|
24272
22202
|
else if ("object" == typeof e) if (Array.isArray(e)) {
|
|
24273
22203
|
var o = e.length;
|
|
24274
|
-
for (
|
|
22204
|
+
for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
|
|
24275
22205
|
} else for (f in e) e[f] && (n && (n += " "), n += f);
|
|
24276
22206
|
return n;
|
|
24277
22207
|
}
|
|
24278
22208
|
function clsx() {
|
|
24279
|
-
for (var e,
|
|
22209
|
+
for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
|
|
24280
22210
|
return n;
|
|
24281
22211
|
}
|
|
24282
22212
|
|