@forsakringskassan/docs-generator 2.24.0 → 2.25.1
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/compile-example.js +2 -2
- package/dist/{create-markdown-renderer-wbIE-KQj.js → create-markdown-renderer-Ch-EjWgQ.js} +5 -4
- package/dist/create-markdown-renderer-Ch-EjWgQ.js.map +1 -0
- package/dist/index.js +60 -4
- package/dist/index.js.map +1 -1
- package/dist/markdown.js +3 -3
- package/dist/style/core.css +35 -0
- package/dist/style/index.css +37 -0
- package/dist/style/site.css +2 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/{vendor-DQQ31U4v.js → vendor-CIZoJHXd.js} +2265 -28
- package/dist/vendor-CIZoJHXd.js.map +1 -0
- package/dist/{vue3-BQVQQ2Vn.js → vue3-CkmHk7uJ.js} +2 -2
- package/dist/{vue3-BQVQQ2Vn.js.map → vue3-CkmHk7uJ.js.map} +1 -1
- package/package.json +1 -1
- package/templates/base.template.html +1 -1
- package/templates/component.template.html +16 -13
- package/templates/partials/search-dialog.html +3 -3
- package/templates/partials/search-toolbar.html +1 -1
- package/dist/create-markdown-renderer-wbIE-KQj.js.map +0 -1
- package/dist/vendor-DQQ31U4v.js.map +0 -1
|
@@ -1157,7 +1157,7 @@ function decodeHTML(str, mode = DecodingMode.Legacy) {
|
|
|
1157
1157
|
|
|
1158
1158
|
function _class$1 (obj) { return Object.prototype.toString.call(obj) }
|
|
1159
1159
|
|
|
1160
|
-
function isString$
|
|
1160
|
+
function isString$2 (obj) { return _class$1(obj) === '[object String]' }
|
|
1161
1161
|
|
|
1162
1162
|
const _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
1163
1163
|
|
|
@@ -1445,7 +1445,7 @@ var utils$3 = /*#__PURE__*/Object.freeze({
|
|
|
1445
1445
|
isMdAsciiPunct: isMdAsciiPunct,
|
|
1446
1446
|
isPunctChar: isPunctChar,
|
|
1447
1447
|
isSpace: isSpace,
|
|
1448
|
-
isString: isString$
|
|
1448
|
+
isString: isString$2,
|
|
1449
1449
|
isValidEntityCode: isValidEntityCode,
|
|
1450
1450
|
isWhiteSpace: isWhiteSpace,
|
|
1451
1451
|
lib: lib$3,
|
|
@@ -5221,7 +5221,7 @@ for (let i = 0; i < 256; i++) { ESCAPED.push(0); }
|
|
|
5221
5221
|
'\\!"#$%&\'()*+,./:;<=>?@[]^_`{|}~-'
|
|
5222
5222
|
.split('').forEach(function (ch) { ESCAPED[ch.charCodeAt(0)] = 1; });
|
|
5223
5223
|
|
|
5224
|
-
function escape$
|
|
5224
|
+
function escape$3 (state, silent) {
|
|
5225
5225
|
let pos = state.pos;
|
|
5226
5226
|
const max = state.posMax;
|
|
5227
5227
|
|
|
@@ -6220,7 +6220,7 @@ const _rules = [
|
|
|
6220
6220
|
['text', text],
|
|
6221
6221
|
['linkify', linkify],
|
|
6222
6222
|
['newline', newline],
|
|
6223
|
-
['escape', escape$
|
|
6223
|
+
['escape', escape$3],
|
|
6224
6224
|
['backticks', backtick],
|
|
6225
6225
|
['strikethrough', r_strikethrough.tokenize],
|
|
6226
6226
|
['emphasis', r_emphasis.tokenize],
|
|
@@ -6594,7 +6594,7 @@ function assign (obj /* from1, from2, from3, ... */) {
|
|
|
6594
6594
|
}
|
|
6595
6595
|
|
|
6596
6596
|
function _class (obj) { return Object.prototype.toString.call(obj) }
|
|
6597
|
-
function isString (obj) { return _class(obj) === '[object String]' }
|
|
6597
|
+
function isString$1 (obj) { return _class(obj) === '[object String]' }
|
|
6598
6598
|
function isObject (obj) { return _class(obj) === '[object Object]' }
|
|
6599
6599
|
function isRegExp (obj) { return _class(obj) === '[object RegExp]' }
|
|
6600
6600
|
function isFunction (obj) { return _class(obj) === '[object Function]' }
|
|
@@ -6777,7 +6777,7 @@ function compile (self) {
|
|
|
6777
6777
|
return
|
|
6778
6778
|
}
|
|
6779
6779
|
|
|
6780
|
-
if (isString(val)) {
|
|
6780
|
+
if (isString$1(val)) {
|
|
6781
6781
|
aliases.push(name);
|
|
6782
6782
|
return
|
|
6783
6783
|
}
|
|
@@ -8069,7 +8069,7 @@ function MarkdownIt (presetName, options) {
|
|
|
8069
8069
|
}
|
|
8070
8070
|
|
|
8071
8071
|
if (!options) {
|
|
8072
|
-
if (!isString$
|
|
8072
|
+
if (!isString$2(presetName)) {
|
|
8073
8073
|
options = presetName || {};
|
|
8074
8074
|
presetName = 'default';
|
|
8075
8075
|
}
|
|
@@ -8227,7 +8227,7 @@ MarkdownIt.prototype.set = function (options) {
|
|
|
8227
8227
|
MarkdownIt.prototype.configure = function (presets) {
|
|
8228
8228
|
const self = this;
|
|
8229
8229
|
|
|
8230
|
-
if (isString$
|
|
8230
|
+
if (isString$2(presets)) {
|
|
8231
8231
|
const presetName = presets;
|
|
8232
8232
|
presets = config$1[presetName];
|
|
8233
8233
|
if (!presets) { throw new Error('Wrong `markdown-it` preset "' + presetName + '", check name') }
|
|
@@ -9474,7 +9474,7 @@ class AST {
|
|
|
9474
9474
|
* that exact character. In this mode, `\` is _not_ escaped, because it is
|
|
9475
9475
|
* not interpreted as a magic character, but instead as a path separator.
|
|
9476
9476
|
*/
|
|
9477
|
-
const escape$
|
|
9477
|
+
const escape$2 = (s, { windowsPathsNoEscape = false, } = {}) => {
|
|
9478
9478
|
// don't need to escape +@! because we escape the parens
|
|
9479
9479
|
// that make those magic, and escaping ! as [!] isn't valid,
|
|
9480
9480
|
// because [!]] is a valid glob class meaning not ']'.
|
|
@@ -10472,7 +10472,7 @@ class Minimatch {
|
|
|
10472
10472
|
/* c8 ignore stop */
|
|
10473
10473
|
minimatch.AST = AST;
|
|
10474
10474
|
minimatch.Minimatch = Minimatch;
|
|
10475
|
-
minimatch.escape = escape$
|
|
10475
|
+
minimatch.escape = escape$2;
|
|
10476
10476
|
minimatch.unescape = unescape$1;
|
|
10477
10477
|
|
|
10478
10478
|
/**
|
|
@@ -12100,7 +12100,7 @@ const ABORTED = Symbol('aborted');
|
|
|
12100
12100
|
const SIGNAL = Symbol('signal');
|
|
12101
12101
|
const DATALISTENERS = Symbol('dataListeners');
|
|
12102
12102
|
const DISCARDED = Symbol('discarded');
|
|
12103
|
-
const defer = (fn) => Promise.resolve().then(fn);
|
|
12103
|
+
const defer$1 = (fn) => Promise.resolve().then(fn);
|
|
12104
12104
|
const nodefer = (fn) => fn();
|
|
12105
12105
|
const isEndish = (ev) => ev === 'end' || ev === 'finish' || ev === 'prefinish';
|
|
12106
12106
|
const isArrayBufferLike = (b) => b instanceof ArrayBuffer ||
|
|
@@ -12336,7 +12336,7 @@ class Minipass extends node_events.EventEmitter {
|
|
|
12336
12336
|
}
|
|
12337
12337
|
if (!encoding)
|
|
12338
12338
|
encoding = 'utf8';
|
|
12339
|
-
const fn = this[ASYNC] ? defer : nodefer;
|
|
12339
|
+
const fn = this[ASYNC] ? defer$1 : nodefer;
|
|
12340
12340
|
// convert array buffers and typed array views into buffers
|
|
12341
12341
|
// at some point in the future, we may want to do the opposite!
|
|
12342
12342
|
// leave strings and buffers as-is
|
|
@@ -12598,7 +12598,7 @@ class Minipass extends node_events.EventEmitter {
|
|
|
12598
12598
|
? new Pipe(this, dest, opts)
|
|
12599
12599
|
: new PipeProxyErrors(this, dest, opts));
|
|
12600
12600
|
if (this[ASYNC])
|
|
12601
|
-
defer(() => this[RESUME]());
|
|
12601
|
+
defer$1(() => this[RESUME]());
|
|
12602
12602
|
else
|
|
12603
12603
|
this[RESUME]();
|
|
12604
12604
|
}
|
|
@@ -12668,7 +12668,7 @@ class Minipass extends node_events.EventEmitter {
|
|
|
12668
12668
|
else if (ev === 'error' && this[EMITTED_ERROR]) {
|
|
12669
12669
|
const h = handler;
|
|
12670
12670
|
if (this[ASYNC])
|
|
12671
|
-
defer(() => h.call(this, this[EMITTED_ERROR]));
|
|
12671
|
+
defer$1(() => h.call(this, this[EMITTED_ERROR]));
|
|
12672
12672
|
else
|
|
12673
12673
|
h.call(this, this[EMITTED_ERROR]);
|
|
12674
12674
|
}
|
|
@@ -12779,7 +12779,7 @@ class Minipass extends node_events.EventEmitter {
|
|
|
12779
12779
|
return !this[OBJECTMODE] && !data
|
|
12780
12780
|
? false
|
|
12781
12781
|
: this[ASYNC]
|
|
12782
|
-
? (defer(() => this[EMITDATA](data)), true)
|
|
12782
|
+
? (defer$1(() => this[EMITDATA](data)), true)
|
|
12783
12783
|
: this[EMITDATA](data);
|
|
12784
12784
|
}
|
|
12785
12785
|
else if (ev === 'end') {
|
|
@@ -12833,7 +12833,7 @@ class Minipass extends node_events.EventEmitter {
|
|
|
12833
12833
|
this[EMITTED_END] = true;
|
|
12834
12834
|
this.readable = false;
|
|
12835
12835
|
return this[ASYNC]
|
|
12836
|
-
? (defer(() => this[EMITEND2]()), true)
|
|
12836
|
+
? (defer$1(() => this[EMITEND2]()), true)
|
|
12837
12837
|
: this[EMITEND2]();
|
|
12838
12838
|
}
|
|
12839
12839
|
[EMITEND2]() {
|
|
@@ -16322,7 +16322,7 @@ const glob = Object.assign(glob_, {
|
|
|
16322
16322
|
iterateSync,
|
|
16323
16323
|
Glob,
|
|
16324
16324
|
hasMagic,
|
|
16325
|
-
escape: escape$
|
|
16325
|
+
escape: escape$2,
|
|
16326
16326
|
unescape: unescape$1,
|
|
16327
16327
|
});
|
|
16328
16328
|
glob.glob = glob;
|
|
@@ -23106,19 +23106,19 @@ function requireCopySync () {
|
|
|
23106
23106
|
return copySync_1;
|
|
23107
23107
|
}
|
|
23108
23108
|
|
|
23109
|
-
var copy;
|
|
23109
|
+
var copy$1;
|
|
23110
23110
|
var hasRequiredCopy;
|
|
23111
23111
|
|
|
23112
23112
|
function requireCopy () {
|
|
23113
|
-
if (hasRequiredCopy) return copy;
|
|
23113
|
+
if (hasRequiredCopy) return copy$1;
|
|
23114
23114
|
hasRequiredCopy = 1;
|
|
23115
23115
|
|
|
23116
23116
|
const u = requireUniversalify().fromPromise;
|
|
23117
|
-
copy = {
|
|
23117
|
+
copy$1 = {
|
|
23118
23118
|
copy: u(requireCopy$1()),
|
|
23119
23119
|
copySync: requireCopySync()
|
|
23120
23120
|
};
|
|
23121
|
-
return copy;
|
|
23121
|
+
return copy$1;
|
|
23122
23122
|
}
|
|
23123
23123
|
|
|
23124
23124
|
var remove_1;
|
|
@@ -24010,6 +24010,2242 @@ function requireLib$2 () {
|
|
|
24010
24010
|
var libExports$1 = /*@__PURE__*/ requireLib$2();
|
|
24011
24011
|
var fse = /*@__PURE__*/getDefaultExportFromCjs(libExports$1);
|
|
24012
24012
|
|
|
24013
|
+
const isString = obj => typeof obj === 'string';
|
|
24014
|
+
const defer = () => {
|
|
24015
|
+
let res;
|
|
24016
|
+
let rej;
|
|
24017
|
+
const promise = new Promise((resolve, reject) => {
|
|
24018
|
+
res = resolve;
|
|
24019
|
+
rej = reject;
|
|
24020
|
+
});
|
|
24021
|
+
promise.resolve = res;
|
|
24022
|
+
promise.reject = rej;
|
|
24023
|
+
return promise;
|
|
24024
|
+
};
|
|
24025
|
+
const makeString = object => {
|
|
24026
|
+
if (object == null) return '';
|
|
24027
|
+
return '' + object;
|
|
24028
|
+
};
|
|
24029
|
+
const copy = (a, s, t) => {
|
|
24030
|
+
a.forEach(m => {
|
|
24031
|
+
if (s[m]) t[m] = s[m];
|
|
24032
|
+
});
|
|
24033
|
+
};
|
|
24034
|
+
const lastOfPathSeparatorRegExp = /###/g;
|
|
24035
|
+
const cleanKey = key => key && key.indexOf('###') > -1 ? key.replace(lastOfPathSeparatorRegExp, '.') : key;
|
|
24036
|
+
const canNotTraverseDeeper = object => !object || isString(object);
|
|
24037
|
+
const getLastOfPath = (object, path, Empty) => {
|
|
24038
|
+
const stack = !isString(path) ? path : path.split('.');
|
|
24039
|
+
let stackIndex = 0;
|
|
24040
|
+
while (stackIndex < stack.length - 1) {
|
|
24041
|
+
if (canNotTraverseDeeper(object)) return {};
|
|
24042
|
+
const key = cleanKey(stack[stackIndex]);
|
|
24043
|
+
if (!object[key] && Empty) object[key] = new Empty();
|
|
24044
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
24045
|
+
object = object[key];
|
|
24046
|
+
} else {
|
|
24047
|
+
object = {};
|
|
24048
|
+
}
|
|
24049
|
+
++stackIndex;
|
|
24050
|
+
}
|
|
24051
|
+
if (canNotTraverseDeeper(object)) return {};
|
|
24052
|
+
return {
|
|
24053
|
+
obj: object,
|
|
24054
|
+
k: cleanKey(stack[stackIndex])
|
|
24055
|
+
};
|
|
24056
|
+
};
|
|
24057
|
+
const setPath = (object, path, newValue) => {
|
|
24058
|
+
const {
|
|
24059
|
+
obj,
|
|
24060
|
+
k
|
|
24061
|
+
} = getLastOfPath(object, path, Object);
|
|
24062
|
+
if (obj !== undefined || path.length === 1) {
|
|
24063
|
+
obj[k] = newValue;
|
|
24064
|
+
return;
|
|
24065
|
+
}
|
|
24066
|
+
let e = path[path.length - 1];
|
|
24067
|
+
let p = path.slice(0, path.length - 1);
|
|
24068
|
+
let last = getLastOfPath(object, p, Object);
|
|
24069
|
+
while (last.obj === undefined && p.length) {
|
|
24070
|
+
e = `${p[p.length - 1]}.${e}`;
|
|
24071
|
+
p = p.slice(0, p.length - 1);
|
|
24072
|
+
last = getLastOfPath(object, p, Object);
|
|
24073
|
+
if (last?.obj && typeof last.obj[`${last.k}.${e}`] !== 'undefined') {
|
|
24074
|
+
last.obj = undefined;
|
|
24075
|
+
}
|
|
24076
|
+
}
|
|
24077
|
+
last.obj[`${last.k}.${e}`] = newValue;
|
|
24078
|
+
};
|
|
24079
|
+
const pushPath = (object, path, newValue, concat) => {
|
|
24080
|
+
const {
|
|
24081
|
+
obj,
|
|
24082
|
+
k
|
|
24083
|
+
} = getLastOfPath(object, path, Object);
|
|
24084
|
+
obj[k] = obj[k] || [];
|
|
24085
|
+
obj[k].push(newValue);
|
|
24086
|
+
};
|
|
24087
|
+
const getPath = (object, path) => {
|
|
24088
|
+
const {
|
|
24089
|
+
obj,
|
|
24090
|
+
k
|
|
24091
|
+
} = getLastOfPath(object, path);
|
|
24092
|
+
if (!obj) return undefined;
|
|
24093
|
+
if (!Object.prototype.hasOwnProperty.call(obj, k)) return undefined;
|
|
24094
|
+
return obj[k];
|
|
24095
|
+
};
|
|
24096
|
+
const getPathWithDefaults = (data, defaultData, key) => {
|
|
24097
|
+
const value = getPath(data, key);
|
|
24098
|
+
if (value !== undefined) {
|
|
24099
|
+
return value;
|
|
24100
|
+
}
|
|
24101
|
+
return getPath(defaultData, key);
|
|
24102
|
+
};
|
|
24103
|
+
const deepExtend = (target, source, overwrite) => {
|
|
24104
|
+
for (const prop in source) {
|
|
24105
|
+
if (prop !== '__proto__' && prop !== 'constructor') {
|
|
24106
|
+
if (prop in target) {
|
|
24107
|
+
if (isString(target[prop]) || target[prop] instanceof String || isString(source[prop]) || source[prop] instanceof String) {
|
|
24108
|
+
if (overwrite) target[prop] = source[prop];
|
|
24109
|
+
} else {
|
|
24110
|
+
deepExtend(target[prop], source[prop], overwrite);
|
|
24111
|
+
}
|
|
24112
|
+
} else {
|
|
24113
|
+
target[prop] = source[prop];
|
|
24114
|
+
}
|
|
24115
|
+
}
|
|
24116
|
+
}
|
|
24117
|
+
return target;
|
|
24118
|
+
};
|
|
24119
|
+
const regexEscape = str => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
|
|
24120
|
+
var _entityMap = {
|
|
24121
|
+
'&': '&',
|
|
24122
|
+
'<': '<',
|
|
24123
|
+
'>': '>',
|
|
24124
|
+
'"': '"',
|
|
24125
|
+
"'": ''',
|
|
24126
|
+
'/': '/'
|
|
24127
|
+
};
|
|
24128
|
+
const escape$1 = data => {
|
|
24129
|
+
if (isString(data)) {
|
|
24130
|
+
return data.replace(/[&<>"'\/]/g, s => _entityMap[s]);
|
|
24131
|
+
}
|
|
24132
|
+
return data;
|
|
24133
|
+
};
|
|
24134
|
+
class RegExpCache {
|
|
24135
|
+
constructor(capacity) {
|
|
24136
|
+
this.capacity = capacity;
|
|
24137
|
+
this.regExpMap = new Map();
|
|
24138
|
+
this.regExpQueue = [];
|
|
24139
|
+
}
|
|
24140
|
+
getRegExp(pattern) {
|
|
24141
|
+
const regExpFromCache = this.regExpMap.get(pattern);
|
|
24142
|
+
if (regExpFromCache !== undefined) {
|
|
24143
|
+
return regExpFromCache;
|
|
24144
|
+
}
|
|
24145
|
+
const regExpNew = new RegExp(pattern);
|
|
24146
|
+
if (this.regExpQueue.length === this.capacity) {
|
|
24147
|
+
this.regExpMap.delete(this.regExpQueue.shift());
|
|
24148
|
+
}
|
|
24149
|
+
this.regExpMap.set(pattern, regExpNew);
|
|
24150
|
+
this.regExpQueue.push(pattern);
|
|
24151
|
+
return regExpNew;
|
|
24152
|
+
}
|
|
24153
|
+
}
|
|
24154
|
+
const chars = [' ', ',', '?', '!', ';'];
|
|
24155
|
+
const looksLikeObjectPathRegExpCache = new RegExpCache(20);
|
|
24156
|
+
const looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
|
|
24157
|
+
nsSeparator = nsSeparator || '';
|
|
24158
|
+
keySeparator = keySeparator || '';
|
|
24159
|
+
const possibleChars = chars.filter(c => nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0);
|
|
24160
|
+
if (possibleChars.length === 0) return true;
|
|
24161
|
+
const r = looksLikeObjectPathRegExpCache.getRegExp(`(${possibleChars.map(c => c === '?' ? '\\?' : c).join('|')})`);
|
|
24162
|
+
let matched = !r.test(key);
|
|
24163
|
+
if (!matched) {
|
|
24164
|
+
const ki = key.indexOf(keySeparator);
|
|
24165
|
+
if (ki > 0 && !r.test(key.substring(0, ki))) {
|
|
24166
|
+
matched = true;
|
|
24167
|
+
}
|
|
24168
|
+
}
|
|
24169
|
+
return matched;
|
|
24170
|
+
};
|
|
24171
|
+
const deepFind = function (obj, path) {
|
|
24172
|
+
let keySeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
|
|
24173
|
+
if (!obj) return undefined;
|
|
24174
|
+
if (obj[path]) {
|
|
24175
|
+
if (!Object.prototype.hasOwnProperty.call(obj, path)) return undefined;
|
|
24176
|
+
return obj[path];
|
|
24177
|
+
}
|
|
24178
|
+
const tokens = path.split(keySeparator);
|
|
24179
|
+
let current = obj;
|
|
24180
|
+
for (let i = 0; i < tokens.length;) {
|
|
24181
|
+
if (!current || typeof current !== 'object') {
|
|
24182
|
+
return undefined;
|
|
24183
|
+
}
|
|
24184
|
+
let next;
|
|
24185
|
+
let nextPath = '';
|
|
24186
|
+
for (let j = i; j < tokens.length; ++j) {
|
|
24187
|
+
if (j !== i) {
|
|
24188
|
+
nextPath += keySeparator;
|
|
24189
|
+
}
|
|
24190
|
+
nextPath += tokens[j];
|
|
24191
|
+
next = current[nextPath];
|
|
24192
|
+
if (next !== undefined) {
|
|
24193
|
+
if (['string', 'number', 'boolean'].indexOf(typeof next) > -1 && j < tokens.length - 1) {
|
|
24194
|
+
continue;
|
|
24195
|
+
}
|
|
24196
|
+
i += j - i + 1;
|
|
24197
|
+
break;
|
|
24198
|
+
}
|
|
24199
|
+
}
|
|
24200
|
+
current = next;
|
|
24201
|
+
}
|
|
24202
|
+
return current;
|
|
24203
|
+
};
|
|
24204
|
+
const getCleanedCode = code => code?.replace('_', '-');
|
|
24205
|
+
|
|
24206
|
+
const consoleLogger = {
|
|
24207
|
+
type: 'logger',
|
|
24208
|
+
log(args) {
|
|
24209
|
+
this.output('log', args);
|
|
24210
|
+
},
|
|
24211
|
+
warn(args) {
|
|
24212
|
+
this.output('warn', args);
|
|
24213
|
+
},
|
|
24214
|
+
error(args) {
|
|
24215
|
+
this.output('error', args);
|
|
24216
|
+
},
|
|
24217
|
+
output(type, args) {
|
|
24218
|
+
console?.[type]?.apply?.(console, args);
|
|
24219
|
+
}
|
|
24220
|
+
};
|
|
24221
|
+
class Logger {
|
|
24222
|
+
constructor(concreteLogger) {
|
|
24223
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
24224
|
+
this.init(concreteLogger, options);
|
|
24225
|
+
}
|
|
24226
|
+
init(concreteLogger) {
|
|
24227
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
24228
|
+
this.prefix = options.prefix || 'i18next:';
|
|
24229
|
+
this.logger = concreteLogger || consoleLogger;
|
|
24230
|
+
this.options = options;
|
|
24231
|
+
this.debug = options.debug;
|
|
24232
|
+
}
|
|
24233
|
+
log() {
|
|
24234
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
24235
|
+
args[_key] = arguments[_key];
|
|
24236
|
+
}
|
|
24237
|
+
return this.forward(args, 'log', '', true);
|
|
24238
|
+
}
|
|
24239
|
+
warn() {
|
|
24240
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
24241
|
+
args[_key2] = arguments[_key2];
|
|
24242
|
+
}
|
|
24243
|
+
return this.forward(args, 'warn', '', true);
|
|
24244
|
+
}
|
|
24245
|
+
error() {
|
|
24246
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
24247
|
+
args[_key3] = arguments[_key3];
|
|
24248
|
+
}
|
|
24249
|
+
return this.forward(args, 'error', '');
|
|
24250
|
+
}
|
|
24251
|
+
deprecate() {
|
|
24252
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
24253
|
+
args[_key4] = arguments[_key4];
|
|
24254
|
+
}
|
|
24255
|
+
return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
|
|
24256
|
+
}
|
|
24257
|
+
forward(args, lvl, prefix, debugOnly) {
|
|
24258
|
+
if (debugOnly && !this.debug) return null;
|
|
24259
|
+
if (isString(args[0])) args[0] = `${prefix}${this.prefix} ${args[0]}`;
|
|
24260
|
+
return this.logger[lvl](args);
|
|
24261
|
+
}
|
|
24262
|
+
create(moduleName) {
|
|
24263
|
+
return new Logger(this.logger, {
|
|
24264
|
+
...{
|
|
24265
|
+
prefix: `${this.prefix}:${moduleName}:`
|
|
24266
|
+
},
|
|
24267
|
+
...this.options
|
|
24268
|
+
});
|
|
24269
|
+
}
|
|
24270
|
+
clone(options) {
|
|
24271
|
+
options = options || this.options;
|
|
24272
|
+
options.prefix = options.prefix || this.prefix;
|
|
24273
|
+
return new Logger(this.logger, options);
|
|
24274
|
+
}
|
|
24275
|
+
}
|
|
24276
|
+
var baseLogger = new Logger();
|
|
24277
|
+
|
|
24278
|
+
class EventEmitter {
|
|
24279
|
+
constructor() {
|
|
24280
|
+
this.observers = {};
|
|
24281
|
+
}
|
|
24282
|
+
on(events, listener) {
|
|
24283
|
+
events.split(' ').forEach(event => {
|
|
24284
|
+
if (!this.observers[event]) this.observers[event] = new Map();
|
|
24285
|
+
const numListeners = this.observers[event].get(listener) || 0;
|
|
24286
|
+
this.observers[event].set(listener, numListeners + 1);
|
|
24287
|
+
});
|
|
24288
|
+
return this;
|
|
24289
|
+
}
|
|
24290
|
+
off(event, listener) {
|
|
24291
|
+
if (!this.observers[event]) return;
|
|
24292
|
+
if (!listener) {
|
|
24293
|
+
delete this.observers[event];
|
|
24294
|
+
return;
|
|
24295
|
+
}
|
|
24296
|
+
this.observers[event].delete(listener);
|
|
24297
|
+
}
|
|
24298
|
+
emit(event) {
|
|
24299
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
24300
|
+
args[_key - 1] = arguments[_key];
|
|
24301
|
+
}
|
|
24302
|
+
if (this.observers[event]) {
|
|
24303
|
+
const cloned = Array.from(this.observers[event].entries());
|
|
24304
|
+
cloned.forEach(_ref => {
|
|
24305
|
+
let [observer, numTimesAdded] = _ref;
|
|
24306
|
+
for (let i = 0; i < numTimesAdded; i++) {
|
|
24307
|
+
observer(...args);
|
|
24308
|
+
}
|
|
24309
|
+
});
|
|
24310
|
+
}
|
|
24311
|
+
if (this.observers['*']) {
|
|
24312
|
+
const cloned = Array.from(this.observers['*'].entries());
|
|
24313
|
+
cloned.forEach(_ref2 => {
|
|
24314
|
+
let [observer, numTimesAdded] = _ref2;
|
|
24315
|
+
for (let i = 0; i < numTimesAdded; i++) {
|
|
24316
|
+
observer.apply(observer, [event, ...args]);
|
|
24317
|
+
}
|
|
24318
|
+
});
|
|
24319
|
+
}
|
|
24320
|
+
}
|
|
24321
|
+
}
|
|
24322
|
+
|
|
24323
|
+
class ResourceStore extends EventEmitter {
|
|
24324
|
+
constructor(data) {
|
|
24325
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
24326
|
+
ns: ['translation'],
|
|
24327
|
+
defaultNS: 'translation'
|
|
24328
|
+
};
|
|
24329
|
+
super();
|
|
24330
|
+
this.data = data || {};
|
|
24331
|
+
this.options = options;
|
|
24332
|
+
if (this.options.keySeparator === undefined) {
|
|
24333
|
+
this.options.keySeparator = '.';
|
|
24334
|
+
}
|
|
24335
|
+
if (this.options.ignoreJSONStructure === undefined) {
|
|
24336
|
+
this.options.ignoreJSONStructure = true;
|
|
24337
|
+
}
|
|
24338
|
+
}
|
|
24339
|
+
addNamespaces(ns) {
|
|
24340
|
+
if (this.options.ns.indexOf(ns) < 0) {
|
|
24341
|
+
this.options.ns.push(ns);
|
|
24342
|
+
}
|
|
24343
|
+
}
|
|
24344
|
+
removeNamespaces(ns) {
|
|
24345
|
+
const index = this.options.ns.indexOf(ns);
|
|
24346
|
+
if (index > -1) {
|
|
24347
|
+
this.options.ns.splice(index, 1);
|
|
24348
|
+
}
|
|
24349
|
+
}
|
|
24350
|
+
getResource(lng, ns, key) {
|
|
24351
|
+
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
24352
|
+
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
24353
|
+
const ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
24354
|
+
let path;
|
|
24355
|
+
if (lng.indexOf('.') > -1) {
|
|
24356
|
+
path = lng.split('.');
|
|
24357
|
+
} else {
|
|
24358
|
+
path = [lng, ns];
|
|
24359
|
+
if (key) {
|
|
24360
|
+
if (Array.isArray(key)) {
|
|
24361
|
+
path.push(...key);
|
|
24362
|
+
} else if (isString(key) && keySeparator) {
|
|
24363
|
+
path.push(...key.split(keySeparator));
|
|
24364
|
+
} else {
|
|
24365
|
+
path.push(key);
|
|
24366
|
+
}
|
|
24367
|
+
}
|
|
24368
|
+
}
|
|
24369
|
+
const result = getPath(this.data, path);
|
|
24370
|
+
if (!result && !ns && !key && lng.indexOf('.') > -1) {
|
|
24371
|
+
lng = path[0];
|
|
24372
|
+
ns = path[1];
|
|
24373
|
+
key = path.slice(2).join('.');
|
|
24374
|
+
}
|
|
24375
|
+
if (result || !ignoreJSONStructure || !isString(key)) return result;
|
|
24376
|
+
return deepFind(this.data?.[lng]?.[ns], key, keySeparator);
|
|
24377
|
+
}
|
|
24378
|
+
addResource(lng, ns, key, value) {
|
|
24379
|
+
let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
|
24380
|
+
silent: false
|
|
24381
|
+
};
|
|
24382
|
+
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
24383
|
+
let path = [lng, ns];
|
|
24384
|
+
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
24385
|
+
if (lng.indexOf('.') > -1) {
|
|
24386
|
+
path = lng.split('.');
|
|
24387
|
+
value = ns;
|
|
24388
|
+
ns = path[1];
|
|
24389
|
+
}
|
|
24390
|
+
this.addNamespaces(ns);
|
|
24391
|
+
setPath(this.data, path, value);
|
|
24392
|
+
if (!options.silent) this.emit('added', lng, ns, key, value);
|
|
24393
|
+
}
|
|
24394
|
+
addResources(lng, ns, resources) {
|
|
24395
|
+
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
24396
|
+
silent: false
|
|
24397
|
+
};
|
|
24398
|
+
for (const m in resources) {
|
|
24399
|
+
if (isString(resources[m]) || Array.isArray(resources[m])) this.addResource(lng, ns, m, resources[m], {
|
|
24400
|
+
silent: true
|
|
24401
|
+
});
|
|
24402
|
+
}
|
|
24403
|
+
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
24404
|
+
}
|
|
24405
|
+
addResourceBundle(lng, ns, resources, deep, overwrite) {
|
|
24406
|
+
let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {
|
|
24407
|
+
silent: false,
|
|
24408
|
+
skipCopy: false
|
|
24409
|
+
};
|
|
24410
|
+
let path = [lng, ns];
|
|
24411
|
+
if (lng.indexOf('.') > -1) {
|
|
24412
|
+
path = lng.split('.');
|
|
24413
|
+
deep = resources;
|
|
24414
|
+
resources = ns;
|
|
24415
|
+
ns = path[1];
|
|
24416
|
+
}
|
|
24417
|
+
this.addNamespaces(ns);
|
|
24418
|
+
let pack = getPath(this.data, path) || {};
|
|
24419
|
+
if (!options.skipCopy) resources = JSON.parse(JSON.stringify(resources));
|
|
24420
|
+
if (deep) {
|
|
24421
|
+
deepExtend(pack, resources, overwrite);
|
|
24422
|
+
} else {
|
|
24423
|
+
pack = {
|
|
24424
|
+
...pack,
|
|
24425
|
+
...resources
|
|
24426
|
+
};
|
|
24427
|
+
}
|
|
24428
|
+
setPath(this.data, path, pack);
|
|
24429
|
+
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
24430
|
+
}
|
|
24431
|
+
removeResourceBundle(lng, ns) {
|
|
24432
|
+
if (this.hasResourceBundle(lng, ns)) {
|
|
24433
|
+
delete this.data[lng][ns];
|
|
24434
|
+
}
|
|
24435
|
+
this.removeNamespaces(ns);
|
|
24436
|
+
this.emit('removed', lng, ns);
|
|
24437
|
+
}
|
|
24438
|
+
hasResourceBundle(lng, ns) {
|
|
24439
|
+
return this.getResource(lng, ns) !== undefined;
|
|
24440
|
+
}
|
|
24441
|
+
getResourceBundle(lng, ns) {
|
|
24442
|
+
if (!ns) ns = this.options.defaultNS;
|
|
24443
|
+
return this.getResource(lng, ns);
|
|
24444
|
+
}
|
|
24445
|
+
getDataByLanguage(lng) {
|
|
24446
|
+
return this.data[lng];
|
|
24447
|
+
}
|
|
24448
|
+
hasLanguageSomeTranslations(lng) {
|
|
24449
|
+
const data = this.getDataByLanguage(lng);
|
|
24450
|
+
const n = data && Object.keys(data) || [];
|
|
24451
|
+
return !!n.find(v => data[v] && Object.keys(data[v]).length > 0);
|
|
24452
|
+
}
|
|
24453
|
+
toJSON() {
|
|
24454
|
+
return this.data;
|
|
24455
|
+
}
|
|
24456
|
+
}
|
|
24457
|
+
|
|
24458
|
+
var postProcessor = {
|
|
24459
|
+
processors: {},
|
|
24460
|
+
addPostProcessor(module) {
|
|
24461
|
+
this.processors[module.name] = module;
|
|
24462
|
+
},
|
|
24463
|
+
handle(processors, value, key, options, translator) {
|
|
24464
|
+
processors.forEach(processor => {
|
|
24465
|
+
value = this.processors[processor]?.process(value, key, options, translator) ?? value;
|
|
24466
|
+
});
|
|
24467
|
+
return value;
|
|
24468
|
+
}
|
|
24469
|
+
};
|
|
24470
|
+
|
|
24471
|
+
const checkedLoadedFor = {};
|
|
24472
|
+
const shouldHandleAsObject = res => !isString(res) && typeof res !== 'boolean' && typeof res !== 'number';
|
|
24473
|
+
class Translator extends EventEmitter {
|
|
24474
|
+
constructor(services) {
|
|
24475
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
24476
|
+
super();
|
|
24477
|
+
copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector', 'i18nFormat', 'utils'], services, this);
|
|
24478
|
+
this.options = options;
|
|
24479
|
+
if (this.options.keySeparator === undefined) {
|
|
24480
|
+
this.options.keySeparator = '.';
|
|
24481
|
+
}
|
|
24482
|
+
this.logger = baseLogger.create('translator');
|
|
24483
|
+
}
|
|
24484
|
+
changeLanguage(lng) {
|
|
24485
|
+
if (lng) this.language = lng;
|
|
24486
|
+
}
|
|
24487
|
+
exists(key) {
|
|
24488
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
24489
|
+
interpolation: {}
|
|
24490
|
+
};
|
|
24491
|
+
if (key == null) {
|
|
24492
|
+
return false;
|
|
24493
|
+
}
|
|
24494
|
+
const resolved = this.resolve(key, options);
|
|
24495
|
+
return resolved?.res !== undefined;
|
|
24496
|
+
}
|
|
24497
|
+
extractFromKey(key, opt) {
|
|
24498
|
+
let nsSeparator = opt.nsSeparator !== undefined ? opt.nsSeparator : this.options.nsSeparator;
|
|
24499
|
+
if (nsSeparator === undefined) nsSeparator = ':';
|
|
24500
|
+
const keySeparator = opt.keySeparator !== undefined ? opt.keySeparator : this.options.keySeparator;
|
|
24501
|
+
let namespaces = opt.ns || this.options.defaultNS || [];
|
|
24502
|
+
const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
|
|
24503
|
+
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !opt.keySeparator && !this.options.userDefinedNsSeparator && !opt.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
24504
|
+
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
24505
|
+
const m = key.match(this.interpolator.nestingRegexp);
|
|
24506
|
+
if (m && m.length > 0) {
|
|
24507
|
+
return {
|
|
24508
|
+
key,
|
|
24509
|
+
namespaces: isString(namespaces) ? [namespaces] : namespaces
|
|
24510
|
+
};
|
|
24511
|
+
}
|
|
24512
|
+
const parts = key.split(nsSeparator);
|
|
24513
|
+
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
|
|
24514
|
+
key = parts.join(keySeparator);
|
|
24515
|
+
}
|
|
24516
|
+
return {
|
|
24517
|
+
key,
|
|
24518
|
+
namespaces: isString(namespaces) ? [namespaces] : namespaces
|
|
24519
|
+
};
|
|
24520
|
+
}
|
|
24521
|
+
translate(keys, opt, lastKey) {
|
|
24522
|
+
if (typeof opt !== 'object' && this.options.overloadTranslationOptionHandler) {
|
|
24523
|
+
opt = this.options.overloadTranslationOptionHandler(arguments);
|
|
24524
|
+
}
|
|
24525
|
+
if (typeof options === 'object') opt = {
|
|
24526
|
+
...opt
|
|
24527
|
+
};
|
|
24528
|
+
if (!opt) opt = {};
|
|
24529
|
+
if (keys == null) return '';
|
|
24530
|
+
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
24531
|
+
const returnDetails = opt.returnDetails !== undefined ? opt.returnDetails : this.options.returnDetails;
|
|
24532
|
+
const keySeparator = opt.keySeparator !== undefined ? opt.keySeparator : this.options.keySeparator;
|
|
24533
|
+
const {
|
|
24534
|
+
key,
|
|
24535
|
+
namespaces
|
|
24536
|
+
} = this.extractFromKey(keys[keys.length - 1], opt);
|
|
24537
|
+
const namespace = namespaces[namespaces.length - 1];
|
|
24538
|
+
const lng = opt.lng || this.language;
|
|
24539
|
+
const appendNamespaceToCIMode = opt.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
24540
|
+
if (lng?.toLowerCase() === 'cimode') {
|
|
24541
|
+
if (appendNamespaceToCIMode) {
|
|
24542
|
+
const nsSeparator = opt.nsSeparator || this.options.nsSeparator;
|
|
24543
|
+
if (returnDetails) {
|
|
24544
|
+
return {
|
|
24545
|
+
res: `${namespace}${nsSeparator}${key}`,
|
|
24546
|
+
usedKey: key,
|
|
24547
|
+
exactUsedKey: key,
|
|
24548
|
+
usedLng: lng,
|
|
24549
|
+
usedNS: namespace,
|
|
24550
|
+
usedParams: this.getUsedParamsDetails(opt)
|
|
24551
|
+
};
|
|
24552
|
+
}
|
|
24553
|
+
return `${namespace}${nsSeparator}${key}`;
|
|
24554
|
+
}
|
|
24555
|
+
if (returnDetails) {
|
|
24556
|
+
return {
|
|
24557
|
+
res: key,
|
|
24558
|
+
usedKey: key,
|
|
24559
|
+
exactUsedKey: key,
|
|
24560
|
+
usedLng: lng,
|
|
24561
|
+
usedNS: namespace,
|
|
24562
|
+
usedParams: this.getUsedParamsDetails(opt)
|
|
24563
|
+
};
|
|
24564
|
+
}
|
|
24565
|
+
return key;
|
|
24566
|
+
}
|
|
24567
|
+
const resolved = this.resolve(keys, opt);
|
|
24568
|
+
let res = resolved?.res;
|
|
24569
|
+
const resUsedKey = resolved?.usedKey || key;
|
|
24570
|
+
const resExactUsedKey = resolved?.exactUsedKey || key;
|
|
24571
|
+
const noObject = ['[object Number]', '[object Function]', '[object RegExp]'];
|
|
24572
|
+
const joinArrays = opt.joinArrays !== undefined ? opt.joinArrays : this.options.joinArrays;
|
|
24573
|
+
const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
24574
|
+
const needsPluralHandling = opt.count !== undefined && !isString(opt.count);
|
|
24575
|
+
const hasDefaultValue = Translator.hasDefaultValue(opt);
|
|
24576
|
+
const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, opt) : '';
|
|
24577
|
+
const defaultValueSuffixOrdinalFallback = opt.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, {
|
|
24578
|
+
ordinal: false
|
|
24579
|
+
}) : '';
|
|
24580
|
+
const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
|
|
24581
|
+
const defaultValue = needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] || opt[`defaultValue${defaultValueSuffix}`] || opt[`defaultValue${defaultValueSuffixOrdinalFallback}`] || opt.defaultValue;
|
|
24582
|
+
let resForObjHndl = res;
|
|
24583
|
+
if (handleAsObjectInI18nFormat && !res && hasDefaultValue) {
|
|
24584
|
+
resForObjHndl = defaultValue;
|
|
24585
|
+
}
|
|
24586
|
+
const handleAsObject = shouldHandleAsObject(resForObjHndl);
|
|
24587
|
+
const resType = Object.prototype.toString.apply(resForObjHndl);
|
|
24588
|
+
if (handleAsObjectInI18nFormat && resForObjHndl && handleAsObject && noObject.indexOf(resType) < 0 && !(isString(joinArrays) && Array.isArray(resForObjHndl))) {
|
|
24589
|
+
if (!opt.returnObjects && !this.options.returnObjects) {
|
|
24590
|
+
if (!this.options.returnedObjectHandler) {
|
|
24591
|
+
this.logger.warn('accessing an object - but returnObjects options is not enabled!');
|
|
24592
|
+
}
|
|
24593
|
+
const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, resForObjHndl, {
|
|
24594
|
+
...opt,
|
|
24595
|
+
ns: namespaces
|
|
24596
|
+
}) : `key '${key} (${this.language})' returned an object instead of string.`;
|
|
24597
|
+
if (returnDetails) {
|
|
24598
|
+
resolved.res = r;
|
|
24599
|
+
resolved.usedParams = this.getUsedParamsDetails(opt);
|
|
24600
|
+
return resolved;
|
|
24601
|
+
}
|
|
24602
|
+
return r;
|
|
24603
|
+
}
|
|
24604
|
+
if (keySeparator) {
|
|
24605
|
+
const resTypeIsArray = Array.isArray(resForObjHndl);
|
|
24606
|
+
const copy = resTypeIsArray ? [] : {};
|
|
24607
|
+
const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
24608
|
+
for (const m in resForObjHndl) {
|
|
24609
|
+
if (Object.prototype.hasOwnProperty.call(resForObjHndl, m)) {
|
|
24610
|
+
const deepKey = `${newKeyToUse}${keySeparator}${m}`;
|
|
24611
|
+
if (hasDefaultValue && !res) {
|
|
24612
|
+
copy[m] = this.translate(deepKey, {
|
|
24613
|
+
...opt,
|
|
24614
|
+
defaultValue: shouldHandleAsObject(defaultValue) ? defaultValue[m] : undefined,
|
|
24615
|
+
...{
|
|
24616
|
+
joinArrays: false,
|
|
24617
|
+
ns: namespaces
|
|
24618
|
+
}
|
|
24619
|
+
});
|
|
24620
|
+
} else {
|
|
24621
|
+
copy[m] = this.translate(deepKey, {
|
|
24622
|
+
...opt,
|
|
24623
|
+
...{
|
|
24624
|
+
joinArrays: false,
|
|
24625
|
+
ns: namespaces
|
|
24626
|
+
}
|
|
24627
|
+
});
|
|
24628
|
+
}
|
|
24629
|
+
if (copy[m] === deepKey) copy[m] = resForObjHndl[m];
|
|
24630
|
+
}
|
|
24631
|
+
}
|
|
24632
|
+
res = copy;
|
|
24633
|
+
}
|
|
24634
|
+
} else if (handleAsObjectInI18nFormat && isString(joinArrays) && Array.isArray(res)) {
|
|
24635
|
+
res = res.join(joinArrays);
|
|
24636
|
+
if (res) res = this.extendTranslation(res, keys, opt, lastKey);
|
|
24637
|
+
} else {
|
|
24638
|
+
let usedDefault = false;
|
|
24639
|
+
let usedKey = false;
|
|
24640
|
+
if (!this.isValidLookup(res) && hasDefaultValue) {
|
|
24641
|
+
usedDefault = true;
|
|
24642
|
+
res = defaultValue;
|
|
24643
|
+
}
|
|
24644
|
+
if (!this.isValidLookup(res)) {
|
|
24645
|
+
usedKey = true;
|
|
24646
|
+
res = key;
|
|
24647
|
+
}
|
|
24648
|
+
const missingKeyNoValueFallbackToKey = opt.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
|
|
24649
|
+
const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? undefined : res;
|
|
24650
|
+
const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
24651
|
+
if (usedKey || usedDefault || updateMissing) {
|
|
24652
|
+
this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? defaultValue : res);
|
|
24653
|
+
if (keySeparator) {
|
|
24654
|
+
const fk = this.resolve(key, {
|
|
24655
|
+
...opt,
|
|
24656
|
+
keySeparator: false
|
|
24657
|
+
});
|
|
24658
|
+
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.');
|
|
24659
|
+
}
|
|
24660
|
+
let lngs = [];
|
|
24661
|
+
const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, opt.lng || this.language);
|
|
24662
|
+
if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) {
|
|
24663
|
+
for (let i = 0; i < fallbackLngs.length; i++) {
|
|
24664
|
+
lngs.push(fallbackLngs[i]);
|
|
24665
|
+
}
|
|
24666
|
+
} else if (this.options.saveMissingTo === 'all') {
|
|
24667
|
+
lngs = this.languageUtils.toResolveHierarchy(opt.lng || this.language);
|
|
24668
|
+
} else {
|
|
24669
|
+
lngs.push(opt.lng || this.language);
|
|
24670
|
+
}
|
|
24671
|
+
const send = (l, k, specificDefaultValue) => {
|
|
24672
|
+
const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
24673
|
+
if (this.options.missingKeyHandler) {
|
|
24674
|
+
this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, opt);
|
|
24675
|
+
} else if (this.backendConnector?.saveMissing) {
|
|
24676
|
+
this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, opt);
|
|
24677
|
+
}
|
|
24678
|
+
this.emit('missingKey', l, namespace, k, res);
|
|
24679
|
+
};
|
|
24680
|
+
if (this.options.saveMissing) {
|
|
24681
|
+
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
24682
|
+
lngs.forEach(language => {
|
|
24683
|
+
const suffixes = this.pluralResolver.getSuffixes(language, opt);
|
|
24684
|
+
if (needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.indexOf(`${this.options.pluralSeparator}zero`) < 0) {
|
|
24685
|
+
suffixes.push(`${this.options.pluralSeparator}zero`);
|
|
24686
|
+
}
|
|
24687
|
+
suffixes.forEach(suffix => {
|
|
24688
|
+
send([language], key + suffix, opt[`defaultValue${suffix}`] || defaultValue);
|
|
24689
|
+
});
|
|
24690
|
+
});
|
|
24691
|
+
} else {
|
|
24692
|
+
send(lngs, key, defaultValue);
|
|
24693
|
+
}
|
|
24694
|
+
}
|
|
24695
|
+
}
|
|
24696
|
+
res = this.extendTranslation(res, keys, opt, resolved, lastKey);
|
|
24697
|
+
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
|
|
24698
|
+
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
|
|
24699
|
+
res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : undefined);
|
|
24700
|
+
}
|
|
24701
|
+
}
|
|
24702
|
+
if (returnDetails) {
|
|
24703
|
+
resolved.res = res;
|
|
24704
|
+
resolved.usedParams = this.getUsedParamsDetails(opt);
|
|
24705
|
+
return resolved;
|
|
24706
|
+
}
|
|
24707
|
+
return res;
|
|
24708
|
+
}
|
|
24709
|
+
extendTranslation(res, key, opt, resolved, lastKey) {
|
|
24710
|
+
var _this = this;
|
|
24711
|
+
if (this.i18nFormat?.parse) {
|
|
24712
|
+
res = this.i18nFormat.parse(res, {
|
|
24713
|
+
...this.options.interpolation.defaultVariables,
|
|
24714
|
+
...opt
|
|
24715
|
+
}, opt.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
|
|
24716
|
+
resolved
|
|
24717
|
+
});
|
|
24718
|
+
} else if (!opt.skipInterpolation) {
|
|
24719
|
+
if (opt.interpolation) this.interpolator.init({
|
|
24720
|
+
...opt,
|
|
24721
|
+
...{
|
|
24722
|
+
interpolation: {
|
|
24723
|
+
...this.options.interpolation,
|
|
24724
|
+
...opt.interpolation
|
|
24725
|
+
}
|
|
24726
|
+
}
|
|
24727
|
+
});
|
|
24728
|
+
const skipOnVariables = isString(res) && (opt?.interpolation?.skipOnVariables !== undefined ? opt.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
24729
|
+
let nestBef;
|
|
24730
|
+
if (skipOnVariables) {
|
|
24731
|
+
const nb = res.match(this.interpolator.nestingRegexp);
|
|
24732
|
+
nestBef = nb && nb.length;
|
|
24733
|
+
}
|
|
24734
|
+
let data = opt.replace && !isString(opt.replace) ? opt.replace : opt;
|
|
24735
|
+
if (this.options.interpolation.defaultVariables) data = {
|
|
24736
|
+
...this.options.interpolation.defaultVariables,
|
|
24737
|
+
...data
|
|
24738
|
+
};
|
|
24739
|
+
res = this.interpolator.interpolate(res, data, opt.lng || this.language || resolved.usedLng, opt);
|
|
24740
|
+
if (skipOnVariables) {
|
|
24741
|
+
const na = res.match(this.interpolator.nestingRegexp);
|
|
24742
|
+
const nestAft = na && na.length;
|
|
24743
|
+
if (nestBef < nestAft) opt.nest = false;
|
|
24744
|
+
}
|
|
24745
|
+
if (!opt.lng && resolved && resolved.res) opt.lng = this.language || resolved.usedLng;
|
|
24746
|
+
if (opt.nest !== false) res = this.interpolator.nest(res, function () {
|
|
24747
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
24748
|
+
args[_key] = arguments[_key];
|
|
24749
|
+
}
|
|
24750
|
+
if (lastKey?.[0] === args[0] && !opt.context) {
|
|
24751
|
+
_this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
|
|
24752
|
+
return null;
|
|
24753
|
+
}
|
|
24754
|
+
return _this.translate(...args, key);
|
|
24755
|
+
}, opt);
|
|
24756
|
+
if (opt.interpolation) this.interpolator.reset();
|
|
24757
|
+
}
|
|
24758
|
+
const postProcess = opt.postProcess || this.options.postProcess;
|
|
24759
|
+
const postProcessorNames = isString(postProcess) ? [postProcess] : postProcess;
|
|
24760
|
+
if (res != null && postProcessorNames?.length && opt.applyPostProcessor !== false) {
|
|
24761
|
+
res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
|
|
24762
|
+
i18nResolved: {
|
|
24763
|
+
...resolved,
|
|
24764
|
+
usedParams: this.getUsedParamsDetails(opt)
|
|
24765
|
+
},
|
|
24766
|
+
...opt
|
|
24767
|
+
} : opt, this);
|
|
24768
|
+
}
|
|
24769
|
+
return res;
|
|
24770
|
+
}
|
|
24771
|
+
resolve(keys) {
|
|
24772
|
+
let opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
24773
|
+
let found;
|
|
24774
|
+
let usedKey;
|
|
24775
|
+
let exactUsedKey;
|
|
24776
|
+
let usedLng;
|
|
24777
|
+
let usedNS;
|
|
24778
|
+
if (isString(keys)) keys = [keys];
|
|
24779
|
+
keys.forEach(k => {
|
|
24780
|
+
if (this.isValidLookup(found)) return;
|
|
24781
|
+
const extracted = this.extractFromKey(k, opt);
|
|
24782
|
+
const key = extracted.key;
|
|
24783
|
+
usedKey = key;
|
|
24784
|
+
let namespaces = extracted.namespaces;
|
|
24785
|
+
if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
|
|
24786
|
+
const needsPluralHandling = opt.count !== undefined && !isString(opt.count);
|
|
24787
|
+
const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
|
|
24788
|
+
const needsContextHandling = opt.context !== undefined && (isString(opt.context) || typeof opt.context === 'number') && opt.context !== '';
|
|
24789
|
+
const codes = opt.lngs ? opt.lngs : this.languageUtils.toResolveHierarchy(opt.lng || this.language, opt.fallbackLng);
|
|
24790
|
+
namespaces.forEach(ns => {
|
|
24791
|
+
if (this.isValidLookup(found)) return;
|
|
24792
|
+
usedNS = ns;
|
|
24793
|
+
if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils?.hasLoadedNamespace && !this.utils?.hasLoadedNamespace(usedNS)) {
|
|
24794
|
+
checkedLoadedFor[`${codes[0]}-${ns}`] = true;
|
|
24795
|
+
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!!!');
|
|
24796
|
+
}
|
|
24797
|
+
codes.forEach(code => {
|
|
24798
|
+
if (this.isValidLookup(found)) return;
|
|
24799
|
+
usedLng = code;
|
|
24800
|
+
const finalKeys = [key];
|
|
24801
|
+
if (this.i18nFormat?.addLookupKeys) {
|
|
24802
|
+
this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, opt);
|
|
24803
|
+
} else {
|
|
24804
|
+
let pluralSuffix;
|
|
24805
|
+
if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, opt.count, opt);
|
|
24806
|
+
const zeroSuffix = `${this.options.pluralSeparator}zero`;
|
|
24807
|
+
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
|
|
24808
|
+
if (needsPluralHandling) {
|
|
24809
|
+
finalKeys.push(key + pluralSuffix);
|
|
24810
|
+
if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
24811
|
+
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
24812
|
+
}
|
|
24813
|
+
if (needsZeroSuffixLookup) {
|
|
24814
|
+
finalKeys.push(key + zeroSuffix);
|
|
24815
|
+
}
|
|
24816
|
+
}
|
|
24817
|
+
if (needsContextHandling) {
|
|
24818
|
+
const contextKey = `${key}${this.options.contextSeparator}${opt.context}`;
|
|
24819
|
+
finalKeys.push(contextKey);
|
|
24820
|
+
if (needsPluralHandling) {
|
|
24821
|
+
finalKeys.push(contextKey + pluralSuffix);
|
|
24822
|
+
if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
24823
|
+
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
24824
|
+
}
|
|
24825
|
+
if (needsZeroSuffixLookup) {
|
|
24826
|
+
finalKeys.push(contextKey + zeroSuffix);
|
|
24827
|
+
}
|
|
24828
|
+
}
|
|
24829
|
+
}
|
|
24830
|
+
}
|
|
24831
|
+
let possibleKey;
|
|
24832
|
+
while (possibleKey = finalKeys.pop()) {
|
|
24833
|
+
if (!this.isValidLookup(found)) {
|
|
24834
|
+
exactUsedKey = possibleKey;
|
|
24835
|
+
found = this.getResource(code, ns, possibleKey, opt);
|
|
24836
|
+
}
|
|
24837
|
+
}
|
|
24838
|
+
});
|
|
24839
|
+
});
|
|
24840
|
+
});
|
|
24841
|
+
return {
|
|
24842
|
+
res: found,
|
|
24843
|
+
usedKey,
|
|
24844
|
+
exactUsedKey,
|
|
24845
|
+
usedLng,
|
|
24846
|
+
usedNS
|
|
24847
|
+
};
|
|
24848
|
+
}
|
|
24849
|
+
isValidLookup(res) {
|
|
24850
|
+
return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === '');
|
|
24851
|
+
}
|
|
24852
|
+
getResource(code, ns, key) {
|
|
24853
|
+
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
24854
|
+
if (this.i18nFormat?.getResource) return this.i18nFormat.getResource(code, ns, key, options);
|
|
24855
|
+
return this.resourceStore.getResource(code, ns, key, options);
|
|
24856
|
+
}
|
|
24857
|
+
getUsedParamsDetails() {
|
|
24858
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
24859
|
+
const optionsKeys = ['defaultValue', 'ordinal', 'context', 'replace', 'lng', 'lngs', 'fallbackLng', 'ns', 'keySeparator', 'nsSeparator', 'returnObjects', 'returnDetails', 'joinArrays', 'postProcess', 'interpolation'];
|
|
24860
|
+
const useOptionsReplaceForData = options.replace && !isString(options.replace);
|
|
24861
|
+
let data = useOptionsReplaceForData ? options.replace : options;
|
|
24862
|
+
if (useOptionsReplaceForData && typeof options.count !== 'undefined') {
|
|
24863
|
+
data.count = options.count;
|
|
24864
|
+
}
|
|
24865
|
+
if (this.options.interpolation.defaultVariables) {
|
|
24866
|
+
data = {
|
|
24867
|
+
...this.options.interpolation.defaultVariables,
|
|
24868
|
+
...data
|
|
24869
|
+
};
|
|
24870
|
+
}
|
|
24871
|
+
if (!useOptionsReplaceForData) {
|
|
24872
|
+
data = {
|
|
24873
|
+
...data
|
|
24874
|
+
};
|
|
24875
|
+
for (const key of optionsKeys) {
|
|
24876
|
+
delete data[key];
|
|
24877
|
+
}
|
|
24878
|
+
}
|
|
24879
|
+
return data;
|
|
24880
|
+
}
|
|
24881
|
+
static hasDefaultValue(options) {
|
|
24882
|
+
const prefix = 'defaultValue';
|
|
24883
|
+
for (const option in options) {
|
|
24884
|
+
if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && undefined !== options[option]) {
|
|
24885
|
+
return true;
|
|
24886
|
+
}
|
|
24887
|
+
}
|
|
24888
|
+
return false;
|
|
24889
|
+
}
|
|
24890
|
+
}
|
|
24891
|
+
|
|
24892
|
+
class LanguageUtil {
|
|
24893
|
+
constructor(options) {
|
|
24894
|
+
this.options = options;
|
|
24895
|
+
this.supportedLngs = this.options.supportedLngs || false;
|
|
24896
|
+
this.logger = baseLogger.create('languageUtils');
|
|
24897
|
+
}
|
|
24898
|
+
getScriptPartFromCode(code) {
|
|
24899
|
+
code = getCleanedCode(code);
|
|
24900
|
+
if (!code || code.indexOf('-') < 0) return null;
|
|
24901
|
+
const p = code.split('-');
|
|
24902
|
+
if (p.length === 2) return null;
|
|
24903
|
+
p.pop();
|
|
24904
|
+
if (p[p.length - 1].toLowerCase() === 'x') return null;
|
|
24905
|
+
return this.formatLanguageCode(p.join('-'));
|
|
24906
|
+
}
|
|
24907
|
+
getLanguagePartFromCode(code) {
|
|
24908
|
+
code = getCleanedCode(code);
|
|
24909
|
+
if (!code || code.indexOf('-') < 0) return code;
|
|
24910
|
+
const p = code.split('-');
|
|
24911
|
+
return this.formatLanguageCode(p[0]);
|
|
24912
|
+
}
|
|
24913
|
+
formatLanguageCode(code) {
|
|
24914
|
+
if (isString(code) && code.indexOf('-') > -1) {
|
|
24915
|
+
let formattedCode;
|
|
24916
|
+
try {
|
|
24917
|
+
formattedCode = Intl.getCanonicalLocales(code)[0];
|
|
24918
|
+
} catch (e) {}
|
|
24919
|
+
if (formattedCode && this.options.lowerCaseLng) {
|
|
24920
|
+
formattedCode = formattedCode.toLowerCase();
|
|
24921
|
+
}
|
|
24922
|
+
if (formattedCode) return formattedCode;
|
|
24923
|
+
if (this.options.lowerCaseLng) {
|
|
24924
|
+
return code.toLowerCase();
|
|
24925
|
+
}
|
|
24926
|
+
return code;
|
|
24927
|
+
}
|
|
24928
|
+
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
|
|
24929
|
+
}
|
|
24930
|
+
isSupportedCode(code) {
|
|
24931
|
+
if (this.options.load === 'languageOnly' || this.options.nonExplicitSupportedLngs) {
|
|
24932
|
+
code = this.getLanguagePartFromCode(code);
|
|
24933
|
+
}
|
|
24934
|
+
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
|
|
24935
|
+
}
|
|
24936
|
+
getBestMatchFromCodes(codes) {
|
|
24937
|
+
if (!codes) return null;
|
|
24938
|
+
let found;
|
|
24939
|
+
codes.forEach(code => {
|
|
24940
|
+
if (found) return;
|
|
24941
|
+
const cleanedLng = this.formatLanguageCode(code);
|
|
24942
|
+
if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
|
|
24943
|
+
});
|
|
24944
|
+
if (!found && this.options.supportedLngs) {
|
|
24945
|
+
codes.forEach(code => {
|
|
24946
|
+
if (found) return;
|
|
24947
|
+
const lngScOnly = this.getScriptPartFromCode(code);
|
|
24948
|
+
if (this.isSupportedCode(lngScOnly)) return found = lngScOnly;
|
|
24949
|
+
const lngOnly = this.getLanguagePartFromCode(code);
|
|
24950
|
+
if (this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
24951
|
+
found = this.options.supportedLngs.find(supportedLng => {
|
|
24952
|
+
if (supportedLng === lngOnly) return supportedLng;
|
|
24953
|
+
if (supportedLng.indexOf('-') < 0 && lngOnly.indexOf('-') < 0) return;
|
|
24954
|
+
if (supportedLng.indexOf('-') > 0 && lngOnly.indexOf('-') < 0 && supportedLng.substring(0, supportedLng.indexOf('-')) === lngOnly) return supportedLng;
|
|
24955
|
+
if (supportedLng.indexOf(lngOnly) === 0 && lngOnly.length > 1) return supportedLng;
|
|
24956
|
+
});
|
|
24957
|
+
});
|
|
24958
|
+
}
|
|
24959
|
+
if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
|
|
24960
|
+
return found;
|
|
24961
|
+
}
|
|
24962
|
+
getFallbackCodes(fallbacks, code) {
|
|
24963
|
+
if (!fallbacks) return [];
|
|
24964
|
+
if (typeof fallbacks === 'function') fallbacks = fallbacks(code);
|
|
24965
|
+
if (isString(fallbacks)) fallbacks = [fallbacks];
|
|
24966
|
+
if (Array.isArray(fallbacks)) return fallbacks;
|
|
24967
|
+
if (!code) return fallbacks.default || [];
|
|
24968
|
+
let found = fallbacks[code];
|
|
24969
|
+
if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
|
|
24970
|
+
if (!found) found = fallbacks[this.formatLanguageCode(code)];
|
|
24971
|
+
if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
24972
|
+
if (!found) found = fallbacks.default;
|
|
24973
|
+
return found || [];
|
|
24974
|
+
}
|
|
24975
|
+
toResolveHierarchy(code, fallbackCode) {
|
|
24976
|
+
const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
|
|
24977
|
+
const codes = [];
|
|
24978
|
+
const addCode = c => {
|
|
24979
|
+
if (!c) return;
|
|
24980
|
+
if (this.isSupportedCode(c)) {
|
|
24981
|
+
codes.push(c);
|
|
24982
|
+
} else {
|
|
24983
|
+
this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
|
|
24984
|
+
}
|
|
24985
|
+
};
|
|
24986
|
+
if (isString(code) && (code.indexOf('-') > -1 || code.indexOf('_') > -1)) {
|
|
24987
|
+
if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code));
|
|
24988
|
+
if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code));
|
|
24989
|
+
if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code));
|
|
24990
|
+
} else if (isString(code)) {
|
|
24991
|
+
addCode(this.formatLanguageCode(code));
|
|
24992
|
+
}
|
|
24993
|
+
fallbackCodes.forEach(fc => {
|
|
24994
|
+
if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
|
|
24995
|
+
});
|
|
24996
|
+
return codes;
|
|
24997
|
+
}
|
|
24998
|
+
}
|
|
24999
|
+
|
|
25000
|
+
const suffixesOrder = {
|
|
25001
|
+
zero: 0,
|
|
25002
|
+
one: 1,
|
|
25003
|
+
two: 2,
|
|
25004
|
+
few: 3,
|
|
25005
|
+
many: 4,
|
|
25006
|
+
other: 5
|
|
25007
|
+
};
|
|
25008
|
+
const dummyRule = {
|
|
25009
|
+
select: count => count === 1 ? 'one' : 'other',
|
|
25010
|
+
resolvedOptions: () => ({
|
|
25011
|
+
pluralCategories: ['one', 'other']
|
|
25012
|
+
})
|
|
25013
|
+
};
|
|
25014
|
+
class PluralResolver {
|
|
25015
|
+
constructor(languageUtils) {
|
|
25016
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
25017
|
+
this.languageUtils = languageUtils;
|
|
25018
|
+
this.options = options;
|
|
25019
|
+
this.logger = baseLogger.create('pluralResolver');
|
|
25020
|
+
this.pluralRulesCache = {};
|
|
25021
|
+
}
|
|
25022
|
+
addRule(lng, obj) {
|
|
25023
|
+
this.rules[lng] = obj;
|
|
25024
|
+
}
|
|
25025
|
+
clearCache() {
|
|
25026
|
+
this.pluralRulesCache = {};
|
|
25027
|
+
}
|
|
25028
|
+
getRule(code) {
|
|
25029
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
25030
|
+
const cleanedCode = getCleanedCode(code === 'dev' ? 'en' : code);
|
|
25031
|
+
const type = options.ordinal ? 'ordinal' : 'cardinal';
|
|
25032
|
+
const cacheKey = JSON.stringify({
|
|
25033
|
+
cleanedCode,
|
|
25034
|
+
type
|
|
25035
|
+
});
|
|
25036
|
+
if (cacheKey in this.pluralRulesCache) {
|
|
25037
|
+
return this.pluralRulesCache[cacheKey];
|
|
25038
|
+
}
|
|
25039
|
+
let rule;
|
|
25040
|
+
try {
|
|
25041
|
+
rule = new Intl.PluralRules(cleanedCode, {
|
|
25042
|
+
type
|
|
25043
|
+
});
|
|
25044
|
+
} catch (err) {
|
|
25045
|
+
if (!Intl) {
|
|
25046
|
+
this.logger.error('No Intl support, please use an Intl polyfill!');
|
|
25047
|
+
return dummyRule;
|
|
25048
|
+
}
|
|
25049
|
+
if (!code.match(/-|_/)) return dummyRule;
|
|
25050
|
+
const lngPart = this.languageUtils.getLanguagePartFromCode(code);
|
|
25051
|
+
rule = this.getRule(lngPart, options);
|
|
25052
|
+
}
|
|
25053
|
+
this.pluralRulesCache[cacheKey] = rule;
|
|
25054
|
+
return rule;
|
|
25055
|
+
}
|
|
25056
|
+
needsPlural(code) {
|
|
25057
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
25058
|
+
let rule = this.getRule(code, options);
|
|
25059
|
+
if (!rule) rule = this.getRule('dev', options);
|
|
25060
|
+
return rule?.resolvedOptions().pluralCategories.length > 1;
|
|
25061
|
+
}
|
|
25062
|
+
getPluralFormsOfKey(code, key) {
|
|
25063
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
25064
|
+
return this.getSuffixes(code, options).map(suffix => `${key}${suffix}`);
|
|
25065
|
+
}
|
|
25066
|
+
getSuffixes(code) {
|
|
25067
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
25068
|
+
let rule = this.getRule(code, options);
|
|
25069
|
+
if (!rule) rule = this.getRule('dev', options);
|
|
25070
|
+
if (!rule) return [];
|
|
25071
|
+
return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map(pluralCategory => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${pluralCategory}`);
|
|
25072
|
+
}
|
|
25073
|
+
getSuffix(code, count) {
|
|
25074
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
25075
|
+
const rule = this.getRule(code, options);
|
|
25076
|
+
if (rule) {
|
|
25077
|
+
return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${rule.select(count)}`;
|
|
25078
|
+
}
|
|
25079
|
+
this.logger.warn(`no plural rule found for: ${code}`);
|
|
25080
|
+
return this.getSuffix('dev', count, options);
|
|
25081
|
+
}
|
|
25082
|
+
}
|
|
25083
|
+
|
|
25084
|
+
const deepFindWithDefaults = function (data, defaultData, key) {
|
|
25085
|
+
let keySeparator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '.';
|
|
25086
|
+
let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
25087
|
+
let path = getPathWithDefaults(data, defaultData, key);
|
|
25088
|
+
if (!path && ignoreJSONStructure && isString(key)) {
|
|
25089
|
+
path = deepFind(data, key, keySeparator);
|
|
25090
|
+
if (path === undefined) path = deepFind(defaultData, key, keySeparator);
|
|
25091
|
+
}
|
|
25092
|
+
return path;
|
|
25093
|
+
};
|
|
25094
|
+
const regexSafe = val => val.replace(/\$/g, '$$$$');
|
|
25095
|
+
class Interpolator {
|
|
25096
|
+
constructor() {
|
|
25097
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
25098
|
+
this.logger = baseLogger.create('interpolator');
|
|
25099
|
+
this.options = options;
|
|
25100
|
+
this.format = options?.interpolation?.format || (value => value);
|
|
25101
|
+
this.init(options);
|
|
25102
|
+
}
|
|
25103
|
+
init() {
|
|
25104
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
25105
|
+
if (!options.interpolation) options.interpolation = {
|
|
25106
|
+
escapeValue: true
|
|
25107
|
+
};
|
|
25108
|
+
const {
|
|
25109
|
+
escape: escape$1$1,
|
|
25110
|
+
escapeValue,
|
|
25111
|
+
useRawValueToEscape,
|
|
25112
|
+
prefix,
|
|
25113
|
+
prefixEscaped,
|
|
25114
|
+
suffix,
|
|
25115
|
+
suffixEscaped,
|
|
25116
|
+
formatSeparator,
|
|
25117
|
+
unescapeSuffix,
|
|
25118
|
+
unescapePrefix,
|
|
25119
|
+
nestingPrefix,
|
|
25120
|
+
nestingPrefixEscaped,
|
|
25121
|
+
nestingSuffix,
|
|
25122
|
+
nestingSuffixEscaped,
|
|
25123
|
+
nestingOptionsSeparator,
|
|
25124
|
+
maxReplaces,
|
|
25125
|
+
alwaysFormat
|
|
25126
|
+
} = options.interpolation;
|
|
25127
|
+
this.escape = escape$1$1 !== undefined ? escape$1$1 : escape$1;
|
|
25128
|
+
this.escapeValue = escapeValue !== undefined ? escapeValue : true;
|
|
25129
|
+
this.useRawValueToEscape = useRawValueToEscape !== undefined ? useRawValueToEscape : false;
|
|
25130
|
+
this.prefix = prefix ? regexEscape(prefix) : prefixEscaped || '{{';
|
|
25131
|
+
this.suffix = suffix ? regexEscape(suffix) : suffixEscaped || '}}';
|
|
25132
|
+
this.formatSeparator = formatSeparator || ',';
|
|
25133
|
+
this.unescapePrefix = unescapeSuffix ? '' : unescapePrefix || '-';
|
|
25134
|
+
this.unescapeSuffix = this.unescapePrefix ? '' : unescapeSuffix || '';
|
|
25135
|
+
this.nestingPrefix = nestingPrefix ? regexEscape(nestingPrefix) : nestingPrefixEscaped || regexEscape('$t(');
|
|
25136
|
+
this.nestingSuffix = nestingSuffix ? regexEscape(nestingSuffix) : nestingSuffixEscaped || regexEscape(')');
|
|
25137
|
+
this.nestingOptionsSeparator = nestingOptionsSeparator || ',';
|
|
25138
|
+
this.maxReplaces = maxReplaces || 1000;
|
|
25139
|
+
this.alwaysFormat = alwaysFormat !== undefined ? alwaysFormat : false;
|
|
25140
|
+
this.resetRegExp();
|
|
25141
|
+
}
|
|
25142
|
+
reset() {
|
|
25143
|
+
if (this.options) this.init(this.options);
|
|
25144
|
+
}
|
|
25145
|
+
resetRegExp() {
|
|
25146
|
+
const getOrResetRegExp = (existingRegExp, pattern) => {
|
|
25147
|
+
if (existingRegExp?.source === pattern) {
|
|
25148
|
+
existingRegExp.lastIndex = 0;
|
|
25149
|
+
return existingRegExp;
|
|
25150
|
+
}
|
|
25151
|
+
return new RegExp(pattern, 'g');
|
|
25152
|
+
};
|
|
25153
|
+
this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
|
|
25154
|
+
this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
|
|
25155
|
+
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}(.+?)${this.nestingSuffix}`);
|
|
25156
|
+
}
|
|
25157
|
+
interpolate(str, data, lng, options) {
|
|
25158
|
+
let match;
|
|
25159
|
+
let value;
|
|
25160
|
+
let replaces;
|
|
25161
|
+
const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
25162
|
+
const handleFormat = key => {
|
|
25163
|
+
if (key.indexOf(this.formatSeparator) < 0) {
|
|
25164
|
+
const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
|
|
25165
|
+
return this.alwaysFormat ? this.format(path, undefined, lng, {
|
|
25166
|
+
...options,
|
|
25167
|
+
...data,
|
|
25168
|
+
interpolationkey: key
|
|
25169
|
+
}) : path;
|
|
25170
|
+
}
|
|
25171
|
+
const p = key.split(this.formatSeparator);
|
|
25172
|
+
const k = p.shift().trim();
|
|
25173
|
+
const f = p.join(this.formatSeparator).trim();
|
|
25174
|
+
return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
|
|
25175
|
+
...options,
|
|
25176
|
+
...data,
|
|
25177
|
+
interpolationkey: k
|
|
25178
|
+
});
|
|
25179
|
+
};
|
|
25180
|
+
this.resetRegExp();
|
|
25181
|
+
const missingInterpolationHandler = options?.missingInterpolationHandler || this.options.missingInterpolationHandler;
|
|
25182
|
+
const skipOnVariables = options?.interpolation?.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
|
|
25183
|
+
const todos = [{
|
|
25184
|
+
regex: this.regexpUnescape,
|
|
25185
|
+
safeValue: val => regexSafe(val)
|
|
25186
|
+
}, {
|
|
25187
|
+
regex: this.regexp,
|
|
25188
|
+
safeValue: val => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
|
|
25189
|
+
}];
|
|
25190
|
+
todos.forEach(todo => {
|
|
25191
|
+
replaces = 0;
|
|
25192
|
+
while (match = todo.regex.exec(str)) {
|
|
25193
|
+
const matchedVar = match[1].trim();
|
|
25194
|
+
value = handleFormat(matchedVar);
|
|
25195
|
+
if (value === undefined) {
|
|
25196
|
+
if (typeof missingInterpolationHandler === 'function') {
|
|
25197
|
+
const temp = missingInterpolationHandler(str, match, options);
|
|
25198
|
+
value = isString(temp) ? temp : '';
|
|
25199
|
+
} else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
|
|
25200
|
+
value = '';
|
|
25201
|
+
} else if (skipOnVariables) {
|
|
25202
|
+
value = match[0];
|
|
25203
|
+
continue;
|
|
25204
|
+
} else {
|
|
25205
|
+
this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
|
|
25206
|
+
value = '';
|
|
25207
|
+
}
|
|
25208
|
+
} else if (!isString(value) && !this.useRawValueToEscape) {
|
|
25209
|
+
value = makeString(value);
|
|
25210
|
+
}
|
|
25211
|
+
const safeValue = todo.safeValue(value);
|
|
25212
|
+
str = str.replace(match[0], safeValue);
|
|
25213
|
+
if (skipOnVariables) {
|
|
25214
|
+
todo.regex.lastIndex += value.length;
|
|
25215
|
+
todo.regex.lastIndex -= match[0].length;
|
|
25216
|
+
} else {
|
|
25217
|
+
todo.regex.lastIndex = 0;
|
|
25218
|
+
}
|
|
25219
|
+
replaces++;
|
|
25220
|
+
if (replaces >= this.maxReplaces) {
|
|
25221
|
+
break;
|
|
25222
|
+
}
|
|
25223
|
+
}
|
|
25224
|
+
});
|
|
25225
|
+
return str;
|
|
25226
|
+
}
|
|
25227
|
+
nest(str, fc) {
|
|
25228
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
25229
|
+
let match;
|
|
25230
|
+
let value;
|
|
25231
|
+
let clonedOptions;
|
|
25232
|
+
const handleHasOptions = (key, inheritedOptions) => {
|
|
25233
|
+
const sep = this.nestingOptionsSeparator;
|
|
25234
|
+
if (key.indexOf(sep) < 0) return key;
|
|
25235
|
+
const c = key.split(new RegExp(`${sep}[ ]*{`));
|
|
25236
|
+
let optionsString = `{${c[1]}`;
|
|
25237
|
+
key = c[0];
|
|
25238
|
+
optionsString = this.interpolate(optionsString, clonedOptions);
|
|
25239
|
+
const matchedSingleQuotes = optionsString.match(/'/g);
|
|
25240
|
+
const matchedDoubleQuotes = optionsString.match(/"/g);
|
|
25241
|
+
if ((matchedSingleQuotes?.length ?? 0) % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
|
|
25242
|
+
optionsString = optionsString.replace(/'/g, '"');
|
|
25243
|
+
}
|
|
25244
|
+
try {
|
|
25245
|
+
clonedOptions = JSON.parse(optionsString);
|
|
25246
|
+
if (inheritedOptions) clonedOptions = {
|
|
25247
|
+
...inheritedOptions,
|
|
25248
|
+
...clonedOptions
|
|
25249
|
+
};
|
|
25250
|
+
} catch (e) {
|
|
25251
|
+
this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
|
|
25252
|
+
return `${key}${sep}${optionsString}`;
|
|
25253
|
+
}
|
|
25254
|
+
if (clonedOptions.defaultValue && clonedOptions.defaultValue.indexOf(this.prefix) > -1) delete clonedOptions.defaultValue;
|
|
25255
|
+
return key;
|
|
25256
|
+
};
|
|
25257
|
+
while (match = this.nestingRegexp.exec(str)) {
|
|
25258
|
+
let formatters = [];
|
|
25259
|
+
clonedOptions = {
|
|
25260
|
+
...options
|
|
25261
|
+
};
|
|
25262
|
+
clonedOptions = clonedOptions.replace && !isString(clonedOptions.replace) ? clonedOptions.replace : clonedOptions;
|
|
25263
|
+
clonedOptions.applyPostProcessor = false;
|
|
25264
|
+
delete clonedOptions.defaultValue;
|
|
25265
|
+
let doReduce = false;
|
|
25266
|
+
if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
|
|
25267
|
+
const r = match[1].split(this.formatSeparator).map(elem => elem.trim());
|
|
25268
|
+
match[1] = r.shift();
|
|
25269
|
+
formatters = r;
|
|
25270
|
+
doReduce = true;
|
|
25271
|
+
}
|
|
25272
|
+
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
25273
|
+
if (value && match[0] === str && !isString(value)) return value;
|
|
25274
|
+
if (!isString(value)) value = makeString(value);
|
|
25275
|
+
if (!value) {
|
|
25276
|
+
this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
|
|
25277
|
+
value = '';
|
|
25278
|
+
}
|
|
25279
|
+
if (doReduce) {
|
|
25280
|
+
value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
|
|
25281
|
+
...options,
|
|
25282
|
+
interpolationkey: match[1].trim()
|
|
25283
|
+
}), value.trim());
|
|
25284
|
+
}
|
|
25285
|
+
str = str.replace(match[0], value);
|
|
25286
|
+
this.regexp.lastIndex = 0;
|
|
25287
|
+
}
|
|
25288
|
+
return str;
|
|
25289
|
+
}
|
|
25290
|
+
}
|
|
25291
|
+
|
|
25292
|
+
const parseFormatStr = formatStr => {
|
|
25293
|
+
let formatName = formatStr.toLowerCase().trim();
|
|
25294
|
+
const formatOptions = {};
|
|
25295
|
+
if (formatStr.indexOf('(') > -1) {
|
|
25296
|
+
const p = formatStr.split('(');
|
|
25297
|
+
formatName = p[0].toLowerCase().trim();
|
|
25298
|
+
const optStr = p[1].substring(0, p[1].length - 1);
|
|
25299
|
+
if (formatName === 'currency' && optStr.indexOf(':') < 0) {
|
|
25300
|
+
if (!formatOptions.currency) formatOptions.currency = optStr.trim();
|
|
25301
|
+
} else if (formatName === 'relativetime' && optStr.indexOf(':') < 0) {
|
|
25302
|
+
if (!formatOptions.range) formatOptions.range = optStr.trim();
|
|
25303
|
+
} else {
|
|
25304
|
+
const opts = optStr.split(';');
|
|
25305
|
+
opts.forEach(opt => {
|
|
25306
|
+
if (opt) {
|
|
25307
|
+
const [key, ...rest] = opt.split(':');
|
|
25308
|
+
const val = rest.join(':').trim().replace(/^'+|'+$/g, '');
|
|
25309
|
+
const trimmedKey = key.trim();
|
|
25310
|
+
if (!formatOptions[trimmedKey]) formatOptions[trimmedKey] = val;
|
|
25311
|
+
if (val === 'false') formatOptions[trimmedKey] = false;
|
|
25312
|
+
if (val === 'true') formatOptions[trimmedKey] = true;
|
|
25313
|
+
if (!isNaN(val)) formatOptions[trimmedKey] = parseInt(val, 10);
|
|
25314
|
+
}
|
|
25315
|
+
});
|
|
25316
|
+
}
|
|
25317
|
+
}
|
|
25318
|
+
return {
|
|
25319
|
+
formatName,
|
|
25320
|
+
formatOptions
|
|
25321
|
+
};
|
|
25322
|
+
};
|
|
25323
|
+
const createCachedFormatter = fn => {
|
|
25324
|
+
const cache = {};
|
|
25325
|
+
return (val, lng, options) => {
|
|
25326
|
+
let optForCache = options;
|
|
25327
|
+
if (options && options.interpolationkey && options.formatParams && options.formatParams[options.interpolationkey] && options[options.interpolationkey]) {
|
|
25328
|
+
optForCache = {
|
|
25329
|
+
...optForCache,
|
|
25330
|
+
[options.interpolationkey]: undefined
|
|
25331
|
+
};
|
|
25332
|
+
}
|
|
25333
|
+
const key = lng + JSON.stringify(optForCache);
|
|
25334
|
+
let formatter = cache[key];
|
|
25335
|
+
if (!formatter) {
|
|
25336
|
+
formatter = fn(getCleanedCode(lng), options);
|
|
25337
|
+
cache[key] = formatter;
|
|
25338
|
+
}
|
|
25339
|
+
return formatter(val);
|
|
25340
|
+
};
|
|
25341
|
+
};
|
|
25342
|
+
class Formatter {
|
|
25343
|
+
constructor() {
|
|
25344
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
25345
|
+
this.logger = baseLogger.create('formatter');
|
|
25346
|
+
this.options = options;
|
|
25347
|
+
this.formats = {
|
|
25348
|
+
number: createCachedFormatter((lng, opt) => {
|
|
25349
|
+
const formatter = new Intl.NumberFormat(lng, {
|
|
25350
|
+
...opt
|
|
25351
|
+
});
|
|
25352
|
+
return val => formatter.format(val);
|
|
25353
|
+
}),
|
|
25354
|
+
currency: createCachedFormatter((lng, opt) => {
|
|
25355
|
+
const formatter = new Intl.NumberFormat(lng, {
|
|
25356
|
+
...opt,
|
|
25357
|
+
style: 'currency'
|
|
25358
|
+
});
|
|
25359
|
+
return val => formatter.format(val);
|
|
25360
|
+
}),
|
|
25361
|
+
datetime: createCachedFormatter((lng, opt) => {
|
|
25362
|
+
const formatter = new Intl.DateTimeFormat(lng, {
|
|
25363
|
+
...opt
|
|
25364
|
+
});
|
|
25365
|
+
return val => formatter.format(val);
|
|
25366
|
+
}),
|
|
25367
|
+
relativetime: createCachedFormatter((lng, opt) => {
|
|
25368
|
+
const formatter = new Intl.RelativeTimeFormat(lng, {
|
|
25369
|
+
...opt
|
|
25370
|
+
});
|
|
25371
|
+
return val => formatter.format(val, opt.range || 'day');
|
|
25372
|
+
}),
|
|
25373
|
+
list: createCachedFormatter((lng, opt) => {
|
|
25374
|
+
const formatter = new Intl.ListFormat(lng, {
|
|
25375
|
+
...opt
|
|
25376
|
+
});
|
|
25377
|
+
return val => formatter.format(val);
|
|
25378
|
+
})
|
|
25379
|
+
};
|
|
25380
|
+
this.init(options);
|
|
25381
|
+
}
|
|
25382
|
+
init(services) {
|
|
25383
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
25384
|
+
interpolation: {}
|
|
25385
|
+
};
|
|
25386
|
+
this.formatSeparator = options.interpolation.formatSeparator || ',';
|
|
25387
|
+
}
|
|
25388
|
+
add(name, fc) {
|
|
25389
|
+
this.formats[name.toLowerCase().trim()] = fc;
|
|
25390
|
+
}
|
|
25391
|
+
addCached(name, fc) {
|
|
25392
|
+
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
25393
|
+
}
|
|
25394
|
+
format(value, format, lng) {
|
|
25395
|
+
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
25396
|
+
const formats = format.split(this.formatSeparator);
|
|
25397
|
+
if (formats.length > 1 && formats[0].indexOf('(') > 1 && formats[0].indexOf(')') < 0 && formats.find(f => f.indexOf(')') > -1)) {
|
|
25398
|
+
const lastIndex = formats.findIndex(f => f.indexOf(')') > -1);
|
|
25399
|
+
formats[0] = [formats[0], ...formats.splice(1, lastIndex)].join(this.formatSeparator);
|
|
25400
|
+
}
|
|
25401
|
+
const result = formats.reduce((mem, f) => {
|
|
25402
|
+
const {
|
|
25403
|
+
formatName,
|
|
25404
|
+
formatOptions
|
|
25405
|
+
} = parseFormatStr(f);
|
|
25406
|
+
if (this.formats[formatName]) {
|
|
25407
|
+
let formatted = mem;
|
|
25408
|
+
try {
|
|
25409
|
+
const valOptions = options?.formatParams?.[options.interpolationkey] || {};
|
|
25410
|
+
const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
|
|
25411
|
+
formatted = this.formats[formatName](mem, l, {
|
|
25412
|
+
...formatOptions,
|
|
25413
|
+
...options,
|
|
25414
|
+
...valOptions
|
|
25415
|
+
});
|
|
25416
|
+
} catch (error) {
|
|
25417
|
+
this.logger.warn(error);
|
|
25418
|
+
}
|
|
25419
|
+
return formatted;
|
|
25420
|
+
} else {
|
|
25421
|
+
this.logger.warn(`there was no format function for ${formatName}`);
|
|
25422
|
+
}
|
|
25423
|
+
return mem;
|
|
25424
|
+
}, value);
|
|
25425
|
+
return result;
|
|
25426
|
+
}
|
|
25427
|
+
}
|
|
25428
|
+
|
|
25429
|
+
const removePending = (q, name) => {
|
|
25430
|
+
if (q.pending[name] !== undefined) {
|
|
25431
|
+
delete q.pending[name];
|
|
25432
|
+
q.pendingCount--;
|
|
25433
|
+
}
|
|
25434
|
+
};
|
|
25435
|
+
class Connector extends EventEmitter {
|
|
25436
|
+
constructor(backend, store, services) {
|
|
25437
|
+
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
25438
|
+
super();
|
|
25439
|
+
this.backend = backend;
|
|
25440
|
+
this.store = store;
|
|
25441
|
+
this.services = services;
|
|
25442
|
+
this.languageUtils = services.languageUtils;
|
|
25443
|
+
this.options = options;
|
|
25444
|
+
this.logger = baseLogger.create('backendConnector');
|
|
25445
|
+
this.waitingReads = [];
|
|
25446
|
+
this.maxParallelReads = options.maxParallelReads || 10;
|
|
25447
|
+
this.readingCalls = 0;
|
|
25448
|
+
this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
|
|
25449
|
+
this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
|
|
25450
|
+
this.state = {};
|
|
25451
|
+
this.queue = [];
|
|
25452
|
+
this.backend?.init?.(services, options.backend, options);
|
|
25453
|
+
}
|
|
25454
|
+
queueLoad(languages, namespaces, options, callback) {
|
|
25455
|
+
const toLoad = {};
|
|
25456
|
+
const pending = {};
|
|
25457
|
+
const toLoadLanguages = {};
|
|
25458
|
+
const toLoadNamespaces = {};
|
|
25459
|
+
languages.forEach(lng => {
|
|
25460
|
+
let hasAllNamespaces = true;
|
|
25461
|
+
namespaces.forEach(ns => {
|
|
25462
|
+
const name = `${lng}|${ns}`;
|
|
25463
|
+
if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
|
|
25464
|
+
this.state[name] = 2;
|
|
25465
|
+
} else if (this.state[name] < 0) ; else if (this.state[name] === 1) {
|
|
25466
|
+
if (pending[name] === undefined) pending[name] = true;
|
|
25467
|
+
} else {
|
|
25468
|
+
this.state[name] = 1;
|
|
25469
|
+
hasAllNamespaces = false;
|
|
25470
|
+
if (pending[name] === undefined) pending[name] = true;
|
|
25471
|
+
if (toLoad[name] === undefined) toLoad[name] = true;
|
|
25472
|
+
if (toLoadNamespaces[ns] === undefined) toLoadNamespaces[ns] = true;
|
|
25473
|
+
}
|
|
25474
|
+
});
|
|
25475
|
+
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
25476
|
+
});
|
|
25477
|
+
if (Object.keys(toLoad).length || Object.keys(pending).length) {
|
|
25478
|
+
this.queue.push({
|
|
25479
|
+
pending,
|
|
25480
|
+
pendingCount: Object.keys(pending).length,
|
|
25481
|
+
loaded: {},
|
|
25482
|
+
errors: [],
|
|
25483
|
+
callback
|
|
25484
|
+
});
|
|
25485
|
+
}
|
|
25486
|
+
return {
|
|
25487
|
+
toLoad: Object.keys(toLoad),
|
|
25488
|
+
pending: Object.keys(pending),
|
|
25489
|
+
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
25490
|
+
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
25491
|
+
};
|
|
25492
|
+
}
|
|
25493
|
+
loaded(name, err, data) {
|
|
25494
|
+
const s = name.split('|');
|
|
25495
|
+
const lng = s[0];
|
|
25496
|
+
const ns = s[1];
|
|
25497
|
+
if (err) this.emit('failedLoading', lng, ns, err);
|
|
25498
|
+
if (!err && data) {
|
|
25499
|
+
this.store.addResourceBundle(lng, ns, data, undefined, undefined, {
|
|
25500
|
+
skipCopy: true
|
|
25501
|
+
});
|
|
25502
|
+
}
|
|
25503
|
+
this.state[name] = err ? -1 : 2;
|
|
25504
|
+
if (err && data) this.state[name] = 0;
|
|
25505
|
+
const loaded = {};
|
|
25506
|
+
this.queue.forEach(q => {
|
|
25507
|
+
pushPath(q.loaded, [lng], ns);
|
|
25508
|
+
removePending(q, name);
|
|
25509
|
+
if (err) q.errors.push(err);
|
|
25510
|
+
if (q.pendingCount === 0 && !q.done) {
|
|
25511
|
+
Object.keys(q.loaded).forEach(l => {
|
|
25512
|
+
if (!loaded[l]) loaded[l] = {};
|
|
25513
|
+
const loadedKeys = q.loaded[l];
|
|
25514
|
+
if (loadedKeys.length) {
|
|
25515
|
+
loadedKeys.forEach(n => {
|
|
25516
|
+
if (loaded[l][n] === undefined) loaded[l][n] = true;
|
|
25517
|
+
});
|
|
25518
|
+
}
|
|
25519
|
+
});
|
|
25520
|
+
q.done = true;
|
|
25521
|
+
if (q.errors.length) {
|
|
25522
|
+
q.callback(q.errors);
|
|
25523
|
+
} else {
|
|
25524
|
+
q.callback();
|
|
25525
|
+
}
|
|
25526
|
+
}
|
|
25527
|
+
});
|
|
25528
|
+
this.emit('loaded', loaded);
|
|
25529
|
+
this.queue = this.queue.filter(q => !q.done);
|
|
25530
|
+
}
|
|
25531
|
+
read(lng, ns, fcName) {
|
|
25532
|
+
let tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
25533
|
+
let wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
|
|
25534
|
+
let callback = arguments.length > 5 ? arguments[5] : undefined;
|
|
25535
|
+
if (!lng.length) return callback(null, {});
|
|
25536
|
+
if (this.readingCalls >= this.maxParallelReads) {
|
|
25537
|
+
this.waitingReads.push({
|
|
25538
|
+
lng,
|
|
25539
|
+
ns,
|
|
25540
|
+
fcName,
|
|
25541
|
+
tried,
|
|
25542
|
+
wait,
|
|
25543
|
+
callback
|
|
25544
|
+
});
|
|
25545
|
+
return;
|
|
25546
|
+
}
|
|
25547
|
+
this.readingCalls++;
|
|
25548
|
+
const resolver = (err, data) => {
|
|
25549
|
+
this.readingCalls--;
|
|
25550
|
+
if (this.waitingReads.length > 0) {
|
|
25551
|
+
const next = this.waitingReads.shift();
|
|
25552
|
+
this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
25553
|
+
}
|
|
25554
|
+
if (err && data && tried < this.maxRetries) {
|
|
25555
|
+
setTimeout(() => {
|
|
25556
|
+
this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
25557
|
+
}, wait);
|
|
25558
|
+
return;
|
|
25559
|
+
}
|
|
25560
|
+
callback(err, data);
|
|
25561
|
+
};
|
|
25562
|
+
const fc = this.backend[fcName].bind(this.backend);
|
|
25563
|
+
if (fc.length === 2) {
|
|
25564
|
+
try {
|
|
25565
|
+
const r = fc(lng, ns);
|
|
25566
|
+
if (r && typeof r.then === 'function') {
|
|
25567
|
+
r.then(data => resolver(null, data)).catch(resolver);
|
|
25568
|
+
} else {
|
|
25569
|
+
resolver(null, r);
|
|
25570
|
+
}
|
|
25571
|
+
} catch (err) {
|
|
25572
|
+
resolver(err);
|
|
25573
|
+
}
|
|
25574
|
+
return;
|
|
25575
|
+
}
|
|
25576
|
+
return fc(lng, ns, resolver);
|
|
25577
|
+
}
|
|
25578
|
+
prepareLoading(languages, namespaces) {
|
|
25579
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
25580
|
+
let callback = arguments.length > 3 ? arguments[3] : undefined;
|
|
25581
|
+
if (!this.backend) {
|
|
25582
|
+
this.logger.warn('No backend was added via i18next.use. Will not load resources.');
|
|
25583
|
+
return callback && callback();
|
|
25584
|
+
}
|
|
25585
|
+
if (isString(languages)) languages = this.languageUtils.toResolveHierarchy(languages);
|
|
25586
|
+
if (isString(namespaces)) namespaces = [namespaces];
|
|
25587
|
+
const toLoad = this.queueLoad(languages, namespaces, options, callback);
|
|
25588
|
+
if (!toLoad.toLoad.length) {
|
|
25589
|
+
if (!toLoad.pending.length) callback();
|
|
25590
|
+
return null;
|
|
25591
|
+
}
|
|
25592
|
+
toLoad.toLoad.forEach(name => {
|
|
25593
|
+
this.loadOne(name);
|
|
25594
|
+
});
|
|
25595
|
+
}
|
|
25596
|
+
load(languages, namespaces, callback) {
|
|
25597
|
+
this.prepareLoading(languages, namespaces, {}, callback);
|
|
25598
|
+
}
|
|
25599
|
+
reload(languages, namespaces, callback) {
|
|
25600
|
+
this.prepareLoading(languages, namespaces, {
|
|
25601
|
+
reload: true
|
|
25602
|
+
}, callback);
|
|
25603
|
+
}
|
|
25604
|
+
loadOne(name) {
|
|
25605
|
+
let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
25606
|
+
const s = name.split('|');
|
|
25607
|
+
const lng = s[0];
|
|
25608
|
+
const ns = s[1];
|
|
25609
|
+
this.read(lng, ns, 'read', undefined, undefined, (err, data) => {
|
|
25610
|
+
if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
|
|
25611
|
+
if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
|
|
25612
|
+
this.loaded(name, err, data);
|
|
25613
|
+
});
|
|
25614
|
+
}
|
|
25615
|
+
saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
|
|
25616
|
+
let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
25617
|
+
let clb = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : () => {};
|
|
25618
|
+
if (this.services?.utils?.hasLoadedNamespace && !this.services?.utils?.hasLoadedNamespace(namespace)) {
|
|
25619
|
+
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!!!');
|
|
25620
|
+
return;
|
|
25621
|
+
}
|
|
25622
|
+
if (key === undefined || key === null || key === '') return;
|
|
25623
|
+
if (this.backend?.create) {
|
|
25624
|
+
const opts = {
|
|
25625
|
+
...options,
|
|
25626
|
+
isUpdate
|
|
25627
|
+
};
|
|
25628
|
+
const fc = this.backend.create.bind(this.backend);
|
|
25629
|
+
if (fc.length < 6) {
|
|
25630
|
+
try {
|
|
25631
|
+
let r;
|
|
25632
|
+
if (fc.length === 5) {
|
|
25633
|
+
r = fc(languages, namespace, key, fallbackValue, opts);
|
|
25634
|
+
} else {
|
|
25635
|
+
r = fc(languages, namespace, key, fallbackValue);
|
|
25636
|
+
}
|
|
25637
|
+
if (r && typeof r.then === 'function') {
|
|
25638
|
+
r.then(data => clb(null, data)).catch(clb);
|
|
25639
|
+
} else {
|
|
25640
|
+
clb(null, r);
|
|
25641
|
+
}
|
|
25642
|
+
} catch (err) {
|
|
25643
|
+
clb(err);
|
|
25644
|
+
}
|
|
25645
|
+
} else {
|
|
25646
|
+
fc(languages, namespace, key, fallbackValue, clb, opts);
|
|
25647
|
+
}
|
|
25648
|
+
}
|
|
25649
|
+
if (!languages || !languages[0]) return;
|
|
25650
|
+
this.store.addResource(languages[0], namespace, key, fallbackValue);
|
|
25651
|
+
}
|
|
25652
|
+
}
|
|
25653
|
+
|
|
25654
|
+
const get$1 = () => ({
|
|
25655
|
+
debug: false,
|
|
25656
|
+
initAsync: true,
|
|
25657
|
+
ns: ['translation'],
|
|
25658
|
+
defaultNS: ['translation'],
|
|
25659
|
+
fallbackLng: ['dev'],
|
|
25660
|
+
fallbackNS: false,
|
|
25661
|
+
supportedLngs: false,
|
|
25662
|
+
nonExplicitSupportedLngs: false,
|
|
25663
|
+
load: 'all',
|
|
25664
|
+
preload: false,
|
|
25665
|
+
simplifyPluralSuffix: true,
|
|
25666
|
+
keySeparator: '.',
|
|
25667
|
+
nsSeparator: ':',
|
|
25668
|
+
pluralSeparator: '_',
|
|
25669
|
+
contextSeparator: '_',
|
|
25670
|
+
partialBundledLanguages: false,
|
|
25671
|
+
saveMissing: false,
|
|
25672
|
+
updateMissing: false,
|
|
25673
|
+
saveMissingTo: 'fallback',
|
|
25674
|
+
saveMissingPlurals: true,
|
|
25675
|
+
missingKeyHandler: false,
|
|
25676
|
+
missingInterpolationHandler: false,
|
|
25677
|
+
postProcess: false,
|
|
25678
|
+
postProcessPassResolved: false,
|
|
25679
|
+
returnNull: false,
|
|
25680
|
+
returnEmptyString: true,
|
|
25681
|
+
returnObjects: false,
|
|
25682
|
+
joinArrays: false,
|
|
25683
|
+
returnedObjectHandler: false,
|
|
25684
|
+
parseMissingKeyHandler: false,
|
|
25685
|
+
appendNamespaceToMissingKey: false,
|
|
25686
|
+
appendNamespaceToCIMode: false,
|
|
25687
|
+
overloadTranslationOptionHandler: args => {
|
|
25688
|
+
let ret = {};
|
|
25689
|
+
if (typeof args[1] === 'object') ret = args[1];
|
|
25690
|
+
if (isString(args[1])) ret.defaultValue = args[1];
|
|
25691
|
+
if (isString(args[2])) ret.tDescription = args[2];
|
|
25692
|
+
if (typeof args[2] === 'object' || typeof args[3] === 'object') {
|
|
25693
|
+
const options = args[3] || args[2];
|
|
25694
|
+
Object.keys(options).forEach(key => {
|
|
25695
|
+
ret[key] = options[key];
|
|
25696
|
+
});
|
|
25697
|
+
}
|
|
25698
|
+
return ret;
|
|
25699
|
+
},
|
|
25700
|
+
interpolation: {
|
|
25701
|
+
escapeValue: true,
|
|
25702
|
+
format: value => value,
|
|
25703
|
+
prefix: '{{',
|
|
25704
|
+
suffix: '}}',
|
|
25705
|
+
formatSeparator: ',',
|
|
25706
|
+
unescapePrefix: '-',
|
|
25707
|
+
nestingPrefix: '$t(',
|
|
25708
|
+
nestingSuffix: ')',
|
|
25709
|
+
nestingOptionsSeparator: ',',
|
|
25710
|
+
maxReplaces: 1000,
|
|
25711
|
+
skipOnVariables: true
|
|
25712
|
+
}
|
|
25713
|
+
});
|
|
25714
|
+
const transformOptions = options => {
|
|
25715
|
+
if (isString(options.ns)) options.ns = [options.ns];
|
|
25716
|
+
if (isString(options.fallbackLng)) options.fallbackLng = [options.fallbackLng];
|
|
25717
|
+
if (isString(options.fallbackNS)) options.fallbackNS = [options.fallbackNS];
|
|
25718
|
+
if (options.supportedLngs?.indexOf?.('cimode') < 0) {
|
|
25719
|
+
options.supportedLngs = options.supportedLngs.concat(['cimode']);
|
|
25720
|
+
}
|
|
25721
|
+
if (typeof options.initImmediate === 'boolean') options.initAsync = options.initImmediate;
|
|
25722
|
+
return options;
|
|
25723
|
+
};
|
|
25724
|
+
|
|
25725
|
+
const noop = () => {};
|
|
25726
|
+
const bindMemberFunctions = inst => {
|
|
25727
|
+
const mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
|
|
25728
|
+
mems.forEach(mem => {
|
|
25729
|
+
if (typeof inst[mem] === 'function') {
|
|
25730
|
+
inst[mem] = inst[mem].bind(inst);
|
|
25731
|
+
}
|
|
25732
|
+
});
|
|
25733
|
+
};
|
|
25734
|
+
class I18n extends EventEmitter {
|
|
25735
|
+
constructor() {
|
|
25736
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
25737
|
+
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
25738
|
+
super();
|
|
25739
|
+
this.options = transformOptions(options);
|
|
25740
|
+
this.services = {};
|
|
25741
|
+
this.logger = baseLogger;
|
|
25742
|
+
this.modules = {
|
|
25743
|
+
external: []
|
|
25744
|
+
};
|
|
25745
|
+
bindMemberFunctions(this);
|
|
25746
|
+
if (callback && !this.isInitialized && !options.isClone) {
|
|
25747
|
+
if (!this.options.initAsync) {
|
|
25748
|
+
this.init(options, callback);
|
|
25749
|
+
return this;
|
|
25750
|
+
}
|
|
25751
|
+
setTimeout(() => {
|
|
25752
|
+
this.init(options, callback);
|
|
25753
|
+
}, 0);
|
|
25754
|
+
}
|
|
25755
|
+
}
|
|
25756
|
+
init() {
|
|
25757
|
+
var _this = this;
|
|
25758
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
25759
|
+
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
25760
|
+
this.isInitializing = true;
|
|
25761
|
+
if (typeof options === 'function') {
|
|
25762
|
+
callback = options;
|
|
25763
|
+
options = {};
|
|
25764
|
+
}
|
|
25765
|
+
if (options.defaultNS == null && options.ns) {
|
|
25766
|
+
if (isString(options.ns)) {
|
|
25767
|
+
options.defaultNS = options.ns;
|
|
25768
|
+
} else if (options.ns.indexOf('translation') < 0) {
|
|
25769
|
+
options.defaultNS = options.ns[0];
|
|
25770
|
+
}
|
|
25771
|
+
}
|
|
25772
|
+
const defOpts = get$1();
|
|
25773
|
+
this.options = {
|
|
25774
|
+
...defOpts,
|
|
25775
|
+
...this.options,
|
|
25776
|
+
...transformOptions(options)
|
|
25777
|
+
};
|
|
25778
|
+
this.options.interpolation = {
|
|
25779
|
+
...defOpts.interpolation,
|
|
25780
|
+
...this.options.interpolation
|
|
25781
|
+
};
|
|
25782
|
+
if (options.keySeparator !== undefined) {
|
|
25783
|
+
this.options.userDefinedKeySeparator = options.keySeparator;
|
|
25784
|
+
}
|
|
25785
|
+
if (options.nsSeparator !== undefined) {
|
|
25786
|
+
this.options.userDefinedNsSeparator = options.nsSeparator;
|
|
25787
|
+
}
|
|
25788
|
+
const createClassOnDemand = ClassOrObject => {
|
|
25789
|
+
if (!ClassOrObject) return null;
|
|
25790
|
+
if (typeof ClassOrObject === 'function') return new ClassOrObject();
|
|
25791
|
+
return ClassOrObject;
|
|
25792
|
+
};
|
|
25793
|
+
if (!this.options.isClone) {
|
|
25794
|
+
if (this.modules.logger) {
|
|
25795
|
+
baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
|
|
25796
|
+
} else {
|
|
25797
|
+
baseLogger.init(null, this.options);
|
|
25798
|
+
}
|
|
25799
|
+
let formatter;
|
|
25800
|
+
if (this.modules.formatter) {
|
|
25801
|
+
formatter = this.modules.formatter;
|
|
25802
|
+
} else {
|
|
25803
|
+
formatter = Formatter;
|
|
25804
|
+
}
|
|
25805
|
+
const lu = new LanguageUtil(this.options);
|
|
25806
|
+
this.store = new ResourceStore(this.options.resources, this.options);
|
|
25807
|
+
const s = this.services;
|
|
25808
|
+
s.logger = baseLogger;
|
|
25809
|
+
s.resourceStore = this.store;
|
|
25810
|
+
s.languageUtils = lu;
|
|
25811
|
+
s.pluralResolver = new PluralResolver(lu, {
|
|
25812
|
+
prepend: this.options.pluralSeparator,
|
|
25813
|
+
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
25814
|
+
});
|
|
25815
|
+
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
|
|
25816
|
+
s.formatter = createClassOnDemand(formatter);
|
|
25817
|
+
s.formatter.init(s, this.options);
|
|
25818
|
+
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
25819
|
+
}
|
|
25820
|
+
s.interpolator = new Interpolator(this.options);
|
|
25821
|
+
s.utils = {
|
|
25822
|
+
hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
|
|
25823
|
+
};
|
|
25824
|
+
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
25825
|
+
s.backendConnector.on('*', function (event) {
|
|
25826
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
25827
|
+
args[_key - 1] = arguments[_key];
|
|
25828
|
+
}
|
|
25829
|
+
_this.emit(event, ...args);
|
|
25830
|
+
});
|
|
25831
|
+
if (this.modules.languageDetector) {
|
|
25832
|
+
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
25833
|
+
if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
|
|
25834
|
+
}
|
|
25835
|
+
if (this.modules.i18nFormat) {
|
|
25836
|
+
s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
|
|
25837
|
+
if (s.i18nFormat.init) s.i18nFormat.init(this);
|
|
25838
|
+
}
|
|
25839
|
+
this.translator = new Translator(this.services, this.options);
|
|
25840
|
+
this.translator.on('*', function (event) {
|
|
25841
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
25842
|
+
args[_key2 - 1] = arguments[_key2];
|
|
25843
|
+
}
|
|
25844
|
+
_this.emit(event, ...args);
|
|
25845
|
+
});
|
|
25846
|
+
this.modules.external.forEach(m => {
|
|
25847
|
+
if (m.init) m.init(this);
|
|
25848
|
+
});
|
|
25849
|
+
}
|
|
25850
|
+
this.format = this.options.interpolation.format;
|
|
25851
|
+
if (!callback) callback = noop;
|
|
25852
|
+
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
25853
|
+
const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
25854
|
+
if (codes.length > 0 && codes[0] !== 'dev') this.options.lng = codes[0];
|
|
25855
|
+
}
|
|
25856
|
+
if (!this.services.languageDetector && !this.options.lng) {
|
|
25857
|
+
this.logger.warn('init: no languageDetector is used and no lng is defined');
|
|
25858
|
+
}
|
|
25859
|
+
const storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
|
|
25860
|
+
storeApi.forEach(fcName => {
|
|
25861
|
+
this[fcName] = function () {
|
|
25862
|
+
return _this.store[fcName](...arguments);
|
|
25863
|
+
};
|
|
25864
|
+
});
|
|
25865
|
+
const storeApiChained = ['addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle'];
|
|
25866
|
+
storeApiChained.forEach(fcName => {
|
|
25867
|
+
this[fcName] = function () {
|
|
25868
|
+
_this.store[fcName](...arguments);
|
|
25869
|
+
return _this;
|
|
25870
|
+
};
|
|
25871
|
+
});
|
|
25872
|
+
const deferred = defer();
|
|
25873
|
+
const load = () => {
|
|
25874
|
+
const finish = (err, t) => {
|
|
25875
|
+
this.isInitializing = false;
|
|
25876
|
+
if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn('init: i18next is already initialized. You should call init just once!');
|
|
25877
|
+
this.isInitialized = true;
|
|
25878
|
+
if (!this.options.isClone) this.logger.log('initialized', this.options);
|
|
25879
|
+
this.emit('initialized', this.options);
|
|
25880
|
+
deferred.resolve(t);
|
|
25881
|
+
callback(err, t);
|
|
25882
|
+
};
|
|
25883
|
+
if (this.languages && !this.isInitialized) return finish(null, this.t.bind(this));
|
|
25884
|
+
this.changeLanguage(this.options.lng, finish);
|
|
25885
|
+
};
|
|
25886
|
+
if (this.options.resources || !this.options.initAsync) {
|
|
25887
|
+
load();
|
|
25888
|
+
} else {
|
|
25889
|
+
setTimeout(load, 0);
|
|
25890
|
+
}
|
|
25891
|
+
return deferred;
|
|
25892
|
+
}
|
|
25893
|
+
loadResources(language) {
|
|
25894
|
+
let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
|
|
25895
|
+
let usedCallback = callback;
|
|
25896
|
+
const usedLng = isString(language) ? language : this.language;
|
|
25897
|
+
if (typeof language === 'function') usedCallback = language;
|
|
25898
|
+
if (!this.options.resources || this.options.partialBundledLanguages) {
|
|
25899
|
+
if (usedLng?.toLowerCase() === 'cimode' && (!this.options.preload || this.options.preload.length === 0)) return usedCallback();
|
|
25900
|
+
const toLoad = [];
|
|
25901
|
+
const append = lng => {
|
|
25902
|
+
if (!lng) return;
|
|
25903
|
+
if (lng === 'cimode') return;
|
|
25904
|
+
const lngs = this.services.languageUtils.toResolveHierarchy(lng);
|
|
25905
|
+
lngs.forEach(l => {
|
|
25906
|
+
if (l === 'cimode') return;
|
|
25907
|
+
if (toLoad.indexOf(l) < 0) toLoad.push(l);
|
|
25908
|
+
});
|
|
25909
|
+
};
|
|
25910
|
+
if (!usedLng) {
|
|
25911
|
+
const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
25912
|
+
fallbacks.forEach(l => append(l));
|
|
25913
|
+
} else {
|
|
25914
|
+
append(usedLng);
|
|
25915
|
+
}
|
|
25916
|
+
this.options.preload?.forEach?.(l => append(l));
|
|
25917
|
+
this.services.backendConnector.load(toLoad, this.options.ns, e => {
|
|
25918
|
+
if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
|
|
25919
|
+
usedCallback(e);
|
|
25920
|
+
});
|
|
25921
|
+
} else {
|
|
25922
|
+
usedCallback(null);
|
|
25923
|
+
}
|
|
25924
|
+
}
|
|
25925
|
+
reloadResources(lngs, ns, callback) {
|
|
25926
|
+
const deferred = defer();
|
|
25927
|
+
if (typeof lngs === 'function') {
|
|
25928
|
+
callback = lngs;
|
|
25929
|
+
lngs = undefined;
|
|
25930
|
+
}
|
|
25931
|
+
if (typeof ns === 'function') {
|
|
25932
|
+
callback = ns;
|
|
25933
|
+
ns = undefined;
|
|
25934
|
+
}
|
|
25935
|
+
if (!lngs) lngs = this.languages;
|
|
25936
|
+
if (!ns) ns = this.options.ns;
|
|
25937
|
+
if (!callback) callback = noop;
|
|
25938
|
+
this.services.backendConnector.reload(lngs, ns, err => {
|
|
25939
|
+
deferred.resolve();
|
|
25940
|
+
callback(err);
|
|
25941
|
+
});
|
|
25942
|
+
return deferred;
|
|
25943
|
+
}
|
|
25944
|
+
use(module) {
|
|
25945
|
+
if (!module) throw new Error('You are passing an undefined module! Please check the object you are passing to i18next.use()');
|
|
25946
|
+
if (!module.type) throw new Error('You are passing a wrong module! Please check the object you are passing to i18next.use()');
|
|
25947
|
+
if (module.type === 'backend') {
|
|
25948
|
+
this.modules.backend = module;
|
|
25949
|
+
}
|
|
25950
|
+
if (module.type === 'logger' || module.log && module.warn && module.error) {
|
|
25951
|
+
this.modules.logger = module;
|
|
25952
|
+
}
|
|
25953
|
+
if (module.type === 'languageDetector') {
|
|
25954
|
+
this.modules.languageDetector = module;
|
|
25955
|
+
}
|
|
25956
|
+
if (module.type === 'i18nFormat') {
|
|
25957
|
+
this.modules.i18nFormat = module;
|
|
25958
|
+
}
|
|
25959
|
+
if (module.type === 'postProcessor') {
|
|
25960
|
+
postProcessor.addPostProcessor(module);
|
|
25961
|
+
}
|
|
25962
|
+
if (module.type === 'formatter') {
|
|
25963
|
+
this.modules.formatter = module;
|
|
25964
|
+
}
|
|
25965
|
+
if (module.type === '3rdParty') {
|
|
25966
|
+
this.modules.external.push(module);
|
|
25967
|
+
}
|
|
25968
|
+
return this;
|
|
25969
|
+
}
|
|
25970
|
+
setResolvedLanguage(l) {
|
|
25971
|
+
if (!l || !this.languages) return;
|
|
25972
|
+
if (['cimode', 'dev'].indexOf(l) > -1) return;
|
|
25973
|
+
for (let li = 0; li < this.languages.length; li++) {
|
|
25974
|
+
const lngInLngs = this.languages[li];
|
|
25975
|
+
if (['cimode', 'dev'].indexOf(lngInLngs) > -1) continue;
|
|
25976
|
+
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
25977
|
+
this.resolvedLanguage = lngInLngs;
|
|
25978
|
+
break;
|
|
25979
|
+
}
|
|
25980
|
+
}
|
|
25981
|
+
if (!this.resolvedLanguage && this.languages.indexOf(l) < 0 && this.store.hasLanguageSomeTranslations(l)) {
|
|
25982
|
+
this.resolvedLanguage = l;
|
|
25983
|
+
if (this.languages.indexOf(l) < 0) this.languages.unshift(l);
|
|
25984
|
+
}
|
|
25985
|
+
}
|
|
25986
|
+
changeLanguage(lng, callback) {
|
|
25987
|
+
var _this2 = this;
|
|
25988
|
+
this.isLanguageChangingTo = lng;
|
|
25989
|
+
const deferred = defer();
|
|
25990
|
+
this.emit('languageChanging', lng);
|
|
25991
|
+
const setLngProps = l => {
|
|
25992
|
+
this.language = l;
|
|
25993
|
+
this.languages = this.services.languageUtils.toResolveHierarchy(l);
|
|
25994
|
+
this.resolvedLanguage = undefined;
|
|
25995
|
+
this.setResolvedLanguage(l);
|
|
25996
|
+
};
|
|
25997
|
+
const done = (err, l) => {
|
|
25998
|
+
if (l) {
|
|
25999
|
+
if (this.isLanguageChangingTo === lng) {
|
|
26000
|
+
setLngProps(l);
|
|
26001
|
+
this.translator.changeLanguage(l);
|
|
26002
|
+
this.isLanguageChangingTo = undefined;
|
|
26003
|
+
this.emit('languageChanged', l);
|
|
26004
|
+
this.logger.log('languageChanged', l);
|
|
26005
|
+
}
|
|
26006
|
+
} else {
|
|
26007
|
+
this.isLanguageChangingTo = undefined;
|
|
26008
|
+
}
|
|
26009
|
+
deferred.resolve(function () {
|
|
26010
|
+
return _this2.t(...arguments);
|
|
26011
|
+
});
|
|
26012
|
+
if (callback) callback(err, function () {
|
|
26013
|
+
return _this2.t(...arguments);
|
|
26014
|
+
});
|
|
26015
|
+
};
|
|
26016
|
+
const setLng = lngs => {
|
|
26017
|
+
if (!lng && !lngs && this.services.languageDetector) lngs = [];
|
|
26018
|
+
const fl = isString(lngs) ? lngs : lngs && lngs[0];
|
|
26019
|
+
const l = this.store.hasLanguageSomeTranslations(fl) ? fl : this.services.languageUtils.getBestMatchFromCodes(isString(lngs) ? [lngs] : lngs);
|
|
26020
|
+
if (l) {
|
|
26021
|
+
if (!this.language) {
|
|
26022
|
+
setLngProps(l);
|
|
26023
|
+
}
|
|
26024
|
+
if (!this.translator.language) this.translator.changeLanguage(l);
|
|
26025
|
+
this.services.languageDetector?.cacheUserLanguage?.(l);
|
|
26026
|
+
}
|
|
26027
|
+
this.loadResources(l, err => {
|
|
26028
|
+
done(err, l);
|
|
26029
|
+
});
|
|
26030
|
+
};
|
|
26031
|
+
if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
|
|
26032
|
+
setLng(this.services.languageDetector.detect());
|
|
26033
|
+
} else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
|
|
26034
|
+
if (this.services.languageDetector.detect.length === 0) {
|
|
26035
|
+
this.services.languageDetector.detect().then(setLng);
|
|
26036
|
+
} else {
|
|
26037
|
+
this.services.languageDetector.detect(setLng);
|
|
26038
|
+
}
|
|
26039
|
+
} else {
|
|
26040
|
+
setLng(lng);
|
|
26041
|
+
}
|
|
26042
|
+
return deferred;
|
|
26043
|
+
}
|
|
26044
|
+
getFixedT(lng, ns, keyPrefix) {
|
|
26045
|
+
var _this3 = this;
|
|
26046
|
+
const fixedT = function (key, opts) {
|
|
26047
|
+
let o;
|
|
26048
|
+
if (typeof opts !== 'object') {
|
|
26049
|
+
for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
26050
|
+
rest[_key3 - 2] = arguments[_key3];
|
|
26051
|
+
}
|
|
26052
|
+
o = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
26053
|
+
} else {
|
|
26054
|
+
o = {
|
|
26055
|
+
...opts
|
|
26056
|
+
};
|
|
26057
|
+
}
|
|
26058
|
+
o.lng = o.lng || fixedT.lng;
|
|
26059
|
+
o.lngs = o.lngs || fixedT.lngs;
|
|
26060
|
+
o.ns = o.ns || fixedT.ns;
|
|
26061
|
+
if (o.keyPrefix !== '') o.keyPrefix = o.keyPrefix || keyPrefix || fixedT.keyPrefix;
|
|
26062
|
+
const keySeparator = _this3.options.keySeparator || '.';
|
|
26063
|
+
let resultKey;
|
|
26064
|
+
if (o.keyPrefix && Array.isArray(key)) {
|
|
26065
|
+
resultKey = key.map(k => `${o.keyPrefix}${keySeparator}${k}`);
|
|
26066
|
+
} else {
|
|
26067
|
+
resultKey = o.keyPrefix ? `${o.keyPrefix}${keySeparator}${key}` : key;
|
|
26068
|
+
}
|
|
26069
|
+
return _this3.t(resultKey, o);
|
|
26070
|
+
};
|
|
26071
|
+
if (isString(lng)) {
|
|
26072
|
+
fixedT.lng = lng;
|
|
26073
|
+
} else {
|
|
26074
|
+
fixedT.lngs = lng;
|
|
26075
|
+
}
|
|
26076
|
+
fixedT.ns = ns;
|
|
26077
|
+
fixedT.keyPrefix = keyPrefix;
|
|
26078
|
+
return fixedT;
|
|
26079
|
+
}
|
|
26080
|
+
t() {
|
|
26081
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
26082
|
+
args[_key4] = arguments[_key4];
|
|
26083
|
+
}
|
|
26084
|
+
return this.translator?.translate(...args);
|
|
26085
|
+
}
|
|
26086
|
+
exists() {
|
|
26087
|
+
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
26088
|
+
args[_key5] = arguments[_key5];
|
|
26089
|
+
}
|
|
26090
|
+
return this.translator?.exists(...args);
|
|
26091
|
+
}
|
|
26092
|
+
setDefaultNamespace(ns) {
|
|
26093
|
+
this.options.defaultNS = ns;
|
|
26094
|
+
}
|
|
26095
|
+
hasLoadedNamespace(ns) {
|
|
26096
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
26097
|
+
if (!this.isInitialized) {
|
|
26098
|
+
this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
|
|
26099
|
+
return false;
|
|
26100
|
+
}
|
|
26101
|
+
if (!this.languages || !this.languages.length) {
|
|
26102
|
+
this.logger.warn('hasLoadedNamespace: i18n.languages were undefined or empty', this.languages);
|
|
26103
|
+
return false;
|
|
26104
|
+
}
|
|
26105
|
+
const lng = options.lng || this.resolvedLanguage || this.languages[0];
|
|
26106
|
+
const fallbackLng = this.options ? this.options.fallbackLng : false;
|
|
26107
|
+
const lastLng = this.languages[this.languages.length - 1];
|
|
26108
|
+
if (lng.toLowerCase() === 'cimode') return true;
|
|
26109
|
+
const loadNotPending = (l, n) => {
|
|
26110
|
+
const loadState = this.services.backendConnector.state[`${l}|${n}`];
|
|
26111
|
+
return loadState === -1 || loadState === 0 || loadState === 2;
|
|
26112
|
+
};
|
|
26113
|
+
if (options.precheck) {
|
|
26114
|
+
const preResult = options.precheck(this, loadNotPending);
|
|
26115
|
+
if (preResult !== undefined) return preResult;
|
|
26116
|
+
}
|
|
26117
|
+
if (this.hasResourceBundle(lng, ns)) return true;
|
|
26118
|
+
if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
|
|
26119
|
+
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
26120
|
+
return false;
|
|
26121
|
+
}
|
|
26122
|
+
loadNamespaces(ns, callback) {
|
|
26123
|
+
const deferred = defer();
|
|
26124
|
+
if (!this.options.ns) {
|
|
26125
|
+
if (callback) callback();
|
|
26126
|
+
return Promise.resolve();
|
|
26127
|
+
}
|
|
26128
|
+
if (isString(ns)) ns = [ns];
|
|
26129
|
+
ns.forEach(n => {
|
|
26130
|
+
if (this.options.ns.indexOf(n) < 0) this.options.ns.push(n);
|
|
26131
|
+
});
|
|
26132
|
+
this.loadResources(err => {
|
|
26133
|
+
deferred.resolve();
|
|
26134
|
+
if (callback) callback(err);
|
|
26135
|
+
});
|
|
26136
|
+
return deferred;
|
|
26137
|
+
}
|
|
26138
|
+
loadLanguages(lngs, callback) {
|
|
26139
|
+
const deferred = defer();
|
|
26140
|
+
if (isString(lngs)) lngs = [lngs];
|
|
26141
|
+
const preloaded = this.options.preload || [];
|
|
26142
|
+
const newLngs = lngs.filter(lng => preloaded.indexOf(lng) < 0 && this.services.languageUtils.isSupportedCode(lng));
|
|
26143
|
+
if (!newLngs.length) {
|
|
26144
|
+
if (callback) callback();
|
|
26145
|
+
return Promise.resolve();
|
|
26146
|
+
}
|
|
26147
|
+
this.options.preload = preloaded.concat(newLngs);
|
|
26148
|
+
this.loadResources(err => {
|
|
26149
|
+
deferred.resolve();
|
|
26150
|
+
if (callback) callback(err);
|
|
26151
|
+
});
|
|
26152
|
+
return deferred;
|
|
26153
|
+
}
|
|
26154
|
+
dir(lng) {
|
|
26155
|
+
if (!lng) lng = this.resolvedLanguage || (this.languages?.length > 0 ? this.languages[0] : this.language);
|
|
26156
|
+
if (!lng) return 'rtl';
|
|
26157
|
+
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'];
|
|
26158
|
+
const languageUtils = this.services?.languageUtils || new LanguageUtil(get$1());
|
|
26159
|
+
return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
|
|
26160
|
+
}
|
|
26161
|
+
static createInstance() {
|
|
26162
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
26163
|
+
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
26164
|
+
return new I18n(options, callback);
|
|
26165
|
+
}
|
|
26166
|
+
cloneInstance() {
|
|
26167
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
26168
|
+
let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
|
|
26169
|
+
const forkResourceStore = options.forkResourceStore;
|
|
26170
|
+
if (forkResourceStore) delete options.forkResourceStore;
|
|
26171
|
+
const mergedOptions = {
|
|
26172
|
+
...this.options,
|
|
26173
|
+
...options,
|
|
26174
|
+
...{
|
|
26175
|
+
isClone: true
|
|
26176
|
+
}
|
|
26177
|
+
};
|
|
26178
|
+
const clone = new I18n(mergedOptions);
|
|
26179
|
+
if (options.debug !== undefined || options.prefix !== undefined) {
|
|
26180
|
+
clone.logger = clone.logger.clone(options);
|
|
26181
|
+
}
|
|
26182
|
+
const membersToCopy = ['store', 'services', 'language'];
|
|
26183
|
+
membersToCopy.forEach(m => {
|
|
26184
|
+
clone[m] = this[m];
|
|
26185
|
+
});
|
|
26186
|
+
clone.services = {
|
|
26187
|
+
...this.services
|
|
26188
|
+
};
|
|
26189
|
+
clone.services.utils = {
|
|
26190
|
+
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
26191
|
+
};
|
|
26192
|
+
if (forkResourceStore) {
|
|
26193
|
+
const clonedData = Object.keys(this.store.data).reduce((prev, l) => {
|
|
26194
|
+
prev[l] = {
|
|
26195
|
+
...this.store.data[l]
|
|
26196
|
+
};
|
|
26197
|
+
return Object.keys(prev[l]).reduce((acc, n) => {
|
|
26198
|
+
acc[n] = {
|
|
26199
|
+
...prev[l][n]
|
|
26200
|
+
};
|
|
26201
|
+
return acc;
|
|
26202
|
+
}, {});
|
|
26203
|
+
}, {});
|
|
26204
|
+
clone.store = new ResourceStore(clonedData, mergedOptions);
|
|
26205
|
+
clone.services.resourceStore = clone.store;
|
|
26206
|
+
}
|
|
26207
|
+
clone.translator = new Translator(clone.services, mergedOptions);
|
|
26208
|
+
clone.translator.on('*', function (event) {
|
|
26209
|
+
for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
|
|
26210
|
+
args[_key6 - 1] = arguments[_key6];
|
|
26211
|
+
}
|
|
26212
|
+
clone.emit(event, ...args);
|
|
26213
|
+
});
|
|
26214
|
+
clone.init(mergedOptions, callback);
|
|
26215
|
+
clone.translator.options = mergedOptions;
|
|
26216
|
+
clone.translator.backendConnector.services.utils = {
|
|
26217
|
+
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
26218
|
+
};
|
|
26219
|
+
return clone;
|
|
26220
|
+
}
|
|
26221
|
+
toJSON() {
|
|
26222
|
+
return {
|
|
26223
|
+
options: this.options,
|
|
26224
|
+
store: this.store,
|
|
26225
|
+
language: this.language,
|
|
26226
|
+
languages: this.languages,
|
|
26227
|
+
resolvedLanguage: this.resolvedLanguage
|
|
26228
|
+
};
|
|
26229
|
+
}
|
|
26230
|
+
}
|
|
26231
|
+
const instance = I18n.createInstance();
|
|
26232
|
+
instance.createInstance = I18n.createInstance;
|
|
26233
|
+
|
|
26234
|
+
const createInstance = instance.createInstance;
|
|
26235
|
+
instance.dir;
|
|
26236
|
+
instance.init;
|
|
26237
|
+
instance.loadResources;
|
|
26238
|
+
instance.reloadResources;
|
|
26239
|
+
instance.use;
|
|
26240
|
+
instance.changeLanguage;
|
|
26241
|
+
instance.getFixedT;
|
|
26242
|
+
instance.t;
|
|
26243
|
+
instance.exists;
|
|
26244
|
+
instance.setDefaultNamespace;
|
|
26245
|
+
instance.hasLoadedNamespace;
|
|
26246
|
+
instance.loadNamespaces;
|
|
26247
|
+
instance.loadLanguages;
|
|
26248
|
+
|
|
24013
26249
|
/*!
|
|
24014
26250
|
* path-root-regex <https://github.com/jonschlinkert/path-root-regex>
|
|
24015
26251
|
*
|
|
@@ -24575,7 +26811,7 @@ function getPackageNameFromPath(input) {
|
|
|
24575
26811
|
|
|
24576
26812
|
// src/importer.js
|
|
24577
26813
|
var { findUpPackagePath } = resolvePackagePath;
|
|
24578
|
-
var require2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vendor-
|
|
26814
|
+
var require2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vendor-CIZoJHXd.js', document.baseURI).href)));
|
|
24579
26815
|
var WEBPACK_NODE_MODULE_PREFIX = "~";
|
|
24580
26816
|
var selfPackageJson = null;
|
|
24581
26817
|
var selfPackageJsonPath = null;
|
|
@@ -24587,7 +26823,7 @@ var moduleImporter = {
|
|
|
24587
26823
|
findUrl = url.substring(1);
|
|
24588
26824
|
}
|
|
24589
26825
|
const packageName = getPackageNameFromPath(findUrl);
|
|
24590
|
-
const filePath = findUrl.
|
|
26826
|
+
const filePath = findUrl.replace(packageName, "");
|
|
24591
26827
|
if (!packageName) {
|
|
24592
26828
|
return null;
|
|
24593
26829
|
}
|
|
@@ -25247,11 +27483,11 @@ function requireFormatter () {
|
|
|
25247
27483
|
return formatter;
|
|
25248
27484
|
}
|
|
25249
27485
|
|
|
25250
|
-
var options;
|
|
27486
|
+
var options$1;
|
|
25251
27487
|
var hasRequiredOptions;
|
|
25252
27488
|
|
|
25253
27489
|
function requireOptions () {
|
|
25254
|
-
if (hasRequiredOptions) return options;
|
|
27490
|
+
if (hasRequiredOptions) return options$1;
|
|
25255
27491
|
hasRequiredOptions = 1;
|
|
25256
27492
|
// utility to merge defaults
|
|
25257
27493
|
function mergeOption(v, defaultValue){
|
|
@@ -25262,7 +27498,7 @@ function requireOptions () {
|
|
|
25262
27498
|
}
|
|
25263
27499
|
}
|
|
25264
27500
|
|
|
25265
|
-
options = {
|
|
27501
|
+
options$1 = {
|
|
25266
27502
|
// set global options
|
|
25267
27503
|
parse: function parse(rawOptions, preset){
|
|
25268
27504
|
|
|
@@ -25363,7 +27599,7 @@ function requireOptions () {
|
|
|
25363
27599
|
return options;
|
|
25364
27600
|
}
|
|
25365
27601
|
};
|
|
25366
|
-
return options;
|
|
27602
|
+
return options$1;
|
|
25367
27603
|
}
|
|
25368
27604
|
|
|
25369
27605
|
var genericBar;
|
|
@@ -54841,6 +57077,7 @@ exports.HighlightJS = HighlightJS;
|
|
|
54841
57077
|
exports.MarkdownIt = MarkdownIt;
|
|
54842
57078
|
exports.cliProgress = cliProgress;
|
|
54843
57079
|
exports.closest = closest;
|
|
57080
|
+
exports.createInstance = createInstance;
|
|
54844
57081
|
exports.createTwoFilesPatch = createTwoFilesPatch;
|
|
54845
57082
|
exports.dedent = dedent;
|
|
54846
57083
|
exports.deflist_plugin = deflist_plugin;
|
|
@@ -54855,4 +57092,4 @@ exports.moduleImporter = moduleImporter;
|
|
|
54855
57092
|
exports.spawn = spawn;
|
|
54856
57093
|
exports.tinylr = tinylr;
|
|
54857
57094
|
exports.watch = watch$1;
|
|
54858
|
-
//# sourceMappingURL=vendor-
|
|
57095
|
+
//# sourceMappingURL=vendor-CIZoJHXd.js.map
|