@fleox-agent-crm/agentcrm 0.0.0-stage → 0.3.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/LICENSE +143 -0
- package/README.md +223 -2
- package/changelog.json +76 -0
- package/dist/admin/admin-files.json +26 -0
- package/dist/admin/assets/chartsImpl-B45AAqnr.js +91 -0
- package/dist/admin/assets/firebase-C1x_l9P9.js +2 -0
- package/dist/admin/assets/gitJson-CAUSxl8d.js +3 -0
- package/dist/admin/assets/index-ChFauO8y.js +1181 -0
- package/dist/admin/assets/index-TcjySLVg.css +1 -0
- package/dist/admin/assets/index.esm-BFc7vwnl.js +400 -0
- package/dist/admin/assets/index.esm-CtEQZRb1.js +1651 -0
- package/dist/admin/assets/index.esm-Dum0J07z.js +16 -0
- package/dist/admin/assets/index.esm2017-EOzKbpUS.js +390 -0
- package/dist/admin/assets/lucide-react.min--rznIkmQ.js +6 -0
- package/dist/admin/assets/sdk-DgzLACmL.js +1717 -0
- package/dist/admin/config.js +3 -0
- package/dist/admin/favicon.svg +1 -0
- package/dist/admin/index.html +139 -0
- package/dist/admin/runtime/agentcrm-runtime.js +104 -0
- package/dist/admin/runtime/lucide-react.js +791 -0
- package/dist/admin/runtime/react-dom-client.js +17 -0
- package/dist/admin/runtime/react-dom.js +20 -0
- package/dist/admin/runtime/react-i18next.js +19 -0
- package/dist/admin/runtime/react-jsx-runtime.js +17 -0
- package/dist/admin/runtime/react.js +22 -0
- package/dist/agent/agentcrm.mjs +4057 -0
- package/dist/agent/chunks/_commonjsHelpers-ClciMIcB.mjs +14 -0
- package/dist/agent/chunks/activities-Cj_SIOay.mjs +227 -0
- package/dist/agent/chunks/api-Cz0Ubj-B.mjs +98 -0
- package/dist/agent/chunks/appearance-BloHbiLA.mjs +174 -0
- package/dist/agent/chunks/automations-DwWruxmu.mjs +698 -0
- package/dist/agent/chunks/backup-W3CjgkAJ.mjs +116 -0
- package/dist/agent/chunks/batch-CVETiJj5.mjs +142 -0
- package/dist/agent/chunks/compact-BGHI92tm.mjs +69 -0
- package/dist/agent/chunks/context-CxFfqS4D.mjs +65 -0
- package/dist/agent/chunks/core-Dy7vY9H6.mjs +255 -0
- package/dist/agent/chunks/dedupe-BepmsaHv.mjs +123 -0
- package/dist/agent/chunks/encoding-C9MzdP95.mjs +36 -0
- package/dist/agent/chunks/exportCsv-C6e6XEmB.mjs +130 -0
- package/dist/agent/chunks/extCheck-GgHG1dYB.mjs +200 -0
- package/dist/agent/chunks/extPackage-DuZ6GZhp.mjs +115 -0
- package/dist/agent/chunks/extScaffold-Aqyjf1nr.mjs +320 -0
- package/dist/agent/chunks/extensionActions-D2HtpQz4.mjs +48 -0
- package/dist/agent/chunks/extensions-Bp72uZ9a.mjs +164 -0
- package/dist/agent/chunks/featureRegistry-DSsZbhrh.mjs +149 -0
- package/dist/agent/chunks/fields-B0bitgmr.mjs +476 -0
- package/dist/agent/chunks/files-CjsPJSR6.mjs +158 -0
- package/dist/agent/chunks/files-D1daDgY0.mjs +367 -0
- package/dist/agent/chunks/firebase-DxGVQV9E.mjs +454 -0
- package/dist/agent/chunks/firebaseRules-iori-s7U.mjs +221 -0
- package/dist/agent/chunks/forms-BfuWaQjA.mjs +847 -0
- package/dist/agent/chunks/gitJson-fjr8mcHe.mjs +528 -0
- package/dist/agent/chunks/hosting-Bme7LxPc.mjs +144 -0
- package/dist/agent/chunks/http-Bk9ICb7I.mjs +127 -0
- package/dist/agent/chunks/ids-CvnmrMJX.mjs +59 -0
- package/dist/agent/chunks/ids-u-noYcy5.mjs +14 -0
- package/dist/agent/chunks/importCsv-LVmMTaWU.mjs +334 -0
- package/dist/agent/chunks/index-B-4W0-P4.mjs +535 -0
- package/dist/agent/chunks/index-BM8qeGOb.mjs +2489 -0
- package/dist/agent/chunks/index-Bnmav-Oh.mjs +311 -0
- package/dist/agent/chunks/index-CRkw3_iF.mjs +147 -0
- package/dist/agent/chunks/index-CWrrF1wl.mjs +111 -0
- package/dist/agent/chunks/index-DUSdTBkz.mjs +2988 -0
- package/dist/agent/chunks/index-RCmo-uld.mjs +26 -0
- package/dist/agent/chunks/index-w03ReRs4.mjs +9780 -0
- package/dist/agent/chunks/install-CbpD_7gd.mjs +188 -0
- package/dist/agent/chunks/jsx-runtime-Ca2uwGDr.mjs +76 -0
- package/dist/agent/chunks/loader-MPD9iAvh.mjs +184 -0
- package/dist/agent/chunks/lucide-react.min-Bt3gtepY.mjs +64 -0
- package/dist/agent/chunks/memory-WNR3VHUJ.mjs +56 -0
- package/dist/agent/chunks/migrate-CsClnnN8.mjs +182 -0
- package/dist/agent/chunks/modules-clWdE-K2.mjs +202 -0
- package/dist/agent/chunks/nodeImport-ylfRDvqt.mjs +38 -0
- package/dist/agent/chunks/package-B7mI6HGi.mjs +194 -0
- package/dist/agent/chunks/papaparse-Df7i1dHr.mjs +1309 -0
- package/dist/agent/chunks/pipelines-BAKpPk1w.mjs +234 -0
- package/dist/agent/chunks/plan-BmTat6-T.mjs +254 -0
- package/dist/agent/chunks/pluginRegistry-DyHtlkcr.mjs +83 -0
- package/dist/agent/chunks/query-C5nJB_3C.mjs +192 -0
- package/dist/agent/chunks/records-DcHFelq5.mjs +2195 -0
- package/dist/agent/chunks/registry-COfJrSmg.mjs +182 -0
- package/dist/agent/chunks/registry-DijAKZ24.mjs +431 -0
- package/dist/agent/chunks/relations-B9TynBmA.mjs +191 -0
- package/dist/agent/chunks/reports-BACHGccj.mjs +189 -0
- package/dist/agent/chunks/runtime-C0Xf0Axi.mjs +14873 -0
- package/dist/agent/chunks/runtimeConfig-CCOFg1RM.mjs +250 -0
- package/dist/agent/chunks/s3-Dz50-NuA.mjs +903 -0
- package/dist/agent/chunks/schema-C4lSslXv.mjs +373 -0
- package/dist/agent/chunks/schema-DnLj8dUO.mjs +213 -0
- package/dist/agent/chunks/sdk-whvfg786.mjs +43644 -0
- package/dist/agent/chunks/seed-6MRmQQBR.mjs +541 -0
- package/dist/agent/chunks/server-DC3t8r30.mjs +242 -0
- package/dist/agent/chunks/settings-Di8nzNEL.mjs +111 -0
- package/dist/agent/chunks/standardObjects-CheqfDqa.mjs +243 -0
- package/dist/agent/chunks/stats-BfuLWhVV.mjs +51 -0
- package/dist/agent/chunks/store-5gqRSKXg.mjs +122 -0
- package/dist/agent/chunks/themes-DPZFv3yc.mjs +43 -0
- package/dist/agent/chunks/tools-iSH-yMpl.mjs +884 -0
- package/dist/agent/chunks/types-BOy9PUl7.mjs +44 -0
- package/dist/agent/chunks/users-DI1BvS0f.mjs +107 -0
- package/dist/agent/chunks/utils-DmI8FtXP.mjs +83 -0
- package/dist/agent/chunks/views-DH1n9Lrt.mjs +109 -0
- package/dist/version.json +7 -0
- package/package.json +97 -4
- package/plugin/.claude-plugin/plugin.json +17 -0
- package/plugin/skills/agentcrm-admin/SKILL.md +191 -0
- package/plugin/skills/agentcrm-admin/references/appearance.md +26 -0
- package/plugin/skills/agentcrm-admin/references/import.md +16 -0
- package/plugin/skills/agentcrm-admin/references/records.md +30 -0
- package/plugin/skills/agentcrm-admin/references/schema.md +59 -0
- package/plugin/skills/agentcrm-extensions/SKILL.md +93 -0
- package/plugin/skills/agentcrm-extensions/references/module-recipes.md +213 -0
- package/plugin/skills/agentcrm-extensions/references/runtime-api.md +41 -0
- package/plugin/skills/agentcrm-extensions/references/testing.md +78 -0
- package/plugin/skills/agentcrm-extensions/references/theme-recipes.md +65 -0
- package/plugin/skills/agentcrm-install/SKILL.md +116 -0
- package/plugin/skills/agentcrm-install/references/firebase.md +18 -0
- package/plugin/skills/agentcrm-install/references/github.md +20 -0
- package/plugin/skills/agentcrm-install/references/mcp.md +17 -0
- package/plugin/skills/agentcrm-install/references/plans.md +45 -0
- package/plugin/skills/agentcrm-install/references/s3.md +24 -0
- package/plugin/skills/agentcrm-manage/SKILL.md +108 -0
- package/plugin/skills/agentcrm-manage/references/cron.md +11 -0
- package/plugin/skills/agentcrm-manage/references/doctor.md +18 -0
- package/plugin/skills/agentcrm-sales/SKILL.md +92 -0
- package/plugin/skills/agentcrm-sales/references/enrichment.md +13 -0
- package/plugin/skills/agentcrm-sales/references/playbooks.md +29 -0
- package/plugin/skills/agentcrm-sales/references/weekly-report.md +27 -0
- package/types/agentcrm-runtime.d.ts +894 -0
|
@@ -0,0 +1,2489 @@
|
|
|
1
|
+
import { createRequire as __acrmRequire } from "node:module";
|
|
2
|
+
import { fileURLToPath as __acrmPath } from "node:url";
|
|
3
|
+
import { dirname as __acrmDirname } from "node:path";
|
|
4
|
+
const require2 = __acrmRequire(import.meta.url);
|
|
5
|
+
const __filename = __acrmPath(import.meta.url);
|
|
6
|
+
const __dirname = __acrmDirname(__filename);
|
|
7
|
+
const isString = (obj) => typeof obj === "string";
|
|
8
|
+
const defer = () => {
|
|
9
|
+
let res;
|
|
10
|
+
let rej;
|
|
11
|
+
const promise = new Promise((resolve, reject) => {
|
|
12
|
+
res = resolve;
|
|
13
|
+
rej = reject;
|
|
14
|
+
});
|
|
15
|
+
promise.resolve = res;
|
|
16
|
+
promise.reject = rej;
|
|
17
|
+
return promise;
|
|
18
|
+
};
|
|
19
|
+
const makeString = (object) => {
|
|
20
|
+
if (object == null) return "";
|
|
21
|
+
return "" + object;
|
|
22
|
+
};
|
|
23
|
+
const copy = (a, s, t) => {
|
|
24
|
+
a.forEach((m) => {
|
|
25
|
+
if (s[m]) t[m] = s[m];
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const lastOfPathSeparatorRegExp = /###/g;
|
|
29
|
+
const cleanKey = (key) => key && key.indexOf("###") > -1 ? key.replace(lastOfPathSeparatorRegExp, ".") : key;
|
|
30
|
+
const canNotTraverseDeeper = (object) => !object || isString(object);
|
|
31
|
+
const getLastOfPath = (object, path, Empty) => {
|
|
32
|
+
const stack = !isString(path) ? path : path.split(".");
|
|
33
|
+
let stackIndex = 0;
|
|
34
|
+
while (stackIndex < stack.length - 1) {
|
|
35
|
+
if (canNotTraverseDeeper(object)) return {};
|
|
36
|
+
const key = cleanKey(stack[stackIndex]);
|
|
37
|
+
if (!object[key] && Empty) object[key] = new Empty();
|
|
38
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
39
|
+
object = object[key];
|
|
40
|
+
} else {
|
|
41
|
+
object = {};
|
|
42
|
+
}
|
|
43
|
+
++stackIndex;
|
|
44
|
+
}
|
|
45
|
+
if (canNotTraverseDeeper(object)) return {};
|
|
46
|
+
return {
|
|
47
|
+
obj: object,
|
|
48
|
+
k: cleanKey(stack[stackIndex])
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
const setPath = (object, path, newValue) => {
|
|
52
|
+
const {
|
|
53
|
+
obj,
|
|
54
|
+
k
|
|
55
|
+
} = getLastOfPath(object, path, Object);
|
|
56
|
+
if (obj !== void 0 || path.length === 1) {
|
|
57
|
+
obj[k] = newValue;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
let e = path[path.length - 1];
|
|
61
|
+
let p = path.slice(0, path.length - 1);
|
|
62
|
+
let last = getLastOfPath(object, p, Object);
|
|
63
|
+
while (last.obj === void 0 && p.length) {
|
|
64
|
+
e = `${p[p.length - 1]}.${e}`;
|
|
65
|
+
p = p.slice(0, p.length - 1);
|
|
66
|
+
last = getLastOfPath(object, p, Object);
|
|
67
|
+
if (last && last.obj && typeof last.obj[`${last.k}.${e}`] !== "undefined") {
|
|
68
|
+
last.obj = void 0;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
last.obj[`${last.k}.${e}`] = newValue;
|
|
72
|
+
};
|
|
73
|
+
const pushPath = (object, path, newValue, concat) => {
|
|
74
|
+
const {
|
|
75
|
+
obj,
|
|
76
|
+
k
|
|
77
|
+
} = getLastOfPath(object, path, Object);
|
|
78
|
+
obj[k] = obj[k] || [];
|
|
79
|
+
obj[k].push(newValue);
|
|
80
|
+
};
|
|
81
|
+
const getPath = (object, path) => {
|
|
82
|
+
const {
|
|
83
|
+
obj,
|
|
84
|
+
k
|
|
85
|
+
} = getLastOfPath(object, path);
|
|
86
|
+
if (!obj) return void 0;
|
|
87
|
+
return obj[k];
|
|
88
|
+
};
|
|
89
|
+
const getPathWithDefaults = (data, defaultData, key) => {
|
|
90
|
+
const value = getPath(data, key);
|
|
91
|
+
if (value !== void 0) {
|
|
92
|
+
return value;
|
|
93
|
+
}
|
|
94
|
+
return getPath(defaultData, key);
|
|
95
|
+
};
|
|
96
|
+
const deepExtend = (target, source, overwrite) => {
|
|
97
|
+
for (const prop in source) {
|
|
98
|
+
if (prop !== "__proto__" && prop !== "constructor") {
|
|
99
|
+
if (prop in target) {
|
|
100
|
+
if (isString(target[prop]) || target[prop] instanceof String || isString(source[prop]) || source[prop] instanceof String) {
|
|
101
|
+
if (overwrite) target[prop] = source[prop];
|
|
102
|
+
} else {
|
|
103
|
+
deepExtend(target[prop], source[prop], overwrite);
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
target[prop] = source[prop];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return target;
|
|
111
|
+
};
|
|
112
|
+
const regexEscape = (str) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
|
113
|
+
var _entityMap = {
|
|
114
|
+
"&": "&",
|
|
115
|
+
"<": "<",
|
|
116
|
+
">": ">",
|
|
117
|
+
'"': """,
|
|
118
|
+
"'": "'",
|
|
119
|
+
"/": "/"
|
|
120
|
+
};
|
|
121
|
+
const escape = (data) => {
|
|
122
|
+
if (isString(data)) {
|
|
123
|
+
return data.replace(/[&<>"'\/]/g, (s) => _entityMap[s]);
|
|
124
|
+
}
|
|
125
|
+
return data;
|
|
126
|
+
};
|
|
127
|
+
class RegExpCache {
|
|
128
|
+
constructor(capacity) {
|
|
129
|
+
this.capacity = capacity;
|
|
130
|
+
this.regExpMap = /* @__PURE__ */ new Map();
|
|
131
|
+
this.regExpQueue = [];
|
|
132
|
+
}
|
|
133
|
+
getRegExp(pattern) {
|
|
134
|
+
const regExpFromCache = this.regExpMap.get(pattern);
|
|
135
|
+
if (regExpFromCache !== void 0) {
|
|
136
|
+
return regExpFromCache;
|
|
137
|
+
}
|
|
138
|
+
const regExpNew = new RegExp(pattern);
|
|
139
|
+
if (this.regExpQueue.length === this.capacity) {
|
|
140
|
+
this.regExpMap.delete(this.regExpQueue.shift());
|
|
141
|
+
}
|
|
142
|
+
this.regExpMap.set(pattern, regExpNew);
|
|
143
|
+
this.regExpQueue.push(pattern);
|
|
144
|
+
return regExpNew;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const chars = [" ", ",", "?", "!", ";"];
|
|
148
|
+
const looksLikeObjectPathRegExpCache = new RegExpCache(20);
|
|
149
|
+
const looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
|
|
150
|
+
nsSeparator = nsSeparator || "";
|
|
151
|
+
keySeparator = keySeparator || "";
|
|
152
|
+
const possibleChars = chars.filter((c) => nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0);
|
|
153
|
+
if (possibleChars.length === 0) return true;
|
|
154
|
+
const r = looksLikeObjectPathRegExpCache.getRegExp(`(${possibleChars.map((c) => c === "?" ? "\\?" : c).join("|")})`);
|
|
155
|
+
let matched = !r.test(key);
|
|
156
|
+
if (!matched) {
|
|
157
|
+
const ki = key.indexOf(keySeparator);
|
|
158
|
+
if (ki > 0 && !r.test(key.substring(0, ki))) {
|
|
159
|
+
matched = true;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return matched;
|
|
163
|
+
};
|
|
164
|
+
const deepFind = function(obj, path) {
|
|
165
|
+
let keySeparator = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : ".";
|
|
166
|
+
if (!obj) return void 0;
|
|
167
|
+
if (obj[path]) return obj[path];
|
|
168
|
+
const tokens = path.split(keySeparator);
|
|
169
|
+
let current = obj;
|
|
170
|
+
for (let i = 0; i < tokens.length; ) {
|
|
171
|
+
if (!current || typeof current !== "object") {
|
|
172
|
+
return void 0;
|
|
173
|
+
}
|
|
174
|
+
let next;
|
|
175
|
+
let nextPath = "";
|
|
176
|
+
for (let j = i; j < tokens.length; ++j) {
|
|
177
|
+
if (j !== i) {
|
|
178
|
+
nextPath += keySeparator;
|
|
179
|
+
}
|
|
180
|
+
nextPath += tokens[j];
|
|
181
|
+
next = current[nextPath];
|
|
182
|
+
if (next !== void 0) {
|
|
183
|
+
if (["string", "number", "boolean"].indexOf(typeof next) > -1 && j < tokens.length - 1) {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
i += j - i + 1;
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
current = next;
|
|
191
|
+
}
|
|
192
|
+
return current;
|
|
193
|
+
};
|
|
194
|
+
const getCleanedCode = (code) => code && code.replace("_", "-");
|
|
195
|
+
const consoleLogger = {
|
|
196
|
+
type: "logger",
|
|
197
|
+
log(args) {
|
|
198
|
+
this.output("log", args);
|
|
199
|
+
},
|
|
200
|
+
warn(args) {
|
|
201
|
+
this.output("warn", args);
|
|
202
|
+
},
|
|
203
|
+
error(args) {
|
|
204
|
+
this.output("error", args);
|
|
205
|
+
},
|
|
206
|
+
output(type, args) {
|
|
207
|
+
if (console && console[type]) console[type].apply(console, args);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
class Logger {
|
|
211
|
+
constructor(concreteLogger) {
|
|
212
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
213
|
+
this.init(concreteLogger, options);
|
|
214
|
+
}
|
|
215
|
+
init(concreteLogger) {
|
|
216
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
217
|
+
this.prefix = options.prefix || "i18next:";
|
|
218
|
+
this.logger = concreteLogger || consoleLogger;
|
|
219
|
+
this.options = options;
|
|
220
|
+
this.debug = options.debug;
|
|
221
|
+
}
|
|
222
|
+
log() {
|
|
223
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
224
|
+
args[_key] = arguments[_key];
|
|
225
|
+
}
|
|
226
|
+
return this.forward(args, "log", "", true);
|
|
227
|
+
}
|
|
228
|
+
warn() {
|
|
229
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
230
|
+
args[_key2] = arguments[_key2];
|
|
231
|
+
}
|
|
232
|
+
return this.forward(args, "warn", "", true);
|
|
233
|
+
}
|
|
234
|
+
error() {
|
|
235
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
236
|
+
args[_key3] = arguments[_key3];
|
|
237
|
+
}
|
|
238
|
+
return this.forward(args, "error", "");
|
|
239
|
+
}
|
|
240
|
+
deprecate() {
|
|
241
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
242
|
+
args[_key4] = arguments[_key4];
|
|
243
|
+
}
|
|
244
|
+
return this.forward(args, "warn", "WARNING DEPRECATED: ", true);
|
|
245
|
+
}
|
|
246
|
+
forward(args, lvl, prefix, debugOnly) {
|
|
247
|
+
if (debugOnly && !this.debug) return null;
|
|
248
|
+
if (isString(args[0])) args[0] = `${prefix}${this.prefix} ${args[0]}`;
|
|
249
|
+
return this.logger[lvl](args);
|
|
250
|
+
}
|
|
251
|
+
create(moduleName) {
|
|
252
|
+
return new Logger(this.logger, {
|
|
253
|
+
...{
|
|
254
|
+
prefix: `${this.prefix}:${moduleName}:`
|
|
255
|
+
},
|
|
256
|
+
...this.options
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
clone(options) {
|
|
260
|
+
options = options || this.options;
|
|
261
|
+
options.prefix = options.prefix || this.prefix;
|
|
262
|
+
return new Logger(this.logger, options);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
var baseLogger = new Logger();
|
|
266
|
+
class EventEmitter {
|
|
267
|
+
constructor() {
|
|
268
|
+
this.observers = {};
|
|
269
|
+
}
|
|
270
|
+
on(events, listener) {
|
|
271
|
+
events.split(" ").forEach((event) => {
|
|
272
|
+
if (!this.observers[event]) this.observers[event] = /* @__PURE__ */ new Map();
|
|
273
|
+
const numListeners = this.observers[event].get(listener) || 0;
|
|
274
|
+
this.observers[event].set(listener, numListeners + 1);
|
|
275
|
+
});
|
|
276
|
+
return this;
|
|
277
|
+
}
|
|
278
|
+
off(event, listener) {
|
|
279
|
+
if (!this.observers[event]) return;
|
|
280
|
+
if (!listener) {
|
|
281
|
+
delete this.observers[event];
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
this.observers[event].delete(listener);
|
|
285
|
+
}
|
|
286
|
+
emit(event) {
|
|
287
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
288
|
+
args[_key - 1] = arguments[_key];
|
|
289
|
+
}
|
|
290
|
+
if (this.observers[event]) {
|
|
291
|
+
const cloned = Array.from(this.observers[event].entries());
|
|
292
|
+
cloned.forEach((_ref) => {
|
|
293
|
+
let [observer, numTimesAdded] = _ref;
|
|
294
|
+
for (let i = 0; i < numTimesAdded; i++) {
|
|
295
|
+
observer(...args);
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
if (this.observers["*"]) {
|
|
300
|
+
const cloned = Array.from(this.observers["*"].entries());
|
|
301
|
+
cloned.forEach((_ref2) => {
|
|
302
|
+
let [observer, numTimesAdded] = _ref2;
|
|
303
|
+
for (let i = 0; i < numTimesAdded; i++) {
|
|
304
|
+
observer.apply(observer, [event, ...args]);
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
class ResourceStore extends EventEmitter {
|
|
311
|
+
constructor(data) {
|
|
312
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
|
|
313
|
+
ns: ["translation"],
|
|
314
|
+
defaultNS: "translation"
|
|
315
|
+
};
|
|
316
|
+
super();
|
|
317
|
+
this.data = data || {};
|
|
318
|
+
this.options = options;
|
|
319
|
+
if (this.options.keySeparator === void 0) {
|
|
320
|
+
this.options.keySeparator = ".";
|
|
321
|
+
}
|
|
322
|
+
if (this.options.ignoreJSONStructure === void 0) {
|
|
323
|
+
this.options.ignoreJSONStructure = true;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
addNamespaces(ns) {
|
|
327
|
+
if (this.options.ns.indexOf(ns) < 0) {
|
|
328
|
+
this.options.ns.push(ns);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
removeNamespaces(ns) {
|
|
332
|
+
const index = this.options.ns.indexOf(ns);
|
|
333
|
+
if (index > -1) {
|
|
334
|
+
this.options.ns.splice(index, 1);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
getResource(lng, ns, key) {
|
|
338
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
339
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
340
|
+
const ignoreJSONStructure = options.ignoreJSONStructure !== void 0 ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
341
|
+
let path;
|
|
342
|
+
if (lng.indexOf(".") > -1) {
|
|
343
|
+
path = lng.split(".");
|
|
344
|
+
} else {
|
|
345
|
+
path = [lng, ns];
|
|
346
|
+
if (key) {
|
|
347
|
+
if (Array.isArray(key)) {
|
|
348
|
+
path.push(...key);
|
|
349
|
+
} else if (isString(key) && keySeparator) {
|
|
350
|
+
path.push(...key.split(keySeparator));
|
|
351
|
+
} else {
|
|
352
|
+
path.push(key);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
const result = getPath(this.data, path);
|
|
357
|
+
if (!result && !ns && !key && lng.indexOf(".") > -1) {
|
|
358
|
+
lng = path[0];
|
|
359
|
+
ns = path[1];
|
|
360
|
+
key = path.slice(2).join(".");
|
|
361
|
+
}
|
|
362
|
+
if (result || !ignoreJSONStructure || !isString(key)) return result;
|
|
363
|
+
return deepFind(this.data && this.data[lng] && this.data[lng][ns], key, keySeparator);
|
|
364
|
+
}
|
|
365
|
+
addResource(lng, ns, key, value) {
|
|
366
|
+
let options = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : {
|
|
367
|
+
silent: false
|
|
368
|
+
};
|
|
369
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
370
|
+
let path = [lng, ns];
|
|
371
|
+
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
372
|
+
if (lng.indexOf(".") > -1) {
|
|
373
|
+
path = lng.split(".");
|
|
374
|
+
value = ns;
|
|
375
|
+
ns = path[1];
|
|
376
|
+
}
|
|
377
|
+
this.addNamespaces(ns);
|
|
378
|
+
setPath(this.data, path, value);
|
|
379
|
+
if (!options.silent) this.emit("added", lng, ns, key, value);
|
|
380
|
+
}
|
|
381
|
+
addResources(lng, ns, resources) {
|
|
382
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {
|
|
383
|
+
silent: false
|
|
384
|
+
};
|
|
385
|
+
for (const m in resources) {
|
|
386
|
+
if (isString(resources[m]) || Array.isArray(resources[m])) this.addResource(lng, ns, m, resources[m], {
|
|
387
|
+
silent: true
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
if (!options.silent) this.emit("added", lng, ns, resources);
|
|
391
|
+
}
|
|
392
|
+
addResourceBundle(lng, ns, resources, deep, overwrite) {
|
|
393
|
+
let options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {
|
|
394
|
+
silent: false,
|
|
395
|
+
skipCopy: false
|
|
396
|
+
};
|
|
397
|
+
let path = [lng, ns];
|
|
398
|
+
if (lng.indexOf(".") > -1) {
|
|
399
|
+
path = lng.split(".");
|
|
400
|
+
deep = resources;
|
|
401
|
+
resources = ns;
|
|
402
|
+
ns = path[1];
|
|
403
|
+
}
|
|
404
|
+
this.addNamespaces(ns);
|
|
405
|
+
let pack = getPath(this.data, path) || {};
|
|
406
|
+
if (!options.skipCopy) resources = JSON.parse(JSON.stringify(resources));
|
|
407
|
+
if (deep) {
|
|
408
|
+
deepExtend(pack, resources, overwrite);
|
|
409
|
+
} else {
|
|
410
|
+
pack = {
|
|
411
|
+
...pack,
|
|
412
|
+
...resources
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
setPath(this.data, path, pack);
|
|
416
|
+
if (!options.silent) this.emit("added", lng, ns, resources);
|
|
417
|
+
}
|
|
418
|
+
removeResourceBundle(lng, ns) {
|
|
419
|
+
if (this.hasResourceBundle(lng, ns)) {
|
|
420
|
+
delete this.data[lng][ns];
|
|
421
|
+
}
|
|
422
|
+
this.removeNamespaces(ns);
|
|
423
|
+
this.emit("removed", lng, ns);
|
|
424
|
+
}
|
|
425
|
+
hasResourceBundle(lng, ns) {
|
|
426
|
+
return this.getResource(lng, ns) !== void 0;
|
|
427
|
+
}
|
|
428
|
+
getResourceBundle(lng, ns) {
|
|
429
|
+
if (!ns) ns = this.options.defaultNS;
|
|
430
|
+
if (this.options.compatibilityAPI === "v1") return {
|
|
431
|
+
...{},
|
|
432
|
+
...this.getResource(lng, ns)
|
|
433
|
+
};
|
|
434
|
+
return this.getResource(lng, ns);
|
|
435
|
+
}
|
|
436
|
+
getDataByLanguage(lng) {
|
|
437
|
+
return this.data[lng];
|
|
438
|
+
}
|
|
439
|
+
hasLanguageSomeTranslations(lng) {
|
|
440
|
+
const data = this.getDataByLanguage(lng);
|
|
441
|
+
const n = data && Object.keys(data) || [];
|
|
442
|
+
return !!n.find((v) => data[v] && Object.keys(data[v]).length > 0);
|
|
443
|
+
}
|
|
444
|
+
toJSON() {
|
|
445
|
+
return this.data;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
var postProcessor = {
|
|
449
|
+
processors: {},
|
|
450
|
+
addPostProcessor(module) {
|
|
451
|
+
this.processors[module.name] = module;
|
|
452
|
+
},
|
|
453
|
+
handle(processors, value, key, options, translator) {
|
|
454
|
+
processors.forEach((processor) => {
|
|
455
|
+
if (this.processors[processor]) value = this.processors[processor].process(value, key, options, translator);
|
|
456
|
+
});
|
|
457
|
+
return value;
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
const checkedLoadedFor = {};
|
|
461
|
+
class Translator extends EventEmitter {
|
|
462
|
+
constructor(services) {
|
|
463
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
464
|
+
super();
|
|
465
|
+
copy(["resourceStore", "languageUtils", "pluralResolver", "interpolator", "backendConnector", "i18nFormat", "utils"], services, this);
|
|
466
|
+
this.options = options;
|
|
467
|
+
if (this.options.keySeparator === void 0) {
|
|
468
|
+
this.options.keySeparator = ".";
|
|
469
|
+
}
|
|
470
|
+
this.logger = baseLogger.create("translator");
|
|
471
|
+
}
|
|
472
|
+
changeLanguage(lng) {
|
|
473
|
+
if (lng) this.language = lng;
|
|
474
|
+
}
|
|
475
|
+
exists(key) {
|
|
476
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
|
|
477
|
+
interpolation: {}
|
|
478
|
+
};
|
|
479
|
+
if (key === void 0 || key === null) {
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
const resolved = this.resolve(key, options);
|
|
483
|
+
return resolved && resolved.res !== void 0;
|
|
484
|
+
}
|
|
485
|
+
extractFromKey(key, options) {
|
|
486
|
+
let nsSeparator = options.nsSeparator !== void 0 ? options.nsSeparator : this.options.nsSeparator;
|
|
487
|
+
if (nsSeparator === void 0) nsSeparator = ":";
|
|
488
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
489
|
+
let namespaces = options.ns || this.options.defaultNS || [];
|
|
490
|
+
const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
|
|
491
|
+
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
492
|
+
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
493
|
+
const m = key.match(this.interpolator.nestingRegexp);
|
|
494
|
+
if (m && m.length > 0) {
|
|
495
|
+
return {
|
|
496
|
+
key,
|
|
497
|
+
namespaces: isString(namespaces) ? [namespaces] : namespaces
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
const parts = key.split(nsSeparator);
|
|
501
|
+
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
|
|
502
|
+
key = parts.join(keySeparator);
|
|
503
|
+
}
|
|
504
|
+
return {
|
|
505
|
+
key,
|
|
506
|
+
namespaces: isString(namespaces) ? [namespaces] : namespaces
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
translate(keys, options, lastKey) {
|
|
510
|
+
if (typeof options !== "object" && this.options.overloadTranslationOptionHandler) {
|
|
511
|
+
options = this.options.overloadTranslationOptionHandler(arguments);
|
|
512
|
+
}
|
|
513
|
+
if (typeof options === "object") options = {
|
|
514
|
+
...options
|
|
515
|
+
};
|
|
516
|
+
if (!options) options = {};
|
|
517
|
+
if (keys === void 0 || keys === null) return "";
|
|
518
|
+
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
519
|
+
const returnDetails = options.returnDetails !== void 0 ? options.returnDetails : this.options.returnDetails;
|
|
520
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
521
|
+
const {
|
|
522
|
+
key,
|
|
523
|
+
namespaces
|
|
524
|
+
} = this.extractFromKey(keys[keys.length - 1], options);
|
|
525
|
+
const namespace = namespaces[namespaces.length - 1];
|
|
526
|
+
const lng = options.lng || this.language;
|
|
527
|
+
const appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
528
|
+
if (lng && lng.toLowerCase() === "cimode") {
|
|
529
|
+
if (appendNamespaceToCIMode) {
|
|
530
|
+
const nsSeparator = options.nsSeparator || this.options.nsSeparator;
|
|
531
|
+
if (returnDetails) {
|
|
532
|
+
return {
|
|
533
|
+
res: `${namespace}${nsSeparator}${key}`,
|
|
534
|
+
usedKey: key,
|
|
535
|
+
exactUsedKey: key,
|
|
536
|
+
usedLng: lng,
|
|
537
|
+
usedNS: namespace,
|
|
538
|
+
usedParams: this.getUsedParamsDetails(options)
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
return `${namespace}${nsSeparator}${key}`;
|
|
542
|
+
}
|
|
543
|
+
if (returnDetails) {
|
|
544
|
+
return {
|
|
545
|
+
res: key,
|
|
546
|
+
usedKey: key,
|
|
547
|
+
exactUsedKey: key,
|
|
548
|
+
usedLng: lng,
|
|
549
|
+
usedNS: namespace,
|
|
550
|
+
usedParams: this.getUsedParamsDetails(options)
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
return key;
|
|
554
|
+
}
|
|
555
|
+
const resolved = this.resolve(keys, options);
|
|
556
|
+
let res = resolved && resolved.res;
|
|
557
|
+
const resUsedKey = resolved && resolved.usedKey || key;
|
|
558
|
+
const resExactUsedKey = resolved && resolved.exactUsedKey || key;
|
|
559
|
+
const resType = Object.prototype.toString.apply(res);
|
|
560
|
+
const noObject = ["[object Number]", "[object Function]", "[object RegExp]"];
|
|
561
|
+
const joinArrays = options.joinArrays !== void 0 ? options.joinArrays : this.options.joinArrays;
|
|
562
|
+
const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
563
|
+
const handleAsObject = !isString(res) && typeof res !== "boolean" && typeof res !== "number";
|
|
564
|
+
if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(isString(joinArrays) && Array.isArray(res))) {
|
|
565
|
+
if (!options.returnObjects && !this.options.returnObjects) {
|
|
566
|
+
if (!this.options.returnedObjectHandler) {
|
|
567
|
+
this.logger.warn("accessing an object - but returnObjects options is not enabled!");
|
|
568
|
+
}
|
|
569
|
+
const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, {
|
|
570
|
+
...options,
|
|
571
|
+
ns: namespaces
|
|
572
|
+
}) : `key '${key} (${this.language})' returned an object instead of string.`;
|
|
573
|
+
if (returnDetails) {
|
|
574
|
+
resolved.res = r;
|
|
575
|
+
resolved.usedParams = this.getUsedParamsDetails(options);
|
|
576
|
+
return resolved;
|
|
577
|
+
}
|
|
578
|
+
return r;
|
|
579
|
+
}
|
|
580
|
+
if (keySeparator) {
|
|
581
|
+
const resTypeIsArray = Array.isArray(res);
|
|
582
|
+
const copy2 = resTypeIsArray ? [] : {};
|
|
583
|
+
const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
584
|
+
for (const m in res) {
|
|
585
|
+
if (Object.prototype.hasOwnProperty.call(res, m)) {
|
|
586
|
+
const deepKey = `${newKeyToUse}${keySeparator}${m}`;
|
|
587
|
+
copy2[m] = this.translate(deepKey, {
|
|
588
|
+
...options,
|
|
589
|
+
...{
|
|
590
|
+
joinArrays: false,
|
|
591
|
+
ns: namespaces
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
if (copy2[m] === deepKey) copy2[m] = res[m];
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
res = copy2;
|
|
598
|
+
}
|
|
599
|
+
} else if (handleAsObjectInI18nFormat && isString(joinArrays) && Array.isArray(res)) {
|
|
600
|
+
res = res.join(joinArrays);
|
|
601
|
+
if (res) res = this.extendTranslation(res, keys, options, lastKey);
|
|
602
|
+
} else {
|
|
603
|
+
let usedDefault = false;
|
|
604
|
+
let usedKey = false;
|
|
605
|
+
const needsPluralHandling = options.count !== void 0 && !isString(options.count);
|
|
606
|
+
const hasDefaultValue = Translator.hasDefaultValue(options);
|
|
607
|
+
const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : "";
|
|
608
|
+
const defaultValueSuffixOrdinalFallback = options.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, {
|
|
609
|
+
ordinal: false
|
|
610
|
+
}) : "";
|
|
611
|
+
const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
|
|
612
|
+
const defaultValue = needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] || options[`defaultValue${defaultValueSuffix}`] || options[`defaultValue${defaultValueSuffixOrdinalFallback}`] || options.defaultValue;
|
|
613
|
+
if (!this.isValidLookup(res) && hasDefaultValue) {
|
|
614
|
+
usedDefault = true;
|
|
615
|
+
res = defaultValue;
|
|
616
|
+
}
|
|
617
|
+
if (!this.isValidLookup(res)) {
|
|
618
|
+
usedKey = true;
|
|
619
|
+
res = key;
|
|
620
|
+
}
|
|
621
|
+
const missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
|
|
622
|
+
const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? void 0 : res;
|
|
623
|
+
const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
624
|
+
if (usedKey || usedDefault || updateMissing) {
|
|
625
|
+
this.logger.log(updateMissing ? "updateKey" : "missingKey", lng, namespace, key, updateMissing ? defaultValue : res);
|
|
626
|
+
if (keySeparator) {
|
|
627
|
+
const fk = this.resolve(key, {
|
|
628
|
+
...options,
|
|
629
|
+
keySeparator: false
|
|
630
|
+
});
|
|
631
|
+
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.");
|
|
632
|
+
}
|
|
633
|
+
let lngs = [];
|
|
634
|
+
const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
|
|
635
|
+
if (this.options.saveMissingTo === "fallback" && fallbackLngs && fallbackLngs[0]) {
|
|
636
|
+
for (let i = 0; i < fallbackLngs.length; i++) {
|
|
637
|
+
lngs.push(fallbackLngs[i]);
|
|
638
|
+
}
|
|
639
|
+
} else if (this.options.saveMissingTo === "all") {
|
|
640
|
+
lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
|
|
641
|
+
} else {
|
|
642
|
+
lngs.push(options.lng || this.language);
|
|
643
|
+
}
|
|
644
|
+
const send = (l, k, specificDefaultValue) => {
|
|
645
|
+
const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
646
|
+
if (this.options.missingKeyHandler) {
|
|
647
|
+
this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
648
|
+
} else if (this.backendConnector && this.backendConnector.saveMissing) {
|
|
649
|
+
this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
650
|
+
}
|
|
651
|
+
this.emit("missingKey", l, namespace, k, res);
|
|
652
|
+
};
|
|
653
|
+
if (this.options.saveMissing) {
|
|
654
|
+
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
655
|
+
lngs.forEach((language) => {
|
|
656
|
+
const suffixes = this.pluralResolver.getSuffixes(language, options);
|
|
657
|
+
if (needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.indexOf(`${this.options.pluralSeparator}zero`) < 0) {
|
|
658
|
+
suffixes.push(`${this.options.pluralSeparator}zero`);
|
|
659
|
+
}
|
|
660
|
+
suffixes.forEach((suffix) => {
|
|
661
|
+
send([language], key + suffix, options[`defaultValue${suffix}`] || defaultValue);
|
|
662
|
+
});
|
|
663
|
+
});
|
|
664
|
+
} else {
|
|
665
|
+
send(lngs, key, defaultValue);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
res = this.extendTranslation(res, keys, options, resolved, lastKey);
|
|
670
|
+
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
|
|
671
|
+
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
|
|
672
|
+
if (this.options.compatibilityAPI !== "v1") {
|
|
673
|
+
res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : void 0);
|
|
674
|
+
} else {
|
|
675
|
+
res = this.options.parseMissingKeyHandler(res);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
if (returnDetails) {
|
|
680
|
+
resolved.res = res;
|
|
681
|
+
resolved.usedParams = this.getUsedParamsDetails(options);
|
|
682
|
+
return resolved;
|
|
683
|
+
}
|
|
684
|
+
return res;
|
|
685
|
+
}
|
|
686
|
+
extendTranslation(res, key, options, resolved, lastKey) {
|
|
687
|
+
var _this = this;
|
|
688
|
+
if (this.i18nFormat && this.i18nFormat.parse) {
|
|
689
|
+
res = this.i18nFormat.parse(res, {
|
|
690
|
+
...this.options.interpolation.defaultVariables,
|
|
691
|
+
...options
|
|
692
|
+
}, options.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
|
|
693
|
+
resolved
|
|
694
|
+
});
|
|
695
|
+
} else if (!options.skipInterpolation) {
|
|
696
|
+
if (options.interpolation) this.interpolator.init({
|
|
697
|
+
...options,
|
|
698
|
+
...{
|
|
699
|
+
interpolation: {
|
|
700
|
+
...this.options.interpolation,
|
|
701
|
+
...options.interpolation
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
const skipOnVariables = isString(res) && (options && options.interpolation && options.interpolation.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
706
|
+
let nestBef;
|
|
707
|
+
if (skipOnVariables) {
|
|
708
|
+
const nb = res.match(this.interpolator.nestingRegexp);
|
|
709
|
+
nestBef = nb && nb.length;
|
|
710
|
+
}
|
|
711
|
+
let data = options.replace && !isString(options.replace) ? options.replace : options;
|
|
712
|
+
if (this.options.interpolation.defaultVariables) data = {
|
|
713
|
+
...this.options.interpolation.defaultVariables,
|
|
714
|
+
...data
|
|
715
|
+
};
|
|
716
|
+
res = this.interpolator.interpolate(res, data, options.lng || this.language || resolved.usedLng, options);
|
|
717
|
+
if (skipOnVariables) {
|
|
718
|
+
const na = res.match(this.interpolator.nestingRegexp);
|
|
719
|
+
const nestAft = na && na.length;
|
|
720
|
+
if (nestBef < nestAft) options.nest = false;
|
|
721
|
+
}
|
|
722
|
+
if (!options.lng && this.options.compatibilityAPI !== "v1" && resolved && resolved.res) options.lng = this.language || resolved.usedLng;
|
|
723
|
+
if (options.nest !== false) res = this.interpolator.nest(res, function() {
|
|
724
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
725
|
+
args[_key] = arguments[_key];
|
|
726
|
+
}
|
|
727
|
+
if (lastKey && lastKey[0] === args[0] && !options.context) {
|
|
728
|
+
_this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
|
|
729
|
+
return null;
|
|
730
|
+
}
|
|
731
|
+
return _this.translate(...args, key);
|
|
732
|
+
}, options);
|
|
733
|
+
if (options.interpolation) this.interpolator.reset();
|
|
734
|
+
}
|
|
735
|
+
const postProcess = options.postProcess || this.options.postProcess;
|
|
736
|
+
const postProcessorNames = isString(postProcess) ? [postProcess] : postProcess;
|
|
737
|
+
if (res !== void 0 && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) {
|
|
738
|
+
res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
|
|
739
|
+
i18nResolved: {
|
|
740
|
+
...resolved,
|
|
741
|
+
usedParams: this.getUsedParamsDetails(options)
|
|
742
|
+
},
|
|
743
|
+
...options
|
|
744
|
+
} : options, this);
|
|
745
|
+
}
|
|
746
|
+
return res;
|
|
747
|
+
}
|
|
748
|
+
resolve(keys) {
|
|
749
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
750
|
+
let found;
|
|
751
|
+
let usedKey;
|
|
752
|
+
let exactUsedKey;
|
|
753
|
+
let usedLng;
|
|
754
|
+
let usedNS;
|
|
755
|
+
if (isString(keys)) keys = [keys];
|
|
756
|
+
keys.forEach((k) => {
|
|
757
|
+
if (this.isValidLookup(found)) return;
|
|
758
|
+
const extracted = this.extractFromKey(k, options);
|
|
759
|
+
const key = extracted.key;
|
|
760
|
+
usedKey = key;
|
|
761
|
+
let namespaces = extracted.namespaces;
|
|
762
|
+
if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
|
|
763
|
+
const needsPluralHandling = options.count !== void 0 && !isString(options.count);
|
|
764
|
+
const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
|
|
765
|
+
const needsContextHandling = options.context !== void 0 && (isString(options.context) || typeof options.context === "number") && options.context !== "";
|
|
766
|
+
const codes = options.lngs ? options.lngs : this.languageUtils.toResolveHierarchy(options.lng || this.language, options.fallbackLng);
|
|
767
|
+
namespaces.forEach((ns) => {
|
|
768
|
+
if (this.isValidLookup(found)) return;
|
|
769
|
+
usedNS = ns;
|
|
770
|
+
if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils && this.utils.hasLoadedNamespace && !this.utils.hasLoadedNamespace(usedNS)) {
|
|
771
|
+
checkedLoadedFor[`${codes[0]}-${ns}`] = true;
|
|
772
|
+
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!!!");
|
|
773
|
+
}
|
|
774
|
+
codes.forEach((code) => {
|
|
775
|
+
if (this.isValidLookup(found)) return;
|
|
776
|
+
usedLng = code;
|
|
777
|
+
const finalKeys = [key];
|
|
778
|
+
if (this.i18nFormat && this.i18nFormat.addLookupKeys) {
|
|
779
|
+
this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
|
|
780
|
+
} else {
|
|
781
|
+
let pluralSuffix;
|
|
782
|
+
if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, options.count, options);
|
|
783
|
+
const zeroSuffix = `${this.options.pluralSeparator}zero`;
|
|
784
|
+
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
|
|
785
|
+
if (needsPluralHandling) {
|
|
786
|
+
finalKeys.push(key + pluralSuffix);
|
|
787
|
+
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
788
|
+
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
789
|
+
}
|
|
790
|
+
if (needsZeroSuffixLookup) {
|
|
791
|
+
finalKeys.push(key + zeroSuffix);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
if (needsContextHandling) {
|
|
795
|
+
const contextKey = `${key}${this.options.contextSeparator}${options.context}`;
|
|
796
|
+
finalKeys.push(contextKey);
|
|
797
|
+
if (needsPluralHandling) {
|
|
798
|
+
finalKeys.push(contextKey + pluralSuffix);
|
|
799
|
+
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
800
|
+
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
801
|
+
}
|
|
802
|
+
if (needsZeroSuffixLookup) {
|
|
803
|
+
finalKeys.push(contextKey + zeroSuffix);
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
let possibleKey;
|
|
809
|
+
while (possibleKey = finalKeys.pop()) {
|
|
810
|
+
if (!this.isValidLookup(found)) {
|
|
811
|
+
exactUsedKey = possibleKey;
|
|
812
|
+
found = this.getResource(code, ns, possibleKey, options);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
});
|
|
816
|
+
});
|
|
817
|
+
});
|
|
818
|
+
return {
|
|
819
|
+
res: found,
|
|
820
|
+
usedKey,
|
|
821
|
+
exactUsedKey,
|
|
822
|
+
usedLng,
|
|
823
|
+
usedNS
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
isValidLookup(res) {
|
|
827
|
+
return res !== void 0 && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === "");
|
|
828
|
+
}
|
|
829
|
+
getResource(code, ns, key) {
|
|
830
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
831
|
+
if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options);
|
|
832
|
+
return this.resourceStore.getResource(code, ns, key, options);
|
|
833
|
+
}
|
|
834
|
+
getUsedParamsDetails() {
|
|
835
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
836
|
+
const optionsKeys = ["defaultValue", "ordinal", "context", "replace", "lng", "lngs", "fallbackLng", "ns", "keySeparator", "nsSeparator", "returnObjects", "returnDetails", "joinArrays", "postProcess", "interpolation"];
|
|
837
|
+
const useOptionsReplaceForData = options.replace && !isString(options.replace);
|
|
838
|
+
let data = useOptionsReplaceForData ? options.replace : options;
|
|
839
|
+
if (useOptionsReplaceForData && typeof options.count !== "undefined") {
|
|
840
|
+
data.count = options.count;
|
|
841
|
+
}
|
|
842
|
+
if (this.options.interpolation.defaultVariables) {
|
|
843
|
+
data = {
|
|
844
|
+
...this.options.interpolation.defaultVariables,
|
|
845
|
+
...data
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
if (!useOptionsReplaceForData) {
|
|
849
|
+
data = {
|
|
850
|
+
...data
|
|
851
|
+
};
|
|
852
|
+
for (const key of optionsKeys) {
|
|
853
|
+
delete data[key];
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
return data;
|
|
857
|
+
}
|
|
858
|
+
static hasDefaultValue(options) {
|
|
859
|
+
const prefix = "defaultValue";
|
|
860
|
+
for (const option in options) {
|
|
861
|
+
if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && void 0 !== options[option]) {
|
|
862
|
+
return true;
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
return false;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
const capitalize = (string) => string.charAt(0).toUpperCase() + string.slice(1);
|
|
869
|
+
class LanguageUtil {
|
|
870
|
+
constructor(options) {
|
|
871
|
+
this.options = options;
|
|
872
|
+
this.supportedLngs = this.options.supportedLngs || false;
|
|
873
|
+
this.logger = baseLogger.create("languageUtils");
|
|
874
|
+
}
|
|
875
|
+
getScriptPartFromCode(code) {
|
|
876
|
+
code = getCleanedCode(code);
|
|
877
|
+
if (!code || code.indexOf("-") < 0) return null;
|
|
878
|
+
const p = code.split("-");
|
|
879
|
+
if (p.length === 2) return null;
|
|
880
|
+
p.pop();
|
|
881
|
+
if (p[p.length - 1].toLowerCase() === "x") return null;
|
|
882
|
+
return this.formatLanguageCode(p.join("-"));
|
|
883
|
+
}
|
|
884
|
+
getLanguagePartFromCode(code) {
|
|
885
|
+
code = getCleanedCode(code);
|
|
886
|
+
if (!code || code.indexOf("-") < 0) return code;
|
|
887
|
+
const p = code.split("-");
|
|
888
|
+
return this.formatLanguageCode(p[0]);
|
|
889
|
+
}
|
|
890
|
+
formatLanguageCode(code) {
|
|
891
|
+
if (isString(code) && code.indexOf("-") > -1) {
|
|
892
|
+
if (typeof Intl !== "undefined" && typeof Intl.getCanonicalLocales !== "undefined") {
|
|
893
|
+
try {
|
|
894
|
+
let formattedCode = Intl.getCanonicalLocales(code)[0];
|
|
895
|
+
if (formattedCode && this.options.lowerCaseLng) {
|
|
896
|
+
formattedCode = formattedCode.toLowerCase();
|
|
897
|
+
}
|
|
898
|
+
if (formattedCode) return formattedCode;
|
|
899
|
+
} catch (e) {
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
const specialCases = ["hans", "hant", "latn", "cyrl", "cans", "mong", "arab"];
|
|
903
|
+
let p = code.split("-");
|
|
904
|
+
if (this.options.lowerCaseLng) {
|
|
905
|
+
p = p.map((part) => part.toLowerCase());
|
|
906
|
+
} else if (p.length === 2) {
|
|
907
|
+
p[0] = p[0].toLowerCase();
|
|
908
|
+
p[1] = p[1].toUpperCase();
|
|
909
|
+
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
|
|
910
|
+
} else if (p.length === 3) {
|
|
911
|
+
p[0] = p[0].toLowerCase();
|
|
912
|
+
if (p[1].length === 2) p[1] = p[1].toUpperCase();
|
|
913
|
+
if (p[0] !== "sgn" && p[2].length === 2) p[2] = p[2].toUpperCase();
|
|
914
|
+
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
|
|
915
|
+
if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize(p[2].toLowerCase());
|
|
916
|
+
}
|
|
917
|
+
return p.join("-");
|
|
918
|
+
}
|
|
919
|
+
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
|
|
920
|
+
}
|
|
921
|
+
isSupportedCode(code) {
|
|
922
|
+
if (this.options.load === "languageOnly" || this.options.nonExplicitSupportedLngs) {
|
|
923
|
+
code = this.getLanguagePartFromCode(code);
|
|
924
|
+
}
|
|
925
|
+
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
|
|
926
|
+
}
|
|
927
|
+
getBestMatchFromCodes(codes) {
|
|
928
|
+
if (!codes) return null;
|
|
929
|
+
let found;
|
|
930
|
+
codes.forEach((code) => {
|
|
931
|
+
if (found) return;
|
|
932
|
+
const cleanedLng = this.formatLanguageCode(code);
|
|
933
|
+
if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
|
|
934
|
+
});
|
|
935
|
+
if (!found && this.options.supportedLngs) {
|
|
936
|
+
codes.forEach((code) => {
|
|
937
|
+
if (found) return;
|
|
938
|
+
const lngOnly = this.getLanguagePartFromCode(code);
|
|
939
|
+
if (this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
940
|
+
found = this.options.supportedLngs.find((supportedLng) => {
|
|
941
|
+
if (supportedLng === lngOnly) return supportedLng;
|
|
942
|
+
if (supportedLng.indexOf("-") < 0 && lngOnly.indexOf("-") < 0) return;
|
|
943
|
+
if (supportedLng.indexOf("-") > 0 && lngOnly.indexOf("-") < 0 && supportedLng.substring(0, supportedLng.indexOf("-")) === lngOnly) return supportedLng;
|
|
944
|
+
if (supportedLng.indexOf(lngOnly) === 0 && lngOnly.length > 1) return supportedLng;
|
|
945
|
+
});
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
|
|
949
|
+
return found;
|
|
950
|
+
}
|
|
951
|
+
getFallbackCodes(fallbacks, code) {
|
|
952
|
+
if (!fallbacks) return [];
|
|
953
|
+
if (typeof fallbacks === "function") fallbacks = fallbacks(code);
|
|
954
|
+
if (isString(fallbacks)) fallbacks = [fallbacks];
|
|
955
|
+
if (Array.isArray(fallbacks)) return fallbacks;
|
|
956
|
+
if (!code) return fallbacks.default || [];
|
|
957
|
+
let found = fallbacks[code];
|
|
958
|
+
if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
|
|
959
|
+
if (!found) found = fallbacks[this.formatLanguageCode(code)];
|
|
960
|
+
if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
961
|
+
if (!found) found = fallbacks.default;
|
|
962
|
+
return found || [];
|
|
963
|
+
}
|
|
964
|
+
toResolveHierarchy(code, fallbackCode) {
|
|
965
|
+
const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
|
|
966
|
+
const codes = [];
|
|
967
|
+
const addCode = (c) => {
|
|
968
|
+
if (!c) return;
|
|
969
|
+
if (this.isSupportedCode(c)) {
|
|
970
|
+
codes.push(c);
|
|
971
|
+
} else {
|
|
972
|
+
this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
if (isString(code) && (code.indexOf("-") > -1 || code.indexOf("_") > -1)) {
|
|
976
|
+
if (this.options.load !== "languageOnly") addCode(this.formatLanguageCode(code));
|
|
977
|
+
if (this.options.load !== "languageOnly" && this.options.load !== "currentOnly") addCode(this.getScriptPartFromCode(code));
|
|
978
|
+
if (this.options.load !== "currentOnly") addCode(this.getLanguagePartFromCode(code));
|
|
979
|
+
} else if (isString(code)) {
|
|
980
|
+
addCode(this.formatLanguageCode(code));
|
|
981
|
+
}
|
|
982
|
+
fallbackCodes.forEach((fc) => {
|
|
983
|
+
if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
|
|
984
|
+
});
|
|
985
|
+
return codes;
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
let sets = [{
|
|
989
|
+
lngs: ["ach", "ak", "am", "arn", "br", "fil", "gun", "ln", "mfe", "mg", "mi", "oc", "pt", "pt-BR", "tg", "tl", "ti", "tr", "uz", "wa"],
|
|
990
|
+
nr: [1, 2],
|
|
991
|
+
fc: 1
|
|
992
|
+
}, {
|
|
993
|
+
lngs: ["af", "an", "ast", "az", "bg", "bn", "ca", "da", "de", "dev", "el", "en", "eo", "es", "et", "eu", "fi", "fo", "fur", "fy", "gl", "gu", "ha", "hi", "hu", "hy", "ia", "it", "kk", "kn", "ku", "lb", "mai", "ml", "mn", "mr", "nah", "nap", "nb", "ne", "nl", "nn", "no", "nso", "pa", "pap", "pms", "ps", "pt-PT", "rm", "sco", "se", "si", "so", "son", "sq", "sv", "sw", "ta", "te", "tk", "ur", "yo"],
|
|
994
|
+
nr: [1, 2],
|
|
995
|
+
fc: 2
|
|
996
|
+
}, {
|
|
997
|
+
lngs: ["ay", "bo", "cgg", "fa", "ht", "id", "ja", "jbo", "ka", "km", "ko", "ky", "lo", "ms", "sah", "su", "th", "tt", "ug", "vi", "wo", "zh"],
|
|
998
|
+
nr: [1],
|
|
999
|
+
fc: 3
|
|
1000
|
+
}, {
|
|
1001
|
+
lngs: ["be", "bs", "cnr", "dz", "hr", "ru", "sr", "uk"],
|
|
1002
|
+
nr: [1, 2, 5],
|
|
1003
|
+
fc: 4
|
|
1004
|
+
}, {
|
|
1005
|
+
lngs: ["ar"],
|
|
1006
|
+
nr: [0, 1, 2, 3, 11, 100],
|
|
1007
|
+
fc: 5
|
|
1008
|
+
}, {
|
|
1009
|
+
lngs: ["cs", "sk"],
|
|
1010
|
+
nr: [1, 2, 5],
|
|
1011
|
+
fc: 6
|
|
1012
|
+
}, {
|
|
1013
|
+
lngs: ["csb", "pl"],
|
|
1014
|
+
nr: [1, 2, 5],
|
|
1015
|
+
fc: 7
|
|
1016
|
+
}, {
|
|
1017
|
+
lngs: ["cy"],
|
|
1018
|
+
nr: [1, 2, 3, 8],
|
|
1019
|
+
fc: 8
|
|
1020
|
+
}, {
|
|
1021
|
+
lngs: ["fr"],
|
|
1022
|
+
nr: [1, 2],
|
|
1023
|
+
fc: 9
|
|
1024
|
+
}, {
|
|
1025
|
+
lngs: ["ga"],
|
|
1026
|
+
nr: [1, 2, 3, 7, 11],
|
|
1027
|
+
fc: 10
|
|
1028
|
+
}, {
|
|
1029
|
+
lngs: ["gd"],
|
|
1030
|
+
nr: [1, 2, 3, 20],
|
|
1031
|
+
fc: 11
|
|
1032
|
+
}, {
|
|
1033
|
+
lngs: ["is"],
|
|
1034
|
+
nr: [1, 2],
|
|
1035
|
+
fc: 12
|
|
1036
|
+
}, {
|
|
1037
|
+
lngs: ["jv"],
|
|
1038
|
+
nr: [0, 1],
|
|
1039
|
+
fc: 13
|
|
1040
|
+
}, {
|
|
1041
|
+
lngs: ["kw"],
|
|
1042
|
+
nr: [1, 2, 3, 4],
|
|
1043
|
+
fc: 14
|
|
1044
|
+
}, {
|
|
1045
|
+
lngs: ["lt"],
|
|
1046
|
+
nr: [1, 2, 10],
|
|
1047
|
+
fc: 15
|
|
1048
|
+
}, {
|
|
1049
|
+
lngs: ["lv"],
|
|
1050
|
+
nr: [1, 2, 0],
|
|
1051
|
+
fc: 16
|
|
1052
|
+
}, {
|
|
1053
|
+
lngs: ["mk"],
|
|
1054
|
+
nr: [1, 2],
|
|
1055
|
+
fc: 17
|
|
1056
|
+
}, {
|
|
1057
|
+
lngs: ["mnk"],
|
|
1058
|
+
nr: [0, 1, 2],
|
|
1059
|
+
fc: 18
|
|
1060
|
+
}, {
|
|
1061
|
+
lngs: ["mt"],
|
|
1062
|
+
nr: [1, 2, 11, 20],
|
|
1063
|
+
fc: 19
|
|
1064
|
+
}, {
|
|
1065
|
+
lngs: ["or"],
|
|
1066
|
+
nr: [2, 1],
|
|
1067
|
+
fc: 2
|
|
1068
|
+
}, {
|
|
1069
|
+
lngs: ["ro"],
|
|
1070
|
+
nr: [1, 2, 20],
|
|
1071
|
+
fc: 20
|
|
1072
|
+
}, {
|
|
1073
|
+
lngs: ["sl"],
|
|
1074
|
+
nr: [5, 1, 2, 3],
|
|
1075
|
+
fc: 21
|
|
1076
|
+
}, {
|
|
1077
|
+
lngs: ["he", "iw"],
|
|
1078
|
+
nr: [1, 2, 20, 21],
|
|
1079
|
+
fc: 22
|
|
1080
|
+
}];
|
|
1081
|
+
let _rulesPluralsTypes = {
|
|
1082
|
+
1: (n) => Number(n > 1),
|
|
1083
|
+
2: (n) => Number(n != 1),
|
|
1084
|
+
3: (n) => 0,
|
|
1085
|
+
4: (n) => Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2),
|
|
1086
|
+
5: (n) => Number(n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5),
|
|
1087
|
+
6: (n) => Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2),
|
|
1088
|
+
7: (n) => Number(n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2),
|
|
1089
|
+
8: (n) => Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3),
|
|
1090
|
+
9: (n) => Number(n >= 2),
|
|
1091
|
+
10: (n) => Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4),
|
|
1092
|
+
11: (n) => Number(n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3),
|
|
1093
|
+
12: (n) => Number(n % 10 != 1 || n % 100 == 11),
|
|
1094
|
+
13: (n) => Number(n !== 0),
|
|
1095
|
+
14: (n) => Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3),
|
|
1096
|
+
15: (n) => Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2),
|
|
1097
|
+
16: (n) => Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2),
|
|
1098
|
+
17: (n) => Number(n == 1 || n % 10 == 1 && n % 100 != 11 ? 0 : 1),
|
|
1099
|
+
18: (n) => Number(n == 0 ? 0 : n == 1 ? 1 : 2),
|
|
1100
|
+
19: (n) => Number(n == 1 ? 0 : n == 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3),
|
|
1101
|
+
20: (n) => Number(n == 1 ? 0 : n == 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2),
|
|
1102
|
+
21: (n) => Number(n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0),
|
|
1103
|
+
22: (n) => Number(n == 1 ? 0 : n == 2 ? 1 : (n < 0 || n > 10) && n % 10 == 0 ? 2 : 3)
|
|
1104
|
+
};
|
|
1105
|
+
const nonIntlVersions = ["v1", "v2", "v3"];
|
|
1106
|
+
const intlVersions = ["v4"];
|
|
1107
|
+
const suffixesOrder = {
|
|
1108
|
+
zero: 0,
|
|
1109
|
+
one: 1,
|
|
1110
|
+
two: 2,
|
|
1111
|
+
few: 3,
|
|
1112
|
+
many: 4,
|
|
1113
|
+
other: 5
|
|
1114
|
+
};
|
|
1115
|
+
const createRules = () => {
|
|
1116
|
+
const rules = {};
|
|
1117
|
+
sets.forEach((set) => {
|
|
1118
|
+
set.lngs.forEach((l) => {
|
|
1119
|
+
rules[l] = {
|
|
1120
|
+
numbers: set.nr,
|
|
1121
|
+
plurals: _rulesPluralsTypes[set.fc]
|
|
1122
|
+
};
|
|
1123
|
+
});
|
|
1124
|
+
});
|
|
1125
|
+
return rules;
|
|
1126
|
+
};
|
|
1127
|
+
class PluralResolver {
|
|
1128
|
+
constructor(languageUtils) {
|
|
1129
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1130
|
+
this.languageUtils = languageUtils;
|
|
1131
|
+
this.options = options;
|
|
1132
|
+
this.logger = baseLogger.create("pluralResolver");
|
|
1133
|
+
if ((!this.options.compatibilityJSON || intlVersions.includes(this.options.compatibilityJSON)) && (typeof Intl === "undefined" || !Intl.PluralRules)) {
|
|
1134
|
+
this.options.compatibilityJSON = "v3";
|
|
1135
|
+
this.logger.error("Your environment seems not to be Intl API compatible, use an Intl.PluralRules polyfill. Will fallback to the compatibilityJSON v3 format handling.");
|
|
1136
|
+
}
|
|
1137
|
+
this.rules = createRules();
|
|
1138
|
+
this.pluralRulesCache = {};
|
|
1139
|
+
}
|
|
1140
|
+
addRule(lng, obj) {
|
|
1141
|
+
this.rules[lng] = obj;
|
|
1142
|
+
}
|
|
1143
|
+
clearCache() {
|
|
1144
|
+
this.pluralRulesCache = {};
|
|
1145
|
+
}
|
|
1146
|
+
getRule(code) {
|
|
1147
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1148
|
+
if (this.shouldUseIntlApi()) {
|
|
1149
|
+
const cleanedCode = getCleanedCode(code === "dev" ? "en" : code);
|
|
1150
|
+
const type = options.ordinal ? "ordinal" : "cardinal";
|
|
1151
|
+
const cacheKey = JSON.stringify({
|
|
1152
|
+
cleanedCode,
|
|
1153
|
+
type
|
|
1154
|
+
});
|
|
1155
|
+
if (cacheKey in this.pluralRulesCache) {
|
|
1156
|
+
return this.pluralRulesCache[cacheKey];
|
|
1157
|
+
}
|
|
1158
|
+
let rule;
|
|
1159
|
+
try {
|
|
1160
|
+
rule = new Intl.PluralRules(cleanedCode, {
|
|
1161
|
+
type
|
|
1162
|
+
});
|
|
1163
|
+
} catch (err) {
|
|
1164
|
+
if (!code.match(/-|_/)) return;
|
|
1165
|
+
const lngPart = this.languageUtils.getLanguagePartFromCode(code);
|
|
1166
|
+
rule = this.getRule(lngPart, options);
|
|
1167
|
+
}
|
|
1168
|
+
this.pluralRulesCache[cacheKey] = rule;
|
|
1169
|
+
return rule;
|
|
1170
|
+
}
|
|
1171
|
+
return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
|
|
1172
|
+
}
|
|
1173
|
+
needsPlural(code) {
|
|
1174
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1175
|
+
const rule = this.getRule(code, options);
|
|
1176
|
+
if (this.shouldUseIntlApi()) {
|
|
1177
|
+
return rule && rule.resolvedOptions().pluralCategories.length > 1;
|
|
1178
|
+
}
|
|
1179
|
+
return rule && rule.numbers.length > 1;
|
|
1180
|
+
}
|
|
1181
|
+
getPluralFormsOfKey(code, key) {
|
|
1182
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1183
|
+
return this.getSuffixes(code, options).map((suffix) => `${key}${suffix}`);
|
|
1184
|
+
}
|
|
1185
|
+
getSuffixes(code) {
|
|
1186
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1187
|
+
const rule = this.getRule(code, options);
|
|
1188
|
+
if (!rule) {
|
|
1189
|
+
return [];
|
|
1190
|
+
}
|
|
1191
|
+
if (this.shouldUseIntlApi()) {
|
|
1192
|
+
return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map((pluralCategory) => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${pluralCategory}`);
|
|
1193
|
+
}
|
|
1194
|
+
return rule.numbers.map((number) => this.getSuffix(code, number, options));
|
|
1195
|
+
}
|
|
1196
|
+
getSuffix(code, count) {
|
|
1197
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1198
|
+
const rule = this.getRule(code, options);
|
|
1199
|
+
if (rule) {
|
|
1200
|
+
if (this.shouldUseIntlApi()) {
|
|
1201
|
+
return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${rule.select(count)}`;
|
|
1202
|
+
}
|
|
1203
|
+
return this.getSuffixRetroCompatible(rule, count);
|
|
1204
|
+
}
|
|
1205
|
+
this.logger.warn(`no plural rule found for: ${code}`);
|
|
1206
|
+
return "";
|
|
1207
|
+
}
|
|
1208
|
+
getSuffixRetroCompatible(rule, count) {
|
|
1209
|
+
const idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
|
|
1210
|
+
let suffix = rule.numbers[idx];
|
|
1211
|
+
if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
1212
|
+
if (suffix === 2) {
|
|
1213
|
+
suffix = "plural";
|
|
1214
|
+
} else if (suffix === 1) {
|
|
1215
|
+
suffix = "";
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
const returnSuffix = () => this.options.prepend && suffix.toString() ? this.options.prepend + suffix.toString() : suffix.toString();
|
|
1219
|
+
if (this.options.compatibilityJSON === "v1") {
|
|
1220
|
+
if (suffix === 1) return "";
|
|
1221
|
+
if (typeof suffix === "number") return `_plural_${suffix.toString()}`;
|
|
1222
|
+
return returnSuffix();
|
|
1223
|
+
} else if (this.options.compatibilityJSON === "v2") {
|
|
1224
|
+
return returnSuffix();
|
|
1225
|
+
} else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
1226
|
+
return returnSuffix();
|
|
1227
|
+
}
|
|
1228
|
+
return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
|
|
1229
|
+
}
|
|
1230
|
+
shouldUseIntlApi() {
|
|
1231
|
+
return !nonIntlVersions.includes(this.options.compatibilityJSON);
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
const deepFindWithDefaults = function(data, defaultData, key) {
|
|
1235
|
+
let keySeparator = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : ".";
|
|
1236
|
+
let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : true;
|
|
1237
|
+
let path = getPathWithDefaults(data, defaultData, key);
|
|
1238
|
+
if (!path && ignoreJSONStructure && isString(key)) {
|
|
1239
|
+
path = deepFind(data, key, keySeparator);
|
|
1240
|
+
if (path === void 0) path = deepFind(defaultData, key, keySeparator);
|
|
1241
|
+
}
|
|
1242
|
+
return path;
|
|
1243
|
+
};
|
|
1244
|
+
const regexSafe = (val) => val.replace(/\$/g, "$$$$");
|
|
1245
|
+
class Interpolator {
|
|
1246
|
+
constructor() {
|
|
1247
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1248
|
+
this.logger = baseLogger.create("interpolator");
|
|
1249
|
+
this.options = options;
|
|
1250
|
+
this.format = options.interpolation && options.interpolation.format || ((value) => value);
|
|
1251
|
+
this.init(options);
|
|
1252
|
+
}
|
|
1253
|
+
init() {
|
|
1254
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1255
|
+
if (!options.interpolation) options.interpolation = {
|
|
1256
|
+
escapeValue: true
|
|
1257
|
+
};
|
|
1258
|
+
const {
|
|
1259
|
+
escape: escape$1,
|
|
1260
|
+
escapeValue,
|
|
1261
|
+
useRawValueToEscape,
|
|
1262
|
+
prefix,
|
|
1263
|
+
prefixEscaped,
|
|
1264
|
+
suffix,
|
|
1265
|
+
suffixEscaped,
|
|
1266
|
+
formatSeparator,
|
|
1267
|
+
unescapeSuffix,
|
|
1268
|
+
unescapePrefix,
|
|
1269
|
+
nestingPrefix,
|
|
1270
|
+
nestingPrefixEscaped,
|
|
1271
|
+
nestingSuffix,
|
|
1272
|
+
nestingSuffixEscaped,
|
|
1273
|
+
nestingOptionsSeparator,
|
|
1274
|
+
maxReplaces,
|
|
1275
|
+
alwaysFormat
|
|
1276
|
+
} = options.interpolation;
|
|
1277
|
+
this.escape = escape$1 !== void 0 ? escape$1 : escape;
|
|
1278
|
+
this.escapeValue = escapeValue !== void 0 ? escapeValue : true;
|
|
1279
|
+
this.useRawValueToEscape = useRawValueToEscape !== void 0 ? useRawValueToEscape : false;
|
|
1280
|
+
this.prefix = prefix ? regexEscape(prefix) : prefixEscaped || "{{";
|
|
1281
|
+
this.suffix = suffix ? regexEscape(suffix) : suffixEscaped || "}}";
|
|
1282
|
+
this.formatSeparator = formatSeparator || ",";
|
|
1283
|
+
this.unescapePrefix = unescapeSuffix ? "" : unescapePrefix || "-";
|
|
1284
|
+
this.unescapeSuffix = this.unescapePrefix ? "" : unescapeSuffix || "";
|
|
1285
|
+
this.nestingPrefix = nestingPrefix ? regexEscape(nestingPrefix) : nestingPrefixEscaped || regexEscape("$t(");
|
|
1286
|
+
this.nestingSuffix = nestingSuffix ? regexEscape(nestingSuffix) : nestingSuffixEscaped || regexEscape(")");
|
|
1287
|
+
this.nestingOptionsSeparator = nestingOptionsSeparator || ",";
|
|
1288
|
+
this.maxReplaces = maxReplaces || 1e3;
|
|
1289
|
+
this.alwaysFormat = alwaysFormat !== void 0 ? alwaysFormat : false;
|
|
1290
|
+
this.resetRegExp();
|
|
1291
|
+
}
|
|
1292
|
+
reset() {
|
|
1293
|
+
if (this.options) this.init(this.options);
|
|
1294
|
+
}
|
|
1295
|
+
resetRegExp() {
|
|
1296
|
+
const getOrResetRegExp = (existingRegExp, pattern) => {
|
|
1297
|
+
if (existingRegExp && existingRegExp.source === pattern) {
|
|
1298
|
+
existingRegExp.lastIndex = 0;
|
|
1299
|
+
return existingRegExp;
|
|
1300
|
+
}
|
|
1301
|
+
return new RegExp(pattern, "g");
|
|
1302
|
+
};
|
|
1303
|
+
this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
|
|
1304
|
+
this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
|
|
1305
|
+
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}(.+?)${this.nestingSuffix}`);
|
|
1306
|
+
}
|
|
1307
|
+
interpolate(str, data, lng, options) {
|
|
1308
|
+
let match;
|
|
1309
|
+
let value;
|
|
1310
|
+
let replaces;
|
|
1311
|
+
const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
1312
|
+
const handleFormat = (key) => {
|
|
1313
|
+
if (key.indexOf(this.formatSeparator) < 0) {
|
|
1314
|
+
const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
|
|
1315
|
+
return this.alwaysFormat ? this.format(path, void 0, lng, {
|
|
1316
|
+
...options,
|
|
1317
|
+
...data,
|
|
1318
|
+
interpolationkey: key
|
|
1319
|
+
}) : path;
|
|
1320
|
+
}
|
|
1321
|
+
const p = key.split(this.formatSeparator);
|
|
1322
|
+
const k = p.shift().trim();
|
|
1323
|
+
const f = p.join(this.formatSeparator).trim();
|
|
1324
|
+
return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
|
|
1325
|
+
...options,
|
|
1326
|
+
...data,
|
|
1327
|
+
interpolationkey: k
|
|
1328
|
+
});
|
|
1329
|
+
};
|
|
1330
|
+
this.resetRegExp();
|
|
1331
|
+
const missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler;
|
|
1332
|
+
const skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
|
|
1333
|
+
const todos = [{
|
|
1334
|
+
regex: this.regexpUnescape,
|
|
1335
|
+
safeValue: (val) => regexSafe(val)
|
|
1336
|
+
}, {
|
|
1337
|
+
regex: this.regexp,
|
|
1338
|
+
safeValue: (val) => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
|
|
1339
|
+
}];
|
|
1340
|
+
todos.forEach((todo) => {
|
|
1341
|
+
replaces = 0;
|
|
1342
|
+
while (match = todo.regex.exec(str)) {
|
|
1343
|
+
const matchedVar = match[1].trim();
|
|
1344
|
+
value = handleFormat(matchedVar);
|
|
1345
|
+
if (value === void 0) {
|
|
1346
|
+
if (typeof missingInterpolationHandler === "function") {
|
|
1347
|
+
const temp = missingInterpolationHandler(str, match, options);
|
|
1348
|
+
value = isString(temp) ? temp : "";
|
|
1349
|
+
} else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
|
|
1350
|
+
value = "";
|
|
1351
|
+
} else if (skipOnVariables) {
|
|
1352
|
+
value = match[0];
|
|
1353
|
+
continue;
|
|
1354
|
+
} else {
|
|
1355
|
+
this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
|
|
1356
|
+
value = "";
|
|
1357
|
+
}
|
|
1358
|
+
} else if (!isString(value) && !this.useRawValueToEscape) {
|
|
1359
|
+
value = makeString(value);
|
|
1360
|
+
}
|
|
1361
|
+
const safeValue = todo.safeValue(value);
|
|
1362
|
+
str = str.replace(match[0], safeValue);
|
|
1363
|
+
if (skipOnVariables) {
|
|
1364
|
+
todo.regex.lastIndex += value.length;
|
|
1365
|
+
todo.regex.lastIndex -= match[0].length;
|
|
1366
|
+
} else {
|
|
1367
|
+
todo.regex.lastIndex = 0;
|
|
1368
|
+
}
|
|
1369
|
+
replaces++;
|
|
1370
|
+
if (replaces >= this.maxReplaces) {
|
|
1371
|
+
break;
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
});
|
|
1375
|
+
return str;
|
|
1376
|
+
}
|
|
1377
|
+
nest(str, fc) {
|
|
1378
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1379
|
+
let match;
|
|
1380
|
+
let value;
|
|
1381
|
+
let clonedOptions;
|
|
1382
|
+
const handleHasOptions = (key, inheritedOptions) => {
|
|
1383
|
+
const sep = this.nestingOptionsSeparator;
|
|
1384
|
+
if (key.indexOf(sep) < 0) return key;
|
|
1385
|
+
const c = key.split(new RegExp(`${sep}[ ]*{`));
|
|
1386
|
+
let optionsString = `{${c[1]}`;
|
|
1387
|
+
key = c[0];
|
|
1388
|
+
optionsString = this.interpolate(optionsString, clonedOptions);
|
|
1389
|
+
const matchedSingleQuotes = optionsString.match(/'/g);
|
|
1390
|
+
const matchedDoubleQuotes = optionsString.match(/"/g);
|
|
1391
|
+
if (matchedSingleQuotes && matchedSingleQuotes.length % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
|
|
1392
|
+
optionsString = optionsString.replace(/'/g, '"');
|
|
1393
|
+
}
|
|
1394
|
+
try {
|
|
1395
|
+
clonedOptions = JSON.parse(optionsString);
|
|
1396
|
+
if (inheritedOptions) clonedOptions = {
|
|
1397
|
+
...inheritedOptions,
|
|
1398
|
+
...clonedOptions
|
|
1399
|
+
};
|
|
1400
|
+
} catch (e) {
|
|
1401
|
+
this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
|
|
1402
|
+
return `${key}${sep}${optionsString}`;
|
|
1403
|
+
}
|
|
1404
|
+
if (clonedOptions.defaultValue && clonedOptions.defaultValue.indexOf(this.prefix) > -1) delete clonedOptions.defaultValue;
|
|
1405
|
+
return key;
|
|
1406
|
+
};
|
|
1407
|
+
while (match = this.nestingRegexp.exec(str)) {
|
|
1408
|
+
let formatters = [];
|
|
1409
|
+
clonedOptions = {
|
|
1410
|
+
...options
|
|
1411
|
+
};
|
|
1412
|
+
clonedOptions = clonedOptions.replace && !isString(clonedOptions.replace) ? clonedOptions.replace : clonedOptions;
|
|
1413
|
+
clonedOptions.applyPostProcessor = false;
|
|
1414
|
+
delete clonedOptions.defaultValue;
|
|
1415
|
+
let doReduce = false;
|
|
1416
|
+
if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
|
|
1417
|
+
const r = match[1].split(this.formatSeparator).map((elem) => elem.trim());
|
|
1418
|
+
match[1] = r.shift();
|
|
1419
|
+
formatters = r;
|
|
1420
|
+
doReduce = true;
|
|
1421
|
+
}
|
|
1422
|
+
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
1423
|
+
if (value && match[0] === str && !isString(value)) return value;
|
|
1424
|
+
if (!isString(value)) value = makeString(value);
|
|
1425
|
+
if (!value) {
|
|
1426
|
+
this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
|
|
1427
|
+
value = "";
|
|
1428
|
+
}
|
|
1429
|
+
if (doReduce) {
|
|
1430
|
+
value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
|
|
1431
|
+
...options,
|
|
1432
|
+
interpolationkey: match[1].trim()
|
|
1433
|
+
}), value.trim());
|
|
1434
|
+
}
|
|
1435
|
+
str = str.replace(match[0], value);
|
|
1436
|
+
this.regexp.lastIndex = 0;
|
|
1437
|
+
}
|
|
1438
|
+
return str;
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
const parseFormatStr = (formatStr) => {
|
|
1442
|
+
let formatName = formatStr.toLowerCase().trim();
|
|
1443
|
+
const formatOptions = {};
|
|
1444
|
+
if (formatStr.indexOf("(") > -1) {
|
|
1445
|
+
const p = formatStr.split("(");
|
|
1446
|
+
formatName = p[0].toLowerCase().trim();
|
|
1447
|
+
const optStr = p[1].substring(0, p[1].length - 1);
|
|
1448
|
+
if (formatName === "currency" && optStr.indexOf(":") < 0) {
|
|
1449
|
+
if (!formatOptions.currency) formatOptions.currency = optStr.trim();
|
|
1450
|
+
} else if (formatName === "relativetime" && optStr.indexOf(":") < 0) {
|
|
1451
|
+
if (!formatOptions.range) formatOptions.range = optStr.trim();
|
|
1452
|
+
} else {
|
|
1453
|
+
const opts = optStr.split(";");
|
|
1454
|
+
opts.forEach((opt) => {
|
|
1455
|
+
if (opt) {
|
|
1456
|
+
const [key, ...rest] = opt.split(":");
|
|
1457
|
+
const val = rest.join(":").trim().replace(/^'+|'+$/g, "");
|
|
1458
|
+
const trimmedKey = key.trim();
|
|
1459
|
+
if (!formatOptions[trimmedKey]) formatOptions[trimmedKey] = val;
|
|
1460
|
+
if (val === "false") formatOptions[trimmedKey] = false;
|
|
1461
|
+
if (val === "true") formatOptions[trimmedKey] = true;
|
|
1462
|
+
if (!isNaN(val)) formatOptions[trimmedKey] = parseInt(val, 10);
|
|
1463
|
+
}
|
|
1464
|
+
});
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
return {
|
|
1468
|
+
formatName,
|
|
1469
|
+
formatOptions
|
|
1470
|
+
};
|
|
1471
|
+
};
|
|
1472
|
+
const createCachedFormatter = (fn) => {
|
|
1473
|
+
const cache = {};
|
|
1474
|
+
return (val, lng, options) => {
|
|
1475
|
+
let optForCache = options;
|
|
1476
|
+
if (options && options.interpolationkey && options.formatParams && options.formatParams[options.interpolationkey] && options[options.interpolationkey]) {
|
|
1477
|
+
optForCache = {
|
|
1478
|
+
...optForCache,
|
|
1479
|
+
[options.interpolationkey]: void 0
|
|
1480
|
+
};
|
|
1481
|
+
}
|
|
1482
|
+
const key = lng + JSON.stringify(optForCache);
|
|
1483
|
+
let formatter = cache[key];
|
|
1484
|
+
if (!formatter) {
|
|
1485
|
+
formatter = fn(getCleanedCode(lng), options);
|
|
1486
|
+
cache[key] = formatter;
|
|
1487
|
+
}
|
|
1488
|
+
return formatter(val);
|
|
1489
|
+
};
|
|
1490
|
+
};
|
|
1491
|
+
class Formatter {
|
|
1492
|
+
constructor() {
|
|
1493
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1494
|
+
this.logger = baseLogger.create("formatter");
|
|
1495
|
+
this.options = options;
|
|
1496
|
+
this.formats = {
|
|
1497
|
+
number: createCachedFormatter((lng, opt) => {
|
|
1498
|
+
const formatter = new Intl.NumberFormat(lng, {
|
|
1499
|
+
...opt
|
|
1500
|
+
});
|
|
1501
|
+
return (val) => formatter.format(val);
|
|
1502
|
+
}),
|
|
1503
|
+
currency: createCachedFormatter((lng, opt) => {
|
|
1504
|
+
const formatter = new Intl.NumberFormat(lng, {
|
|
1505
|
+
...opt,
|
|
1506
|
+
style: "currency"
|
|
1507
|
+
});
|
|
1508
|
+
return (val) => formatter.format(val);
|
|
1509
|
+
}),
|
|
1510
|
+
datetime: createCachedFormatter((lng, opt) => {
|
|
1511
|
+
const formatter = new Intl.DateTimeFormat(lng, {
|
|
1512
|
+
...opt
|
|
1513
|
+
});
|
|
1514
|
+
return (val) => formatter.format(val);
|
|
1515
|
+
}),
|
|
1516
|
+
relativetime: createCachedFormatter((lng, opt) => {
|
|
1517
|
+
const formatter = new Intl.RelativeTimeFormat(lng, {
|
|
1518
|
+
...opt
|
|
1519
|
+
});
|
|
1520
|
+
return (val) => formatter.format(val, opt.range || "day");
|
|
1521
|
+
}),
|
|
1522
|
+
list: createCachedFormatter((lng, opt) => {
|
|
1523
|
+
const formatter = new Intl.ListFormat(lng, {
|
|
1524
|
+
...opt
|
|
1525
|
+
});
|
|
1526
|
+
return (val) => formatter.format(val);
|
|
1527
|
+
})
|
|
1528
|
+
};
|
|
1529
|
+
this.init(options);
|
|
1530
|
+
}
|
|
1531
|
+
init(services) {
|
|
1532
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
|
|
1533
|
+
interpolation: {}
|
|
1534
|
+
};
|
|
1535
|
+
this.formatSeparator = options.interpolation.formatSeparator || ",";
|
|
1536
|
+
}
|
|
1537
|
+
add(name, fc) {
|
|
1538
|
+
this.formats[name.toLowerCase().trim()] = fc;
|
|
1539
|
+
}
|
|
1540
|
+
addCached(name, fc) {
|
|
1541
|
+
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
1542
|
+
}
|
|
1543
|
+
format(value, format, lng) {
|
|
1544
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
1545
|
+
const formats = format.split(this.formatSeparator);
|
|
1546
|
+
if (formats.length > 1 && formats[0].indexOf("(") > 1 && formats[0].indexOf(")") < 0 && formats.find((f) => f.indexOf(")") > -1)) {
|
|
1547
|
+
const lastIndex = formats.findIndex((f) => f.indexOf(")") > -1);
|
|
1548
|
+
formats[0] = [formats[0], ...formats.splice(1, lastIndex)].join(this.formatSeparator);
|
|
1549
|
+
}
|
|
1550
|
+
const result = formats.reduce((mem, f) => {
|
|
1551
|
+
const {
|
|
1552
|
+
formatName,
|
|
1553
|
+
formatOptions
|
|
1554
|
+
} = parseFormatStr(f);
|
|
1555
|
+
if (this.formats[formatName]) {
|
|
1556
|
+
let formatted = mem;
|
|
1557
|
+
try {
|
|
1558
|
+
const valOptions = options && options.formatParams && options.formatParams[options.interpolationkey] || {};
|
|
1559
|
+
const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
|
|
1560
|
+
formatted = this.formats[formatName](mem, l, {
|
|
1561
|
+
...formatOptions,
|
|
1562
|
+
...options,
|
|
1563
|
+
...valOptions
|
|
1564
|
+
});
|
|
1565
|
+
} catch (error) {
|
|
1566
|
+
this.logger.warn(error);
|
|
1567
|
+
}
|
|
1568
|
+
return formatted;
|
|
1569
|
+
} else {
|
|
1570
|
+
this.logger.warn(`there was no format function for ${formatName}`);
|
|
1571
|
+
}
|
|
1572
|
+
return mem;
|
|
1573
|
+
}, value);
|
|
1574
|
+
return result;
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
const removePending = (q, name) => {
|
|
1578
|
+
if (q.pending[name] !== void 0) {
|
|
1579
|
+
delete q.pending[name];
|
|
1580
|
+
q.pendingCount--;
|
|
1581
|
+
}
|
|
1582
|
+
};
|
|
1583
|
+
class Connector extends EventEmitter {
|
|
1584
|
+
constructor(backend, store, services) {
|
|
1585
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
1586
|
+
super();
|
|
1587
|
+
this.backend = backend;
|
|
1588
|
+
this.store = store;
|
|
1589
|
+
this.services = services;
|
|
1590
|
+
this.languageUtils = services.languageUtils;
|
|
1591
|
+
this.options = options;
|
|
1592
|
+
this.logger = baseLogger.create("backendConnector");
|
|
1593
|
+
this.waitingReads = [];
|
|
1594
|
+
this.maxParallelReads = options.maxParallelReads || 10;
|
|
1595
|
+
this.readingCalls = 0;
|
|
1596
|
+
this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
|
|
1597
|
+
this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
|
|
1598
|
+
this.state = {};
|
|
1599
|
+
this.queue = [];
|
|
1600
|
+
if (this.backend && this.backend.init) {
|
|
1601
|
+
this.backend.init(services, options.backend, options);
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
queueLoad(languages, namespaces, options, callback) {
|
|
1605
|
+
const toLoad = {};
|
|
1606
|
+
const pending = {};
|
|
1607
|
+
const toLoadLanguages = {};
|
|
1608
|
+
const toLoadNamespaces = {};
|
|
1609
|
+
languages.forEach((lng) => {
|
|
1610
|
+
let hasAllNamespaces = true;
|
|
1611
|
+
namespaces.forEach((ns) => {
|
|
1612
|
+
const name = `${lng}|${ns}`;
|
|
1613
|
+
if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
|
|
1614
|
+
this.state[name] = 2;
|
|
1615
|
+
} else if (this.state[name] < 0) ;
|
|
1616
|
+
else if (this.state[name] === 1) {
|
|
1617
|
+
if (pending[name] === void 0) pending[name] = true;
|
|
1618
|
+
} else {
|
|
1619
|
+
this.state[name] = 1;
|
|
1620
|
+
hasAllNamespaces = false;
|
|
1621
|
+
if (pending[name] === void 0) pending[name] = true;
|
|
1622
|
+
if (toLoad[name] === void 0) toLoad[name] = true;
|
|
1623
|
+
if (toLoadNamespaces[ns] === void 0) toLoadNamespaces[ns] = true;
|
|
1624
|
+
}
|
|
1625
|
+
});
|
|
1626
|
+
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
1627
|
+
});
|
|
1628
|
+
if (Object.keys(toLoad).length || Object.keys(pending).length) {
|
|
1629
|
+
this.queue.push({
|
|
1630
|
+
pending,
|
|
1631
|
+
pendingCount: Object.keys(pending).length,
|
|
1632
|
+
loaded: {},
|
|
1633
|
+
errors: [],
|
|
1634
|
+
callback
|
|
1635
|
+
});
|
|
1636
|
+
}
|
|
1637
|
+
return {
|
|
1638
|
+
toLoad: Object.keys(toLoad),
|
|
1639
|
+
pending: Object.keys(pending),
|
|
1640
|
+
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
1641
|
+
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
1642
|
+
};
|
|
1643
|
+
}
|
|
1644
|
+
loaded(name, err, data) {
|
|
1645
|
+
const s = name.split("|");
|
|
1646
|
+
const lng = s[0];
|
|
1647
|
+
const ns = s[1];
|
|
1648
|
+
if (err) this.emit("failedLoading", lng, ns, err);
|
|
1649
|
+
if (!err && data) {
|
|
1650
|
+
this.store.addResourceBundle(lng, ns, data, void 0, void 0, {
|
|
1651
|
+
skipCopy: true
|
|
1652
|
+
});
|
|
1653
|
+
}
|
|
1654
|
+
this.state[name] = err ? -1 : 2;
|
|
1655
|
+
if (err && data) this.state[name] = 0;
|
|
1656
|
+
const loaded = {};
|
|
1657
|
+
this.queue.forEach((q) => {
|
|
1658
|
+
pushPath(q.loaded, [lng], ns);
|
|
1659
|
+
removePending(q, name);
|
|
1660
|
+
if (err) q.errors.push(err);
|
|
1661
|
+
if (q.pendingCount === 0 && !q.done) {
|
|
1662
|
+
Object.keys(q.loaded).forEach((l) => {
|
|
1663
|
+
if (!loaded[l]) loaded[l] = {};
|
|
1664
|
+
const loadedKeys = q.loaded[l];
|
|
1665
|
+
if (loadedKeys.length) {
|
|
1666
|
+
loadedKeys.forEach((n) => {
|
|
1667
|
+
if (loaded[l][n] === void 0) loaded[l][n] = true;
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1670
|
+
});
|
|
1671
|
+
q.done = true;
|
|
1672
|
+
if (q.errors.length) {
|
|
1673
|
+
q.callback(q.errors);
|
|
1674
|
+
} else {
|
|
1675
|
+
q.callback();
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
});
|
|
1679
|
+
this.emit("loaded", loaded);
|
|
1680
|
+
this.queue = this.queue.filter((q) => !q.done);
|
|
1681
|
+
}
|
|
1682
|
+
read(lng, ns, fcName) {
|
|
1683
|
+
let tried = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0;
|
|
1684
|
+
let wait = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : this.retryTimeout;
|
|
1685
|
+
let callback = arguments.length > 5 ? arguments[5] : void 0;
|
|
1686
|
+
if (!lng.length) return callback(null, {});
|
|
1687
|
+
if (this.readingCalls >= this.maxParallelReads) {
|
|
1688
|
+
this.waitingReads.push({
|
|
1689
|
+
lng,
|
|
1690
|
+
ns,
|
|
1691
|
+
fcName,
|
|
1692
|
+
tried,
|
|
1693
|
+
wait,
|
|
1694
|
+
callback
|
|
1695
|
+
});
|
|
1696
|
+
return;
|
|
1697
|
+
}
|
|
1698
|
+
this.readingCalls++;
|
|
1699
|
+
const resolver = (err, data) => {
|
|
1700
|
+
this.readingCalls--;
|
|
1701
|
+
if (this.waitingReads.length > 0) {
|
|
1702
|
+
const next = this.waitingReads.shift();
|
|
1703
|
+
this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
1704
|
+
}
|
|
1705
|
+
if (err && data && tried < this.maxRetries) {
|
|
1706
|
+
setTimeout(() => {
|
|
1707
|
+
this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
1708
|
+
}, wait);
|
|
1709
|
+
return;
|
|
1710
|
+
}
|
|
1711
|
+
callback(err, data);
|
|
1712
|
+
};
|
|
1713
|
+
const fc = this.backend[fcName].bind(this.backend);
|
|
1714
|
+
if (fc.length === 2) {
|
|
1715
|
+
try {
|
|
1716
|
+
const r = fc(lng, ns);
|
|
1717
|
+
if (r && typeof r.then === "function") {
|
|
1718
|
+
r.then((data) => resolver(null, data)).catch(resolver);
|
|
1719
|
+
} else {
|
|
1720
|
+
resolver(null, r);
|
|
1721
|
+
}
|
|
1722
|
+
} catch (err) {
|
|
1723
|
+
resolver(err);
|
|
1724
|
+
}
|
|
1725
|
+
return;
|
|
1726
|
+
}
|
|
1727
|
+
return fc(lng, ns, resolver);
|
|
1728
|
+
}
|
|
1729
|
+
prepareLoading(languages, namespaces) {
|
|
1730
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1731
|
+
let callback = arguments.length > 3 ? arguments[3] : void 0;
|
|
1732
|
+
if (!this.backend) {
|
|
1733
|
+
this.logger.warn("No backend was added via i18next.use. Will not load resources.");
|
|
1734
|
+
return callback && callback();
|
|
1735
|
+
}
|
|
1736
|
+
if (isString(languages)) languages = this.languageUtils.toResolveHierarchy(languages);
|
|
1737
|
+
if (isString(namespaces)) namespaces = [namespaces];
|
|
1738
|
+
const toLoad = this.queueLoad(languages, namespaces, options, callback);
|
|
1739
|
+
if (!toLoad.toLoad.length) {
|
|
1740
|
+
if (!toLoad.pending.length) callback();
|
|
1741
|
+
return null;
|
|
1742
|
+
}
|
|
1743
|
+
toLoad.toLoad.forEach((name) => {
|
|
1744
|
+
this.loadOne(name);
|
|
1745
|
+
});
|
|
1746
|
+
}
|
|
1747
|
+
load(languages, namespaces, callback) {
|
|
1748
|
+
this.prepareLoading(languages, namespaces, {}, callback);
|
|
1749
|
+
}
|
|
1750
|
+
reload(languages, namespaces, callback) {
|
|
1751
|
+
this.prepareLoading(languages, namespaces, {
|
|
1752
|
+
reload: true
|
|
1753
|
+
}, callback);
|
|
1754
|
+
}
|
|
1755
|
+
loadOne(name) {
|
|
1756
|
+
let prefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
|
|
1757
|
+
const s = name.split("|");
|
|
1758
|
+
const lng = s[0];
|
|
1759
|
+
const ns = s[1];
|
|
1760
|
+
this.read(lng, ns, "read", void 0, void 0, (err, data) => {
|
|
1761
|
+
if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
|
|
1762
|
+
if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
|
|
1763
|
+
this.loaded(name, err, data);
|
|
1764
|
+
});
|
|
1765
|
+
}
|
|
1766
|
+
saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
|
|
1767
|
+
let options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {};
|
|
1768
|
+
let clb = arguments.length > 6 && arguments[6] !== void 0 ? arguments[6] : () => {
|
|
1769
|
+
};
|
|
1770
|
+
if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
|
|
1771
|
+
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!!!");
|
|
1772
|
+
return;
|
|
1773
|
+
}
|
|
1774
|
+
if (key === void 0 || key === null || key === "") return;
|
|
1775
|
+
if (this.backend && this.backend.create) {
|
|
1776
|
+
const opts = {
|
|
1777
|
+
...options,
|
|
1778
|
+
isUpdate
|
|
1779
|
+
};
|
|
1780
|
+
const fc = this.backend.create.bind(this.backend);
|
|
1781
|
+
if (fc.length < 6) {
|
|
1782
|
+
try {
|
|
1783
|
+
let r;
|
|
1784
|
+
if (fc.length === 5) {
|
|
1785
|
+
r = fc(languages, namespace, key, fallbackValue, opts);
|
|
1786
|
+
} else {
|
|
1787
|
+
r = fc(languages, namespace, key, fallbackValue);
|
|
1788
|
+
}
|
|
1789
|
+
if (r && typeof r.then === "function") {
|
|
1790
|
+
r.then((data) => clb(null, data)).catch(clb);
|
|
1791
|
+
} else {
|
|
1792
|
+
clb(null, r);
|
|
1793
|
+
}
|
|
1794
|
+
} catch (err) {
|
|
1795
|
+
clb(err);
|
|
1796
|
+
}
|
|
1797
|
+
} else {
|
|
1798
|
+
fc(languages, namespace, key, fallbackValue, clb, opts);
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
if (!languages || !languages[0]) return;
|
|
1802
|
+
this.store.addResource(languages[0], namespace, key, fallbackValue);
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
const get = () => ({
|
|
1806
|
+
debug: false,
|
|
1807
|
+
initImmediate: true,
|
|
1808
|
+
ns: ["translation"],
|
|
1809
|
+
defaultNS: ["translation"],
|
|
1810
|
+
fallbackLng: ["dev"],
|
|
1811
|
+
fallbackNS: false,
|
|
1812
|
+
supportedLngs: false,
|
|
1813
|
+
nonExplicitSupportedLngs: false,
|
|
1814
|
+
load: "all",
|
|
1815
|
+
preload: false,
|
|
1816
|
+
simplifyPluralSuffix: true,
|
|
1817
|
+
keySeparator: ".",
|
|
1818
|
+
nsSeparator: ":",
|
|
1819
|
+
pluralSeparator: "_",
|
|
1820
|
+
contextSeparator: "_",
|
|
1821
|
+
partialBundledLanguages: false,
|
|
1822
|
+
saveMissing: false,
|
|
1823
|
+
updateMissing: false,
|
|
1824
|
+
saveMissingTo: "fallback",
|
|
1825
|
+
saveMissingPlurals: true,
|
|
1826
|
+
missingKeyHandler: false,
|
|
1827
|
+
missingInterpolationHandler: false,
|
|
1828
|
+
postProcess: false,
|
|
1829
|
+
postProcessPassResolved: false,
|
|
1830
|
+
returnNull: false,
|
|
1831
|
+
returnEmptyString: true,
|
|
1832
|
+
returnObjects: false,
|
|
1833
|
+
joinArrays: false,
|
|
1834
|
+
returnedObjectHandler: false,
|
|
1835
|
+
parseMissingKeyHandler: false,
|
|
1836
|
+
appendNamespaceToMissingKey: false,
|
|
1837
|
+
appendNamespaceToCIMode: false,
|
|
1838
|
+
overloadTranslationOptionHandler: (args) => {
|
|
1839
|
+
let ret = {};
|
|
1840
|
+
if (typeof args[1] === "object") ret = args[1];
|
|
1841
|
+
if (isString(args[1])) ret.defaultValue = args[1];
|
|
1842
|
+
if (isString(args[2])) ret.tDescription = args[2];
|
|
1843
|
+
if (typeof args[2] === "object" || typeof args[3] === "object") {
|
|
1844
|
+
const options = args[3] || args[2];
|
|
1845
|
+
Object.keys(options).forEach((key) => {
|
|
1846
|
+
ret[key] = options[key];
|
|
1847
|
+
});
|
|
1848
|
+
}
|
|
1849
|
+
return ret;
|
|
1850
|
+
},
|
|
1851
|
+
interpolation: {
|
|
1852
|
+
escapeValue: true,
|
|
1853
|
+
format: (value) => value,
|
|
1854
|
+
prefix: "{{",
|
|
1855
|
+
suffix: "}}",
|
|
1856
|
+
formatSeparator: ",",
|
|
1857
|
+
unescapePrefix: "-",
|
|
1858
|
+
nestingPrefix: "$t(",
|
|
1859
|
+
nestingSuffix: ")",
|
|
1860
|
+
nestingOptionsSeparator: ",",
|
|
1861
|
+
maxReplaces: 1e3,
|
|
1862
|
+
skipOnVariables: true
|
|
1863
|
+
}
|
|
1864
|
+
});
|
|
1865
|
+
const transformOptions = (options) => {
|
|
1866
|
+
if (isString(options.ns)) options.ns = [options.ns];
|
|
1867
|
+
if (isString(options.fallbackLng)) options.fallbackLng = [options.fallbackLng];
|
|
1868
|
+
if (isString(options.fallbackNS)) options.fallbackNS = [options.fallbackNS];
|
|
1869
|
+
if (options.supportedLngs && options.supportedLngs.indexOf("cimode") < 0) {
|
|
1870
|
+
options.supportedLngs = options.supportedLngs.concat(["cimode"]);
|
|
1871
|
+
}
|
|
1872
|
+
return options;
|
|
1873
|
+
};
|
|
1874
|
+
const noop = () => {
|
|
1875
|
+
};
|
|
1876
|
+
const bindMemberFunctions = (inst) => {
|
|
1877
|
+
const mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
|
|
1878
|
+
mems.forEach((mem) => {
|
|
1879
|
+
if (typeof inst[mem] === "function") {
|
|
1880
|
+
inst[mem] = inst[mem].bind(inst);
|
|
1881
|
+
}
|
|
1882
|
+
});
|
|
1883
|
+
};
|
|
1884
|
+
class I18n extends EventEmitter {
|
|
1885
|
+
constructor() {
|
|
1886
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1887
|
+
let callback = arguments.length > 1 ? arguments[1] : void 0;
|
|
1888
|
+
super();
|
|
1889
|
+
this.options = transformOptions(options);
|
|
1890
|
+
this.services = {};
|
|
1891
|
+
this.logger = baseLogger;
|
|
1892
|
+
this.modules = {
|
|
1893
|
+
external: []
|
|
1894
|
+
};
|
|
1895
|
+
bindMemberFunctions(this);
|
|
1896
|
+
if (callback && !this.isInitialized && !options.isClone) {
|
|
1897
|
+
if (!this.options.initImmediate) {
|
|
1898
|
+
this.init(options, callback);
|
|
1899
|
+
return this;
|
|
1900
|
+
}
|
|
1901
|
+
setTimeout(() => {
|
|
1902
|
+
this.init(options, callback);
|
|
1903
|
+
}, 0);
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
init() {
|
|
1907
|
+
var _this = this;
|
|
1908
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1909
|
+
let callback = arguments.length > 1 ? arguments[1] : void 0;
|
|
1910
|
+
this.isInitializing = true;
|
|
1911
|
+
if (typeof options === "function") {
|
|
1912
|
+
callback = options;
|
|
1913
|
+
options = {};
|
|
1914
|
+
}
|
|
1915
|
+
if (!options.defaultNS && options.defaultNS !== false && options.ns) {
|
|
1916
|
+
if (isString(options.ns)) {
|
|
1917
|
+
options.defaultNS = options.ns;
|
|
1918
|
+
} else if (options.ns.indexOf("translation") < 0) {
|
|
1919
|
+
options.defaultNS = options.ns[0];
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
const defOpts = get();
|
|
1923
|
+
this.options = {
|
|
1924
|
+
...defOpts,
|
|
1925
|
+
...this.options,
|
|
1926
|
+
...transformOptions(options)
|
|
1927
|
+
};
|
|
1928
|
+
if (this.options.compatibilityAPI !== "v1") {
|
|
1929
|
+
this.options.interpolation = {
|
|
1930
|
+
...defOpts.interpolation,
|
|
1931
|
+
...this.options.interpolation
|
|
1932
|
+
};
|
|
1933
|
+
}
|
|
1934
|
+
if (options.keySeparator !== void 0) {
|
|
1935
|
+
this.options.userDefinedKeySeparator = options.keySeparator;
|
|
1936
|
+
}
|
|
1937
|
+
if (options.nsSeparator !== void 0) {
|
|
1938
|
+
this.options.userDefinedNsSeparator = options.nsSeparator;
|
|
1939
|
+
}
|
|
1940
|
+
const createClassOnDemand = (ClassOrObject) => {
|
|
1941
|
+
if (!ClassOrObject) return null;
|
|
1942
|
+
if (typeof ClassOrObject === "function") return new ClassOrObject();
|
|
1943
|
+
return ClassOrObject;
|
|
1944
|
+
};
|
|
1945
|
+
if (!this.options.isClone) {
|
|
1946
|
+
if (this.modules.logger) {
|
|
1947
|
+
baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
|
|
1948
|
+
} else {
|
|
1949
|
+
baseLogger.init(null, this.options);
|
|
1950
|
+
}
|
|
1951
|
+
let formatter;
|
|
1952
|
+
if (this.modules.formatter) {
|
|
1953
|
+
formatter = this.modules.formatter;
|
|
1954
|
+
} else if (typeof Intl !== "undefined") {
|
|
1955
|
+
formatter = Formatter;
|
|
1956
|
+
}
|
|
1957
|
+
const lu = new LanguageUtil(this.options);
|
|
1958
|
+
this.store = new ResourceStore(this.options.resources, this.options);
|
|
1959
|
+
const s = this.services;
|
|
1960
|
+
s.logger = baseLogger;
|
|
1961
|
+
s.resourceStore = this.store;
|
|
1962
|
+
s.languageUtils = lu;
|
|
1963
|
+
s.pluralResolver = new PluralResolver(lu, {
|
|
1964
|
+
prepend: this.options.pluralSeparator,
|
|
1965
|
+
compatibilityJSON: this.options.compatibilityJSON,
|
|
1966
|
+
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
1967
|
+
});
|
|
1968
|
+
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
|
|
1969
|
+
s.formatter = createClassOnDemand(formatter);
|
|
1970
|
+
s.formatter.init(s, this.options);
|
|
1971
|
+
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
1972
|
+
}
|
|
1973
|
+
s.interpolator = new Interpolator(this.options);
|
|
1974
|
+
s.utils = {
|
|
1975
|
+
hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
|
|
1976
|
+
};
|
|
1977
|
+
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
1978
|
+
s.backendConnector.on("*", function(event) {
|
|
1979
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1980
|
+
args[_key - 1] = arguments[_key];
|
|
1981
|
+
}
|
|
1982
|
+
_this.emit(event, ...args);
|
|
1983
|
+
});
|
|
1984
|
+
if (this.modules.languageDetector) {
|
|
1985
|
+
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
1986
|
+
if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
|
|
1987
|
+
}
|
|
1988
|
+
if (this.modules.i18nFormat) {
|
|
1989
|
+
s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
|
|
1990
|
+
if (s.i18nFormat.init) s.i18nFormat.init(this);
|
|
1991
|
+
}
|
|
1992
|
+
this.translator = new Translator(this.services, this.options);
|
|
1993
|
+
this.translator.on("*", function(event) {
|
|
1994
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
1995
|
+
args[_key2 - 1] = arguments[_key2];
|
|
1996
|
+
}
|
|
1997
|
+
_this.emit(event, ...args);
|
|
1998
|
+
});
|
|
1999
|
+
this.modules.external.forEach((m) => {
|
|
2000
|
+
if (m.init) m.init(this);
|
|
2001
|
+
});
|
|
2002
|
+
}
|
|
2003
|
+
this.format = this.options.interpolation.format;
|
|
2004
|
+
if (!callback) callback = noop;
|
|
2005
|
+
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
2006
|
+
const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
2007
|
+
if (codes.length > 0 && codes[0] !== "dev") this.options.lng = codes[0];
|
|
2008
|
+
}
|
|
2009
|
+
if (!this.services.languageDetector && !this.options.lng) {
|
|
2010
|
+
this.logger.warn("init: no languageDetector is used and no lng is defined");
|
|
2011
|
+
}
|
|
2012
|
+
const storeApi = ["getResource", "hasResourceBundle", "getResourceBundle", "getDataByLanguage"];
|
|
2013
|
+
storeApi.forEach((fcName) => {
|
|
2014
|
+
this[fcName] = function() {
|
|
2015
|
+
return _this.store[fcName](...arguments);
|
|
2016
|
+
};
|
|
2017
|
+
});
|
|
2018
|
+
const storeApiChained = ["addResource", "addResources", "addResourceBundle", "removeResourceBundle"];
|
|
2019
|
+
storeApiChained.forEach((fcName) => {
|
|
2020
|
+
this[fcName] = function() {
|
|
2021
|
+
_this.store[fcName](...arguments);
|
|
2022
|
+
return _this;
|
|
2023
|
+
};
|
|
2024
|
+
});
|
|
2025
|
+
const deferred = defer();
|
|
2026
|
+
const load = () => {
|
|
2027
|
+
const finish = (err, t) => {
|
|
2028
|
+
this.isInitializing = false;
|
|
2029
|
+
if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn("init: i18next is already initialized. You should call init just once!");
|
|
2030
|
+
this.isInitialized = true;
|
|
2031
|
+
if (!this.options.isClone) this.logger.log("initialized", this.options);
|
|
2032
|
+
this.emit("initialized", this.options);
|
|
2033
|
+
deferred.resolve(t);
|
|
2034
|
+
callback(err, t);
|
|
2035
|
+
};
|
|
2036
|
+
if (this.languages && this.options.compatibilityAPI !== "v1" && !this.isInitialized) return finish(null, this.t.bind(this));
|
|
2037
|
+
this.changeLanguage(this.options.lng, finish);
|
|
2038
|
+
};
|
|
2039
|
+
if (this.options.resources || !this.options.initImmediate) {
|
|
2040
|
+
load();
|
|
2041
|
+
} else {
|
|
2042
|
+
setTimeout(load, 0);
|
|
2043
|
+
}
|
|
2044
|
+
return deferred;
|
|
2045
|
+
}
|
|
2046
|
+
loadResources(language) {
|
|
2047
|
+
let callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
2048
|
+
let usedCallback = callback;
|
|
2049
|
+
const usedLng = isString(language) ? language : this.language;
|
|
2050
|
+
if (typeof language === "function") usedCallback = language;
|
|
2051
|
+
if (!this.options.resources || this.options.partialBundledLanguages) {
|
|
2052
|
+
if (usedLng && usedLng.toLowerCase() === "cimode" && (!this.options.preload || this.options.preload.length === 0)) return usedCallback();
|
|
2053
|
+
const toLoad = [];
|
|
2054
|
+
const append = (lng) => {
|
|
2055
|
+
if (!lng) return;
|
|
2056
|
+
if (lng === "cimode") return;
|
|
2057
|
+
const lngs = this.services.languageUtils.toResolveHierarchy(lng);
|
|
2058
|
+
lngs.forEach((l) => {
|
|
2059
|
+
if (l === "cimode") return;
|
|
2060
|
+
if (toLoad.indexOf(l) < 0) toLoad.push(l);
|
|
2061
|
+
});
|
|
2062
|
+
};
|
|
2063
|
+
if (!usedLng) {
|
|
2064
|
+
const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
2065
|
+
fallbacks.forEach((l) => append(l));
|
|
2066
|
+
} else {
|
|
2067
|
+
append(usedLng);
|
|
2068
|
+
}
|
|
2069
|
+
if (this.options.preload) {
|
|
2070
|
+
this.options.preload.forEach((l) => append(l));
|
|
2071
|
+
}
|
|
2072
|
+
this.services.backendConnector.load(toLoad, this.options.ns, (e) => {
|
|
2073
|
+
if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
|
|
2074
|
+
usedCallback(e);
|
|
2075
|
+
});
|
|
2076
|
+
} else {
|
|
2077
|
+
usedCallback(null);
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
reloadResources(lngs, ns, callback) {
|
|
2081
|
+
const deferred = defer();
|
|
2082
|
+
if (typeof lngs === "function") {
|
|
2083
|
+
callback = lngs;
|
|
2084
|
+
lngs = void 0;
|
|
2085
|
+
}
|
|
2086
|
+
if (typeof ns === "function") {
|
|
2087
|
+
callback = ns;
|
|
2088
|
+
ns = void 0;
|
|
2089
|
+
}
|
|
2090
|
+
if (!lngs) lngs = this.languages;
|
|
2091
|
+
if (!ns) ns = this.options.ns;
|
|
2092
|
+
if (!callback) callback = noop;
|
|
2093
|
+
this.services.backendConnector.reload(lngs, ns, (err) => {
|
|
2094
|
+
deferred.resolve();
|
|
2095
|
+
callback(err);
|
|
2096
|
+
});
|
|
2097
|
+
return deferred;
|
|
2098
|
+
}
|
|
2099
|
+
use(module) {
|
|
2100
|
+
if (!module) throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");
|
|
2101
|
+
if (!module.type) throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");
|
|
2102
|
+
if (module.type === "backend") {
|
|
2103
|
+
this.modules.backend = module;
|
|
2104
|
+
}
|
|
2105
|
+
if (module.type === "logger" || module.log && module.warn && module.error) {
|
|
2106
|
+
this.modules.logger = module;
|
|
2107
|
+
}
|
|
2108
|
+
if (module.type === "languageDetector") {
|
|
2109
|
+
this.modules.languageDetector = module;
|
|
2110
|
+
}
|
|
2111
|
+
if (module.type === "i18nFormat") {
|
|
2112
|
+
this.modules.i18nFormat = module;
|
|
2113
|
+
}
|
|
2114
|
+
if (module.type === "postProcessor") {
|
|
2115
|
+
postProcessor.addPostProcessor(module);
|
|
2116
|
+
}
|
|
2117
|
+
if (module.type === "formatter") {
|
|
2118
|
+
this.modules.formatter = module;
|
|
2119
|
+
}
|
|
2120
|
+
if (module.type === "3rdParty") {
|
|
2121
|
+
this.modules.external.push(module);
|
|
2122
|
+
}
|
|
2123
|
+
return this;
|
|
2124
|
+
}
|
|
2125
|
+
setResolvedLanguage(l) {
|
|
2126
|
+
if (!l || !this.languages) return;
|
|
2127
|
+
if (["cimode", "dev"].indexOf(l) > -1) return;
|
|
2128
|
+
for (let li = 0; li < this.languages.length; li++) {
|
|
2129
|
+
const lngInLngs = this.languages[li];
|
|
2130
|
+
if (["cimode", "dev"].indexOf(lngInLngs) > -1) continue;
|
|
2131
|
+
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
2132
|
+
this.resolvedLanguage = lngInLngs;
|
|
2133
|
+
break;
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
}
|
|
2137
|
+
changeLanguage(lng, callback) {
|
|
2138
|
+
var _this2 = this;
|
|
2139
|
+
this.isLanguageChangingTo = lng;
|
|
2140
|
+
const deferred = defer();
|
|
2141
|
+
this.emit("languageChanging", lng);
|
|
2142
|
+
const setLngProps = (l) => {
|
|
2143
|
+
this.language = l;
|
|
2144
|
+
this.languages = this.services.languageUtils.toResolveHierarchy(l);
|
|
2145
|
+
this.resolvedLanguage = void 0;
|
|
2146
|
+
this.setResolvedLanguage(l);
|
|
2147
|
+
};
|
|
2148
|
+
const done = (err, l) => {
|
|
2149
|
+
if (l) {
|
|
2150
|
+
setLngProps(l);
|
|
2151
|
+
this.translator.changeLanguage(l);
|
|
2152
|
+
this.isLanguageChangingTo = void 0;
|
|
2153
|
+
this.emit("languageChanged", l);
|
|
2154
|
+
this.logger.log("languageChanged", l);
|
|
2155
|
+
} else {
|
|
2156
|
+
this.isLanguageChangingTo = void 0;
|
|
2157
|
+
}
|
|
2158
|
+
deferred.resolve(function() {
|
|
2159
|
+
return _this2.t(...arguments);
|
|
2160
|
+
});
|
|
2161
|
+
if (callback) callback(err, function() {
|
|
2162
|
+
return _this2.t(...arguments);
|
|
2163
|
+
});
|
|
2164
|
+
};
|
|
2165
|
+
const setLng = (lngs) => {
|
|
2166
|
+
if (!lng && !lngs && this.services.languageDetector) lngs = [];
|
|
2167
|
+
const l = isString(lngs) ? lngs : this.services.languageUtils.getBestMatchFromCodes(lngs);
|
|
2168
|
+
if (l) {
|
|
2169
|
+
if (!this.language) {
|
|
2170
|
+
setLngProps(l);
|
|
2171
|
+
}
|
|
2172
|
+
if (!this.translator.language) this.translator.changeLanguage(l);
|
|
2173
|
+
if (this.services.languageDetector && this.services.languageDetector.cacheUserLanguage) this.services.languageDetector.cacheUserLanguage(l);
|
|
2174
|
+
}
|
|
2175
|
+
this.loadResources(l, (err) => {
|
|
2176
|
+
done(err, l);
|
|
2177
|
+
});
|
|
2178
|
+
};
|
|
2179
|
+
if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
|
|
2180
|
+
setLng(this.services.languageDetector.detect());
|
|
2181
|
+
} else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
|
|
2182
|
+
if (this.services.languageDetector.detect.length === 0) {
|
|
2183
|
+
this.services.languageDetector.detect().then(setLng);
|
|
2184
|
+
} else {
|
|
2185
|
+
this.services.languageDetector.detect(setLng);
|
|
2186
|
+
}
|
|
2187
|
+
} else {
|
|
2188
|
+
setLng(lng);
|
|
2189
|
+
}
|
|
2190
|
+
return deferred;
|
|
2191
|
+
}
|
|
2192
|
+
getFixedT(lng, ns, keyPrefix) {
|
|
2193
|
+
var _this3 = this;
|
|
2194
|
+
const fixedT = function(key, opts) {
|
|
2195
|
+
let options;
|
|
2196
|
+
if (typeof opts !== "object") {
|
|
2197
|
+
for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
2198
|
+
rest[_key3 - 2] = arguments[_key3];
|
|
2199
|
+
}
|
|
2200
|
+
options = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
2201
|
+
} else {
|
|
2202
|
+
options = {
|
|
2203
|
+
...opts
|
|
2204
|
+
};
|
|
2205
|
+
}
|
|
2206
|
+
options.lng = options.lng || fixedT.lng;
|
|
2207
|
+
options.lngs = options.lngs || fixedT.lngs;
|
|
2208
|
+
options.ns = options.ns || fixedT.ns;
|
|
2209
|
+
if (options.keyPrefix !== "") options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
|
|
2210
|
+
const keySeparator = _this3.options.keySeparator || ".";
|
|
2211
|
+
let resultKey;
|
|
2212
|
+
if (options.keyPrefix && Array.isArray(key)) {
|
|
2213
|
+
resultKey = key.map((k) => `${options.keyPrefix}${keySeparator}${k}`);
|
|
2214
|
+
} else {
|
|
2215
|
+
resultKey = options.keyPrefix ? `${options.keyPrefix}${keySeparator}${key}` : key;
|
|
2216
|
+
}
|
|
2217
|
+
return _this3.t(resultKey, options);
|
|
2218
|
+
};
|
|
2219
|
+
if (isString(lng)) {
|
|
2220
|
+
fixedT.lng = lng;
|
|
2221
|
+
} else {
|
|
2222
|
+
fixedT.lngs = lng;
|
|
2223
|
+
}
|
|
2224
|
+
fixedT.ns = ns;
|
|
2225
|
+
fixedT.keyPrefix = keyPrefix;
|
|
2226
|
+
return fixedT;
|
|
2227
|
+
}
|
|
2228
|
+
t() {
|
|
2229
|
+
return this.translator && this.translator.translate(...arguments);
|
|
2230
|
+
}
|
|
2231
|
+
exists() {
|
|
2232
|
+
return this.translator && this.translator.exists(...arguments);
|
|
2233
|
+
}
|
|
2234
|
+
setDefaultNamespace(ns) {
|
|
2235
|
+
this.options.defaultNS = ns;
|
|
2236
|
+
}
|
|
2237
|
+
hasLoadedNamespace(ns) {
|
|
2238
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
2239
|
+
if (!this.isInitialized) {
|
|
2240
|
+
this.logger.warn("hasLoadedNamespace: i18next was not initialized", this.languages);
|
|
2241
|
+
return false;
|
|
2242
|
+
}
|
|
2243
|
+
if (!this.languages || !this.languages.length) {
|
|
2244
|
+
this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty", this.languages);
|
|
2245
|
+
return false;
|
|
2246
|
+
}
|
|
2247
|
+
const lng = options.lng || this.resolvedLanguage || this.languages[0];
|
|
2248
|
+
const fallbackLng = this.options ? this.options.fallbackLng : false;
|
|
2249
|
+
const lastLng = this.languages[this.languages.length - 1];
|
|
2250
|
+
if (lng.toLowerCase() === "cimode") return true;
|
|
2251
|
+
const loadNotPending = (l, n) => {
|
|
2252
|
+
const loadState = this.services.backendConnector.state[`${l}|${n}`];
|
|
2253
|
+
return loadState === -1 || loadState === 0 || loadState === 2;
|
|
2254
|
+
};
|
|
2255
|
+
if (options.precheck) {
|
|
2256
|
+
const preResult = options.precheck(this, loadNotPending);
|
|
2257
|
+
if (preResult !== void 0) return preResult;
|
|
2258
|
+
}
|
|
2259
|
+
if (this.hasResourceBundle(lng, ns)) return true;
|
|
2260
|
+
if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
|
|
2261
|
+
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
2262
|
+
return false;
|
|
2263
|
+
}
|
|
2264
|
+
loadNamespaces(ns, callback) {
|
|
2265
|
+
const deferred = defer();
|
|
2266
|
+
if (!this.options.ns) {
|
|
2267
|
+
if (callback) callback();
|
|
2268
|
+
return Promise.resolve();
|
|
2269
|
+
}
|
|
2270
|
+
if (isString(ns)) ns = [ns];
|
|
2271
|
+
ns.forEach((n) => {
|
|
2272
|
+
if (this.options.ns.indexOf(n) < 0) this.options.ns.push(n);
|
|
2273
|
+
});
|
|
2274
|
+
this.loadResources((err) => {
|
|
2275
|
+
deferred.resolve();
|
|
2276
|
+
if (callback) callback(err);
|
|
2277
|
+
});
|
|
2278
|
+
return deferred;
|
|
2279
|
+
}
|
|
2280
|
+
loadLanguages(lngs, callback) {
|
|
2281
|
+
const deferred = defer();
|
|
2282
|
+
if (isString(lngs)) lngs = [lngs];
|
|
2283
|
+
const preloaded = this.options.preload || [];
|
|
2284
|
+
const newLngs = lngs.filter((lng) => preloaded.indexOf(lng) < 0 && this.services.languageUtils.isSupportedCode(lng));
|
|
2285
|
+
if (!newLngs.length) {
|
|
2286
|
+
if (callback) callback();
|
|
2287
|
+
return Promise.resolve();
|
|
2288
|
+
}
|
|
2289
|
+
this.options.preload = preloaded.concat(newLngs);
|
|
2290
|
+
this.loadResources((err) => {
|
|
2291
|
+
deferred.resolve();
|
|
2292
|
+
if (callback) callback(err);
|
|
2293
|
+
});
|
|
2294
|
+
return deferred;
|
|
2295
|
+
}
|
|
2296
|
+
dir(lng) {
|
|
2297
|
+
if (!lng) lng = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language);
|
|
2298
|
+
if (!lng) return "rtl";
|
|
2299
|
+
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"];
|
|
2300
|
+
const languageUtils = this.services && this.services.languageUtils || new LanguageUtil(get());
|
|
2301
|
+
return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf("-arab") > 1 ? "rtl" : "ltr";
|
|
2302
|
+
}
|
|
2303
|
+
static createInstance() {
|
|
2304
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
2305
|
+
let callback = arguments.length > 1 ? arguments[1] : void 0;
|
|
2306
|
+
return new I18n(options, callback);
|
|
2307
|
+
}
|
|
2308
|
+
cloneInstance() {
|
|
2309
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
2310
|
+
let callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
2311
|
+
const forkResourceStore = options.forkResourceStore;
|
|
2312
|
+
if (forkResourceStore) delete options.forkResourceStore;
|
|
2313
|
+
const mergedOptions = {
|
|
2314
|
+
...this.options,
|
|
2315
|
+
...options,
|
|
2316
|
+
...{
|
|
2317
|
+
isClone: true
|
|
2318
|
+
}
|
|
2319
|
+
};
|
|
2320
|
+
const clone = new I18n(mergedOptions);
|
|
2321
|
+
if (options.debug !== void 0 || options.prefix !== void 0) {
|
|
2322
|
+
clone.logger = clone.logger.clone(options);
|
|
2323
|
+
}
|
|
2324
|
+
const membersToCopy = ["store", "services", "language"];
|
|
2325
|
+
membersToCopy.forEach((m) => {
|
|
2326
|
+
clone[m] = this[m];
|
|
2327
|
+
});
|
|
2328
|
+
clone.services = {
|
|
2329
|
+
...this.services
|
|
2330
|
+
};
|
|
2331
|
+
clone.services.utils = {
|
|
2332
|
+
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2333
|
+
};
|
|
2334
|
+
if (forkResourceStore) {
|
|
2335
|
+
clone.store = new ResourceStore(this.store.data, mergedOptions);
|
|
2336
|
+
clone.services.resourceStore = clone.store;
|
|
2337
|
+
}
|
|
2338
|
+
clone.translator = new Translator(clone.services, mergedOptions);
|
|
2339
|
+
clone.translator.on("*", function(event) {
|
|
2340
|
+
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
2341
|
+
args[_key4 - 1] = arguments[_key4];
|
|
2342
|
+
}
|
|
2343
|
+
clone.emit(event, ...args);
|
|
2344
|
+
});
|
|
2345
|
+
clone.init(mergedOptions, callback);
|
|
2346
|
+
clone.translator.options = mergedOptions;
|
|
2347
|
+
clone.translator.backendConnector.services.utils = {
|
|
2348
|
+
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2349
|
+
};
|
|
2350
|
+
return clone;
|
|
2351
|
+
}
|
|
2352
|
+
toJSON() {
|
|
2353
|
+
return {
|
|
2354
|
+
options: this.options,
|
|
2355
|
+
store: this.store,
|
|
2356
|
+
language: this.language,
|
|
2357
|
+
languages: this.languages,
|
|
2358
|
+
resolvedLanguage: this.resolvedLanguage
|
|
2359
|
+
};
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
const instance = I18n.createInstance();
|
|
2363
|
+
instance.createInstance = I18n.createInstance;
|
|
2364
|
+
instance.createInstance;
|
|
2365
|
+
instance.dir;
|
|
2366
|
+
instance.init;
|
|
2367
|
+
instance.loadResources;
|
|
2368
|
+
instance.reloadResources;
|
|
2369
|
+
instance.use;
|
|
2370
|
+
instance.changeLanguage;
|
|
2371
|
+
instance.getFixedT;
|
|
2372
|
+
instance.t;
|
|
2373
|
+
instance.exists;
|
|
2374
|
+
instance.setDefaultNamespace;
|
|
2375
|
+
instance.hasLoadedNamespace;
|
|
2376
|
+
instance.loadNamespaces;
|
|
2377
|
+
instance.loadLanguages;
|
|
2378
|
+
const app$1 = { "name": "AgentCRM", "loading": "Loading…", "loadError": "Could not load the CRM data.", "retry": "Retry", "notFound": "Page not found", "backHome": "Back to dashboard", "passphraseTitle": "Unlock your CRM", "passphraseHint": "The data is encrypted. Enter the passphrase created at install — it stays in this browser only.", "passphrase": "Passphrase", "passphraseWrong": "Wrong passphrase: the data could not be decrypted.", "unlock": "Unlock", "resetSetup": "Use another CRM", "emptyTitle": "This CRM is empty", "emptyHint": "Create the standard objects (companies, people, deals) and the Sales pipeline — with or without demo data.", "installDemo": "Install with demo data", "installEmpty": "Install empty", "moduleDisabled": { "title": "This module is disabled", "hint": "“{{name}}” is switched off for this workspace. Its data is kept — enable it again in Settings → Modules.", "hintMember": "“{{name}}” is switched off for this workspace. Ask an admin to enable it.", "open": "Open Settings → Modules" }, "safeMode": { "banner": "Safe mode: external extensions are not loaded.", "exit": "Leave safe mode" }, "extensionErrors_one": "{{count}} extension failed to load: {{list}}", "extensionErrors_other": "{{count}} extensions failed to load: {{list}}" };
|
|
2379
|
+
const nav$1 = { "dashboard": "Dashboard", "tasks": "Tasks", "automations": "Automations", "forms": "Forms", "reports": "Reports", "settings": "Settings", "objects": "Records", "workspace": "Workspace", "collapse": "Collapse sidebar", "expand": "Expand sidebar" };
|
|
2380
|
+
const topbar$1 = { "search": "Search…", "searchShortcut": "⌘K", "darkMode": "Dark mode", "lightMode": "Light mode", "language": "Language", "userMenu": "Account", "signOut": "Sign out", "profile": "Profile", "role": "Role: {{role}}" };
|
|
2381
|
+
const roles$1 = { "admin": "Admin", "member": "Member", "viewer": "Viewer" };
|
|
2382
|
+
const common$1 = { "save": "Save", "cancel": "Cancel", "close": "Close", "delete": "Delete", "edit": "Edit", "create": "Create", "add": "Add", "remove": "Remove", "confirm": "Confirm", "search": "Search", "clear": "Clear", "none": "None", "yes": "Yes", "no": "No", "loading": "Loading…", "empty": "Nothing here yet.", "noResults": "No results", "select": "Select…", "more": "More", "back": "Back", "next": "Next", "previous": "Previous", "done": "Done", "today": "Today", "saved": "Saved", "copied": "Copied", "copy": "Copy", "unknown": "Unknown", "comingSoon": "Coming soon", "readOnly": "Read-only access", "error": "Something went wrong." };
|
|
2383
|
+
const confirm$1 = { "title": "Are you sure?", "deleteTitle": "Delete {{name}}?", "irreversible": "This can't be undone." };
|
|
2384
|
+
const fieldTypes$1 = { "text": "Text", "longText": "Long text", "number": "Number", "currency": "Currency", "percent": "Percent", "date": "Date", "datetime": "Date & time", "boolean": "Checkbox", "select": "Select", "multiSelect": "Multi-select", "email": "Email", "phone": "Phone", "url": "Link", "relation": "Relation", "user": "User", "rating": "Rating", "address": "Address", "tags": "Tags", "image": "Image", "files": "Files" };
|
|
2385
|
+
const fieldInput$1 = { "empty": "Empty", "searchRecords": "Search {{object}}…", "noMatch": "No match", "addTag": "Add a tag…", "street": "Street", "city": "City", "postalCode": "Postal code", "region": "Region", "country": "Country", "pickUser": "Pick a user…", "clearValue": "Clear value" };
|
|
2386
|
+
const activityTypes$1 = { "note": "Note", "task": "Task", "call": "Call", "email": "Email", "meeting": "Meeting" };
|
|
2387
|
+
const storage$1 = { "actions": { "upload": "Uploading file", "delete": "Deleting file", "rename": "Renaming file", "get": "Reading file", "list": "Listing files", "createFolder": "Creating folder", "renameFolder": "Renaming folder", "deleteFolder": "Deleting folder", "commit": "Saving changes" }, "errors": { "network": "{{action}}: network error or CORS blocked. Check your connection.", "auth": "{{action}}: authentication failed. Check the storage credentials in Settings.", "notFound": "{{action}}: not found on the storage.", "tooLarge": "{{action}}: file too large for the storage.", "rateLimited": "{{action}}: too many requests, please retry in a moment.", "serverError": "{{action}}: storage server error ({{status}}). Please retry.", "generic": "{{action}} failed ({{status}}){{detail}}.", "unsupported": '{{action}}: not supported by the "{{connector}}" storage.', "unknownConnector": 'Unknown storage "{{connector}}". Check Settings.', "folderAccess": "No access to the local folder. Open Settings and click “Reconnect folder”." } };
|
|
2388
|
+
const connectors$1 = { "pages": { "enabled": "GitHub Pages enabled for this repository.", "enableHint": "Enable GitHub Pages for {{repo}}: Settings → Pages → Deploy from branch {{branch}}, folder {{folder}}." } };
|
|
2389
|
+
const errors$1 = { "forbidden": "You don't have permission to do that.", "notFound": "Not found.", "validation": "Some fields are invalid." };
|
|
2390
|
+
const ui$1 = { "empty": "Nothing to show", "dismiss": "Dismiss", "openMenu": "Open menu", "sortAsc": "Sort ascending", "sortDesc": "Sort descending" };
|
|
2391
|
+
const setupRequired$1 = { "title": "Set up AgentCRM" };
|
|
2392
|
+
const files$1 = { "counter": "{{index}} of {{total}}", "download": "Download", "openNewTab": "Open in a new tab", "loadError": "This file could not be loaded.", "previous": "Previous", "next": "Next", "delete": "Delete file", "deleteTitle": "Delete “{{name}}”?", "deleteHint": "It disappears from the CRM now; its bytes are erased from the storage at the next compaction.", "dropHere": "Drop files to attach them", "attach": "Attach", "failed": "Upload failed", "status": { "processing": "Preparing…", "uploading": "Uploading…" }, "insertInline": "Insert in the text", "removeUpload": "Remove", "notAnImage": "This file is not an image this browser can read.", "cropTitle": "Adjust the picture", "zoom": "Zoom", "cropHint": "Drag to move the picture inside the frame.", "uploadImage": "Upload an image", "replaceImage": "Replace", "removeImage": "Remove", "addFiles": "Add files", "noFiles": "No files", "unavailable": "This data backend can't store files.", "tooLarge": "{{name}} is too large ({{size}} > {{max}})." };
|
|
2393
|
+
const en = {
|
|
2394
|
+
app: app$1,
|
|
2395
|
+
nav: nav$1,
|
|
2396
|
+
topbar: topbar$1,
|
|
2397
|
+
roles: roles$1,
|
|
2398
|
+
common: common$1,
|
|
2399
|
+
confirm: confirm$1,
|
|
2400
|
+
fieldTypes: fieldTypes$1,
|
|
2401
|
+
fieldInput: fieldInput$1,
|
|
2402
|
+
activityTypes: activityTypes$1,
|
|
2403
|
+
storage: storage$1,
|
|
2404
|
+
connectors: connectors$1,
|
|
2405
|
+
errors: errors$1,
|
|
2406
|
+
ui: ui$1,
|
|
2407
|
+
setupRequired: setupRequired$1,
|
|
2408
|
+
files: files$1
|
|
2409
|
+
};
|
|
2410
|
+
const app = { "name": "AgentCRM", "loading": "Chargement…", "loadError": "Impossible de charger les données du CRM.", "retry": "Réessayer", "notFound": "Page introuvable", "backHome": "Retour au tableau de bord", "passphraseTitle": "Déverrouiller votre CRM", "passphraseHint": "Les données sont chiffrées. Saisissez la phrase secrète créée à l'installation — elle reste uniquement dans ce navigateur.", "passphrase": "Phrase secrète", "passphraseWrong": "Phrase secrète incorrecte : les données n'ont pas pu être déchiffrées.", "unlock": "Déverrouiller", "resetSetup": "Utiliser un autre CRM", "emptyTitle": "Ce CRM est vide", "emptyHint": "Créez les objets standard (entreprises, personnes, affaires) et le pipeline Ventes — avec ou sans données de démonstration.", "installDemo": "Installer avec des données de démo", "installEmpty": "Installer à vide", "moduleDisabled": { "title": "Ce module est désactivé", "hint": "« {{name}} » est désactivé pour cet espace. Ses données sont conservées — réactivez-le dans Paramètres → Modules.", "hintMember": "« {{name}} » est désactivé pour cet espace. Demandez à un administrateur de l'activer.", "open": "Ouvrir Paramètres → Modules" }, "safeMode": { "banner": "Mode sans échec : les extensions externes ne sont pas chargées.", "exit": "Quitter le mode sans échec" }, "extensionErrors_one": "{{count}} extension n'a pas pu être chargée : {{list}}", "extensionErrors_other": "{{count}} extensions n'ont pas pu être chargées : {{list}}" };
|
|
2411
|
+
const nav = { "dashboard": "Tableau de bord", "tasks": "Tâches", "automations": "Automatisations", "forms": "Formulaires", "reports": "Rapports", "settings": "Paramètres", "objects": "Fiches", "workspace": "Espace de travail", "collapse": "Réduire la barre latérale", "expand": "Déplier la barre latérale" };
|
|
2412
|
+
const topbar = { "search": "Rechercher…", "searchShortcut": "⌘K", "darkMode": "Mode sombre", "lightMode": "Mode clair", "language": "Langue", "userMenu": "Compte", "signOut": "Se déconnecter", "profile": "Profil", "role": "Rôle : {{role}}" };
|
|
2413
|
+
const roles = { "admin": "Administrateur", "member": "Membre", "viewer": "Lecteur" };
|
|
2414
|
+
const common = { "save": "Enregistrer", "cancel": "Annuler", "close": "Fermer", "delete": "Supprimer", "edit": "Modifier", "create": "Créer", "add": "Ajouter", "remove": "Retirer", "confirm": "Confirmer", "search": "Rechercher", "clear": "Effacer", "none": "Aucun", "yes": "Oui", "no": "Non", "loading": "Chargement…", "empty": "Rien pour l'instant.", "noResults": "Aucun résultat", "select": "Sélectionner…", "more": "Plus", "back": "Retour", "next": "Suivant", "previous": "Précédent", "done": "Terminé", "today": "Aujourd'hui", "saved": "Enregistré", "copied": "Copié", "copy": "Copier", "unknown": "Inconnu", "comingSoon": "Bientôt disponible", "readOnly": "Accès en lecture seule", "error": "Une erreur est survenue." };
|
|
2415
|
+
const confirm = { "title": "Êtes-vous sûr ?", "deleteTitle": "Supprimer {{name}} ?", "irreversible": "Cette action est irréversible." };
|
|
2416
|
+
const fieldTypes = { "text": "Texte", "longText": "Texte long", "number": "Nombre", "currency": "Montant", "percent": "Pourcentage", "date": "Date", "datetime": "Date et heure", "boolean": "Case à cocher", "select": "Liste", "multiSelect": "Liste multiple", "email": "E-mail", "phone": "Téléphone", "url": "Lien", "relation": "Relation", "user": "Utilisateur", "rating": "Note", "address": "Adresse", "tags": "Étiquettes", "image": "Image", "files": "Fichiers" };
|
|
2417
|
+
const fieldInput = { "empty": "Vide", "searchRecords": "Rechercher {{object}}…", "noMatch": "Aucune correspondance", "addTag": "Ajouter une étiquette…", "street": "Rue", "city": "Ville", "postalCode": "Code postal", "region": "Région", "country": "Pays", "pickUser": "Choisir un utilisateur…", "clearValue": "Effacer la valeur" };
|
|
2418
|
+
const activityTypes = { "note": "Note", "task": "Tâche", "call": "Appel", "email": "E-mail", "meeting": "Réunion" };
|
|
2419
|
+
const storage = { "actions": { "upload": "Envoi du fichier", "delete": "Suppression du fichier", "rename": "Renommage du fichier", "get": "Lecture du fichier", "list": "Liste des fichiers", "createFolder": "Création du dossier", "renameFolder": "Renommage du dossier", "deleteFolder": "Suppression du dossier", "commit": "Enregistrement des modifications" }, "errors": { "network": "{{action}} : erreur réseau ou CORS bloqué. Vérifiez votre connexion.", "auth": "{{action}} : échec d'authentification. Vérifiez les identifiants du stockage dans les Paramètres.", "notFound": "{{action}} : introuvable sur le stockage.", "tooLarge": "{{action}} : fichier trop volumineux pour le stockage.", "rateLimited": "{{action}} : trop de requêtes, réessayez dans un instant.", "serverError": "{{action}} : erreur du serveur de stockage ({{status}}). Réessayez.", "generic": "{{action}} a échoué ({{status}}){{detail}}.", "unsupported": "{{action}} : non pris en charge par le stockage « {{connector}} ».", "unknownConnector": "Stockage inconnu « {{connector}} ». Vérifiez les Paramètres.", "folderAccess": "Pas d'accès au dossier local. Ouvrez les Paramètres et cliquez sur « Reconnecter le dossier »." } };
|
|
2420
|
+
const connectors = { "pages": { "enabled": "GitHub Pages activé pour ce dépôt.", "enableHint": "Activez GitHub Pages pour {{repo}} : Settings → Pages → Deploy from branch {{branch}}, dossier {{folder}}." } };
|
|
2421
|
+
const errors = { "forbidden": "Vous n'avez pas la permission de faire cela.", "notFound": "Introuvable.", "validation": "Certains champs sont invalides." };
|
|
2422
|
+
const ui = { "empty": "Rien à afficher", "dismiss": "Ignorer", "openMenu": "Ouvrir le menu", "sortAsc": "Tri croissant", "sortDesc": "Tri décroissant" };
|
|
2423
|
+
const setupRequired = { "title": "Configurer AgentCRM" };
|
|
2424
|
+
const files = { "counter": "{{index}} sur {{total}}", "download": "Télécharger", "openNewTab": "Ouvrir dans un nouvel onglet", "loadError": "Impossible de charger ce fichier.", "previous": "Précédent", "next": "Suivant", "delete": "Supprimer le fichier", "deleteTitle": "Supprimer « {{name}} » ?", "deleteHint": "Il disparaît du CRM tout de suite ; son contenu est effacé du stockage à la prochaine compaction.", "dropHere": "Déposez des fichiers pour les joindre", "attach": "Joindre", "failed": "Échec de l’envoi", "status": { "processing": "Préparation…", "uploading": "Envoi…" }, "insertInline": "Insérer dans le texte", "removeUpload": "Retirer", "notAnImage": "Ce fichier n’est pas une image lisible par ce navigateur.", "cropTitle": "Ajuster la photo", "zoom": "Zoom", "cropHint": "Faites glisser pour déplacer la photo dans le cadre.", "uploadImage": "Envoyer une image", "replaceImage": "Remplacer", "removeImage": "Retirer", "addFiles": "Ajouter des fichiers", "noFiles": "Aucun fichier", "unavailable": "Ce stockage de données ne peut pas contenir de fichiers.", "tooLarge": "{{name}} est trop volumineux ({{size}} > {{max}})." };
|
|
2425
|
+
const fr = {
|
|
2426
|
+
app,
|
|
2427
|
+
nav,
|
|
2428
|
+
topbar,
|
|
2429
|
+
roles,
|
|
2430
|
+
common,
|
|
2431
|
+
confirm,
|
|
2432
|
+
fieldTypes,
|
|
2433
|
+
fieldInput,
|
|
2434
|
+
activityTypes,
|
|
2435
|
+
storage,
|
|
2436
|
+
connectors,
|
|
2437
|
+
errors,
|
|
2438
|
+
ui,
|
|
2439
|
+
setupRequired,
|
|
2440
|
+
files
|
|
2441
|
+
};
|
|
2442
|
+
const SUPPORTED_LOCALES = ["en", "fr"];
|
|
2443
|
+
const DEFAULT_LOCALE = "en";
|
|
2444
|
+
const STORAGE_KEY = "agentcrm.locale";
|
|
2445
|
+
function isSupportedLocale(value) {
|
|
2446
|
+
return typeof value === "string" && SUPPORTED_LOCALES.includes(value);
|
|
2447
|
+
}
|
|
2448
|
+
function resolveInitialLocale(preferred) {
|
|
2449
|
+
if (isSupportedLocale(preferred)) return preferred;
|
|
2450
|
+
try {
|
|
2451
|
+
const stored = typeof localStorage !== "undefined" ? localStorage.getItem(STORAGE_KEY) : null;
|
|
2452
|
+
if (isSupportedLocale(stored)) return stored;
|
|
2453
|
+
} catch {
|
|
2454
|
+
}
|
|
2455
|
+
if (typeof navigator !== "undefined" && typeof navigator.language === "string") {
|
|
2456
|
+
const prefix = navigator.language.split("-")[0]?.toLowerCase();
|
|
2457
|
+
if (isSupportedLocale(prefix)) return prefix;
|
|
2458
|
+
}
|
|
2459
|
+
return DEFAULT_LOCALE;
|
|
2460
|
+
}
|
|
2461
|
+
void instance.init({
|
|
2462
|
+
resources: {
|
|
2463
|
+
en: { translation: en },
|
|
2464
|
+
fr: { translation: fr }
|
|
2465
|
+
},
|
|
2466
|
+
lng: resolveInitialLocale(),
|
|
2467
|
+
fallbackLng: DEFAULT_LOCALE,
|
|
2468
|
+
defaultNS: "translation",
|
|
2469
|
+
interpolation: { escapeValue: false },
|
|
2470
|
+
returnNull: false,
|
|
2471
|
+
initImmediate: false,
|
|
2472
|
+
react: { useSuspense: false }
|
|
2473
|
+
});
|
|
2474
|
+
function registerI18nNamespace(ns, bundles) {
|
|
2475
|
+
instance.addResourceBundle("en", ns, bundles.en, true, true);
|
|
2476
|
+
if (bundles.fr) instance.addResourceBundle("fr", ns, bundles.fr, true, true);
|
|
2477
|
+
}
|
|
2478
|
+
function activeLocale() {
|
|
2479
|
+
return isSupportedLocale(instance.language) ? instance.language : DEFAULT_LOCALE;
|
|
2480
|
+
}
|
|
2481
|
+
function intlLocale() {
|
|
2482
|
+
return activeLocale() === "fr" ? "fr-FR" : "en-US";
|
|
2483
|
+
}
|
|
2484
|
+
export {
|
|
2485
|
+
intlLocale as a,
|
|
2486
|
+
activeLocale as b,
|
|
2487
|
+
instance as i,
|
|
2488
|
+
registerI18nNamespace as r
|
|
2489
|
+
};
|