@serhii.olishevskyi/docs 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/UserPopoverComponent-JBJBONYL.mjs +8 -0
- package/dist/chunk-R2QQMMHL.mjs +1980 -0
- package/dist/index.d.mts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +17 -2297
- package/dist/index.mjs +4 -2
- package/package.json +3 -2
- package/dist/UserPopoverComponent-BNJWFSLT.mjs +0 -399
- package/dist/chunk-CT3G3YSD.mjs +0 -3863
package/dist/chunk-CT3G3YSD.mjs
DELETED
|
@@ -1,3863 +0,0 @@
|
|
|
1
|
-
// src/services/session.service.ts
|
|
2
|
-
var getUserLastSeenAt = async (supabase, userId) => {
|
|
3
|
-
const { data, error } = await supabase.from("user_sessions").select("last_seen_at").eq("user_id", userId).order("last_seen_at", { ascending: false }).limit(1).maybeSingle();
|
|
4
|
-
if (error || !data) return null;
|
|
5
|
-
return data.last_seen_at;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
// src/context/SupabaseProvider.tsx
|
|
9
|
-
import { createContext, useContext, useMemo } from "react";
|
|
10
|
-
import { createClient } from "@supabase/supabase-js";
|
|
11
|
-
import { jsx } from "react/jsx-runtime";
|
|
12
|
-
var SupabaseContext = createContext(null);
|
|
13
|
-
var SupabaseProvider = ({
|
|
14
|
-
children,
|
|
15
|
-
client,
|
|
16
|
-
config
|
|
17
|
-
}) => {
|
|
18
|
-
const supabaseInstance = useMemo(() => {
|
|
19
|
-
if (client) return client;
|
|
20
|
-
if (config?.url && config?.anonKey) {
|
|
21
|
-
return createClient(config.url, config.anonKey);
|
|
22
|
-
}
|
|
23
|
-
throw new Error(
|
|
24
|
-
'[SupabaseProvider]: \u0412\u0430\u043C \u043D\u0443\u0436\u043D\u043E \u043F\u0435\u0440\u0435\u0434\u0430\u0442\u044C \u043B\u0438\u0431\u043E prop "client", \u043B\u0438\u0431\u043E "config" ({ url, anonKey }).'
|
|
25
|
-
);
|
|
26
|
-
}, [client, config]);
|
|
27
|
-
return /* @__PURE__ */ jsx(SupabaseContext.Provider, { value: { supabase: supabaseInstance }, children });
|
|
28
|
-
};
|
|
29
|
-
var useSupabase = () => {
|
|
30
|
-
const context = useContext(SupabaseContext);
|
|
31
|
-
if (!context) {
|
|
32
|
-
throw new Error("useSupabase \u0434\u043E\u043B\u0436\u0435\u043D \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C\u0441\u044F \u0432\u043D\u0443\u0442\u0440\u0438 <SupabaseProvider>");
|
|
33
|
-
}
|
|
34
|
-
return context.supabase;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// src/context/AuthProvider.tsx
|
|
38
|
-
import { createContext as createContext2, useContext as useContext2, useEffect, useState, useCallback, useRef } from "react";
|
|
39
|
-
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
40
|
-
var AuthContext = createContext2(void 0);
|
|
41
|
-
var useAuth = () => {
|
|
42
|
-
const context = useContext2(AuthContext);
|
|
43
|
-
if (!context) {
|
|
44
|
-
throw new Error("useAuth should be used within the AuthProvider");
|
|
45
|
-
}
|
|
46
|
-
return context;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// src/context/TranslationEditProvider.tsx
|
|
50
|
-
import { createContext as createContext3, useContext as useContext3, useState as useState2, useEffect as useEffect2, useCallback as useCallback2 } from "react";
|
|
51
|
-
|
|
52
|
-
// node_modules/i18next/dist/esm/i18next.js
|
|
53
|
-
var isString = (obj) => typeof obj === "string";
|
|
54
|
-
var defer = () => {
|
|
55
|
-
let res;
|
|
56
|
-
let rej;
|
|
57
|
-
const promise = new Promise((resolve, reject) => {
|
|
58
|
-
res = resolve;
|
|
59
|
-
rej = reject;
|
|
60
|
-
});
|
|
61
|
-
promise.resolve = res;
|
|
62
|
-
promise.reject = rej;
|
|
63
|
-
return promise;
|
|
64
|
-
};
|
|
65
|
-
var makeString = (object) => {
|
|
66
|
-
if (object == null) return "";
|
|
67
|
-
return String(object);
|
|
68
|
-
};
|
|
69
|
-
var copy = (a, s, t2) => {
|
|
70
|
-
a.forEach((m) => {
|
|
71
|
-
if (s[m]) t2[m] = s[m];
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
var lastOfPathSeparatorRegExp = /###/g;
|
|
75
|
-
var cleanKey = (key) => key && key.includes("###") ? key.replace(lastOfPathSeparatorRegExp, ".") : key;
|
|
76
|
-
var canNotTraverseDeeper = (object) => !object || isString(object);
|
|
77
|
-
var getLastOfPath = (object, path, Empty) => {
|
|
78
|
-
const stack = !isString(path) ? path : path.split(".");
|
|
79
|
-
let stackIndex = 0;
|
|
80
|
-
while (stackIndex < stack.length - 1) {
|
|
81
|
-
if (canNotTraverseDeeper(object)) return {};
|
|
82
|
-
const key = cleanKey(stack[stackIndex]);
|
|
83
|
-
if (!object[key] && Empty) object[key] = new Empty();
|
|
84
|
-
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
85
|
-
object = object[key];
|
|
86
|
-
} else {
|
|
87
|
-
object = {};
|
|
88
|
-
}
|
|
89
|
-
++stackIndex;
|
|
90
|
-
}
|
|
91
|
-
if (canNotTraverseDeeper(object)) return {};
|
|
92
|
-
return {
|
|
93
|
-
obj: object,
|
|
94
|
-
k: cleanKey(stack[stackIndex])
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
var setPath = (object, path, newValue) => {
|
|
98
|
-
const {
|
|
99
|
-
obj,
|
|
100
|
-
k
|
|
101
|
-
} = getLastOfPath(object, path, Object);
|
|
102
|
-
if (obj !== void 0 || path.length === 1) {
|
|
103
|
-
obj[k] = newValue;
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
let e = path[path.length - 1];
|
|
107
|
-
let p = path.slice(0, path.length - 1);
|
|
108
|
-
let last = getLastOfPath(object, p, Object);
|
|
109
|
-
while (last.obj === void 0 && p.length) {
|
|
110
|
-
e = `${p[p.length - 1]}.${e}`;
|
|
111
|
-
p = p.slice(0, p.length - 1);
|
|
112
|
-
last = getLastOfPath(object, p, Object);
|
|
113
|
-
if (last?.obj && typeof last.obj[`${last.k}.${e}`] !== "undefined") {
|
|
114
|
-
last.obj = void 0;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
last.obj[`${last.k}.${e}`] = newValue;
|
|
118
|
-
};
|
|
119
|
-
var pushPath = (object, path, newValue, concat) => {
|
|
120
|
-
const {
|
|
121
|
-
obj,
|
|
122
|
-
k
|
|
123
|
-
} = getLastOfPath(object, path, Object);
|
|
124
|
-
obj[k] = obj[k] || [];
|
|
125
|
-
obj[k].push(newValue);
|
|
126
|
-
};
|
|
127
|
-
var getPath = (object, path) => {
|
|
128
|
-
const {
|
|
129
|
-
obj,
|
|
130
|
-
k
|
|
131
|
-
} = getLastOfPath(object, path);
|
|
132
|
-
if (!obj) return void 0;
|
|
133
|
-
if (!Object.prototype.hasOwnProperty.call(obj, k)) return void 0;
|
|
134
|
-
return obj[k];
|
|
135
|
-
};
|
|
136
|
-
var getPathWithDefaults = (data, defaultData, key) => {
|
|
137
|
-
const value = getPath(data, key);
|
|
138
|
-
if (value !== void 0) {
|
|
139
|
-
return value;
|
|
140
|
-
}
|
|
141
|
-
return getPath(defaultData, key);
|
|
142
|
-
};
|
|
143
|
-
var deepExtend = (target, source, overwrite) => {
|
|
144
|
-
for (const prop in source) {
|
|
145
|
-
if (prop !== "__proto__" && prop !== "constructor") {
|
|
146
|
-
if (Object.prototype.hasOwnProperty.call(target, prop)) {
|
|
147
|
-
if (isString(target[prop]) || target[prop] instanceof String || isString(source[prop]) || source[prop] instanceof String) {
|
|
148
|
-
if (overwrite) target[prop] = source[prop];
|
|
149
|
-
} else {
|
|
150
|
-
deepExtend(target[prop], source[prop], overwrite);
|
|
151
|
-
}
|
|
152
|
-
} else {
|
|
153
|
-
target[prop] = source[prop];
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return target;
|
|
158
|
-
};
|
|
159
|
-
var regexEscape = (str) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
|
160
|
-
var _entityMap = {
|
|
161
|
-
"&": "&",
|
|
162
|
-
"<": "<",
|
|
163
|
-
">": ">",
|
|
164
|
-
'"': """,
|
|
165
|
-
"'": "'",
|
|
166
|
-
"/": "/"
|
|
167
|
-
};
|
|
168
|
-
var escape = (data) => {
|
|
169
|
-
if (isString(data)) {
|
|
170
|
-
return data.replace(/[&<>"'\/]/g, (s) => _entityMap[s]);
|
|
171
|
-
}
|
|
172
|
-
return data;
|
|
173
|
-
};
|
|
174
|
-
var RegExpCache = class {
|
|
175
|
-
constructor(capacity) {
|
|
176
|
-
this.capacity = capacity;
|
|
177
|
-
this.regExpMap = /* @__PURE__ */ new Map();
|
|
178
|
-
this.regExpQueue = [];
|
|
179
|
-
}
|
|
180
|
-
getRegExp(pattern) {
|
|
181
|
-
const regExpFromCache = this.regExpMap.get(pattern);
|
|
182
|
-
if (regExpFromCache !== void 0) {
|
|
183
|
-
return regExpFromCache;
|
|
184
|
-
}
|
|
185
|
-
const regExpNew = new RegExp(pattern);
|
|
186
|
-
if (this.regExpQueue.length === this.capacity) {
|
|
187
|
-
this.regExpMap.delete(this.regExpQueue.shift());
|
|
188
|
-
}
|
|
189
|
-
this.regExpMap.set(pattern, regExpNew);
|
|
190
|
-
this.regExpQueue.push(pattern);
|
|
191
|
-
return regExpNew;
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
var chars = [" ", ",", "?", "!", ";"];
|
|
195
|
-
var looksLikeObjectPathRegExpCache = new RegExpCache(20);
|
|
196
|
-
var looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
|
|
197
|
-
nsSeparator = nsSeparator || "";
|
|
198
|
-
keySeparator = keySeparator || "";
|
|
199
|
-
const possibleChars = chars.filter((c) => !nsSeparator.includes(c) && !keySeparator.includes(c));
|
|
200
|
-
if (possibleChars.length === 0) return true;
|
|
201
|
-
const r = looksLikeObjectPathRegExpCache.getRegExp(`(${possibleChars.map((c) => c === "?" ? "\\?" : c).join("|")})`);
|
|
202
|
-
let matched = !r.test(key);
|
|
203
|
-
if (!matched) {
|
|
204
|
-
const ki = key.indexOf(keySeparator);
|
|
205
|
-
if (ki > 0 && !r.test(key.substring(0, ki))) {
|
|
206
|
-
matched = true;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return matched;
|
|
210
|
-
};
|
|
211
|
-
var deepFind = (obj, path, keySeparator = ".") => {
|
|
212
|
-
if (!obj) return void 0;
|
|
213
|
-
if (obj[path]) {
|
|
214
|
-
if (!Object.prototype.hasOwnProperty.call(obj, path)) return void 0;
|
|
215
|
-
return obj[path];
|
|
216
|
-
}
|
|
217
|
-
const tokens = path.split(keySeparator);
|
|
218
|
-
let current = obj;
|
|
219
|
-
for (let i = 0; i < tokens.length; ) {
|
|
220
|
-
if (!current || typeof current !== "object") {
|
|
221
|
-
return void 0;
|
|
222
|
-
}
|
|
223
|
-
let next;
|
|
224
|
-
let nextPath = "";
|
|
225
|
-
for (let j = i; j < tokens.length; ++j) {
|
|
226
|
-
if (j !== i) {
|
|
227
|
-
nextPath += keySeparator;
|
|
228
|
-
}
|
|
229
|
-
nextPath += tokens[j];
|
|
230
|
-
next = current[nextPath];
|
|
231
|
-
if (next !== void 0) {
|
|
232
|
-
if (["string", "number", "boolean"].includes(typeof next) && j < tokens.length - 1) {
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
235
|
-
i += j - i + 1;
|
|
236
|
-
break;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
current = next;
|
|
240
|
-
}
|
|
241
|
-
return current;
|
|
242
|
-
};
|
|
243
|
-
var getCleanedCode = (code) => code?.replace(/_/g, "-");
|
|
244
|
-
var consoleLogger = {
|
|
245
|
-
type: "logger",
|
|
246
|
-
log(args) {
|
|
247
|
-
this.output("log", args);
|
|
248
|
-
},
|
|
249
|
-
warn(args) {
|
|
250
|
-
this.output("warn", args);
|
|
251
|
-
},
|
|
252
|
-
error(args) {
|
|
253
|
-
this.output("error", args);
|
|
254
|
-
},
|
|
255
|
-
output(type, args) {
|
|
256
|
-
console?.[type]?.apply?.(console, args);
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
var Logger = class _Logger {
|
|
260
|
-
constructor(concreteLogger, options = {}) {
|
|
261
|
-
this.init(concreteLogger, options);
|
|
262
|
-
}
|
|
263
|
-
init(concreteLogger, options = {}) {
|
|
264
|
-
this.prefix = options.prefix || "i18next:";
|
|
265
|
-
this.logger = concreteLogger || consoleLogger;
|
|
266
|
-
this.options = options;
|
|
267
|
-
this.debug = options.debug;
|
|
268
|
-
}
|
|
269
|
-
log(...args) {
|
|
270
|
-
return this.forward(args, "log", "", true);
|
|
271
|
-
}
|
|
272
|
-
warn(...args) {
|
|
273
|
-
return this.forward(args, "warn", "", true);
|
|
274
|
-
}
|
|
275
|
-
error(...args) {
|
|
276
|
-
return this.forward(args, "error", "");
|
|
277
|
-
}
|
|
278
|
-
deprecate(...args) {
|
|
279
|
-
return this.forward(args, "warn", "WARNING DEPRECATED: ", true);
|
|
280
|
-
}
|
|
281
|
-
forward(args, lvl, prefix, debugOnly) {
|
|
282
|
-
if (debugOnly && !this.debug) return null;
|
|
283
|
-
args = args.map((a) => isString(a) ? a.replace(/[\r\n\x00-\x1F\x7F]/g, " ") : a);
|
|
284
|
-
if (isString(args[0])) args[0] = `${prefix}${this.prefix} ${args[0]}`;
|
|
285
|
-
return this.logger[lvl](args);
|
|
286
|
-
}
|
|
287
|
-
create(moduleName) {
|
|
288
|
-
return new _Logger(this.logger, {
|
|
289
|
-
...{
|
|
290
|
-
prefix: `${this.prefix}:${moduleName}:`
|
|
291
|
-
},
|
|
292
|
-
...this.options
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
clone(options) {
|
|
296
|
-
options = options || this.options;
|
|
297
|
-
options.prefix = options.prefix || this.prefix;
|
|
298
|
-
return new _Logger(this.logger, options);
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
|
-
var baseLogger = new Logger();
|
|
302
|
-
var EventEmitter = class {
|
|
303
|
-
constructor() {
|
|
304
|
-
this.observers = {};
|
|
305
|
-
}
|
|
306
|
-
on(events, listener) {
|
|
307
|
-
events.split(" ").forEach((event) => {
|
|
308
|
-
if (!this.observers[event]) this.observers[event] = /* @__PURE__ */ new Map();
|
|
309
|
-
const numListeners = this.observers[event].get(listener) || 0;
|
|
310
|
-
this.observers[event].set(listener, numListeners + 1);
|
|
311
|
-
});
|
|
312
|
-
return this;
|
|
313
|
-
}
|
|
314
|
-
off(event, listener) {
|
|
315
|
-
if (!this.observers[event]) return;
|
|
316
|
-
if (!listener) {
|
|
317
|
-
delete this.observers[event];
|
|
318
|
-
return;
|
|
319
|
-
}
|
|
320
|
-
this.observers[event].delete(listener);
|
|
321
|
-
}
|
|
322
|
-
once(event, listener) {
|
|
323
|
-
const wrapper = (...args) => {
|
|
324
|
-
listener(...args);
|
|
325
|
-
this.off(event, wrapper);
|
|
326
|
-
};
|
|
327
|
-
this.on(event, wrapper);
|
|
328
|
-
return this;
|
|
329
|
-
}
|
|
330
|
-
emit(event, ...args) {
|
|
331
|
-
if (this.observers[event]) {
|
|
332
|
-
const cloned = Array.from(this.observers[event].entries());
|
|
333
|
-
cloned.forEach(([observer, numTimesAdded]) => {
|
|
334
|
-
for (let i = 0; i < numTimesAdded; i++) {
|
|
335
|
-
observer(...args);
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
if (this.observers["*"]) {
|
|
340
|
-
const cloned = Array.from(this.observers["*"].entries());
|
|
341
|
-
cloned.forEach(([observer, numTimesAdded]) => {
|
|
342
|
-
for (let i = 0; i < numTimesAdded; i++) {
|
|
343
|
-
observer(event, ...args);
|
|
344
|
-
}
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
|
-
var ResourceStore = class extends EventEmitter {
|
|
350
|
-
constructor(data, options = {
|
|
351
|
-
ns: ["translation"],
|
|
352
|
-
defaultNS: "translation"
|
|
353
|
-
}) {
|
|
354
|
-
super();
|
|
355
|
-
this.data = data || {};
|
|
356
|
-
this.options = options;
|
|
357
|
-
if (this.options.keySeparator === void 0) {
|
|
358
|
-
this.options.keySeparator = ".";
|
|
359
|
-
}
|
|
360
|
-
if (this.options.ignoreJSONStructure === void 0) {
|
|
361
|
-
this.options.ignoreJSONStructure = true;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
addNamespaces(ns) {
|
|
365
|
-
if (!this.options.ns.includes(ns)) {
|
|
366
|
-
this.options.ns.push(ns);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
removeNamespaces(ns) {
|
|
370
|
-
const index = this.options.ns.indexOf(ns);
|
|
371
|
-
if (index > -1) {
|
|
372
|
-
this.options.ns.splice(index, 1);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
getResource(lng, ns, key, options = {}) {
|
|
376
|
-
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
377
|
-
const ignoreJSONStructure = options.ignoreJSONStructure !== void 0 ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
378
|
-
let path;
|
|
379
|
-
if (lng.includes(".")) {
|
|
380
|
-
path = lng.split(".");
|
|
381
|
-
} else {
|
|
382
|
-
path = [lng, ns];
|
|
383
|
-
if (key) {
|
|
384
|
-
if (Array.isArray(key)) {
|
|
385
|
-
path.push(...key);
|
|
386
|
-
} else if (isString(key) && keySeparator) {
|
|
387
|
-
path.push(...key.split(keySeparator));
|
|
388
|
-
} else {
|
|
389
|
-
path.push(key);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
const result = getPath(this.data, path);
|
|
394
|
-
if (!result && !ns && !key && lng.includes(".")) {
|
|
395
|
-
lng = path[0];
|
|
396
|
-
ns = path[1];
|
|
397
|
-
key = path.slice(2).join(".");
|
|
398
|
-
}
|
|
399
|
-
if (result || !ignoreJSONStructure || !isString(key)) return result;
|
|
400
|
-
return deepFind(this.data?.[lng]?.[ns], key, keySeparator);
|
|
401
|
-
}
|
|
402
|
-
addResource(lng, ns, key, value, options = {
|
|
403
|
-
silent: false
|
|
404
|
-
}) {
|
|
405
|
-
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
406
|
-
let path = [lng, ns];
|
|
407
|
-
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
408
|
-
if (lng.includes(".")) {
|
|
409
|
-
path = lng.split(".");
|
|
410
|
-
value = ns;
|
|
411
|
-
ns = path[1];
|
|
412
|
-
}
|
|
413
|
-
this.addNamespaces(ns);
|
|
414
|
-
setPath(this.data, path, value);
|
|
415
|
-
if (!options.silent) this.emit("added", lng, ns, key, value);
|
|
416
|
-
}
|
|
417
|
-
addResources(lng, ns, resources, options = {
|
|
418
|
-
silent: false
|
|
419
|
-
}) {
|
|
420
|
-
for (const m in resources) {
|
|
421
|
-
if (isString(resources[m]) || Array.isArray(resources[m])) this.addResource(lng, ns, m, resources[m], {
|
|
422
|
-
silent: true
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
if (!options.silent) this.emit("added", lng, ns, resources);
|
|
426
|
-
}
|
|
427
|
-
addResourceBundle(lng, ns, resources, deep, overwrite, options = {
|
|
428
|
-
silent: false,
|
|
429
|
-
skipCopy: false
|
|
430
|
-
}) {
|
|
431
|
-
let path = [lng, ns];
|
|
432
|
-
if (lng.includes(".")) {
|
|
433
|
-
path = lng.split(".");
|
|
434
|
-
deep = resources;
|
|
435
|
-
resources = ns;
|
|
436
|
-
ns = path[1];
|
|
437
|
-
}
|
|
438
|
-
this.addNamespaces(ns);
|
|
439
|
-
let pack = getPath(this.data, path) || {};
|
|
440
|
-
if (!options.skipCopy) resources = JSON.parse(JSON.stringify(resources));
|
|
441
|
-
if (deep) {
|
|
442
|
-
deepExtend(pack, resources, overwrite);
|
|
443
|
-
} else {
|
|
444
|
-
pack = {
|
|
445
|
-
...pack,
|
|
446
|
-
...resources
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
setPath(this.data, path, pack);
|
|
450
|
-
if (!options.silent) this.emit("added", lng, ns, resources);
|
|
451
|
-
}
|
|
452
|
-
removeResourceBundle(lng, ns) {
|
|
453
|
-
if (this.hasResourceBundle(lng, ns)) {
|
|
454
|
-
delete this.data[lng][ns];
|
|
455
|
-
}
|
|
456
|
-
this.removeNamespaces(ns);
|
|
457
|
-
this.emit("removed", lng, ns);
|
|
458
|
-
}
|
|
459
|
-
hasResourceBundle(lng, ns) {
|
|
460
|
-
return this.getResource(lng, ns) !== void 0;
|
|
461
|
-
}
|
|
462
|
-
getResourceBundle(lng, ns) {
|
|
463
|
-
if (!ns) ns = this.options.defaultNS;
|
|
464
|
-
return this.getResource(lng, ns);
|
|
465
|
-
}
|
|
466
|
-
getDataByLanguage(lng) {
|
|
467
|
-
return this.data[lng];
|
|
468
|
-
}
|
|
469
|
-
hasLanguageSomeTranslations(lng) {
|
|
470
|
-
const data = this.getDataByLanguage(lng);
|
|
471
|
-
const n = data && Object.keys(data) || [];
|
|
472
|
-
return !!n.find((v) => data[v] && Object.keys(data[v]).length > 0);
|
|
473
|
-
}
|
|
474
|
-
toJSON() {
|
|
475
|
-
return this.data;
|
|
476
|
-
}
|
|
477
|
-
};
|
|
478
|
-
var postProcessor = {
|
|
479
|
-
processors: {},
|
|
480
|
-
addPostProcessor(module) {
|
|
481
|
-
this.processors[module.name] = module;
|
|
482
|
-
},
|
|
483
|
-
handle(processors, value, key, options, translator) {
|
|
484
|
-
processors.forEach((processor) => {
|
|
485
|
-
value = this.processors[processor]?.process(value, key, options, translator) ?? value;
|
|
486
|
-
});
|
|
487
|
-
return value;
|
|
488
|
-
}
|
|
489
|
-
};
|
|
490
|
-
var PATH_KEY = /* @__PURE__ */ Symbol("i18next/PATH_KEY");
|
|
491
|
-
function createProxy() {
|
|
492
|
-
const state = [];
|
|
493
|
-
const handler = /* @__PURE__ */ Object.create(null);
|
|
494
|
-
let proxy;
|
|
495
|
-
handler.get = (target, key) => {
|
|
496
|
-
proxy?.revoke?.();
|
|
497
|
-
if (key === PATH_KEY) return state;
|
|
498
|
-
state.push(key);
|
|
499
|
-
proxy = Proxy.revocable(target, handler);
|
|
500
|
-
return proxy.proxy;
|
|
501
|
-
};
|
|
502
|
-
return Proxy.revocable(/* @__PURE__ */ Object.create(null), handler).proxy;
|
|
503
|
-
}
|
|
504
|
-
function keysFromSelector(selector, opts) {
|
|
505
|
-
const {
|
|
506
|
-
[PATH_KEY]: path
|
|
507
|
-
} = selector(createProxy());
|
|
508
|
-
const keySeparator = opts?.keySeparator ?? ".";
|
|
509
|
-
const nsSeparator = opts?.nsSeparator ?? ":";
|
|
510
|
-
const strict = opts?.enableSelector === "strict";
|
|
511
|
-
if (path.length > 1 && nsSeparator) {
|
|
512
|
-
const ns = opts?.ns;
|
|
513
|
-
const nsList = strict ? Array.isArray(ns) ? ns : ns ? [ns] : null : Array.isArray(ns) ? ns : null;
|
|
514
|
-
if (nsList) {
|
|
515
|
-
const candidates = strict ? nsList : nsList.length > 1 ? nsList.slice(1) : [];
|
|
516
|
-
if (candidates.includes(path[0])) {
|
|
517
|
-
return `${path[0]}${nsSeparator}${path.slice(1).join(keySeparator)}`;
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
return path.join(keySeparator);
|
|
522
|
-
}
|
|
523
|
-
var shouldHandleAsObject = (res) => !isString(res) && typeof res !== "boolean" && typeof res !== "number";
|
|
524
|
-
var Translator = class _Translator extends EventEmitter {
|
|
525
|
-
constructor(services, options = {}) {
|
|
526
|
-
super();
|
|
527
|
-
copy(["resourceStore", "languageUtils", "pluralResolver", "interpolator", "backendConnector", "i18nFormat", "utils"], services, this);
|
|
528
|
-
this.options = options;
|
|
529
|
-
if (this.options.keySeparator === void 0) {
|
|
530
|
-
this.options.keySeparator = ".";
|
|
531
|
-
}
|
|
532
|
-
this.logger = baseLogger.create("translator");
|
|
533
|
-
this.checkedLoadedFor = {};
|
|
534
|
-
}
|
|
535
|
-
changeLanguage(lng) {
|
|
536
|
-
if (lng) this.language = lng;
|
|
537
|
-
}
|
|
538
|
-
exists(key, o = {
|
|
539
|
-
interpolation: {}
|
|
540
|
-
}) {
|
|
541
|
-
const opt = {
|
|
542
|
-
...o
|
|
543
|
-
};
|
|
544
|
-
if (key == null) return false;
|
|
545
|
-
const resolved = this.resolve(key, opt);
|
|
546
|
-
if (resolved?.res === void 0) return false;
|
|
547
|
-
const isObject = shouldHandleAsObject(resolved.res);
|
|
548
|
-
if (opt.returnObjects === false && isObject) {
|
|
549
|
-
return false;
|
|
550
|
-
}
|
|
551
|
-
return true;
|
|
552
|
-
}
|
|
553
|
-
extractFromKey(key, opt) {
|
|
554
|
-
let nsSeparator = opt.nsSeparator !== void 0 ? opt.nsSeparator : this.options.nsSeparator;
|
|
555
|
-
if (nsSeparator === void 0) nsSeparator = ":";
|
|
556
|
-
const keySeparator = opt.keySeparator !== void 0 ? opt.keySeparator : this.options.keySeparator;
|
|
557
|
-
let namespaces = opt.ns || this.options.defaultNS || [];
|
|
558
|
-
const wouldCheckForNsInKey = nsSeparator && key.includes(nsSeparator);
|
|
559
|
-
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !opt.keySeparator && !this.options.userDefinedNsSeparator && !opt.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
560
|
-
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
561
|
-
const m = key.match(this.interpolator.nestingRegexp);
|
|
562
|
-
if (m && m.length > 0) {
|
|
563
|
-
return {
|
|
564
|
-
key,
|
|
565
|
-
namespaces: isString(namespaces) ? [namespaces] : namespaces
|
|
566
|
-
};
|
|
567
|
-
}
|
|
568
|
-
const parts = key.split(nsSeparator);
|
|
569
|
-
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.includes(parts[0])) namespaces = parts.shift();
|
|
570
|
-
key = parts.join(keySeparator);
|
|
571
|
-
}
|
|
572
|
-
return {
|
|
573
|
-
key,
|
|
574
|
-
namespaces: isString(namespaces) ? [namespaces] : namespaces
|
|
575
|
-
};
|
|
576
|
-
}
|
|
577
|
-
translate(keys, o, lastKey) {
|
|
578
|
-
let opt = typeof o === "object" ? {
|
|
579
|
-
...o
|
|
580
|
-
} : o;
|
|
581
|
-
if (typeof opt !== "object" && this.options.overloadTranslationOptionHandler) {
|
|
582
|
-
opt = this.options.overloadTranslationOptionHandler(arguments);
|
|
583
|
-
}
|
|
584
|
-
if (typeof opt === "object") opt = {
|
|
585
|
-
...opt
|
|
586
|
-
};
|
|
587
|
-
if (!opt) opt = {};
|
|
588
|
-
if (keys == null) return "";
|
|
589
|
-
if (typeof keys === "function") keys = keysFromSelector(keys, {
|
|
590
|
-
...this.options,
|
|
591
|
-
...opt
|
|
592
|
-
});
|
|
593
|
-
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
594
|
-
keys = keys.map((k) => typeof k === "function" ? keysFromSelector(k, {
|
|
595
|
-
...this.options,
|
|
596
|
-
...opt
|
|
597
|
-
}) : String(k));
|
|
598
|
-
const returnDetails = opt.returnDetails !== void 0 ? opt.returnDetails : this.options.returnDetails;
|
|
599
|
-
const keySeparator = opt.keySeparator !== void 0 ? opt.keySeparator : this.options.keySeparator;
|
|
600
|
-
const {
|
|
601
|
-
key,
|
|
602
|
-
namespaces
|
|
603
|
-
} = this.extractFromKey(keys[keys.length - 1], opt);
|
|
604
|
-
const namespace = namespaces[namespaces.length - 1];
|
|
605
|
-
let nsSeparator = opt.nsSeparator !== void 0 ? opt.nsSeparator : this.options.nsSeparator;
|
|
606
|
-
if (nsSeparator === void 0) nsSeparator = ":";
|
|
607
|
-
const lng = opt.lng || this.language;
|
|
608
|
-
const appendNamespaceToCIMode = opt.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
609
|
-
if (lng?.toLowerCase() === "cimode") {
|
|
610
|
-
if (appendNamespaceToCIMode) {
|
|
611
|
-
if (returnDetails) {
|
|
612
|
-
return {
|
|
613
|
-
res: `${namespace}${nsSeparator}${key}`,
|
|
614
|
-
usedKey: key,
|
|
615
|
-
exactUsedKey: key,
|
|
616
|
-
usedLng: lng,
|
|
617
|
-
usedNS: namespace,
|
|
618
|
-
usedParams: this.getUsedParamsDetails(opt)
|
|
619
|
-
};
|
|
620
|
-
}
|
|
621
|
-
return `${namespace}${nsSeparator}${key}`;
|
|
622
|
-
}
|
|
623
|
-
if (returnDetails) {
|
|
624
|
-
return {
|
|
625
|
-
res: key,
|
|
626
|
-
usedKey: key,
|
|
627
|
-
exactUsedKey: key,
|
|
628
|
-
usedLng: lng,
|
|
629
|
-
usedNS: namespace,
|
|
630
|
-
usedParams: this.getUsedParamsDetails(opt)
|
|
631
|
-
};
|
|
632
|
-
}
|
|
633
|
-
return key;
|
|
634
|
-
}
|
|
635
|
-
const resolved = this.resolve(keys, opt);
|
|
636
|
-
let res = resolved?.res;
|
|
637
|
-
const resUsedKey = resolved?.usedKey || key;
|
|
638
|
-
const resExactUsedKey = resolved?.exactUsedKey || key;
|
|
639
|
-
const noObject = ["[object Number]", "[object Function]", "[object RegExp]"];
|
|
640
|
-
const joinArrays = opt.joinArrays !== void 0 ? opt.joinArrays : this.options.joinArrays;
|
|
641
|
-
const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
642
|
-
const needsPluralHandling = opt.count !== void 0 && !isString(opt.count);
|
|
643
|
-
const hasDefaultValue = _Translator.hasDefaultValue(opt);
|
|
644
|
-
const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, opt) : "";
|
|
645
|
-
const defaultValueSuffixOrdinalFallback = opt.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, {
|
|
646
|
-
ordinal: false
|
|
647
|
-
}) : "";
|
|
648
|
-
const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
|
|
649
|
-
const defaultValue = needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] || opt[`defaultValue${defaultValueSuffix}`] || opt[`defaultValue${defaultValueSuffixOrdinalFallback}`] || opt.defaultValue;
|
|
650
|
-
let resForObjHndl = res;
|
|
651
|
-
if (handleAsObjectInI18nFormat && !res && hasDefaultValue) {
|
|
652
|
-
resForObjHndl = defaultValue;
|
|
653
|
-
}
|
|
654
|
-
const handleAsObject = shouldHandleAsObject(resForObjHndl);
|
|
655
|
-
const resType = Object.prototype.toString.apply(resForObjHndl);
|
|
656
|
-
if (handleAsObjectInI18nFormat && resForObjHndl && handleAsObject && !noObject.includes(resType) && !(isString(joinArrays) && Array.isArray(resForObjHndl))) {
|
|
657
|
-
if (!opt.returnObjects && !this.options.returnObjects) {
|
|
658
|
-
if (!this.options.returnedObjectHandler) {
|
|
659
|
-
this.logger.warn("accessing an object - but returnObjects options is not enabled!");
|
|
660
|
-
}
|
|
661
|
-
const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, resForObjHndl, {
|
|
662
|
-
...opt,
|
|
663
|
-
ns: namespaces
|
|
664
|
-
}) : `key '${key} (${this.language})' returned an object instead of string.`;
|
|
665
|
-
if (returnDetails) {
|
|
666
|
-
resolved.res = r;
|
|
667
|
-
resolved.usedParams = this.getUsedParamsDetails(opt);
|
|
668
|
-
return resolved;
|
|
669
|
-
}
|
|
670
|
-
return r;
|
|
671
|
-
}
|
|
672
|
-
if (keySeparator) {
|
|
673
|
-
const resTypeIsArray = Array.isArray(resForObjHndl);
|
|
674
|
-
const copy2 = resTypeIsArray ? [] : {};
|
|
675
|
-
const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
676
|
-
for (const m in resForObjHndl) {
|
|
677
|
-
if (Object.prototype.hasOwnProperty.call(resForObjHndl, m)) {
|
|
678
|
-
const deepKey = `${newKeyToUse}${keySeparator}${m}`;
|
|
679
|
-
if (hasDefaultValue && !res) {
|
|
680
|
-
copy2[m] = this.translate(deepKey, {
|
|
681
|
-
...opt,
|
|
682
|
-
defaultValue: shouldHandleAsObject(defaultValue) ? defaultValue[m] : void 0,
|
|
683
|
-
...{
|
|
684
|
-
joinArrays: false,
|
|
685
|
-
ns: namespaces
|
|
686
|
-
}
|
|
687
|
-
});
|
|
688
|
-
} else {
|
|
689
|
-
copy2[m] = this.translate(deepKey, {
|
|
690
|
-
...opt,
|
|
691
|
-
...{
|
|
692
|
-
joinArrays: false,
|
|
693
|
-
ns: namespaces
|
|
694
|
-
}
|
|
695
|
-
});
|
|
696
|
-
}
|
|
697
|
-
if (copy2[m] === deepKey) copy2[m] = resForObjHndl[m];
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
res = copy2;
|
|
701
|
-
}
|
|
702
|
-
} else if (handleAsObjectInI18nFormat && isString(joinArrays) && Array.isArray(res)) {
|
|
703
|
-
res = res.join(joinArrays);
|
|
704
|
-
if (res) res = this.extendTranslation(res, keys, opt, lastKey);
|
|
705
|
-
} else {
|
|
706
|
-
let usedDefault = false;
|
|
707
|
-
let usedKey = false;
|
|
708
|
-
if (!this.isValidLookup(res) && hasDefaultValue) {
|
|
709
|
-
usedDefault = true;
|
|
710
|
-
res = defaultValue;
|
|
711
|
-
}
|
|
712
|
-
if (!this.isValidLookup(res)) {
|
|
713
|
-
usedKey = true;
|
|
714
|
-
res = key;
|
|
715
|
-
}
|
|
716
|
-
const missingKeyNoValueFallbackToKey = opt.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
|
|
717
|
-
const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? void 0 : res;
|
|
718
|
-
const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
719
|
-
if (usedKey || usedDefault || updateMissing) {
|
|
720
|
-
this.logger.log(updateMissing ? "updateKey" : "missingKey", lng, namespace, needsPluralHandling && !updateMissing ? `${key}${this.pluralResolver.getSuffix(lng, opt.count, opt)}` : key, updateMissing ? defaultValue : res);
|
|
721
|
-
if (keySeparator) {
|
|
722
|
-
const fk = this.resolve(key, {
|
|
723
|
-
...opt,
|
|
724
|
-
keySeparator: false
|
|
725
|
-
});
|
|
726
|
-
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.");
|
|
727
|
-
}
|
|
728
|
-
let lngs = [];
|
|
729
|
-
const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, opt.lng || this.language);
|
|
730
|
-
if (this.options.saveMissingTo === "fallback" && fallbackLngs && fallbackLngs[0]) {
|
|
731
|
-
for (let i = 0; i < fallbackLngs.length; i++) {
|
|
732
|
-
lngs.push(fallbackLngs[i]);
|
|
733
|
-
}
|
|
734
|
-
} else if (this.options.saveMissingTo === "all") {
|
|
735
|
-
lngs = this.languageUtils.toResolveHierarchy(opt.lng || this.language);
|
|
736
|
-
} else {
|
|
737
|
-
lngs.push(opt.lng || this.language);
|
|
738
|
-
}
|
|
739
|
-
const send = (l, k, specificDefaultValue) => {
|
|
740
|
-
const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
741
|
-
if (this.options.missingKeyHandler) {
|
|
742
|
-
this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, opt);
|
|
743
|
-
} else if (this.backendConnector?.saveMissing) {
|
|
744
|
-
this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, opt);
|
|
745
|
-
}
|
|
746
|
-
this.emit("missingKey", l, namespace, k, res);
|
|
747
|
-
};
|
|
748
|
-
if (this.options.saveMissing) {
|
|
749
|
-
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
750
|
-
lngs.forEach((language) => {
|
|
751
|
-
const suffixes = this.pluralResolver.getSuffixes(language, opt);
|
|
752
|
-
if (needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] && !suffixes.includes(`${this.options.pluralSeparator}zero`)) {
|
|
753
|
-
suffixes.push(`${this.options.pluralSeparator}zero`);
|
|
754
|
-
}
|
|
755
|
-
suffixes.forEach((suffix) => {
|
|
756
|
-
send([language], key + suffix, opt[`defaultValue${suffix}`] || defaultValue);
|
|
757
|
-
});
|
|
758
|
-
});
|
|
759
|
-
} else {
|
|
760
|
-
send(lngs, key, defaultValue);
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
res = this.extendTranslation(res, keys, opt, resolved, lastKey);
|
|
765
|
-
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) {
|
|
766
|
-
res = `${namespace}${nsSeparator}${key}`;
|
|
767
|
-
}
|
|
768
|
-
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
|
|
769
|
-
res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}${nsSeparator}${key}` : key, usedDefault ? res : void 0, opt);
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
if (returnDetails) {
|
|
773
|
-
resolved.res = res;
|
|
774
|
-
resolved.usedParams = this.getUsedParamsDetails(opt);
|
|
775
|
-
return resolved;
|
|
776
|
-
}
|
|
777
|
-
return res;
|
|
778
|
-
}
|
|
779
|
-
extendTranslation(res, key, opt, resolved, lastKey) {
|
|
780
|
-
if (this.i18nFormat?.parse) {
|
|
781
|
-
res = this.i18nFormat.parse(res, {
|
|
782
|
-
...this.options.interpolation.defaultVariables,
|
|
783
|
-
...opt
|
|
784
|
-
}, opt.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
|
|
785
|
-
resolved
|
|
786
|
-
});
|
|
787
|
-
} else if (!opt.skipInterpolation) {
|
|
788
|
-
if (opt.interpolation) this.interpolator.init({
|
|
789
|
-
...opt,
|
|
790
|
-
...{
|
|
791
|
-
interpolation: {
|
|
792
|
-
...this.options.interpolation,
|
|
793
|
-
...opt.interpolation
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
});
|
|
797
|
-
const skipOnVariables = isString(res) && (opt?.interpolation?.skipOnVariables !== void 0 ? opt.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
798
|
-
let nestBef;
|
|
799
|
-
if (skipOnVariables) {
|
|
800
|
-
const nb = res.match(this.interpolator.nestingRegexp);
|
|
801
|
-
nestBef = nb && nb.length;
|
|
802
|
-
}
|
|
803
|
-
let data = opt.replace && !isString(opt.replace) ? opt.replace : opt;
|
|
804
|
-
if (this.options.interpolation.defaultVariables) data = {
|
|
805
|
-
...this.options.interpolation.defaultVariables,
|
|
806
|
-
...data
|
|
807
|
-
};
|
|
808
|
-
res = this.interpolator.interpolate(res, data, opt.lng || this.language || resolved.usedLng, opt);
|
|
809
|
-
if (skipOnVariables) {
|
|
810
|
-
const na = res.match(this.interpolator.nestingRegexp);
|
|
811
|
-
const nestAft = na && na.length;
|
|
812
|
-
if (nestBef < nestAft) opt.nest = false;
|
|
813
|
-
}
|
|
814
|
-
if (!opt.lng && resolved && resolved.res) opt.lng = this.language || resolved.usedLng;
|
|
815
|
-
if (opt.nest !== false) res = this.interpolator.nest(res, (...args) => {
|
|
816
|
-
if (lastKey?.[0] === args[0] && !opt.context) {
|
|
817
|
-
this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
|
|
818
|
-
return null;
|
|
819
|
-
}
|
|
820
|
-
return this.translate(...args, key);
|
|
821
|
-
}, opt);
|
|
822
|
-
if (opt.interpolation) this.interpolator.reset();
|
|
823
|
-
}
|
|
824
|
-
const postProcess = opt.postProcess || this.options.postProcess;
|
|
825
|
-
const postProcessorNames = isString(postProcess) ? [postProcess] : postProcess;
|
|
826
|
-
if (res != null && postProcessorNames?.length && opt.applyPostProcessor !== false) {
|
|
827
|
-
res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
|
|
828
|
-
i18nResolved: {
|
|
829
|
-
...resolved,
|
|
830
|
-
usedParams: this.getUsedParamsDetails(opt)
|
|
831
|
-
},
|
|
832
|
-
...opt
|
|
833
|
-
} : opt, this);
|
|
834
|
-
}
|
|
835
|
-
return res;
|
|
836
|
-
}
|
|
837
|
-
resolve(keys, opt = {}) {
|
|
838
|
-
let found;
|
|
839
|
-
let usedKey;
|
|
840
|
-
let exactUsedKey;
|
|
841
|
-
let usedLng;
|
|
842
|
-
let usedNS;
|
|
843
|
-
if (isString(keys)) keys = [keys];
|
|
844
|
-
if (Array.isArray(keys)) keys = keys.map((k) => typeof k === "function" ? keysFromSelector(k, {
|
|
845
|
-
...this.options,
|
|
846
|
-
...opt
|
|
847
|
-
}) : k);
|
|
848
|
-
keys.forEach((k) => {
|
|
849
|
-
if (this.isValidLookup(found)) return;
|
|
850
|
-
const extracted = this.extractFromKey(k, opt);
|
|
851
|
-
const key = extracted.key;
|
|
852
|
-
usedKey = key;
|
|
853
|
-
let namespaces = extracted.namespaces;
|
|
854
|
-
if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
|
|
855
|
-
const needsPluralHandling = opt.count !== void 0 && !isString(opt.count);
|
|
856
|
-
const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
|
|
857
|
-
const needsContextHandling = opt.context !== void 0 && (isString(opt.context) || typeof opt.context === "number") && opt.context !== "";
|
|
858
|
-
const codes = opt.lngs ? opt.lngs : this.languageUtils.toResolveHierarchy(opt.lng || this.language, opt.fallbackLng);
|
|
859
|
-
namespaces.forEach((ns) => {
|
|
860
|
-
if (this.isValidLookup(found)) return;
|
|
861
|
-
usedNS = ns;
|
|
862
|
-
if (!this.checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils?.hasLoadedNamespace && !this.utils?.hasLoadedNamespace(usedNS)) {
|
|
863
|
-
this.checkedLoadedFor[`${codes[0]}-${ns}`] = true;
|
|
864
|
-
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!!!");
|
|
865
|
-
}
|
|
866
|
-
codes.forEach((code) => {
|
|
867
|
-
if (this.isValidLookup(found)) return;
|
|
868
|
-
usedLng = code;
|
|
869
|
-
const finalKeys = [key];
|
|
870
|
-
if (this.i18nFormat?.addLookupKeys) {
|
|
871
|
-
this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, opt);
|
|
872
|
-
} else {
|
|
873
|
-
let pluralSuffix;
|
|
874
|
-
if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, opt.count, opt);
|
|
875
|
-
const zeroSuffix = `${this.options.pluralSeparator}zero`;
|
|
876
|
-
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
|
|
877
|
-
if (needsPluralHandling) {
|
|
878
|
-
if (opt.ordinal && pluralSuffix.startsWith(ordinalPrefix)) {
|
|
879
|
-
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
880
|
-
}
|
|
881
|
-
finalKeys.push(key + pluralSuffix);
|
|
882
|
-
if (needsZeroSuffixLookup) {
|
|
883
|
-
finalKeys.push(key + zeroSuffix);
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
if (needsContextHandling) {
|
|
887
|
-
const contextKey = `${key}${this.options.contextSeparator || "_"}${opt.context}`;
|
|
888
|
-
finalKeys.push(contextKey);
|
|
889
|
-
if (needsPluralHandling) {
|
|
890
|
-
if (opt.ordinal && pluralSuffix.startsWith(ordinalPrefix)) {
|
|
891
|
-
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
892
|
-
}
|
|
893
|
-
finalKeys.push(contextKey + pluralSuffix);
|
|
894
|
-
if (needsZeroSuffixLookup) {
|
|
895
|
-
finalKeys.push(contextKey + zeroSuffix);
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
let possibleKey;
|
|
901
|
-
while (possibleKey = finalKeys.pop()) {
|
|
902
|
-
if (!this.isValidLookup(found)) {
|
|
903
|
-
exactUsedKey = possibleKey;
|
|
904
|
-
found = this.getResource(code, ns, possibleKey, opt);
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
});
|
|
908
|
-
});
|
|
909
|
-
});
|
|
910
|
-
return {
|
|
911
|
-
res: found,
|
|
912
|
-
usedKey,
|
|
913
|
-
exactUsedKey,
|
|
914
|
-
usedLng,
|
|
915
|
-
usedNS
|
|
916
|
-
};
|
|
917
|
-
}
|
|
918
|
-
isValidLookup(res) {
|
|
919
|
-
return res !== void 0 && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === "");
|
|
920
|
-
}
|
|
921
|
-
getResource(code, ns, key, options = {}) {
|
|
922
|
-
if (this.i18nFormat?.getResource) return this.i18nFormat.getResource(code, ns, key, options);
|
|
923
|
-
return this.resourceStore.getResource(code, ns, key, options);
|
|
924
|
-
}
|
|
925
|
-
getUsedParamsDetails(options = {}) {
|
|
926
|
-
const optionsKeys = ["defaultValue", "ordinal", "context", "replace", "lng", "lngs", "fallbackLng", "ns", "keySeparator", "nsSeparator", "returnObjects", "returnDetails", "joinArrays", "postProcess", "interpolation"];
|
|
927
|
-
const useOptionsReplaceForData = options.replace && !isString(options.replace);
|
|
928
|
-
let data = useOptionsReplaceForData ? options.replace : options;
|
|
929
|
-
if (useOptionsReplaceForData && typeof options.count !== "undefined") {
|
|
930
|
-
data = {
|
|
931
|
-
...data,
|
|
932
|
-
count: options.count
|
|
933
|
-
};
|
|
934
|
-
}
|
|
935
|
-
if (this.options.interpolation.defaultVariables) {
|
|
936
|
-
data = {
|
|
937
|
-
...this.options.interpolation.defaultVariables,
|
|
938
|
-
...data
|
|
939
|
-
};
|
|
940
|
-
}
|
|
941
|
-
if (!useOptionsReplaceForData) {
|
|
942
|
-
data = {
|
|
943
|
-
...data
|
|
944
|
-
};
|
|
945
|
-
for (const key of optionsKeys) {
|
|
946
|
-
delete data[key];
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
return data;
|
|
950
|
-
}
|
|
951
|
-
static hasDefaultValue(options) {
|
|
952
|
-
const prefix = "defaultValue";
|
|
953
|
-
for (const option in options) {
|
|
954
|
-
if (Object.prototype.hasOwnProperty.call(options, option) && option.startsWith(prefix) && void 0 !== options[option]) {
|
|
955
|
-
return true;
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
return false;
|
|
959
|
-
}
|
|
960
|
-
};
|
|
961
|
-
var LanguageUtil = class {
|
|
962
|
-
constructor(options) {
|
|
963
|
-
this.options = options;
|
|
964
|
-
this.supportedLngs = this.options.supportedLngs || false;
|
|
965
|
-
this.logger = baseLogger.create("languageUtils");
|
|
966
|
-
this.resolveHierarchyCache = {};
|
|
967
|
-
}
|
|
968
|
-
clearCache() {
|
|
969
|
-
this.resolveHierarchyCache = {};
|
|
970
|
-
}
|
|
971
|
-
getScriptPartFromCode(code) {
|
|
972
|
-
code = getCleanedCode(code);
|
|
973
|
-
if (!code || !code.includes("-")) return null;
|
|
974
|
-
const p = code.split("-");
|
|
975
|
-
if (p.length === 2) return null;
|
|
976
|
-
p.pop();
|
|
977
|
-
if (p[p.length - 1].toLowerCase() === "x") return null;
|
|
978
|
-
return this.formatLanguageCode(p.join("-"));
|
|
979
|
-
}
|
|
980
|
-
getLanguagePartFromCode(code) {
|
|
981
|
-
code = getCleanedCode(code);
|
|
982
|
-
if (!code || !code.includes("-")) return code;
|
|
983
|
-
const p = code.split("-");
|
|
984
|
-
return this.formatLanguageCode(p[0]);
|
|
985
|
-
}
|
|
986
|
-
formatLanguageCode(code) {
|
|
987
|
-
if (isString(code) && code.includes("-")) {
|
|
988
|
-
let formattedCode;
|
|
989
|
-
try {
|
|
990
|
-
formattedCode = Intl.getCanonicalLocales(code)[0];
|
|
991
|
-
} catch (e) {
|
|
992
|
-
}
|
|
993
|
-
if (formattedCode && this.options.lowerCaseLng) {
|
|
994
|
-
formattedCode = formattedCode.toLowerCase();
|
|
995
|
-
}
|
|
996
|
-
if (formattedCode) return formattedCode;
|
|
997
|
-
if (this.options.lowerCaseLng) {
|
|
998
|
-
return code.toLowerCase();
|
|
999
|
-
}
|
|
1000
|
-
return code;
|
|
1001
|
-
}
|
|
1002
|
-
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
|
|
1003
|
-
}
|
|
1004
|
-
isSupportedCode(code) {
|
|
1005
|
-
if (this.options.load === "languageOnly" || this.options.nonExplicitSupportedLngs) {
|
|
1006
|
-
code = this.getLanguagePartFromCode(code);
|
|
1007
|
-
}
|
|
1008
|
-
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.includes(code);
|
|
1009
|
-
}
|
|
1010
|
-
getBestMatchFromCodes(codes) {
|
|
1011
|
-
if (!codes) return null;
|
|
1012
|
-
let found;
|
|
1013
|
-
codes.forEach((code) => {
|
|
1014
|
-
if (found) return;
|
|
1015
|
-
const cleanedLng = this.formatLanguageCode(code);
|
|
1016
|
-
if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
|
|
1017
|
-
});
|
|
1018
|
-
if (!found && this.options.supportedLngs) {
|
|
1019
|
-
codes.forEach((code) => {
|
|
1020
|
-
if (found) return;
|
|
1021
|
-
const lngScOnly = this.getScriptPartFromCode(code);
|
|
1022
|
-
if (this.isSupportedCode(lngScOnly)) return found = lngScOnly;
|
|
1023
|
-
const lngOnly = this.getLanguagePartFromCode(code);
|
|
1024
|
-
if (this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
1025
|
-
found = this.options.supportedLngs.find((supportedLng) => {
|
|
1026
|
-
if (supportedLng === lngOnly) return true;
|
|
1027
|
-
if (!supportedLng.includes("-") && !lngOnly.includes("-")) return false;
|
|
1028
|
-
if (supportedLng.includes("-") && !lngOnly.includes("-") && supportedLng.slice(0, supportedLng.indexOf("-")) === lngOnly) return true;
|
|
1029
|
-
if (supportedLng.startsWith(lngOnly) && lngOnly.length > 1) return true;
|
|
1030
|
-
return false;
|
|
1031
|
-
});
|
|
1032
|
-
});
|
|
1033
|
-
}
|
|
1034
|
-
if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
|
|
1035
|
-
return found;
|
|
1036
|
-
}
|
|
1037
|
-
getFallbackCodes(fallbacks, code) {
|
|
1038
|
-
if (!fallbacks) return [];
|
|
1039
|
-
if (typeof fallbacks === "function") fallbacks = fallbacks(code);
|
|
1040
|
-
if (isString(fallbacks)) fallbacks = [fallbacks];
|
|
1041
|
-
if (Array.isArray(fallbacks)) return fallbacks;
|
|
1042
|
-
if (!code) return fallbacks.default || [];
|
|
1043
|
-
let found = fallbacks[code];
|
|
1044
|
-
if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
|
|
1045
|
-
if (!found) found = fallbacks[this.formatLanguageCode(code)];
|
|
1046
|
-
if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
1047
|
-
if (!found) found = fallbacks.default;
|
|
1048
|
-
return found || [];
|
|
1049
|
-
}
|
|
1050
|
-
toResolveHierarchy(code, fallbackCode) {
|
|
1051
|
-
const fallbackLng = this.options.fallbackLng;
|
|
1052
|
-
const fallbackLngKey = Array.isArray(fallbackLng) ? fallbackLng.join("|") : fallbackLng;
|
|
1053
|
-
if (fallbackLngKey !== this._cachedFallbackLng) {
|
|
1054
|
-
this.resolveHierarchyCache = {};
|
|
1055
|
-
this._cachedFallbackLng = fallbackLngKey;
|
|
1056
|
-
}
|
|
1057
|
-
const hasCacheableFallback = fallbackCode === void 0 || fallbackCode === false || isString(fallbackCode);
|
|
1058
|
-
const usesUncacheableOptionsFallback = fallbackCode === void 0 && typeof this.options.fallbackLng === "function";
|
|
1059
|
-
const cacheable = isString(code) && hasCacheableFallback && !usesUncacheableOptionsFallback;
|
|
1060
|
-
let cacheKey = null;
|
|
1061
|
-
if (cacheable) {
|
|
1062
|
-
let fallbackCacheKey;
|
|
1063
|
-
if (fallbackCode === void 0) fallbackCacheKey = "undefined";
|
|
1064
|
-
else if (fallbackCode === false) fallbackCacheKey = "boolean:false";
|
|
1065
|
-
else fallbackCacheKey = `string:${fallbackCode}`;
|
|
1066
|
-
cacheKey = `${code.length}:${code}|${fallbackCacheKey}`;
|
|
1067
|
-
}
|
|
1068
|
-
if (cacheKey !== null) {
|
|
1069
|
-
const cached = this.resolveHierarchyCache[cacheKey];
|
|
1070
|
-
if (cached !== void 0) return cached.slice();
|
|
1071
|
-
}
|
|
1072
|
-
const fallbackCodes = this.getFallbackCodes((fallbackCode === false ? [] : fallbackCode) || this.options.fallbackLng || [], code);
|
|
1073
|
-
const codes = [];
|
|
1074
|
-
const addCode = (c) => {
|
|
1075
|
-
if (!c) return;
|
|
1076
|
-
if (this.isSupportedCode(c)) {
|
|
1077
|
-
codes.push(c);
|
|
1078
|
-
} else {
|
|
1079
|
-
this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
|
|
1080
|
-
}
|
|
1081
|
-
};
|
|
1082
|
-
if (isString(code) && (code.includes("-") || code.includes("_"))) {
|
|
1083
|
-
if (this.options.load !== "languageOnly") addCode(this.formatLanguageCode(code));
|
|
1084
|
-
if (this.options.load !== "languageOnly" && this.options.load !== "currentOnly") addCode(this.getScriptPartFromCode(code));
|
|
1085
|
-
if (this.options.load !== "currentOnly") addCode(this.getLanguagePartFromCode(code));
|
|
1086
|
-
} else if (isString(code)) {
|
|
1087
|
-
addCode(this.formatLanguageCode(code));
|
|
1088
|
-
}
|
|
1089
|
-
fallbackCodes.forEach((fc) => {
|
|
1090
|
-
if (!codes.includes(fc)) addCode(this.formatLanguageCode(fc));
|
|
1091
|
-
});
|
|
1092
|
-
if (cacheKey !== null) {
|
|
1093
|
-
this.resolveHierarchyCache[cacheKey] = codes;
|
|
1094
|
-
return codes.slice();
|
|
1095
|
-
}
|
|
1096
|
-
return codes;
|
|
1097
|
-
}
|
|
1098
|
-
};
|
|
1099
|
-
var suffixesOrder = {
|
|
1100
|
-
zero: 0,
|
|
1101
|
-
one: 1,
|
|
1102
|
-
two: 2,
|
|
1103
|
-
few: 3,
|
|
1104
|
-
many: 4,
|
|
1105
|
-
other: 5
|
|
1106
|
-
};
|
|
1107
|
-
var dummyRule = {
|
|
1108
|
-
select: (count) => count === 1 ? "one" : "other",
|
|
1109
|
-
resolvedOptions: () => ({
|
|
1110
|
-
pluralCategories: ["one", "other"]
|
|
1111
|
-
})
|
|
1112
|
-
};
|
|
1113
|
-
var PluralResolver = class {
|
|
1114
|
-
constructor(languageUtils, options = {}) {
|
|
1115
|
-
this.languageUtils = languageUtils;
|
|
1116
|
-
this.options = options;
|
|
1117
|
-
this.logger = baseLogger.create("pluralResolver");
|
|
1118
|
-
this.pluralRulesCache = {};
|
|
1119
|
-
}
|
|
1120
|
-
clearCache() {
|
|
1121
|
-
this.pluralRulesCache = {};
|
|
1122
|
-
}
|
|
1123
|
-
getRule(code, options = {}) {
|
|
1124
|
-
const cleanedCode = getCleanedCode(code === "dev" ? "en" : code);
|
|
1125
|
-
const type = options.ordinal ? "ordinal" : "cardinal";
|
|
1126
|
-
const cacheKey = JSON.stringify({
|
|
1127
|
-
cleanedCode,
|
|
1128
|
-
type
|
|
1129
|
-
});
|
|
1130
|
-
if (cacheKey in this.pluralRulesCache) {
|
|
1131
|
-
return this.pluralRulesCache[cacheKey];
|
|
1132
|
-
}
|
|
1133
|
-
let rule;
|
|
1134
|
-
try {
|
|
1135
|
-
rule = new Intl.PluralRules(cleanedCode, {
|
|
1136
|
-
type
|
|
1137
|
-
});
|
|
1138
|
-
} catch (err) {
|
|
1139
|
-
if (typeof Intl === "undefined") {
|
|
1140
|
-
this.logger.error("No Intl support, please use an Intl polyfill!");
|
|
1141
|
-
return dummyRule;
|
|
1142
|
-
}
|
|
1143
|
-
if (!code.match(/-|_/)) return dummyRule;
|
|
1144
|
-
const lngPart = this.languageUtils.getLanguagePartFromCode(code);
|
|
1145
|
-
rule = this.getRule(lngPart, options);
|
|
1146
|
-
}
|
|
1147
|
-
this.pluralRulesCache[cacheKey] = rule;
|
|
1148
|
-
return rule;
|
|
1149
|
-
}
|
|
1150
|
-
needsPlural(code, options = {}) {
|
|
1151
|
-
let rule = this.getRule(code, options);
|
|
1152
|
-
if (!rule) rule = this.getRule("dev", options);
|
|
1153
|
-
return rule?.resolvedOptions().pluralCategories.length > 1;
|
|
1154
|
-
}
|
|
1155
|
-
getPluralFormsOfKey(code, key, options = {}) {
|
|
1156
|
-
return this.getSuffixes(code, options).map((suffix) => `${key}${suffix}`);
|
|
1157
|
-
}
|
|
1158
|
-
getSuffixes(code, options = {}) {
|
|
1159
|
-
let rule = this.getRule(code, options);
|
|
1160
|
-
if (!rule) rule = this.getRule("dev", options);
|
|
1161
|
-
if (!rule) return [];
|
|
1162
|
-
return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map((pluralCategory) => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${pluralCategory}`);
|
|
1163
|
-
}
|
|
1164
|
-
getSuffix(code, count, options = {}) {
|
|
1165
|
-
const rule = this.getRule(code, options);
|
|
1166
|
-
if (rule) {
|
|
1167
|
-
return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${rule.select(count)}`;
|
|
1168
|
-
}
|
|
1169
|
-
this.logger.warn(`no plural rule found for: ${code}`);
|
|
1170
|
-
return this.getSuffix("dev", count, options);
|
|
1171
|
-
}
|
|
1172
|
-
};
|
|
1173
|
-
var deepFindWithDefaults = (data, defaultData, key, keySeparator = ".", ignoreJSONStructure = true) => {
|
|
1174
|
-
let path = getPathWithDefaults(data, defaultData, key);
|
|
1175
|
-
if (!path && ignoreJSONStructure && isString(key)) {
|
|
1176
|
-
path = deepFind(data, key, keySeparator);
|
|
1177
|
-
if (path === void 0) path = deepFind(defaultData, key, keySeparator);
|
|
1178
|
-
}
|
|
1179
|
-
return path;
|
|
1180
|
-
};
|
|
1181
|
-
var regexSafe = (val) => val.replace(/\$/g, "$$$$");
|
|
1182
|
-
var Interpolator = class {
|
|
1183
|
-
constructor(options = {}) {
|
|
1184
|
-
this.logger = baseLogger.create("interpolator");
|
|
1185
|
-
this.options = options;
|
|
1186
|
-
this.format = options?.interpolation?.format || ((value) => value);
|
|
1187
|
-
this.init(options);
|
|
1188
|
-
}
|
|
1189
|
-
init(options = {}) {
|
|
1190
|
-
if (!options.interpolation) options.interpolation = {
|
|
1191
|
-
escapeValue: true
|
|
1192
|
-
};
|
|
1193
|
-
const {
|
|
1194
|
-
escape: escape$1,
|
|
1195
|
-
escapeValue,
|
|
1196
|
-
useRawValueToEscape,
|
|
1197
|
-
prefix,
|
|
1198
|
-
prefixEscaped,
|
|
1199
|
-
suffix,
|
|
1200
|
-
suffixEscaped,
|
|
1201
|
-
formatSeparator,
|
|
1202
|
-
unescapeSuffix,
|
|
1203
|
-
unescapePrefix,
|
|
1204
|
-
nestingPrefix,
|
|
1205
|
-
nestingPrefixEscaped,
|
|
1206
|
-
nestingSuffix,
|
|
1207
|
-
nestingSuffixEscaped,
|
|
1208
|
-
nestingOptionsSeparator,
|
|
1209
|
-
maxReplaces,
|
|
1210
|
-
alwaysFormat
|
|
1211
|
-
} = options.interpolation;
|
|
1212
|
-
this.escape = escape$1 !== void 0 ? escape$1 : escape;
|
|
1213
|
-
this.escapeValue = escapeValue !== void 0 ? escapeValue : true;
|
|
1214
|
-
this.useRawValueToEscape = useRawValueToEscape !== void 0 ? useRawValueToEscape : false;
|
|
1215
|
-
this.prefix = prefix ? regexEscape(prefix) : prefixEscaped || "{{";
|
|
1216
|
-
this.suffix = suffix ? regexEscape(suffix) : suffixEscaped || "}}";
|
|
1217
|
-
this.formatSeparator = formatSeparator || ",";
|
|
1218
|
-
this.unescapePrefix = unescapeSuffix ? "" : unescapePrefix ? regexEscape(unescapePrefix) : "-";
|
|
1219
|
-
this.unescapeSuffix = this.unescapePrefix ? "" : unescapeSuffix ? regexEscape(unescapeSuffix) : "";
|
|
1220
|
-
this.nestingPrefix = nestingPrefix ? regexEscape(nestingPrefix) : nestingPrefixEscaped || regexEscape("$t(");
|
|
1221
|
-
this.nestingSuffix = nestingSuffix ? regexEscape(nestingSuffix) : nestingSuffixEscaped || regexEscape(")");
|
|
1222
|
-
this.nestingOptionsSeparator = nestingOptionsSeparator || ",";
|
|
1223
|
-
this.maxReplaces = maxReplaces || 1e3;
|
|
1224
|
-
this.alwaysFormat = alwaysFormat !== void 0 ? alwaysFormat : false;
|
|
1225
|
-
this.resetRegExp();
|
|
1226
|
-
}
|
|
1227
|
-
reset() {
|
|
1228
|
-
if (this.options) this.init(this.options);
|
|
1229
|
-
}
|
|
1230
|
-
resetRegExp() {
|
|
1231
|
-
const getOrResetRegExp = (existingRegExp, pattern) => {
|
|
1232
|
-
if (existingRegExp?.source === pattern) {
|
|
1233
|
-
existingRegExp.lastIndex = 0;
|
|
1234
|
-
return existingRegExp;
|
|
1235
|
-
}
|
|
1236
|
-
return new RegExp(pattern, "g");
|
|
1237
|
-
};
|
|
1238
|
-
this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
|
|
1239
|
-
this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
|
|
1240
|
-
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}((?:[^()"']+|"[^"]*"|'[^']*'|\\((?:[^()]|"[^"]*"|'[^']*')*\\))*?)${this.nestingSuffix}`);
|
|
1241
|
-
}
|
|
1242
|
-
interpolate(str, data, lng, options) {
|
|
1243
|
-
let match;
|
|
1244
|
-
let value;
|
|
1245
|
-
let replaces;
|
|
1246
|
-
const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
1247
|
-
const handleFormat = (key) => {
|
|
1248
|
-
if (!key.includes(this.formatSeparator)) {
|
|
1249
|
-
const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
|
|
1250
|
-
return this.alwaysFormat ? this.format(path, void 0, lng, {
|
|
1251
|
-
...options,
|
|
1252
|
-
...data,
|
|
1253
|
-
interpolationkey: key
|
|
1254
|
-
}) : path;
|
|
1255
|
-
}
|
|
1256
|
-
const p = key.split(this.formatSeparator);
|
|
1257
|
-
const k = p.shift().trim();
|
|
1258
|
-
const f = p.join(this.formatSeparator).trim();
|
|
1259
|
-
return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
|
|
1260
|
-
...options,
|
|
1261
|
-
...data,
|
|
1262
|
-
interpolationkey: k
|
|
1263
|
-
});
|
|
1264
|
-
};
|
|
1265
|
-
this.resetRegExp();
|
|
1266
|
-
if (!this.escapeValue && typeof str === "string" && /\$t\([^)]*\{[^}]*\{\{/.test(str)) {
|
|
1267
|
-
this.logger.warn("nesting options string contains interpolated variables with escapeValue: false \u2014 if any of those values are attacker-controlled they can inject additional nesting options (e.g. redirect lng/ns). Sanitise untrusted input before passing it to t(), or keep escapeValue: true.");
|
|
1268
|
-
}
|
|
1269
|
-
const missingInterpolationHandler = options?.missingInterpolationHandler || this.options.missingInterpolationHandler;
|
|
1270
|
-
const skipOnVariables = options?.interpolation?.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
|
|
1271
|
-
const todos = [{
|
|
1272
|
-
regex: this.regexpUnescape,
|
|
1273
|
-
safeValue: (val) => val
|
|
1274
|
-
}, {
|
|
1275
|
-
regex: this.regexp,
|
|
1276
|
-
safeValue: (val) => this.escapeValue ? this.escape(val) : val
|
|
1277
|
-
}];
|
|
1278
|
-
todos.forEach((todo) => {
|
|
1279
|
-
replaces = 0;
|
|
1280
|
-
while (match = todo.regex.exec(str)) {
|
|
1281
|
-
const matchedVar = match[1].trim();
|
|
1282
|
-
value = handleFormat(matchedVar);
|
|
1283
|
-
if (value === void 0) {
|
|
1284
|
-
if (typeof missingInterpolationHandler === "function") {
|
|
1285
|
-
const temp = missingInterpolationHandler(str, match, options);
|
|
1286
|
-
value = isString(temp) ? temp : "";
|
|
1287
|
-
} else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
|
|
1288
|
-
value = "";
|
|
1289
|
-
} else if (skipOnVariables) {
|
|
1290
|
-
value = match[0];
|
|
1291
|
-
continue;
|
|
1292
|
-
} else {
|
|
1293
|
-
this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
|
|
1294
|
-
value = "";
|
|
1295
|
-
}
|
|
1296
|
-
} else if (!isString(value) && !this.useRawValueToEscape) {
|
|
1297
|
-
value = makeString(value);
|
|
1298
|
-
}
|
|
1299
|
-
const safeValue = todo.safeValue(value);
|
|
1300
|
-
str = str.replace(match[0], regexSafe(safeValue));
|
|
1301
|
-
if (skipOnVariables) {
|
|
1302
|
-
todo.regex.lastIndex += safeValue.length;
|
|
1303
|
-
todo.regex.lastIndex -= match[0].length;
|
|
1304
|
-
} else {
|
|
1305
|
-
todo.regex.lastIndex = 0;
|
|
1306
|
-
}
|
|
1307
|
-
replaces++;
|
|
1308
|
-
if (replaces >= this.maxReplaces) {
|
|
1309
|
-
break;
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
});
|
|
1313
|
-
return str;
|
|
1314
|
-
}
|
|
1315
|
-
nest(str, fc, options = {}) {
|
|
1316
|
-
let match;
|
|
1317
|
-
let value;
|
|
1318
|
-
let clonedOptions;
|
|
1319
|
-
const handleHasOptions = (key, inheritedOptions) => {
|
|
1320
|
-
const sep = this.nestingOptionsSeparator;
|
|
1321
|
-
if (!key.includes(sep)) return key;
|
|
1322
|
-
const c = key.split(new RegExp(`${regexEscape(sep)}[ ]*{`));
|
|
1323
|
-
let optionsString = `{${c[1]}`;
|
|
1324
|
-
key = c[0];
|
|
1325
|
-
optionsString = this.interpolate(optionsString, clonedOptions);
|
|
1326
|
-
const matchedSingleQuotes = optionsString.match(/'/g);
|
|
1327
|
-
const matchedDoubleQuotes = optionsString.match(/"/g);
|
|
1328
|
-
if ((matchedSingleQuotes?.length ?? 0) % 2 === 0 && !matchedDoubleQuotes || (matchedDoubleQuotes?.length ?? 0) % 2 !== 0) {
|
|
1329
|
-
optionsString = optionsString.replace(/'/g, '"');
|
|
1330
|
-
}
|
|
1331
|
-
try {
|
|
1332
|
-
clonedOptions = JSON.parse(optionsString);
|
|
1333
|
-
if (inheritedOptions) clonedOptions = {
|
|
1334
|
-
...inheritedOptions,
|
|
1335
|
-
...clonedOptions
|
|
1336
|
-
};
|
|
1337
|
-
} catch (e) {
|
|
1338
|
-
this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
|
|
1339
|
-
return `${key}${sep}${optionsString}`;
|
|
1340
|
-
}
|
|
1341
|
-
if (clonedOptions.defaultValue && clonedOptions.defaultValue.includes(this.prefix)) delete clonedOptions.defaultValue;
|
|
1342
|
-
return key;
|
|
1343
|
-
};
|
|
1344
|
-
while (match = this.nestingRegexp.exec(str)) {
|
|
1345
|
-
let formatters = [];
|
|
1346
|
-
clonedOptions = {
|
|
1347
|
-
...options
|
|
1348
|
-
};
|
|
1349
|
-
clonedOptions = clonedOptions.replace && !isString(clonedOptions.replace) ? clonedOptions.replace : clonedOptions;
|
|
1350
|
-
clonedOptions.applyPostProcessor = false;
|
|
1351
|
-
delete clonedOptions.defaultValue;
|
|
1352
|
-
const keyEndIndex = /{.*}/s.test(match[1]) ? match[1].lastIndexOf("}") + 1 : match[1].indexOf(this.formatSeparator);
|
|
1353
|
-
if (keyEndIndex !== -1) {
|
|
1354
|
-
formatters = match[1].slice(keyEndIndex).split(this.formatSeparator).map((elem) => elem.trim()).filter(Boolean);
|
|
1355
|
-
match[1] = match[1].slice(0, keyEndIndex);
|
|
1356
|
-
}
|
|
1357
|
-
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
1358
|
-
if (value && match[0] === str && !isString(value)) return value;
|
|
1359
|
-
if (!isString(value)) value = makeString(value);
|
|
1360
|
-
if (!value) {
|
|
1361
|
-
this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
|
|
1362
|
-
value = "";
|
|
1363
|
-
}
|
|
1364
|
-
if (formatters.length) {
|
|
1365
|
-
value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
|
|
1366
|
-
...options,
|
|
1367
|
-
interpolationkey: match[1].trim()
|
|
1368
|
-
}), value.trim());
|
|
1369
|
-
}
|
|
1370
|
-
str = str.replace(match[0], regexSafe(makeString(value)));
|
|
1371
|
-
this.regexp.lastIndex = 0;
|
|
1372
|
-
}
|
|
1373
|
-
return str;
|
|
1374
|
-
}
|
|
1375
|
-
};
|
|
1376
|
-
var parseFormatStr = (formatStr) => {
|
|
1377
|
-
let formatName = formatStr.toLowerCase().trim();
|
|
1378
|
-
const formatOptions = {};
|
|
1379
|
-
if (formatStr.includes("(")) {
|
|
1380
|
-
const p = formatStr.split("(");
|
|
1381
|
-
formatName = p[0].toLowerCase().trim();
|
|
1382
|
-
const optStr = p[1].slice(0, -1);
|
|
1383
|
-
if (formatName === "currency" && !optStr.includes(":")) {
|
|
1384
|
-
if (!formatOptions.currency) formatOptions.currency = optStr.trim();
|
|
1385
|
-
} else if (formatName === "relativetime" && !optStr.includes(":")) {
|
|
1386
|
-
if (!formatOptions.range) formatOptions.range = optStr.trim();
|
|
1387
|
-
} else {
|
|
1388
|
-
const opts = optStr.split(";");
|
|
1389
|
-
opts.forEach((opt) => {
|
|
1390
|
-
if (opt) {
|
|
1391
|
-
const [key, ...rest] = opt.split(":");
|
|
1392
|
-
const val = rest.join(":").trim().replace(/^'+|'+$/g, "");
|
|
1393
|
-
const trimmedKey = key.trim();
|
|
1394
|
-
if (!formatOptions[trimmedKey]) formatOptions[trimmedKey] = val;
|
|
1395
|
-
if (val === "false") formatOptions[trimmedKey] = false;
|
|
1396
|
-
if (val === "true") formatOptions[trimmedKey] = true;
|
|
1397
|
-
if (!isNaN(val)) formatOptions[trimmedKey] = parseInt(val, 10);
|
|
1398
|
-
}
|
|
1399
|
-
});
|
|
1400
|
-
}
|
|
1401
|
-
}
|
|
1402
|
-
return {
|
|
1403
|
-
formatName,
|
|
1404
|
-
formatOptions
|
|
1405
|
-
};
|
|
1406
|
-
};
|
|
1407
|
-
var createCachedFormatter = (fn) => {
|
|
1408
|
-
const cache = {};
|
|
1409
|
-
return (v, l, o) => {
|
|
1410
|
-
let optForCache = o;
|
|
1411
|
-
if (o && o.interpolationkey && o.formatParams && o.formatParams[o.interpolationkey] && o[o.interpolationkey]) {
|
|
1412
|
-
optForCache = {
|
|
1413
|
-
...optForCache,
|
|
1414
|
-
[o.interpolationkey]: void 0
|
|
1415
|
-
};
|
|
1416
|
-
}
|
|
1417
|
-
const key = l + JSON.stringify(optForCache);
|
|
1418
|
-
let frm = cache[key];
|
|
1419
|
-
if (!frm) {
|
|
1420
|
-
frm = fn(getCleanedCode(l), o);
|
|
1421
|
-
cache[key] = frm;
|
|
1422
|
-
}
|
|
1423
|
-
return frm(v);
|
|
1424
|
-
};
|
|
1425
|
-
};
|
|
1426
|
-
var createNonCachedFormatter = (fn) => (v, l, o) => fn(getCleanedCode(l), o)(v);
|
|
1427
|
-
var Formatter = class {
|
|
1428
|
-
constructor(options = {}) {
|
|
1429
|
-
this.logger = baseLogger.create("formatter");
|
|
1430
|
-
this.options = options;
|
|
1431
|
-
this.init(options);
|
|
1432
|
-
}
|
|
1433
|
-
init(services, options = {
|
|
1434
|
-
interpolation: {}
|
|
1435
|
-
}) {
|
|
1436
|
-
this.formatSeparator = options.interpolation.formatSeparator || ",";
|
|
1437
|
-
const cf = options.cacheInBuiltFormats ? createCachedFormatter : createNonCachedFormatter;
|
|
1438
|
-
this.formats = {
|
|
1439
|
-
number: cf((lng, opt) => {
|
|
1440
|
-
const formatter = new Intl.NumberFormat(lng, {
|
|
1441
|
-
...opt
|
|
1442
|
-
});
|
|
1443
|
-
return (val) => formatter.format(val);
|
|
1444
|
-
}),
|
|
1445
|
-
currency: cf((lng, opt) => {
|
|
1446
|
-
const formatter = new Intl.NumberFormat(lng, {
|
|
1447
|
-
...opt,
|
|
1448
|
-
style: "currency"
|
|
1449
|
-
});
|
|
1450
|
-
return (val) => formatter.format(val);
|
|
1451
|
-
}),
|
|
1452
|
-
datetime: cf((lng, opt) => {
|
|
1453
|
-
const formatter = new Intl.DateTimeFormat(lng, {
|
|
1454
|
-
...opt
|
|
1455
|
-
});
|
|
1456
|
-
return (val) => formatter.format(val);
|
|
1457
|
-
}),
|
|
1458
|
-
relativetime: cf((lng, opt) => {
|
|
1459
|
-
const formatter = new Intl.RelativeTimeFormat(lng, {
|
|
1460
|
-
...opt
|
|
1461
|
-
});
|
|
1462
|
-
return (val) => formatter.format(val, opt.range || "day");
|
|
1463
|
-
}),
|
|
1464
|
-
list: cf((lng, opt) => {
|
|
1465
|
-
const formatter = new Intl.ListFormat(lng, {
|
|
1466
|
-
...opt
|
|
1467
|
-
});
|
|
1468
|
-
return (val) => formatter.format(val);
|
|
1469
|
-
})
|
|
1470
|
-
};
|
|
1471
|
-
}
|
|
1472
|
-
add(name, fc) {
|
|
1473
|
-
this.formats[name.toLowerCase().trim()] = fc;
|
|
1474
|
-
}
|
|
1475
|
-
addCached(name, fc) {
|
|
1476
|
-
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
1477
|
-
}
|
|
1478
|
-
format(value, format, lng, options = {}) {
|
|
1479
|
-
if (!format) return value;
|
|
1480
|
-
if (value == null) return value;
|
|
1481
|
-
const rawFormats = format.split(this.formatSeparator);
|
|
1482
|
-
const formats = [];
|
|
1483
|
-
for (let i = 0; i < rawFormats.length; i++) {
|
|
1484
|
-
let f = rawFormats[i];
|
|
1485
|
-
while (f.indexOf("(") > -1 && !f.includes(")") && i + 1 < rawFormats.length) {
|
|
1486
|
-
f = `${f}${this.formatSeparator}${rawFormats[++i]}`;
|
|
1487
|
-
}
|
|
1488
|
-
formats.push(f);
|
|
1489
|
-
}
|
|
1490
|
-
const result = formats.reduce((mem, f) => {
|
|
1491
|
-
const {
|
|
1492
|
-
formatName,
|
|
1493
|
-
formatOptions
|
|
1494
|
-
} = parseFormatStr(f);
|
|
1495
|
-
if (this.formats[formatName]) {
|
|
1496
|
-
let formatted = mem;
|
|
1497
|
-
try {
|
|
1498
|
-
const valOptions = options?.formatParams?.[options.interpolationkey] || {};
|
|
1499
|
-
const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
|
|
1500
|
-
formatted = this.formats[formatName](mem, l, {
|
|
1501
|
-
...formatOptions,
|
|
1502
|
-
...options,
|
|
1503
|
-
...valOptions
|
|
1504
|
-
});
|
|
1505
|
-
} catch (error) {
|
|
1506
|
-
this.logger.warn(error);
|
|
1507
|
-
}
|
|
1508
|
-
return formatted;
|
|
1509
|
-
} else {
|
|
1510
|
-
this.logger.warn(`there was no format function for ${formatName}`);
|
|
1511
|
-
}
|
|
1512
|
-
return mem;
|
|
1513
|
-
}, value);
|
|
1514
|
-
return result;
|
|
1515
|
-
}
|
|
1516
|
-
};
|
|
1517
|
-
var removePending = (q, name) => {
|
|
1518
|
-
if (q.pending[name] !== void 0) {
|
|
1519
|
-
delete q.pending[name];
|
|
1520
|
-
q.pendingCount--;
|
|
1521
|
-
}
|
|
1522
|
-
};
|
|
1523
|
-
var Connector = class extends EventEmitter {
|
|
1524
|
-
constructor(backend, store, services, options = {}) {
|
|
1525
|
-
super();
|
|
1526
|
-
this.backend = backend;
|
|
1527
|
-
this.store = store;
|
|
1528
|
-
this.services = services;
|
|
1529
|
-
this.languageUtils = services.languageUtils;
|
|
1530
|
-
this.options = options;
|
|
1531
|
-
this.logger = baseLogger.create("backendConnector");
|
|
1532
|
-
this.waitingReads = [];
|
|
1533
|
-
this.maxParallelReads = options.maxParallelReads || 10;
|
|
1534
|
-
this.readingCalls = 0;
|
|
1535
|
-
this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
|
|
1536
|
-
this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
|
|
1537
|
-
this.state = {};
|
|
1538
|
-
this.queue = [];
|
|
1539
|
-
this.backend?.init?.(services, options.backend, options);
|
|
1540
|
-
}
|
|
1541
|
-
queueLoad(languages, namespaces, options, callback) {
|
|
1542
|
-
const toLoad = {};
|
|
1543
|
-
const pending = {};
|
|
1544
|
-
const toLoadLanguages = {};
|
|
1545
|
-
const toLoadNamespaces = {};
|
|
1546
|
-
languages.forEach((lng) => {
|
|
1547
|
-
let hasAllNamespaces = true;
|
|
1548
|
-
namespaces.forEach((ns) => {
|
|
1549
|
-
const name = `${lng}|${ns}`;
|
|
1550
|
-
if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
|
|
1551
|
-
this.state[name] = 2;
|
|
1552
|
-
} else if (this.state[name] < 0) ;
|
|
1553
|
-
else if (this.state[name] === 1) {
|
|
1554
|
-
if (pending[name] === void 0) pending[name] = true;
|
|
1555
|
-
} else {
|
|
1556
|
-
this.state[name] = 1;
|
|
1557
|
-
hasAllNamespaces = false;
|
|
1558
|
-
if (pending[name] === void 0) pending[name] = true;
|
|
1559
|
-
if (toLoad[name] === void 0) toLoad[name] = true;
|
|
1560
|
-
if (toLoadNamespaces[ns] === void 0) toLoadNamespaces[ns] = true;
|
|
1561
|
-
}
|
|
1562
|
-
});
|
|
1563
|
-
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
1564
|
-
});
|
|
1565
|
-
if (Object.keys(toLoad).length || Object.keys(pending).length) {
|
|
1566
|
-
this.queue.push({
|
|
1567
|
-
pending,
|
|
1568
|
-
pendingCount: Object.keys(pending).length,
|
|
1569
|
-
loaded: {},
|
|
1570
|
-
errors: [],
|
|
1571
|
-
callback
|
|
1572
|
-
});
|
|
1573
|
-
}
|
|
1574
|
-
return {
|
|
1575
|
-
toLoad: Object.keys(toLoad),
|
|
1576
|
-
pending: Object.keys(pending),
|
|
1577
|
-
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
1578
|
-
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
1579
|
-
};
|
|
1580
|
-
}
|
|
1581
|
-
loaded(name, err, data) {
|
|
1582
|
-
const s = name.split("|");
|
|
1583
|
-
const lng = s[0];
|
|
1584
|
-
const ns = s[1];
|
|
1585
|
-
if (err) this.emit("failedLoading", lng, ns, err);
|
|
1586
|
-
if (!err && data) {
|
|
1587
|
-
this.store.addResourceBundle(lng, ns, data, void 0, void 0, {
|
|
1588
|
-
skipCopy: true
|
|
1589
|
-
});
|
|
1590
|
-
}
|
|
1591
|
-
this.state[name] = err ? -1 : 2;
|
|
1592
|
-
if (err && data) this.state[name] = 0;
|
|
1593
|
-
const loaded = {};
|
|
1594
|
-
this.queue.forEach((q) => {
|
|
1595
|
-
pushPath(q.loaded, [lng], ns);
|
|
1596
|
-
removePending(q, name);
|
|
1597
|
-
if (err) q.errors.push(err);
|
|
1598
|
-
if (q.pendingCount === 0 && !q.done) {
|
|
1599
|
-
Object.keys(q.loaded).forEach((l) => {
|
|
1600
|
-
if (!loaded[l]) loaded[l] = {};
|
|
1601
|
-
const loadedKeys = q.loaded[l];
|
|
1602
|
-
if (loadedKeys.length) {
|
|
1603
|
-
loadedKeys.forEach((n) => {
|
|
1604
|
-
if (loaded[l][n] === void 0) loaded[l][n] = true;
|
|
1605
|
-
});
|
|
1606
|
-
}
|
|
1607
|
-
});
|
|
1608
|
-
q.done = true;
|
|
1609
|
-
if (q.errors.length) {
|
|
1610
|
-
q.callback(q.errors);
|
|
1611
|
-
} else {
|
|
1612
|
-
q.callback();
|
|
1613
|
-
}
|
|
1614
|
-
}
|
|
1615
|
-
});
|
|
1616
|
-
this.emit("loaded", loaded);
|
|
1617
|
-
this.queue = this.queue.filter((q) => !q.done);
|
|
1618
|
-
}
|
|
1619
|
-
read(lng, ns, fcName, tried = 0, wait = this.retryTimeout, callback) {
|
|
1620
|
-
if (!lng.length) return callback(null, {});
|
|
1621
|
-
if (this.readingCalls >= this.maxParallelReads) {
|
|
1622
|
-
this.waitingReads.push({
|
|
1623
|
-
lng,
|
|
1624
|
-
ns,
|
|
1625
|
-
fcName,
|
|
1626
|
-
tried,
|
|
1627
|
-
wait,
|
|
1628
|
-
callback
|
|
1629
|
-
});
|
|
1630
|
-
return;
|
|
1631
|
-
}
|
|
1632
|
-
this.readingCalls++;
|
|
1633
|
-
const resolver = (err, data) => {
|
|
1634
|
-
this.readingCalls--;
|
|
1635
|
-
if (this.waitingReads.length > 0) {
|
|
1636
|
-
const next = this.waitingReads.shift();
|
|
1637
|
-
this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
1638
|
-
}
|
|
1639
|
-
if (err && data && tried < this.maxRetries) {
|
|
1640
|
-
setTimeout(() => {
|
|
1641
|
-
this.read(lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
1642
|
-
}, wait);
|
|
1643
|
-
return;
|
|
1644
|
-
}
|
|
1645
|
-
callback(err, data);
|
|
1646
|
-
};
|
|
1647
|
-
const fc = this.backend[fcName].bind(this.backend);
|
|
1648
|
-
if (fc.length === 2) {
|
|
1649
|
-
try {
|
|
1650
|
-
const r = fc(lng, ns);
|
|
1651
|
-
if (r && typeof r.then === "function") {
|
|
1652
|
-
r.then((data) => resolver(null, data)).catch(resolver);
|
|
1653
|
-
} else {
|
|
1654
|
-
resolver(null, r);
|
|
1655
|
-
}
|
|
1656
|
-
} catch (err) {
|
|
1657
|
-
resolver(err);
|
|
1658
|
-
}
|
|
1659
|
-
return;
|
|
1660
|
-
}
|
|
1661
|
-
return fc(lng, ns, resolver);
|
|
1662
|
-
}
|
|
1663
|
-
prepareLoading(languages, namespaces, options = {}, callback) {
|
|
1664
|
-
if (!this.backend) {
|
|
1665
|
-
this.logger.warn("No backend was added via i18next.use. Will not load resources.");
|
|
1666
|
-
return callback && callback();
|
|
1667
|
-
}
|
|
1668
|
-
if (isString(languages)) languages = this.languageUtils.toResolveHierarchy(languages);
|
|
1669
|
-
if (isString(namespaces)) namespaces = [namespaces];
|
|
1670
|
-
const toLoad = this.queueLoad(languages, namespaces, options, callback);
|
|
1671
|
-
if (!toLoad.toLoad.length) {
|
|
1672
|
-
if (!toLoad.pending.length) callback();
|
|
1673
|
-
return null;
|
|
1674
|
-
}
|
|
1675
|
-
toLoad.toLoad.forEach((name) => {
|
|
1676
|
-
this.loadOne(name);
|
|
1677
|
-
});
|
|
1678
|
-
}
|
|
1679
|
-
load(languages, namespaces, callback) {
|
|
1680
|
-
this.prepareLoading(languages, namespaces, {}, callback);
|
|
1681
|
-
}
|
|
1682
|
-
reload(languages, namespaces, callback) {
|
|
1683
|
-
this.prepareLoading(languages, namespaces, {
|
|
1684
|
-
reload: true
|
|
1685
|
-
}, callback);
|
|
1686
|
-
}
|
|
1687
|
-
loadOne(name, prefix = "") {
|
|
1688
|
-
const s = name.split("|");
|
|
1689
|
-
const lng = s[0];
|
|
1690
|
-
const ns = s[1];
|
|
1691
|
-
this.read(lng, ns, "read", void 0, void 0, (err, data) => {
|
|
1692
|
-
if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
|
|
1693
|
-
if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
|
|
1694
|
-
this.loaded(name, err, data);
|
|
1695
|
-
});
|
|
1696
|
-
}
|
|
1697
|
-
saveMissing(languages, namespace, key, fallbackValue, isUpdate, options = {}, clb = () => {
|
|
1698
|
-
}) {
|
|
1699
|
-
if (this.services?.utils?.hasLoadedNamespace && !this.services?.utils?.hasLoadedNamespace(namespace)) {
|
|
1700
|
-
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!!!");
|
|
1701
|
-
return;
|
|
1702
|
-
}
|
|
1703
|
-
if (key === void 0 || key === null || key === "") return;
|
|
1704
|
-
if (this.backend?.create) {
|
|
1705
|
-
const opts = {
|
|
1706
|
-
...options,
|
|
1707
|
-
isUpdate
|
|
1708
|
-
};
|
|
1709
|
-
const fc = this.backend.create.bind(this.backend);
|
|
1710
|
-
if (fc.length < 6) {
|
|
1711
|
-
try {
|
|
1712
|
-
let r;
|
|
1713
|
-
if (fc.length === 5) {
|
|
1714
|
-
r = fc(languages, namespace, key, fallbackValue, opts);
|
|
1715
|
-
} else {
|
|
1716
|
-
r = fc(languages, namespace, key, fallbackValue);
|
|
1717
|
-
}
|
|
1718
|
-
if (r && typeof r.then === "function") {
|
|
1719
|
-
r.then((data) => clb(null, data)).catch(clb);
|
|
1720
|
-
} else {
|
|
1721
|
-
clb(null, r);
|
|
1722
|
-
}
|
|
1723
|
-
} catch (err) {
|
|
1724
|
-
clb(err);
|
|
1725
|
-
}
|
|
1726
|
-
} else {
|
|
1727
|
-
fc(languages, namespace, key, fallbackValue, clb, opts);
|
|
1728
|
-
}
|
|
1729
|
-
}
|
|
1730
|
-
if (!languages || !languages[0]) return;
|
|
1731
|
-
this.store.addResource(languages[0], namespace, key, fallbackValue);
|
|
1732
|
-
}
|
|
1733
|
-
};
|
|
1734
|
-
var get = () => ({
|
|
1735
|
-
debug: false,
|
|
1736
|
-
initAsync: true,
|
|
1737
|
-
ns: ["translation"],
|
|
1738
|
-
defaultNS: ["translation"],
|
|
1739
|
-
fallbackLng: ["dev"],
|
|
1740
|
-
fallbackNS: false,
|
|
1741
|
-
supportedLngs: false,
|
|
1742
|
-
nonExplicitSupportedLngs: false,
|
|
1743
|
-
load: "all",
|
|
1744
|
-
preload: false,
|
|
1745
|
-
keySeparator: ".",
|
|
1746
|
-
nsSeparator: ":",
|
|
1747
|
-
pluralSeparator: "_",
|
|
1748
|
-
contextSeparator: "_",
|
|
1749
|
-
enableSelector: false,
|
|
1750
|
-
partialBundledLanguages: false,
|
|
1751
|
-
saveMissing: false,
|
|
1752
|
-
updateMissing: false,
|
|
1753
|
-
saveMissingTo: "fallback",
|
|
1754
|
-
saveMissingPlurals: true,
|
|
1755
|
-
missingKeyHandler: false,
|
|
1756
|
-
missingInterpolationHandler: false,
|
|
1757
|
-
postProcess: false,
|
|
1758
|
-
postProcessPassResolved: false,
|
|
1759
|
-
returnNull: false,
|
|
1760
|
-
returnEmptyString: true,
|
|
1761
|
-
returnObjects: false,
|
|
1762
|
-
joinArrays: false,
|
|
1763
|
-
returnedObjectHandler: false,
|
|
1764
|
-
parseMissingKeyHandler: false,
|
|
1765
|
-
appendNamespaceToMissingKey: false,
|
|
1766
|
-
appendNamespaceToCIMode: false,
|
|
1767
|
-
overloadTranslationOptionHandler: (args) => {
|
|
1768
|
-
let ret = {};
|
|
1769
|
-
if (typeof args[1] === "object") ret = args[1];
|
|
1770
|
-
if (isString(args[1])) ret.defaultValue = args[1];
|
|
1771
|
-
if (isString(args[2])) ret.tDescription = args[2];
|
|
1772
|
-
if (typeof args[2] === "object" || typeof args[3] === "object") {
|
|
1773
|
-
const options = args[3] || args[2];
|
|
1774
|
-
Object.keys(options).forEach((key) => {
|
|
1775
|
-
ret[key] = options[key];
|
|
1776
|
-
});
|
|
1777
|
-
}
|
|
1778
|
-
return ret;
|
|
1779
|
-
},
|
|
1780
|
-
interpolation: {
|
|
1781
|
-
escapeValue: true,
|
|
1782
|
-
prefix: "{{",
|
|
1783
|
-
suffix: "}}",
|
|
1784
|
-
formatSeparator: ",",
|
|
1785
|
-
unescapePrefix: "-",
|
|
1786
|
-
nestingPrefix: "$t(",
|
|
1787
|
-
nestingSuffix: ")",
|
|
1788
|
-
nestingOptionsSeparator: ",",
|
|
1789
|
-
maxReplaces: 1e3,
|
|
1790
|
-
skipOnVariables: true
|
|
1791
|
-
},
|
|
1792
|
-
cacheInBuiltFormats: true
|
|
1793
|
-
});
|
|
1794
|
-
var transformOptions = (options) => {
|
|
1795
|
-
if (isString(options.ns)) options.ns = [options.ns];
|
|
1796
|
-
if (isString(options.fallbackLng)) options.fallbackLng = [options.fallbackLng];
|
|
1797
|
-
if (isString(options.fallbackNS)) options.fallbackNS = [options.fallbackNS];
|
|
1798
|
-
if (options.supportedLngs && !options.supportedLngs.includes("cimode")) {
|
|
1799
|
-
options.supportedLngs = options.supportedLngs.concat(["cimode"]);
|
|
1800
|
-
}
|
|
1801
|
-
return options;
|
|
1802
|
-
};
|
|
1803
|
-
var noop = () => {
|
|
1804
|
-
};
|
|
1805
|
-
var bindMemberFunctions = (inst) => {
|
|
1806
|
-
const mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
|
|
1807
|
-
mems.forEach((mem) => {
|
|
1808
|
-
if (typeof inst[mem] === "function") {
|
|
1809
|
-
inst[mem] = inst[mem].bind(inst);
|
|
1810
|
-
}
|
|
1811
|
-
});
|
|
1812
|
-
};
|
|
1813
|
-
var I18n = class _I18n extends EventEmitter {
|
|
1814
|
-
constructor(options = {}, callback) {
|
|
1815
|
-
super();
|
|
1816
|
-
this.options = transformOptions(options);
|
|
1817
|
-
this.services = {};
|
|
1818
|
-
this.logger = baseLogger;
|
|
1819
|
-
this.modules = {
|
|
1820
|
-
external: []
|
|
1821
|
-
};
|
|
1822
|
-
bindMemberFunctions(this);
|
|
1823
|
-
if (callback && !this.isInitialized && !options.isClone) {
|
|
1824
|
-
if (!this.options.initAsync) {
|
|
1825
|
-
this.init(options, callback);
|
|
1826
|
-
return this;
|
|
1827
|
-
}
|
|
1828
|
-
setTimeout(() => {
|
|
1829
|
-
this.init(options, callback);
|
|
1830
|
-
}, 0);
|
|
1831
|
-
}
|
|
1832
|
-
}
|
|
1833
|
-
init(options = {}, callback) {
|
|
1834
|
-
this.isInitializing = true;
|
|
1835
|
-
if (typeof options === "function") {
|
|
1836
|
-
callback = options;
|
|
1837
|
-
options = {};
|
|
1838
|
-
}
|
|
1839
|
-
if (options.defaultNS == null && options.ns) {
|
|
1840
|
-
if (isString(options.ns)) {
|
|
1841
|
-
options.defaultNS = options.ns;
|
|
1842
|
-
} else if (!options.ns.includes("translation")) {
|
|
1843
|
-
options.defaultNS = options.ns[0];
|
|
1844
|
-
}
|
|
1845
|
-
}
|
|
1846
|
-
const defOpts = get();
|
|
1847
|
-
this.options = {
|
|
1848
|
-
...defOpts,
|
|
1849
|
-
...this.options,
|
|
1850
|
-
...transformOptions(options)
|
|
1851
|
-
};
|
|
1852
|
-
this.options.interpolation = {
|
|
1853
|
-
...defOpts.interpolation,
|
|
1854
|
-
...this.options.interpolation
|
|
1855
|
-
};
|
|
1856
|
-
if (options.keySeparator !== void 0) {
|
|
1857
|
-
this.options.userDefinedKeySeparator = options.keySeparator;
|
|
1858
|
-
}
|
|
1859
|
-
if (options.nsSeparator !== void 0) {
|
|
1860
|
-
this.options.userDefinedNsSeparator = options.nsSeparator;
|
|
1861
|
-
}
|
|
1862
|
-
if (typeof this.options.overloadTranslationOptionHandler !== "function") {
|
|
1863
|
-
this.options.overloadTranslationOptionHandler = defOpts.overloadTranslationOptionHandler;
|
|
1864
|
-
}
|
|
1865
|
-
const createClassOnDemand = (ClassOrObject) => {
|
|
1866
|
-
if (!ClassOrObject) return null;
|
|
1867
|
-
if (typeof ClassOrObject === "function") return new ClassOrObject();
|
|
1868
|
-
return ClassOrObject;
|
|
1869
|
-
};
|
|
1870
|
-
if (!this.options.isClone) {
|
|
1871
|
-
if (this.modules.logger) {
|
|
1872
|
-
baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
|
|
1873
|
-
} else {
|
|
1874
|
-
baseLogger.init(null, this.options);
|
|
1875
|
-
}
|
|
1876
|
-
let formatter;
|
|
1877
|
-
if (this.modules.formatter) {
|
|
1878
|
-
formatter = this.modules.formatter;
|
|
1879
|
-
} else {
|
|
1880
|
-
formatter = Formatter;
|
|
1881
|
-
}
|
|
1882
|
-
const lu = new LanguageUtil(this.options);
|
|
1883
|
-
this.store = new ResourceStore(this.options.resources, this.options);
|
|
1884
|
-
const s = this.services;
|
|
1885
|
-
s.logger = baseLogger;
|
|
1886
|
-
s.resourceStore = this.store;
|
|
1887
|
-
s.languageUtils = lu;
|
|
1888
|
-
s.pluralResolver = new PluralResolver(lu, {
|
|
1889
|
-
prepend: this.options.pluralSeparator
|
|
1890
|
-
});
|
|
1891
|
-
if (formatter) {
|
|
1892
|
-
s.formatter = createClassOnDemand(formatter);
|
|
1893
|
-
if (s.formatter.init) s.formatter.init(s, this.options);
|
|
1894
|
-
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
1895
|
-
}
|
|
1896
|
-
s.interpolator = new Interpolator(this.options);
|
|
1897
|
-
s.utils = {
|
|
1898
|
-
hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
|
|
1899
|
-
};
|
|
1900
|
-
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
1901
|
-
s.backendConnector.on("*", (event, ...args) => {
|
|
1902
|
-
this.emit(event, ...args);
|
|
1903
|
-
});
|
|
1904
|
-
if (this.modules.languageDetector) {
|
|
1905
|
-
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
1906
|
-
if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
|
|
1907
|
-
}
|
|
1908
|
-
if (this.modules.i18nFormat) {
|
|
1909
|
-
s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
|
|
1910
|
-
if (s.i18nFormat.init) s.i18nFormat.init(this);
|
|
1911
|
-
}
|
|
1912
|
-
this.translator = new Translator(this.services, this.options);
|
|
1913
|
-
this.translator.on("*", (event, ...args) => {
|
|
1914
|
-
this.emit(event, ...args);
|
|
1915
|
-
});
|
|
1916
|
-
this.modules.external.forEach((m) => {
|
|
1917
|
-
if (m.init) m.init(this);
|
|
1918
|
-
});
|
|
1919
|
-
}
|
|
1920
|
-
this.format = this.options.interpolation.format;
|
|
1921
|
-
if (!callback) callback = noop;
|
|
1922
|
-
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
1923
|
-
const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
1924
|
-
if (codes.length > 0 && codes[0] !== "dev") this.options.lng = codes[0];
|
|
1925
|
-
}
|
|
1926
|
-
if (!this.services.languageDetector && !this.options.lng) {
|
|
1927
|
-
this.logger.warn("init: no languageDetector is used and no lng is defined");
|
|
1928
|
-
}
|
|
1929
|
-
const storeApi = ["getResource", "hasResourceBundle", "getResourceBundle", "getDataByLanguage"];
|
|
1930
|
-
storeApi.forEach((fcName) => {
|
|
1931
|
-
this[fcName] = (...args) => this.store[fcName](...args);
|
|
1932
|
-
});
|
|
1933
|
-
const storeApiChained = ["addResource", "addResources", "addResourceBundle", "removeResourceBundle"];
|
|
1934
|
-
storeApiChained.forEach((fcName) => {
|
|
1935
|
-
this[fcName] = (...args) => {
|
|
1936
|
-
this.store[fcName](...args);
|
|
1937
|
-
return this;
|
|
1938
|
-
};
|
|
1939
|
-
});
|
|
1940
|
-
const deferred = defer();
|
|
1941
|
-
const load = () => {
|
|
1942
|
-
const finish = (err, t2) => {
|
|
1943
|
-
this.isInitializing = false;
|
|
1944
|
-
if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn("init: i18next is already initialized. You should call init just once!");
|
|
1945
|
-
this.isInitialized = true;
|
|
1946
|
-
if (!this.options.isClone) this.logger.log("initialized", this.options);
|
|
1947
|
-
this.emit("initialized", this.options);
|
|
1948
|
-
deferred.resolve(t2);
|
|
1949
|
-
callback(err, t2);
|
|
1950
|
-
};
|
|
1951
|
-
if ((this.languages || this.isLanguageChangingTo) && !this.isInitialized) return finish(null, this.t.bind(this));
|
|
1952
|
-
this.changeLanguage(this.options.lng, finish);
|
|
1953
|
-
};
|
|
1954
|
-
if (this.options.resources || !this.options.initAsync) {
|
|
1955
|
-
load();
|
|
1956
|
-
} else {
|
|
1957
|
-
setTimeout(load, 0);
|
|
1958
|
-
}
|
|
1959
|
-
return deferred;
|
|
1960
|
-
}
|
|
1961
|
-
loadResources(language, callback = noop) {
|
|
1962
|
-
let usedCallback = callback;
|
|
1963
|
-
const usedLng = isString(language) ? language : this.language;
|
|
1964
|
-
if (typeof language === "function") usedCallback = language;
|
|
1965
|
-
if (!this.options.resources || this.options.partialBundledLanguages) {
|
|
1966
|
-
if (usedLng?.toLowerCase() === "cimode" && (!this.options.preload || this.options.preload.length === 0)) return usedCallback();
|
|
1967
|
-
const toLoad = [];
|
|
1968
|
-
const append = (lng) => {
|
|
1969
|
-
if (!lng) return;
|
|
1970
|
-
if (lng === "cimode") return;
|
|
1971
|
-
const lngs = this.services.languageUtils.toResolveHierarchy(lng);
|
|
1972
|
-
lngs.forEach((l) => {
|
|
1973
|
-
if (l === "cimode") return;
|
|
1974
|
-
if (!toLoad.includes(l)) toLoad.push(l);
|
|
1975
|
-
});
|
|
1976
|
-
};
|
|
1977
|
-
if (!usedLng) {
|
|
1978
|
-
const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
1979
|
-
fallbacks.forEach((l) => append(l));
|
|
1980
|
-
} else {
|
|
1981
|
-
append(usedLng);
|
|
1982
|
-
}
|
|
1983
|
-
this.options.preload?.forEach?.((l) => append(l));
|
|
1984
|
-
this.services.backendConnector.load(toLoad, this.options.ns, (e) => {
|
|
1985
|
-
if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
|
|
1986
|
-
usedCallback(e);
|
|
1987
|
-
});
|
|
1988
|
-
} else {
|
|
1989
|
-
usedCallback(null);
|
|
1990
|
-
}
|
|
1991
|
-
}
|
|
1992
|
-
reloadResources(lngs, ns, callback) {
|
|
1993
|
-
const deferred = defer();
|
|
1994
|
-
if (typeof lngs === "function") {
|
|
1995
|
-
callback = lngs;
|
|
1996
|
-
lngs = void 0;
|
|
1997
|
-
}
|
|
1998
|
-
if (typeof ns === "function") {
|
|
1999
|
-
callback = ns;
|
|
2000
|
-
ns = void 0;
|
|
2001
|
-
}
|
|
2002
|
-
if (!lngs) lngs = this.languages;
|
|
2003
|
-
if (!ns) ns = this.options.ns;
|
|
2004
|
-
if (!callback) callback = noop;
|
|
2005
|
-
this.services.backendConnector.reload(lngs, ns, (err) => {
|
|
2006
|
-
deferred.resolve();
|
|
2007
|
-
callback(err);
|
|
2008
|
-
});
|
|
2009
|
-
return deferred;
|
|
2010
|
-
}
|
|
2011
|
-
use(module) {
|
|
2012
|
-
if (!module) throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");
|
|
2013
|
-
if (!module.type) throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");
|
|
2014
|
-
if (module.type === "backend") {
|
|
2015
|
-
this.modules.backend = module;
|
|
2016
|
-
}
|
|
2017
|
-
if (module.type === "logger" || module.log && module.warn && module.error) {
|
|
2018
|
-
this.modules.logger = module;
|
|
2019
|
-
}
|
|
2020
|
-
if (module.type === "languageDetector") {
|
|
2021
|
-
this.modules.languageDetector = module;
|
|
2022
|
-
}
|
|
2023
|
-
if (module.type === "i18nFormat") {
|
|
2024
|
-
this.modules.i18nFormat = module;
|
|
2025
|
-
}
|
|
2026
|
-
if (module.type === "postProcessor") {
|
|
2027
|
-
postProcessor.addPostProcessor(module);
|
|
2028
|
-
}
|
|
2029
|
-
if (module.type === "formatter") {
|
|
2030
|
-
this.modules.formatter = module;
|
|
2031
|
-
}
|
|
2032
|
-
if (module.type === "3rdParty") {
|
|
2033
|
-
this.modules.external.push(module);
|
|
2034
|
-
}
|
|
2035
|
-
return this;
|
|
2036
|
-
}
|
|
2037
|
-
setResolvedLanguage(l) {
|
|
2038
|
-
if (!l || !this.languages) return;
|
|
2039
|
-
if (["cimode", "dev"].includes(l)) return;
|
|
2040
|
-
for (let li = 0; li < this.languages.length; li++) {
|
|
2041
|
-
const lngInLngs = this.languages[li];
|
|
2042
|
-
if (["cimode", "dev"].includes(lngInLngs)) continue;
|
|
2043
|
-
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
2044
|
-
this.resolvedLanguage = lngInLngs;
|
|
2045
|
-
break;
|
|
2046
|
-
}
|
|
2047
|
-
}
|
|
2048
|
-
if (!this.resolvedLanguage && !this.languages.includes(l) && this.store.hasLanguageSomeTranslations(l)) {
|
|
2049
|
-
this.resolvedLanguage = l;
|
|
2050
|
-
this.languages.unshift(l);
|
|
2051
|
-
}
|
|
2052
|
-
}
|
|
2053
|
-
changeLanguage(lng, callback) {
|
|
2054
|
-
this.isLanguageChangingTo = lng;
|
|
2055
|
-
const deferred = defer();
|
|
2056
|
-
this.emit("languageChanging", lng);
|
|
2057
|
-
const setLngProps = (l) => {
|
|
2058
|
-
this.language = l;
|
|
2059
|
-
this.languages = this.services.languageUtils.toResolveHierarchy(l);
|
|
2060
|
-
this.resolvedLanguage = void 0;
|
|
2061
|
-
this.setResolvedLanguage(l);
|
|
2062
|
-
};
|
|
2063
|
-
const done = (err, l) => {
|
|
2064
|
-
if (l) {
|
|
2065
|
-
if (this.isLanguageChangingTo === lng) {
|
|
2066
|
-
setLngProps(l);
|
|
2067
|
-
this.translator.changeLanguage(l);
|
|
2068
|
-
this.isLanguageChangingTo = void 0;
|
|
2069
|
-
this.emit("languageChanged", l);
|
|
2070
|
-
this.logger.log("languageChanged", l);
|
|
2071
|
-
}
|
|
2072
|
-
} else {
|
|
2073
|
-
this.isLanguageChangingTo = void 0;
|
|
2074
|
-
}
|
|
2075
|
-
deferred.resolve((...args) => this.t(...args));
|
|
2076
|
-
if (callback) callback(err, (...args) => this.t(...args));
|
|
2077
|
-
};
|
|
2078
|
-
const setLng = (lngs) => {
|
|
2079
|
-
if (!lng && !lngs && this.services.languageDetector) lngs = [];
|
|
2080
|
-
const fl = isString(lngs) ? lngs : lngs && lngs[0];
|
|
2081
|
-
const l = this.store.hasLanguageSomeTranslations(fl) ? fl : this.services.languageUtils.getBestMatchFromCodes(isString(lngs) ? [lngs] : lngs);
|
|
2082
|
-
if (l) {
|
|
2083
|
-
if (!this.language) {
|
|
2084
|
-
setLngProps(l);
|
|
2085
|
-
}
|
|
2086
|
-
if (!this.translator.language) this.translator.changeLanguage(l);
|
|
2087
|
-
this.services.languageDetector?.cacheUserLanguage?.(l);
|
|
2088
|
-
}
|
|
2089
|
-
this.loadResources(l, (err) => {
|
|
2090
|
-
done(err, l);
|
|
2091
|
-
});
|
|
2092
|
-
};
|
|
2093
|
-
if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
|
|
2094
|
-
setLng(this.services.languageDetector.detect());
|
|
2095
|
-
} else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
|
|
2096
|
-
if (this.services.languageDetector.detect.length === 0) {
|
|
2097
|
-
this.services.languageDetector.detect().then(setLng);
|
|
2098
|
-
} else {
|
|
2099
|
-
this.services.languageDetector.detect(setLng);
|
|
2100
|
-
}
|
|
2101
|
-
} else {
|
|
2102
|
-
setLng(lng);
|
|
2103
|
-
}
|
|
2104
|
-
return deferred;
|
|
2105
|
-
}
|
|
2106
|
-
getFixedT(lng, ns, keyPrefix, fixedOpts) {
|
|
2107
|
-
const scopeNs = fixedOpts?.scopeNs;
|
|
2108
|
-
const fixedT = (key, opts, ...rest) => {
|
|
2109
|
-
let o;
|
|
2110
|
-
if (typeof opts !== "object") {
|
|
2111
|
-
o = this.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
2112
|
-
} else {
|
|
2113
|
-
o = {
|
|
2114
|
-
...opts
|
|
2115
|
-
};
|
|
2116
|
-
}
|
|
2117
|
-
o.lng = o.lng || fixedT.lng;
|
|
2118
|
-
o.lngs = o.lngs || fixedT.lngs;
|
|
2119
|
-
const explicitCallNs = o.ns !== void 0 && o.ns !== null;
|
|
2120
|
-
o.ns = o.ns || fixedT.ns;
|
|
2121
|
-
if (o.keyPrefix !== "") o.keyPrefix = o.keyPrefix || keyPrefix || fixedT.keyPrefix;
|
|
2122
|
-
const selectorOpts = {
|
|
2123
|
-
...this.options,
|
|
2124
|
-
...o
|
|
2125
|
-
};
|
|
2126
|
-
if (Array.isArray(scopeNs) && !explicitCallNs) selectorOpts.ns = scopeNs;
|
|
2127
|
-
if (typeof o.keyPrefix === "function") o.keyPrefix = keysFromSelector(o.keyPrefix, selectorOpts);
|
|
2128
|
-
const keySeparator = this.options.keySeparator || ".";
|
|
2129
|
-
let resultKey;
|
|
2130
|
-
if (o.keyPrefix && Array.isArray(key)) {
|
|
2131
|
-
resultKey = key.map((k) => {
|
|
2132
|
-
if (typeof k === "function") k = keysFromSelector(k, selectorOpts);
|
|
2133
|
-
return `${o.keyPrefix}${keySeparator}${k}`;
|
|
2134
|
-
});
|
|
2135
|
-
} else {
|
|
2136
|
-
if (typeof key === "function") key = keysFromSelector(key, selectorOpts);
|
|
2137
|
-
resultKey = o.keyPrefix ? `${o.keyPrefix}${keySeparator}${key}` : key;
|
|
2138
|
-
}
|
|
2139
|
-
return this.t(resultKey, o);
|
|
2140
|
-
};
|
|
2141
|
-
if (isString(lng)) {
|
|
2142
|
-
fixedT.lng = lng;
|
|
2143
|
-
} else {
|
|
2144
|
-
fixedT.lngs = lng;
|
|
2145
|
-
}
|
|
2146
|
-
fixedT.ns = ns;
|
|
2147
|
-
fixedT.keyPrefix = keyPrefix;
|
|
2148
|
-
return fixedT;
|
|
2149
|
-
}
|
|
2150
|
-
t(...args) {
|
|
2151
|
-
return this.translator?.translate(...args);
|
|
2152
|
-
}
|
|
2153
|
-
exists(...args) {
|
|
2154
|
-
return this.translator?.exists(...args);
|
|
2155
|
-
}
|
|
2156
|
-
setDefaultNamespace(ns) {
|
|
2157
|
-
this.options.defaultNS = ns;
|
|
2158
|
-
}
|
|
2159
|
-
hasLoadedNamespace(ns, options = {}) {
|
|
2160
|
-
if (!this.isInitialized) {
|
|
2161
|
-
this.logger.warn("hasLoadedNamespace: i18next was not initialized", this.languages);
|
|
2162
|
-
return false;
|
|
2163
|
-
}
|
|
2164
|
-
if (!this.languages || !this.languages.length) {
|
|
2165
|
-
this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty", this.languages);
|
|
2166
|
-
return false;
|
|
2167
|
-
}
|
|
2168
|
-
const lng = options.lng || this.resolvedLanguage || this.languages[0];
|
|
2169
|
-
const fallbackLng = this.options ? this.options.fallbackLng : false;
|
|
2170
|
-
const lastLng = this.languages[this.languages.length - 1];
|
|
2171
|
-
if (lng.toLowerCase() === "cimode") return true;
|
|
2172
|
-
const loadNotPending = (l, n) => {
|
|
2173
|
-
const loadState = this.services.backendConnector.state[`${l}|${n}`];
|
|
2174
|
-
return loadState === -1 || loadState === 0 || loadState === 2;
|
|
2175
|
-
};
|
|
2176
|
-
if (options.precheck) {
|
|
2177
|
-
const preResult = options.precheck(this, loadNotPending);
|
|
2178
|
-
if (preResult !== void 0) return preResult;
|
|
2179
|
-
}
|
|
2180
|
-
if (this.hasResourceBundle(lng, ns)) return true;
|
|
2181
|
-
if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
|
|
2182
|
-
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
2183
|
-
return false;
|
|
2184
|
-
}
|
|
2185
|
-
loadNamespaces(ns, callback) {
|
|
2186
|
-
const deferred = defer();
|
|
2187
|
-
if (!this.options.ns) {
|
|
2188
|
-
if (callback) callback();
|
|
2189
|
-
return Promise.resolve();
|
|
2190
|
-
}
|
|
2191
|
-
if (isString(ns)) ns = [ns];
|
|
2192
|
-
ns.forEach((n) => {
|
|
2193
|
-
if (!this.options.ns.includes(n)) this.options.ns.push(n);
|
|
2194
|
-
});
|
|
2195
|
-
this.loadResources((err) => {
|
|
2196
|
-
deferred.resolve();
|
|
2197
|
-
if (callback) callback(err);
|
|
2198
|
-
});
|
|
2199
|
-
return deferred;
|
|
2200
|
-
}
|
|
2201
|
-
loadLanguages(lngs, callback) {
|
|
2202
|
-
const deferred = defer();
|
|
2203
|
-
if (isString(lngs)) lngs = [lngs];
|
|
2204
|
-
const preloaded = this.options.preload || [];
|
|
2205
|
-
const newLngs = lngs.filter((lng) => !preloaded.includes(lng) && this.services.languageUtils.isSupportedCode(lng));
|
|
2206
|
-
if (!newLngs.length) {
|
|
2207
|
-
if (callback) callback();
|
|
2208
|
-
return Promise.resolve();
|
|
2209
|
-
}
|
|
2210
|
-
this.options.preload = preloaded.concat(newLngs);
|
|
2211
|
-
this.loadResources((err) => {
|
|
2212
|
-
deferred.resolve();
|
|
2213
|
-
if (callback) callback(err);
|
|
2214
|
-
});
|
|
2215
|
-
return deferred;
|
|
2216
|
-
}
|
|
2217
|
-
dir(lng) {
|
|
2218
|
-
if (!lng) lng = this.resolvedLanguage || (this.languages?.length > 0 ? this.languages[0] : this.language);
|
|
2219
|
-
if (!lng) return "rtl";
|
|
2220
|
-
try {
|
|
2221
|
-
const l = new Intl.Locale(lng);
|
|
2222
|
-
if (l && l.getTextInfo) {
|
|
2223
|
-
const ti = l.getTextInfo();
|
|
2224
|
-
if (ti && ti.direction) return ti.direction;
|
|
2225
|
-
}
|
|
2226
|
-
} catch (e) {
|
|
2227
|
-
}
|
|
2228
|
-
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"];
|
|
2229
|
-
const languageUtils = this.services?.languageUtils || new LanguageUtil(get());
|
|
2230
|
-
if (lng.toLowerCase().indexOf("-latn") > 1) return "ltr";
|
|
2231
|
-
return rtlLngs.includes(languageUtils.getLanguagePartFromCode(lng)) || lng.toLowerCase().indexOf("-arab") > 1 ? "rtl" : "ltr";
|
|
2232
|
-
}
|
|
2233
|
-
static createInstance(options = {}, callback) {
|
|
2234
|
-
const instance2 = new _I18n(options, callback);
|
|
2235
|
-
instance2.createInstance = _I18n.createInstance;
|
|
2236
|
-
return instance2;
|
|
2237
|
-
}
|
|
2238
|
-
cloneInstance(options = {}, callback = noop) {
|
|
2239
|
-
const forkResourceStore = options.forkResourceStore;
|
|
2240
|
-
if (forkResourceStore) delete options.forkResourceStore;
|
|
2241
|
-
const mergedOptions = {
|
|
2242
|
-
...this.options,
|
|
2243
|
-
...options,
|
|
2244
|
-
...{
|
|
2245
|
-
isClone: true
|
|
2246
|
-
}
|
|
2247
|
-
};
|
|
2248
|
-
const clone = new _I18n(mergedOptions);
|
|
2249
|
-
if (options.debug !== void 0 || options.prefix !== void 0) {
|
|
2250
|
-
clone.logger = clone.logger.clone(options);
|
|
2251
|
-
}
|
|
2252
|
-
const membersToCopy = ["store", "services", "language"];
|
|
2253
|
-
membersToCopy.forEach((m) => {
|
|
2254
|
-
clone[m] = this[m];
|
|
2255
|
-
});
|
|
2256
|
-
clone.services = {
|
|
2257
|
-
...this.services
|
|
2258
|
-
};
|
|
2259
|
-
clone.services.utils = {
|
|
2260
|
-
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2261
|
-
};
|
|
2262
|
-
if (forkResourceStore) {
|
|
2263
|
-
const clonedData = Object.keys(this.store.data).reduce((prev, l) => {
|
|
2264
|
-
prev[l] = {
|
|
2265
|
-
...this.store.data[l]
|
|
2266
|
-
};
|
|
2267
|
-
prev[l] = Object.keys(prev[l]).reduce((acc, n) => {
|
|
2268
|
-
acc[n] = {
|
|
2269
|
-
...prev[l][n]
|
|
2270
|
-
};
|
|
2271
|
-
return acc;
|
|
2272
|
-
}, prev[l]);
|
|
2273
|
-
return prev;
|
|
2274
|
-
}, {});
|
|
2275
|
-
clone.store = new ResourceStore(clonedData, mergedOptions);
|
|
2276
|
-
clone.services.resourceStore = clone.store;
|
|
2277
|
-
}
|
|
2278
|
-
if (options.interpolation) {
|
|
2279
|
-
const defOpts = get();
|
|
2280
|
-
const mergedInterpolation = {
|
|
2281
|
-
...defOpts.interpolation,
|
|
2282
|
-
...this.options.interpolation,
|
|
2283
|
-
...options.interpolation
|
|
2284
|
-
};
|
|
2285
|
-
const mergedForInterpolator = {
|
|
2286
|
-
...mergedOptions,
|
|
2287
|
-
interpolation: mergedInterpolation
|
|
2288
|
-
};
|
|
2289
|
-
clone.services.interpolator = new Interpolator(mergedForInterpolator);
|
|
2290
|
-
}
|
|
2291
|
-
clone.translator = new Translator(clone.services, mergedOptions);
|
|
2292
|
-
clone.translator.on("*", (event, ...args) => {
|
|
2293
|
-
clone.emit(event, ...args);
|
|
2294
|
-
});
|
|
2295
|
-
clone.init(mergedOptions, callback);
|
|
2296
|
-
clone.translator.options = mergedOptions;
|
|
2297
|
-
clone.translator.backendConnector.services.utils = {
|
|
2298
|
-
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2299
|
-
};
|
|
2300
|
-
return clone;
|
|
2301
|
-
}
|
|
2302
|
-
toJSON() {
|
|
2303
|
-
return {
|
|
2304
|
-
options: this.options,
|
|
2305
|
-
store: this.store,
|
|
2306
|
-
language: this.language,
|
|
2307
|
-
languages: this.languages,
|
|
2308
|
-
resolvedLanguage: this.resolvedLanguage
|
|
2309
|
-
};
|
|
2310
|
-
}
|
|
2311
|
-
};
|
|
2312
|
-
var instance = I18n.createInstance();
|
|
2313
|
-
var createInstance = instance.createInstance;
|
|
2314
|
-
var dir = instance.dir;
|
|
2315
|
-
var init = instance.init;
|
|
2316
|
-
var loadResources = instance.loadResources;
|
|
2317
|
-
var reloadResources = instance.reloadResources;
|
|
2318
|
-
var use = instance.use;
|
|
2319
|
-
var changeLanguage = instance.changeLanguage;
|
|
2320
|
-
var getFixedT = instance.getFixedT;
|
|
2321
|
-
var t = instance.t;
|
|
2322
|
-
var exists = instance.exists;
|
|
2323
|
-
var setDefaultNamespace = instance.setDefaultNamespace;
|
|
2324
|
-
var hasLoadedNamespace = instance.hasLoadedNamespace;
|
|
2325
|
-
var loadNamespaces = instance.loadNamespaces;
|
|
2326
|
-
var loadLanguages = instance.loadLanguages;
|
|
2327
|
-
|
|
2328
|
-
// src/i18n/config.ts
|
|
2329
|
-
import { initReactI18next } from "react-i18next";
|
|
2330
|
-
|
|
2331
|
-
// src/i18n/customCacheBackend.ts
|
|
2332
|
-
var _SupabaseCacheBackend = class _SupabaseCacheBackend {
|
|
2333
|
-
// 1. Принимаем SupabaseClient в конструктор
|
|
2334
|
-
constructor(supabase) {
|
|
2335
|
-
this.type = "backend";
|
|
2336
|
-
this.supabase = supabase;
|
|
2337
|
-
}
|
|
2338
|
-
init(services, backendOptions, i18nextOptions) {
|
|
2339
|
-
if (backendOptions?.supabase) {
|
|
2340
|
-
this.supabase = backendOptions.supabase;
|
|
2341
|
-
}
|
|
2342
|
-
}
|
|
2343
|
-
/**
|
|
2344
|
-
* Загрузка всего манифеста версий из Supabase в память
|
|
2345
|
-
*/
|
|
2346
|
-
async loadManifest() {
|
|
2347
|
-
if (_SupabaseCacheBackend.isManifestLoaded || !this.supabase) return;
|
|
2348
|
-
try {
|
|
2349
|
-
const { data, error } = await this.supabase.from("translation_versions").select("namespace, lang_code, version");
|
|
2350
|
-
if (error) {
|
|
2351
|
-
if (error.code === "PGRST303" || error.message?.includes("future")) {
|
|
2352
|
-
console.warn("[i18n] Time drift detected (JWT in future). Falling back to cached translations.");
|
|
2353
|
-
}
|
|
2354
|
-
throw error;
|
|
2355
|
-
}
|
|
2356
|
-
if (data) {
|
|
2357
|
-
const manifestMap = {};
|
|
2358
|
-
data.forEach((row) => {
|
|
2359
|
-
manifestMap[`${row.lang_code}:${row.namespace}`] = row.version;
|
|
2360
|
-
});
|
|
2361
|
-
_SupabaseCacheBackend.manifest = manifestMap;
|
|
2362
|
-
_SupabaseCacheBackend.isManifestLoaded = true;
|
|
2363
|
-
}
|
|
2364
|
-
} catch (err) {
|
|
2365
|
-
console.warn("[i18n] Could not load translation versions manifest, using local cache:", err);
|
|
2366
|
-
}
|
|
2367
|
-
}
|
|
2368
|
-
/**
|
|
2369
|
-
* Основной метод чтения локализации
|
|
2370
|
-
*/
|
|
2371
|
-
async read(language, namespace, callback) {
|
|
2372
|
-
const cacheKey = `i18n_${language}_${namespace}`;
|
|
2373
|
-
const versionKey = `i18n_ver_${language}_${namespace}`;
|
|
2374
|
-
const manifestKey = `${language}:${namespace}`;
|
|
2375
|
-
try {
|
|
2376
|
-
await this.loadManifest();
|
|
2377
|
-
const cachedData = localStorage.getItem(cacheKey);
|
|
2378
|
-
const localVersion = parseInt(localStorage.getItem(versionKey) || "0", 10);
|
|
2379
|
-
const serverVersion = _SupabaseCacheBackend.manifest[manifestKey];
|
|
2380
|
-
if (cachedData && serverVersion !== void 0 && localVersion === serverVersion) {
|
|
2381
|
-
callback(null, JSON.parse(cachedData));
|
|
2382
|
-
return;
|
|
2383
|
-
}
|
|
2384
|
-
if (cachedData && !_SupabaseCacheBackend.isManifestLoaded) {
|
|
2385
|
-
callback(null, JSON.parse(cachedData));
|
|
2386
|
-
return;
|
|
2387
|
-
}
|
|
2388
|
-
if (!this.supabase) {
|
|
2389
|
-
throw new Error("[SupabaseCacheBackend]: Supabase client is not initialized.");
|
|
2390
|
-
}
|
|
2391
|
-
const { data, error } = await this.supabase.from("translations").select("key, value").eq("lang_code", language).eq("namespace", namespace);
|
|
2392
|
-
if (error) throw error;
|
|
2393
|
-
const freshData = {};
|
|
2394
|
-
if (data) {
|
|
2395
|
-
data.forEach((row) => {
|
|
2396
|
-
this.setNestedKey(freshData, row.key, row.value);
|
|
2397
|
-
});
|
|
2398
|
-
}
|
|
2399
|
-
localStorage.setItem(cacheKey, JSON.stringify(freshData));
|
|
2400
|
-
if (serverVersion !== void 0) {
|
|
2401
|
-
localStorage.setItem(versionKey, serverVersion.toString());
|
|
2402
|
-
}
|
|
2403
|
-
callback(null, freshData);
|
|
2404
|
-
} catch (err) {
|
|
2405
|
-
console.warn(`[i18n] Fallback to cache for ${language}/${namespace} due to error:`, err);
|
|
2406
|
-
const cachedData = localStorage.getItem(cacheKey);
|
|
2407
|
-
if (cachedData) {
|
|
2408
|
-
callback(null, JSON.parse(cachedData));
|
|
2409
|
-
} else {
|
|
2410
|
-
callback(err, false);
|
|
2411
|
-
}
|
|
2412
|
-
}
|
|
2413
|
-
}
|
|
2414
|
-
setNestedKey(obj, path, value) {
|
|
2415
|
-
const keys = path.split(".");
|
|
2416
|
-
let current = obj;
|
|
2417
|
-
for (let i = 0; i < keys.length - 1; i++) {
|
|
2418
|
-
const key = keys[i];
|
|
2419
|
-
if (!current[key] || typeof current[key] !== "object") {
|
|
2420
|
-
current[key] = {};
|
|
2421
|
-
}
|
|
2422
|
-
current = current[key];
|
|
2423
|
-
}
|
|
2424
|
-
current[keys[keys.length - 1]] = value;
|
|
2425
|
-
}
|
|
2426
|
-
create(languages, namespace, key, fallbackValue) {
|
|
2427
|
-
}
|
|
2428
|
-
};
|
|
2429
|
-
_SupabaseCacheBackend.type = "backend";
|
|
2430
|
-
// Локальный манифест версий
|
|
2431
|
-
_SupabaseCacheBackend.manifest = {};
|
|
2432
|
-
_SupabaseCacheBackend.isManifestLoaded = false;
|
|
2433
|
-
var SupabaseCacheBackend = _SupabaseCacheBackend;
|
|
2434
|
-
|
|
2435
|
-
// src/i18n/config.ts
|
|
2436
|
-
var config_default = instance;
|
|
2437
|
-
|
|
2438
|
-
// src/context/TranslationEditProvider.tsx
|
|
2439
|
-
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
2440
|
-
var TranslationEditContext = createContext3(void 0);
|
|
2441
|
-
var TranslationEditProvider = ({ children }) => {
|
|
2442
|
-
const supabase = useSupabase();
|
|
2443
|
-
const { user } = useAuth();
|
|
2444
|
-
const [isTranslationMode, setIsTranslationMode] = useState2(false);
|
|
2445
|
-
const [canEdit, setCanEdit] = useState2(false);
|
|
2446
|
-
const [isLoadingPermissions, setIsLoadingPermissions] = useState2(true);
|
|
2447
|
-
const checkPermission = useCallback2(async () => {
|
|
2448
|
-
if (!user) {
|
|
2449
|
-
setCanEdit(false);
|
|
2450
|
-
setIsTranslationMode(false);
|
|
2451
|
-
setIsLoadingPermissions(false);
|
|
2452
|
-
return;
|
|
2453
|
-
}
|
|
2454
|
-
try {
|
|
2455
|
-
setIsLoadingPermissions(true);
|
|
2456
|
-
const { data, error } = await supabase.from("translation_responsible_users").select("id").eq("user_id", user.id).maybeSingle();
|
|
2457
|
-
if (error) {
|
|
2458
|
-
console.error("Error checking translation responsibilities:", error);
|
|
2459
|
-
setCanEdit(false);
|
|
2460
|
-
setIsTranslationMode(false);
|
|
2461
|
-
} else {
|
|
2462
|
-
const hasAccess = Boolean(data);
|
|
2463
|
-
setCanEdit(hasAccess);
|
|
2464
|
-
if (!hasAccess) {
|
|
2465
|
-
setIsTranslationMode(false);
|
|
2466
|
-
}
|
|
2467
|
-
}
|
|
2468
|
-
} catch (err) {
|
|
2469
|
-
console.error("Permission check failed:", err);
|
|
2470
|
-
setCanEdit(false);
|
|
2471
|
-
} finally {
|
|
2472
|
-
setIsLoadingPermissions(false);
|
|
2473
|
-
}
|
|
2474
|
-
}, [user]);
|
|
2475
|
-
useEffect2(() => {
|
|
2476
|
-
checkPermission();
|
|
2477
|
-
}, [checkPermission]);
|
|
2478
|
-
const updateTranslation = async (key, namespace, newValue) => {
|
|
2479
|
-
if (!canEdit) return;
|
|
2480
|
-
const currentLang = config_default.language;
|
|
2481
|
-
const { error } = await supabase.from("translations").upsert({
|
|
2482
|
-
key,
|
|
2483
|
-
namespace,
|
|
2484
|
-
lang_code: currentLang,
|
|
2485
|
-
value: newValue
|
|
2486
|
-
}, { onConflict: "key,namespace,lang_code" });
|
|
2487
|
-
if (error) return alert("\u041E\u0448\u0438\u0431\u043A\u0430 \u0441\u043E\u0445\u0440\u0430\u043D\u0435\u043D\u0438\u044F \u0432 \u0411\u0414");
|
|
2488
|
-
localStorage.removeItem(`i18n_ver_${currentLang}_${namespace}`);
|
|
2489
|
-
config_default.addResource(currentLang, namespace, key, newValue);
|
|
2490
|
-
config_default.changeLanguage(currentLang);
|
|
2491
|
-
};
|
|
2492
|
-
const handleSetTranslationMode = (val) => {
|
|
2493
|
-
if (canEdit) {
|
|
2494
|
-
setIsTranslationMode(val);
|
|
2495
|
-
}
|
|
2496
|
-
};
|
|
2497
|
-
return /* @__PURE__ */ jsx3(
|
|
2498
|
-
TranslationEditContext.Provider,
|
|
2499
|
-
{
|
|
2500
|
-
value: {
|
|
2501
|
-
isTranslationMode,
|
|
2502
|
-
setIsTranslationMode: handleSetTranslationMode,
|
|
2503
|
-
canEdit,
|
|
2504
|
-
isLoadingPermissions,
|
|
2505
|
-
updateTranslation
|
|
2506
|
-
},
|
|
2507
|
-
children
|
|
2508
|
-
}
|
|
2509
|
-
);
|
|
2510
|
-
};
|
|
2511
|
-
var useTranslationEdit = () => {
|
|
2512
|
-
const context = useContext3(TranslationEditContext);
|
|
2513
|
-
if (!context) throw new Error("useTranslationEdit must be used within TranslationEditProvider");
|
|
2514
|
-
return context;
|
|
2515
|
-
};
|
|
2516
|
-
|
|
2517
|
-
// src/context/AIProvider.tsx
|
|
2518
|
-
import { createContext as createContext4, useContext as useContext4, useMemo as useMemo2 } from "react";
|
|
2519
|
-
import { GoogleGenAI } from "@google/genai";
|
|
2520
|
-
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
2521
|
-
var AIContext = createContext4(null);
|
|
2522
|
-
var AIProvider = ({
|
|
2523
|
-
children,
|
|
2524
|
-
config,
|
|
2525
|
-
apiKey: directApiKey
|
|
2526
|
-
}) => {
|
|
2527
|
-
const apiKey = directApiKey || config?.apiKey;
|
|
2528
|
-
const provider = config?.provider || "gemini";
|
|
2529
|
-
const modelName = config?.modelName || (provider === "gemini" ? "gemini-2.5-flash" : "gpt-4o-mini");
|
|
2530
|
-
const contextValue = useMemo2(() => {
|
|
2531
|
-
return {
|
|
2532
|
-
apiKey,
|
|
2533
|
-
provider,
|
|
2534
|
-
modelName,
|
|
2535
|
-
generate: async ({
|
|
2536
|
-
prompt,
|
|
2537
|
-
systemInstruction,
|
|
2538
|
-
jsonMode = false,
|
|
2539
|
-
temperature
|
|
2540
|
-
}) => {
|
|
2541
|
-
if (!apiKey) {
|
|
2542
|
-
console.warn("[AIProvider]: API Key \u043D\u0435 \u0437\u0430\u0434\u0430\u043D.");
|
|
2543
|
-
return null;
|
|
2544
|
-
}
|
|
2545
|
-
if (provider === "gemini") {
|
|
2546
|
-
try {
|
|
2547
|
-
const ai = new GoogleGenAI({ apiKey });
|
|
2548
|
-
const response = await ai.models.generateContent({
|
|
2549
|
-
model: modelName,
|
|
2550
|
-
contents: prompt,
|
|
2551
|
-
config: {
|
|
2552
|
-
systemInstruction,
|
|
2553
|
-
temperature,
|
|
2554
|
-
responseMimeType: jsonMode ? "application/json" : "text/plain"
|
|
2555
|
-
}
|
|
2556
|
-
});
|
|
2557
|
-
const rawText = response.text?.trim() || "";
|
|
2558
|
-
if (jsonMode) {
|
|
2559
|
-
const cleanedText = rawText.replace(/^```(?:json)?\s*/i, "").replace(/\s*```$/, "").trim();
|
|
2560
|
-
return JSON.parse(cleanedText);
|
|
2561
|
-
}
|
|
2562
|
-
return rawText;
|
|
2563
|
-
} catch (err) {
|
|
2564
|
-
console.error("[AIProvider Gemini Error]:", err);
|
|
2565
|
-
return null;
|
|
2566
|
-
}
|
|
2567
|
-
}
|
|
2568
|
-
if (provider === "openai") {
|
|
2569
|
-
try {
|
|
2570
|
-
const messages = [];
|
|
2571
|
-
if (systemInstruction) {
|
|
2572
|
-
messages.push({ role: "system", content: systemInstruction });
|
|
2573
|
-
}
|
|
2574
|
-
messages.push({ role: "user", content: prompt });
|
|
2575
|
-
const res = await fetch("https://api.openai.com/v1/chat/completions", {
|
|
2576
|
-
method: "POST",
|
|
2577
|
-
headers: {
|
|
2578
|
-
"Content-Type": "application/json",
|
|
2579
|
-
Authorization: `Bearer ${apiKey}`
|
|
2580
|
-
},
|
|
2581
|
-
body: JSON.stringify({
|
|
2582
|
-
model: modelName,
|
|
2583
|
-
messages,
|
|
2584
|
-
temperature,
|
|
2585
|
-
...jsonMode ? { response_format: { type: "json_object" } } : {}
|
|
2586
|
-
})
|
|
2587
|
-
});
|
|
2588
|
-
const data = await res.json();
|
|
2589
|
-
const content = data.choices?.[0]?.message?.content?.trim() || "";
|
|
2590
|
-
if (jsonMode) {
|
|
2591
|
-
return JSON.parse(content);
|
|
2592
|
-
}
|
|
2593
|
-
return content;
|
|
2594
|
-
} catch (err) {
|
|
2595
|
-
console.error("[AIProvider OpenAI Error]:", err);
|
|
2596
|
-
return null;
|
|
2597
|
-
}
|
|
2598
|
-
}
|
|
2599
|
-
return null;
|
|
2600
|
-
}
|
|
2601
|
-
};
|
|
2602
|
-
}, [apiKey, provider, modelName]);
|
|
2603
|
-
return /* @__PURE__ */ jsx4(AIContext.Provider, { value: contextValue, children });
|
|
2604
|
-
};
|
|
2605
|
-
var useAI = () => {
|
|
2606
|
-
const context = useContext4(AIContext);
|
|
2607
|
-
if (!context) {
|
|
2608
|
-
throw new Error("useAI \u0434\u043E\u043B\u0436\u0435\u043D \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C\u0441\u044F \u0432\u043D\u0443\u0442\u0440\u0438 <AIProvider>");
|
|
2609
|
-
}
|
|
2610
|
-
return context;
|
|
2611
|
-
};
|
|
2612
|
-
|
|
2613
|
-
// src/context/TranslateProvider.tsx
|
|
2614
|
-
import { createContext as createContext5, useContext as useContext5 } from "react";
|
|
2615
|
-
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
2616
|
-
var TranslationNamespaceContext = createContext5({
|
|
2617
|
-
namespace: "common"
|
|
2618
|
-
// значение по умолчанию
|
|
2619
|
-
});
|
|
2620
|
-
var TranslateProvider = ({ namespace, children }) => {
|
|
2621
|
-
return /* @__PURE__ */ jsx5(TranslationNamespaceContext.Provider, { value: { namespace }, children });
|
|
2622
|
-
};
|
|
2623
|
-
var useTranslationNamespace = (overrideNamespace) => {
|
|
2624
|
-
const context = useContext5(TranslationNamespaceContext);
|
|
2625
|
-
return overrideNamespace || context.namespace;
|
|
2626
|
-
};
|
|
2627
|
-
|
|
2628
|
-
// src/i18n/TranslateText.tsx
|
|
2629
|
-
import { useState as useState4, useRef as useRef2, useEffect as useEffect4 } from "react";
|
|
2630
|
-
import { useTranslation } from "react-i18next";
|
|
2631
|
-
import { Box as Box2, Popper, Paper as Paper2, MenuList, MenuItem, ListItemIcon, ListItemText } from "@mui/material";
|
|
2632
|
-
import TranslateIcon2 from "@mui/icons-material/Translate";
|
|
2633
|
-
import LaunchIcon from "@mui/icons-material/Launch";
|
|
2634
|
-
|
|
2635
|
-
// src/i18n/TranslationDialog.tsx
|
|
2636
|
-
import { useEffect as useEffect3, useState as useState3 } from "react";
|
|
2637
|
-
import {
|
|
2638
|
-
Dialog,
|
|
2639
|
-
DialogTitle,
|
|
2640
|
-
DialogContent,
|
|
2641
|
-
DialogActions,
|
|
2642
|
-
Button,
|
|
2643
|
-
TextField,
|
|
2644
|
-
Box,
|
|
2645
|
-
Typography,
|
|
2646
|
-
CircularProgress,
|
|
2647
|
-
IconButton,
|
|
2648
|
-
Tooltip,
|
|
2649
|
-
Paper,
|
|
2650
|
-
Alert
|
|
2651
|
-
} from "@mui/material";
|
|
2652
|
-
import AutoFixHighIcon from "@mui/icons-material/AutoFixHigh";
|
|
2653
|
-
import TranslateIcon from "@mui/icons-material/Translate";
|
|
2654
|
-
import LightbulbIcon from "@mui/icons-material/Lightbulb";
|
|
2655
|
-
|
|
2656
|
-
// src/services/translation.service.ts
|
|
2657
|
-
var translationService = {
|
|
2658
|
-
// 1. Принимаем client первым аргументом
|
|
2659
|
-
incrementVersion: async (client, namespace, langCodes) => {
|
|
2660
|
-
try {
|
|
2661
|
-
const { data } = await client.from("translation_versions").select("version, lang_code").eq("namespace", namespace);
|
|
2662
|
-
const currentVersion = data && data.length > 0 ? Math.max(...data.map((d) => d.version || 0)) : 0;
|
|
2663
|
-
const nextVersion = currentVersion + 1;
|
|
2664
|
-
const languagesToUpdate = langCodes && langCodes.length > 0 ? langCodes : ["uk"];
|
|
2665
|
-
const updates = languagesToUpdate.map((lang_code) => ({
|
|
2666
|
-
namespace,
|
|
2667
|
-
lang_code,
|
|
2668
|
-
version: nextVersion,
|
|
2669
|
-
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2670
|
-
}));
|
|
2671
|
-
const { error } = await client.from("translation_versions").upsert(updates, { onConflict: "namespace,lang_code" });
|
|
2672
|
-
if (error) console.error("Error updating translation version:", error);
|
|
2673
|
-
return nextVersion;
|
|
2674
|
-
} catch (err) {
|
|
2675
|
-
console.error("Failed to increment version in Supabase:", err);
|
|
2676
|
-
return null;
|
|
2677
|
-
}
|
|
2678
|
-
},
|
|
2679
|
-
translateSmart: async (client, aiGenerateFn, params) => {
|
|
2680
|
-
const languagesToTranslate = params.targetLangs || (params.targetLang ? [params.targetLang] : []);
|
|
2681
|
-
try {
|
|
2682
|
-
const { data, error } = await client.functions.invoke("translate-smart", { body: params });
|
|
2683
|
-
if (!error && data) return data;
|
|
2684
|
-
} catch {
|
|
2685
|
-
console.warn("Edge Function translate-smart \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u043D\u0430, \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0435\u043C AIProvider...");
|
|
2686
|
-
}
|
|
2687
|
-
if (aiGenerateFn) {
|
|
2688
|
-
const prompt = `Translate the source text into language codes: ${JSON.stringify(languagesToTranslate)}.
|
|
2689
|
-
Source Text: "${params.text}"
|
|
2690
|
-
${params.contextHint ? `Context Hint: "${params.contextHint}"` : ""}`;
|
|
2691
|
-
const translations = await aiGenerateFn({
|
|
2692
|
-
prompt,
|
|
2693
|
-
systemInstruction: 'Respond STRICTLY with a valid JSON mapping lang code to text. Example: {"en": "Hello"}',
|
|
2694
|
-
jsonMode: true
|
|
2695
|
-
});
|
|
2696
|
-
if (translations) {
|
|
2697
|
-
if (params.targetLang) {
|
|
2698
|
-
return { translatedText: translations[params.targetLang] || params.text };
|
|
2699
|
-
}
|
|
2700
|
-
return { translations };
|
|
2701
|
-
}
|
|
2702
|
-
}
|
|
2703
|
-
if (params.targetLang) {
|
|
2704
|
-
const fallbackUrl = `https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=${params.targetLang}&dt=t&q=${encodeURIComponent(params.text)}`;
|
|
2705
|
-
const res = await fetch(fallbackUrl);
|
|
2706
|
-
if (res.ok) {
|
|
2707
|
-
const data = await res.json();
|
|
2708
|
-
return { translatedText: data[0].map((x) => x[0]).join("") };
|
|
2709
|
-
}
|
|
2710
|
-
}
|
|
2711
|
-
throw new Error("All translation strategies failed.");
|
|
2712
|
-
}
|
|
2713
|
-
};
|
|
2714
|
-
|
|
2715
|
-
// src/i18n/TranslationDialog.tsx
|
|
2716
|
-
import { jsx as jsx6, jsxs } from "react/jsx-runtime";
|
|
2717
|
-
var TranslationDialog = ({
|
|
2718
|
-
open,
|
|
2719
|
-
onClose,
|
|
2720
|
-
translationKey,
|
|
2721
|
-
namespace,
|
|
2722
|
-
onSave
|
|
2723
|
-
}) => {
|
|
2724
|
-
const supabase = useSupabase();
|
|
2725
|
-
const { generate } = useAI();
|
|
2726
|
-
const [languages, setLanguages] = useState3([]);
|
|
2727
|
-
const [values, setValues] = useState3({});
|
|
2728
|
-
const [contextHint, setContextHint] = useState3("");
|
|
2729
|
-
const [loading, setLoading] = useState3(false);
|
|
2730
|
-
const [saving, setSaving] = useState3(false);
|
|
2731
|
-
const [translatingCode, setTranslatingCode] = useState3(null);
|
|
2732
|
-
const [isTranslatingAll, setIsTranslatingAll] = useState3(false);
|
|
2733
|
-
const [error, setError] = useState3(null);
|
|
2734
|
-
useEffect3(() => {
|
|
2735
|
-
if (!open) return;
|
|
2736
|
-
const fetchData = async () => {
|
|
2737
|
-
setLoading(true);
|
|
2738
|
-
setError(null);
|
|
2739
|
-
try {
|
|
2740
|
-
const { data: langs, error: langErr } = await supabase.from("languages").select("code, name, svg_flag").eq("enabled", true);
|
|
2741
|
-
if (langErr) throw langErr;
|
|
2742
|
-
setLanguages(langs || []);
|
|
2743
|
-
const { data: trans, error: transErr } = await supabase.from("translations").select("lang_code, value, context_hint").eq("namespace", namespace).eq("key", translationKey);
|
|
2744
|
-
if (transErr) throw transErr;
|
|
2745
|
-
const initialValues = {};
|
|
2746
|
-
let existingHint = "";
|
|
2747
|
-
langs?.forEach((l) => {
|
|
2748
|
-
const found = trans?.find((t2) => t2.lang_code === l.code);
|
|
2749
|
-
initialValues[l.code] = found ? found.value : "";
|
|
2750
|
-
if (found?.context_hint) {
|
|
2751
|
-
existingHint = found.context_hint;
|
|
2752
|
-
}
|
|
2753
|
-
});
|
|
2754
|
-
setValues(initialValues);
|
|
2755
|
-
setContextHint(existingHint);
|
|
2756
|
-
} catch (err) {
|
|
2757
|
-
console.error("Failed to load translations:", err);
|
|
2758
|
-
setError(err?.message || "Failed to load initial translation data.");
|
|
2759
|
-
} finally {
|
|
2760
|
-
setLoading(false);
|
|
2761
|
-
}
|
|
2762
|
-
};
|
|
2763
|
-
fetchData();
|
|
2764
|
-
}, [open, translationKey, namespace]);
|
|
2765
|
-
const handleAutoTranslate = async (e, targetLang) => {
|
|
2766
|
-
e.preventDefault();
|
|
2767
|
-
e.stopPropagation();
|
|
2768
|
-
setError(null);
|
|
2769
|
-
setTranslatingCode(targetLang);
|
|
2770
|
-
try {
|
|
2771
|
-
const res = await translationService.translateSmart(supabase, generate, {
|
|
2772
|
-
text: translationKey,
|
|
2773
|
-
targetLang,
|
|
2774
|
-
contextHint
|
|
2775
|
-
});
|
|
2776
|
-
if (res?.translatedText) {
|
|
2777
|
-
setValues((prev) => ({ ...prev, [targetLang]: res.translatedText }));
|
|
2778
|
-
}
|
|
2779
|
-
} catch (err) {
|
|
2780
|
-
console.log(err);
|
|
2781
|
-
setError(`Failed to translate into ${targetLang}. ${err?.message || ""}`);
|
|
2782
|
-
} finally {
|
|
2783
|
-
setTranslatingCode(null);
|
|
2784
|
-
}
|
|
2785
|
-
};
|
|
2786
|
-
const handleTranslateAll = async (e) => {
|
|
2787
|
-
e.preventDefault();
|
|
2788
|
-
e.stopPropagation();
|
|
2789
|
-
if (!translationKey || languages.length === 0) return;
|
|
2790
|
-
setIsTranslatingAll(true);
|
|
2791
|
-
setError(null);
|
|
2792
|
-
try {
|
|
2793
|
-
const targetLangs = languages.map((l) => l.code);
|
|
2794
|
-
const res = await translationService.translateSmart(supabase, generate, {
|
|
2795
|
-
text: translationKey,
|
|
2796
|
-
targetLangs,
|
|
2797
|
-
contextHint
|
|
2798
|
-
});
|
|
2799
|
-
if (res?.translations) {
|
|
2800
|
-
setValues((prev) => ({ ...prev, ...res.translations }));
|
|
2801
|
-
}
|
|
2802
|
-
} catch (err) {
|
|
2803
|
-
console.error("Batch translation error:", err);
|
|
2804
|
-
setError(err?.message || "Failed to translate all languages.");
|
|
2805
|
-
} finally {
|
|
2806
|
-
setIsTranslatingAll(false);
|
|
2807
|
-
}
|
|
2808
|
-
};
|
|
2809
|
-
const handleSaveAll = async (e) => {
|
|
2810
|
-
e.preventDefault();
|
|
2811
|
-
e.stopPropagation();
|
|
2812
|
-
setSaving(true);
|
|
2813
|
-
setError(null);
|
|
2814
|
-
try {
|
|
2815
|
-
await onSave(values, contextHint);
|
|
2816
|
-
onClose();
|
|
2817
|
-
} catch (err) {
|
|
2818
|
-
console.error("Failed to save translations:", err);
|
|
2819
|
-
setError(err?.message || "Failed to save translations. Please try again.");
|
|
2820
|
-
} finally {
|
|
2821
|
-
setSaving(false);
|
|
2822
|
-
}
|
|
2823
|
-
};
|
|
2824
|
-
const handleClose = (_, reason) => {
|
|
2825
|
-
if (reason === "backdropClick" && isBusy) return;
|
|
2826
|
-
setError(null);
|
|
2827
|
-
onClose();
|
|
2828
|
-
};
|
|
2829
|
-
const isBusy = loading || saving || isTranslatingAll || translatingCode !== null;
|
|
2830
|
-
return /* @__PURE__ */ jsxs(
|
|
2831
|
-
Dialog,
|
|
2832
|
-
{
|
|
2833
|
-
open,
|
|
2834
|
-
onClose: handleClose,
|
|
2835
|
-
fullWidth: true,
|
|
2836
|
-
maxWidth: "sm",
|
|
2837
|
-
onClick: (e) => e.stopPropagation(),
|
|
2838
|
-
onMouseDown: (e) => e.stopPropagation(),
|
|
2839
|
-
children: [
|
|
2840
|
-
/* @__PURE__ */ jsxs(DialogTitle, { sx: { pb: 1, display: "flex", justifyContent: "space-between", alignItems: "flex-start" }, children: [
|
|
2841
|
-
/* @__PURE__ */ jsxs(Box, { children: [
|
|
2842
|
-
"Context Translation",
|
|
2843
|
-
/* @__PURE__ */ jsxs(Typography, { component: "div", variant: "subtitle2", color: "text.secondary", sx: { wordBreak: "break-all", mt: 0.5 }, children: [
|
|
2844
|
-
"Original: ",
|
|
2845
|
-
/* @__PURE__ */ jsxs("strong", { children: [
|
|
2846
|
-
'"',
|
|
2847
|
-
translationKey,
|
|
2848
|
-
'"'
|
|
2849
|
-
] })
|
|
2850
|
-
] })
|
|
2851
|
-
] }),
|
|
2852
|
-
!loading && /* @__PURE__ */ jsx6(
|
|
2853
|
-
Button,
|
|
2854
|
-
{
|
|
2855
|
-
type: "button",
|
|
2856
|
-
size: "small",
|
|
2857
|
-
variant: "outlined",
|
|
2858
|
-
color: "secondary",
|
|
2859
|
-
startIcon: isTranslatingAll ? /* @__PURE__ */ jsx6(CircularProgress, { size: 16, color: "inherit" }) : /* @__PURE__ */ jsx6(TranslateIcon, { fontSize: "small" }),
|
|
2860
|
-
onClick: handleTranslateAll,
|
|
2861
|
-
disabled: isBusy,
|
|
2862
|
-
sx: { flexShrink: 0, ml: 2, whiteSpace: "nowrap" },
|
|
2863
|
-
children: isTranslatingAll ? "Translating..." : "Translate All"
|
|
2864
|
-
}
|
|
2865
|
-
)
|
|
2866
|
-
] }),
|
|
2867
|
-
/* @__PURE__ */ jsxs(DialogContent, { dividers: true, sx: { pt: 2 }, children: [
|
|
2868
|
-
error && /* @__PURE__ */ jsx6(Alert, { severity: "error", onClose: () => setError(null), sx: { mb: 2 }, children: error }),
|
|
2869
|
-
loading ? /* @__PURE__ */ jsx6(Box, { sx: { display: "flex", justifyContent: "center", py: 4 }, children: /* @__PURE__ */ jsx6(CircularProgress, {}) }) : /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexDirection: "column", gap: 2.5 }, children: [
|
|
2870
|
-
/* @__PURE__ */ jsxs(Paper, { variant: "outlined", sx: { p: 2, bgcolor: "action.hover", borderRadius: 2 }, children: [
|
|
2871
|
-
/* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1, mb: 1 }, children: [
|
|
2872
|
-
/* @__PURE__ */ jsx6(LightbulbIcon, { color: "warning", fontSize: "small" }),
|
|
2873
|
-
/* @__PURE__ */ jsx6(Typography, { variant: "subtitle2", sx: { fontWeight: 600 }, children: "Context Hint / Clarification" })
|
|
2874
|
-
] }),
|
|
2875
|
-
/* @__PURE__ */ jsx6(
|
|
2876
|
-
TextField,
|
|
2877
|
-
{
|
|
2878
|
-
fullWidth: true,
|
|
2879
|
-
multiline: true,
|
|
2880
|
-
rows: 2,
|
|
2881
|
-
size: "small",
|
|
2882
|
-
value: contextHint,
|
|
2883
|
-
onChange: (e) => setContextHint(e.target.value),
|
|
2884
|
-
placeholder: "e.g. Website navigation menu link to the home page",
|
|
2885
|
-
helperText: "This hint explains the exact meaning to AI translation models.",
|
|
2886
|
-
disabled: isBusy
|
|
2887
|
-
}
|
|
2888
|
-
)
|
|
2889
|
-
] }),
|
|
2890
|
-
languages.map((lang) => /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 2 }, children: [
|
|
2891
|
-
/* @__PURE__ */ jsx6(
|
|
2892
|
-
Box,
|
|
2893
|
-
{
|
|
2894
|
-
sx: {
|
|
2895
|
-
width: 32,
|
|
2896
|
-
height: 22,
|
|
2897
|
-
flexShrink: 0,
|
|
2898
|
-
borderRadius: "4px",
|
|
2899
|
-
overflow: "hidden",
|
|
2900
|
-
boxShadow: 1,
|
|
2901
|
-
"& svg": { width: "100%", height: "100%", display: "block" }
|
|
2902
|
-
},
|
|
2903
|
-
dangerouslySetInnerHTML: { __html: lang.svg_flag }
|
|
2904
|
-
}
|
|
2905
|
-
),
|
|
2906
|
-
/* @__PURE__ */ jsx6(
|
|
2907
|
-
TextField,
|
|
2908
|
-
{
|
|
2909
|
-
fullWidth: true,
|
|
2910
|
-
label: lang.name,
|
|
2911
|
-
size: "small",
|
|
2912
|
-
value: values[lang.code] || "",
|
|
2913
|
-
onChange: (e) => setValues((prev) => ({ ...prev, [lang.code]: e.target.value })),
|
|
2914
|
-
placeholder: "Enter manual translation...",
|
|
2915
|
-
disabled: isBusy
|
|
2916
|
-
}
|
|
2917
|
-
),
|
|
2918
|
-
/* @__PURE__ */ jsx6(Tooltip, { title: "Translate with context hint", children: /* @__PURE__ */ jsx6("span", { children: /* @__PURE__ */ jsx6(
|
|
2919
|
-
IconButton,
|
|
2920
|
-
{
|
|
2921
|
-
type: "button",
|
|
2922
|
-
color: "primary",
|
|
2923
|
-
disabled: isBusy,
|
|
2924
|
-
onClick: (e) => handleAutoTranslate(e, lang.code),
|
|
2925
|
-
children: translatingCode === lang.code ? /* @__PURE__ */ jsx6(CircularProgress, { size: 20, color: "inherit" }) : /* @__PURE__ */ jsx6(AutoFixHighIcon, { fontSize: "small" })
|
|
2926
|
-
}
|
|
2927
|
-
) }) })
|
|
2928
|
-
] }, lang.code))
|
|
2929
|
-
] })
|
|
2930
|
-
] }),
|
|
2931
|
-
/* @__PURE__ */ jsxs(DialogActions, { sx: { px: 3, py: 2 }, children: [
|
|
2932
|
-
/* @__PURE__ */ jsx6(Button, { onClick: onClose, disabled: isBusy, color: "inherit", type: "button", children: "Cancel" }),
|
|
2933
|
-
/* @__PURE__ */ jsx6(
|
|
2934
|
-
Button,
|
|
2935
|
-
{
|
|
2936
|
-
onClick: handleSaveAll,
|
|
2937
|
-
variant: "contained",
|
|
2938
|
-
disabled: isBusy,
|
|
2939
|
-
type: "button",
|
|
2940
|
-
children: saving ? "Saving..." : "Save All"
|
|
2941
|
-
}
|
|
2942
|
-
)
|
|
2943
|
-
] })
|
|
2944
|
-
]
|
|
2945
|
-
}
|
|
2946
|
-
);
|
|
2947
|
-
};
|
|
2948
|
-
|
|
2949
|
-
// src/i18n/TranslateText.tsx
|
|
2950
|
-
import { Fragment, jsx as jsx7, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
2951
|
-
var TranslateText = ({
|
|
2952
|
-
overrideNamespace,
|
|
2953
|
-
children,
|
|
2954
|
-
values
|
|
2955
|
-
}) => {
|
|
2956
|
-
const namespace = useTranslationNamespace(overrideNamespace);
|
|
2957
|
-
const { t: t2, i18n } = useTranslation(namespace);
|
|
2958
|
-
const { isTranslationMode, canEdit } = useTranslationEdit();
|
|
2959
|
-
const supabase = useSupabase();
|
|
2960
|
-
const [anchorEl, setAnchorEl] = useState4(null);
|
|
2961
|
-
const [isDialogOpen, setIsDialogOpen] = useState4(false);
|
|
2962
|
-
const timeoutRef = useRef2(null);
|
|
2963
|
-
const translatedValue = t2(children, values);
|
|
2964
|
-
useEffect4(() => {
|
|
2965
|
-
return () => {
|
|
2966
|
-
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
2967
|
-
};
|
|
2968
|
-
}, []);
|
|
2969
|
-
if (!canEdit || !isTranslationMode) {
|
|
2970
|
-
return /* @__PURE__ */ jsx7(Fragment, { children: translatedValue });
|
|
2971
|
-
}
|
|
2972
|
-
const handleSaveTranslations = async (newValues, contextHint) => {
|
|
2973
|
-
const upsertData = Object.entries(newValues).map(([langCode, text]) => ({
|
|
2974
|
-
lang_code: langCode,
|
|
2975
|
-
namespace,
|
|
2976
|
-
key: children,
|
|
2977
|
-
value: text,
|
|
2978
|
-
context_hint: contextHint
|
|
2979
|
-
}));
|
|
2980
|
-
const { error } = await supabase.from("translations").upsert(upsertData, { onConflict: "lang_code,namespace,key" });
|
|
2981
|
-
if (error) {
|
|
2982
|
-
alert("\u041E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u0438 \u0441\u043E\u0445\u0440\u0430\u043D\u0435\u043D\u0438\u0438 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043D\u043D\u044B\u0445");
|
|
2983
|
-
throw error;
|
|
2984
|
-
}
|
|
2985
|
-
await translationService.incrementVersion(supabase, namespace, Object.keys(newValues));
|
|
2986
|
-
Object.entries(newValues).forEach(([langCode, text]) => {
|
|
2987
|
-
i18n.addResource(langCode, namespace, children, text);
|
|
2988
|
-
});
|
|
2989
|
-
};
|
|
2990
|
-
const handleMouseEnter = (event) => {
|
|
2991
|
-
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
2992
|
-
setAnchorEl(event.currentTarget);
|
|
2993
|
-
};
|
|
2994
|
-
const handleMouseLeave = () => {
|
|
2995
|
-
timeoutRef.current = setTimeout(() => {
|
|
2996
|
-
setAnchorEl(null);
|
|
2997
|
-
}, 200);
|
|
2998
|
-
};
|
|
2999
|
-
const handleOpenDialog = (e) => {
|
|
3000
|
-
e.preventDefault();
|
|
3001
|
-
e.stopPropagation();
|
|
3002
|
-
setAnchorEl(null);
|
|
3003
|
-
if (document.activeElement instanceof HTMLElement) {
|
|
3004
|
-
document.activeElement.blur();
|
|
3005
|
-
}
|
|
3006
|
-
setIsDialogOpen(true);
|
|
3007
|
-
};
|
|
3008
|
-
const handleLaunchAction = (_) => {
|
|
3009
|
-
setAnchorEl(null);
|
|
3010
|
-
};
|
|
3011
|
-
const open = Boolean(anchorEl);
|
|
3012
|
-
return /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
3013
|
-
/* @__PURE__ */ jsx7(
|
|
3014
|
-
Box2,
|
|
3015
|
-
{
|
|
3016
|
-
component: "span",
|
|
3017
|
-
onMouseEnter: handleMouseEnter,
|
|
3018
|
-
onMouseLeave: handleMouseLeave,
|
|
3019
|
-
onClick: (e) => {
|
|
3020
|
-
e.preventDefault();
|
|
3021
|
-
e.stopPropagation();
|
|
3022
|
-
},
|
|
3023
|
-
sx: {
|
|
3024
|
-
display: "inline-block",
|
|
3025
|
-
position: "relative",
|
|
3026
|
-
borderRadius: "4px",
|
|
3027
|
-
padding: "0 3px",
|
|
3028
|
-
margin: "0 1px",
|
|
3029
|
-
border: "1px dashed #f59e0b",
|
|
3030
|
-
backgroundColor: "rgba(254, 243, 199, 0.35)",
|
|
3031
|
-
cursor: "pointer",
|
|
3032
|
-
transition: "all 0.2s ease-in-out",
|
|
3033
|
-
userSelect: "none",
|
|
3034
|
-
"&:hover": {
|
|
3035
|
-
backgroundColor: "#fef08a",
|
|
3036
|
-
borderColor: "#d97706",
|
|
3037
|
-
boxShadow: "0 0 0 2px rgba(245, 158, 11, 0.35)",
|
|
3038
|
-
transform: "scale(1.02)"
|
|
3039
|
-
}
|
|
3040
|
-
},
|
|
3041
|
-
children: translatedValue
|
|
3042
|
-
}
|
|
3043
|
-
),
|
|
3044
|
-
/* @__PURE__ */ jsx7(
|
|
3045
|
-
Popper,
|
|
3046
|
-
{
|
|
3047
|
-
open,
|
|
3048
|
-
anchorEl,
|
|
3049
|
-
placement: "bottom-start",
|
|
3050
|
-
style: { zIndex: 1300 },
|
|
3051
|
-
children: /* @__PURE__ */ jsx7(
|
|
3052
|
-
Paper2,
|
|
3053
|
-
{
|
|
3054
|
-
elevation: 4,
|
|
3055
|
-
onMouseEnter: () => {
|
|
3056
|
-
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
3057
|
-
},
|
|
3058
|
-
onMouseLeave: handleMouseLeave,
|
|
3059
|
-
sx: {
|
|
3060
|
-
mt: 0.5,
|
|
3061
|
-
borderRadius: 2,
|
|
3062
|
-
minWidth: 140,
|
|
3063
|
-
boxShadow: "0px 10px 15px -3px rgba(0,0,0,0.1)"
|
|
3064
|
-
},
|
|
3065
|
-
children: /* @__PURE__ */ jsxs2(MenuList, { dense: true, sx: { py: 0.5 }, children: [
|
|
3066
|
-
/* @__PURE__ */ jsxs2(MenuItem, { onClick: handleOpenDialog, sx: { py: 0.8, px: 1.5 }, children: [
|
|
3067
|
-
/* @__PURE__ */ jsx7(ListItemIcon, { sx: { minWidth: "28px !important" }, children: /* @__PURE__ */ jsx7(TranslateIcon2, { fontSize: "small", sx: { color: "#d97706" } }) }),
|
|
3068
|
-
/* @__PURE__ */ jsx7(
|
|
3069
|
-
ListItemText,
|
|
3070
|
-
{
|
|
3071
|
-
primary: "Localization",
|
|
3072
|
-
slotProps: {
|
|
3073
|
-
primary: {
|
|
3074
|
-
sx: {
|
|
3075
|
-
fontSize: "0.825rem",
|
|
3076
|
-
fontWeight: 600,
|
|
3077
|
-
color: "text.primary"
|
|
3078
|
-
}
|
|
3079
|
-
}
|
|
3080
|
-
}
|
|
3081
|
-
}
|
|
3082
|
-
)
|
|
3083
|
-
] }),
|
|
3084
|
-
/* @__PURE__ */ jsxs2(MenuItem, { onClick: handleLaunchAction, sx: { py: 0.8, px: 1.5 }, children: [
|
|
3085
|
-
/* @__PURE__ */ jsx7(ListItemIcon, { sx: { minWidth: "28px !important" }, children: /* @__PURE__ */ jsx7(LaunchIcon, { fontSize: "small", color: "secondary" }) }),
|
|
3086
|
-
/* @__PURE__ */ jsx7(
|
|
3087
|
-
ListItemText,
|
|
3088
|
-
{
|
|
3089
|
-
primary: "Launch action",
|
|
3090
|
-
slotProps: {
|
|
3091
|
-
primary: {
|
|
3092
|
-
sx: {
|
|
3093
|
-
fontSize: "0.825rem",
|
|
3094
|
-
fontWeight: 600,
|
|
3095
|
-
color: "text.primary"
|
|
3096
|
-
}
|
|
3097
|
-
}
|
|
3098
|
-
}
|
|
3099
|
-
}
|
|
3100
|
-
)
|
|
3101
|
-
] })
|
|
3102
|
-
] })
|
|
3103
|
-
}
|
|
3104
|
-
)
|
|
3105
|
-
}
|
|
3106
|
-
),
|
|
3107
|
-
/* @__PURE__ */ jsx7("span", { style: { display: "inline" }, onClick: (e) => e.stopPropagation(), children: /* @__PURE__ */ jsx7(
|
|
3108
|
-
TranslationDialog,
|
|
3109
|
-
{
|
|
3110
|
-
open: isDialogOpen,
|
|
3111
|
-
onClose: () => setIsDialogOpen(false),
|
|
3112
|
-
translationKey: children,
|
|
3113
|
-
namespace,
|
|
3114
|
-
onSave: handleSaveTranslations
|
|
3115
|
-
}
|
|
3116
|
-
) })
|
|
3117
|
-
] });
|
|
3118
|
-
};
|
|
3119
|
-
|
|
3120
|
-
// src/UI/components/data.display/TranslatableTooltipComponent.tsx
|
|
3121
|
-
import { Tooltip as Tooltip2 } from "@mui/material";
|
|
3122
|
-
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
3123
|
-
var TranslatableTooltipComponent = ({
|
|
3124
|
-
overrideNamespace,
|
|
3125
|
-
title,
|
|
3126
|
-
disableSpan,
|
|
3127
|
-
children,
|
|
3128
|
-
...props
|
|
3129
|
-
}) => {
|
|
3130
|
-
const { isTranslationMode } = useTranslationEdit();
|
|
3131
|
-
return /* @__PURE__ */ jsx8(
|
|
3132
|
-
Tooltip2,
|
|
3133
|
-
{
|
|
3134
|
-
title: typeof title === "string" ? /* @__PURE__ */ jsx8(TranslateText, { overrideNamespace, children: title }) : title,
|
|
3135
|
-
slotProps: {
|
|
3136
|
-
popper: {
|
|
3137
|
-
sx: isTranslationMode ? {
|
|
3138
|
-
pointerEvents: "auto",
|
|
3139
|
-
// Разрешаем клики внутри тултипа
|
|
3140
|
-
"& .MuiTooltip-tooltip": {
|
|
3141
|
-
pointerEvents: "auto"
|
|
3142
|
-
}
|
|
3143
|
-
} : void 0
|
|
3144
|
-
}
|
|
3145
|
-
},
|
|
3146
|
-
leaveDelay: isTranslationMode ? 1e3 : 100,
|
|
3147
|
-
...props,
|
|
3148
|
-
children: disableSpan ? children : /* @__PURE__ */ jsx8("span", { children })
|
|
3149
|
-
}
|
|
3150
|
-
);
|
|
3151
|
-
};
|
|
3152
|
-
|
|
3153
|
-
// src/context/LocalizationProvider.tsx
|
|
3154
|
-
import { createContext as createContext6, useContext as useContext6, useMemo as useMemo3, useEffect as useEffect5, useState as useState5 } from "react";
|
|
3155
|
-
import { useTranslation as useTranslation2 } from "react-i18next";
|
|
3156
|
-
import moment from "moment/min/moment-with-locales";
|
|
3157
|
-
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
3158
|
-
var DEFAULT_DATETIME_FORMATS = {
|
|
3159
|
-
uk: "DD.MM.YYYY, HH:mm",
|
|
3160
|
-
de: "DD.MM.YYYY, HH:mm",
|
|
3161
|
-
en: "MM/DD/YYYY, hh:mm A",
|
|
3162
|
-
es: "DD/MM/YYYY, HH:mm",
|
|
3163
|
-
fr: "DD/MM/YYYY, HH:mm",
|
|
3164
|
-
it: "DD/MM/YYYY, HH:mm"
|
|
3165
|
-
};
|
|
3166
|
-
var DEFAULT_DATE_FORMATS = {
|
|
3167
|
-
uk: "DD.MM.YYYY",
|
|
3168
|
-
de: "DD.MM.YYYY",
|
|
3169
|
-
en: "MM/DD/YYYY",
|
|
3170
|
-
es: "DD/MM/YYYY",
|
|
3171
|
-
fr: "DD/MM/YYYY",
|
|
3172
|
-
it: "DD/MM/YYYY"
|
|
3173
|
-
};
|
|
3174
|
-
var DEFAULT_TIME_FORMATS = {
|
|
3175
|
-
uk: "HH:mm:ss",
|
|
3176
|
-
de: "HH:mm:ss",
|
|
3177
|
-
en: "hh:mm:ss A",
|
|
3178
|
-
es: "HH:mm:ss",
|
|
3179
|
-
fr: "HH:mm:ss",
|
|
3180
|
-
it: "HH:mm:ss"
|
|
3181
|
-
};
|
|
3182
|
-
var LocalizationContext = createContext6(void 0);
|
|
3183
|
-
var LocalizationProvider = ({ children }) => {
|
|
3184
|
-
const supabase = useSupabase();
|
|
3185
|
-
const { i18n } = useTranslation2();
|
|
3186
|
-
const [languages, setLanguages] = useState5([]);
|
|
3187
|
-
const [isLoadingLangs, setIsLoadingLangs] = useState5(true);
|
|
3188
|
-
const [languagesError, setLanguagesError] = useState5(null);
|
|
3189
|
-
useEffect5(() => {
|
|
3190
|
-
let isMounted = true;
|
|
3191
|
-
const fetchLanguages = async () => {
|
|
3192
|
-
try {
|
|
3193
|
-
setIsLoadingLangs(true);
|
|
3194
|
-
setLanguagesError(null);
|
|
3195
|
-
const { data: langs, error: langErr } = await supabase.from("languages").select("code, name, svg_flag, enabled, created_at").eq("enabled", true).order("code", { ascending: true });
|
|
3196
|
-
if (langErr) {
|
|
3197
|
-
throw langErr;
|
|
3198
|
-
}
|
|
3199
|
-
if (isMounted && langs) {
|
|
3200
|
-
setLanguages(langs);
|
|
3201
|
-
}
|
|
3202
|
-
} catch (err) {
|
|
3203
|
-
console.error("Failed to load languages from Supabase:", err);
|
|
3204
|
-
if (isMounted) {
|
|
3205
|
-
setLanguagesError(err.message || "Error loading languages");
|
|
3206
|
-
}
|
|
3207
|
-
} finally {
|
|
3208
|
-
if (isMounted) {
|
|
3209
|
-
setIsLoadingLangs(false);
|
|
3210
|
-
}
|
|
3211
|
-
}
|
|
3212
|
-
};
|
|
3213
|
-
fetchLanguages();
|
|
3214
|
-
return () => {
|
|
3215
|
-
isMounted = false;
|
|
3216
|
-
};
|
|
3217
|
-
}, [supabase]);
|
|
3218
|
-
const rawLang = i18n.language || "uk";
|
|
3219
|
-
const currentLang = rawLang.split("-")[0].toLowerCase();
|
|
3220
|
-
const getDateFormat = () => {
|
|
3221
|
-
return DEFAULT_DATE_FORMATS[currentLang] || "DD.MM.YYYY";
|
|
3222
|
-
};
|
|
3223
|
-
const getTimeFormat = () => {
|
|
3224
|
-
return DEFAULT_TIME_FORMATS[currentLang] || "HH:mm:ss";
|
|
3225
|
-
};
|
|
3226
|
-
const getDateTimeFormat = () => {
|
|
3227
|
-
return DEFAULT_DATETIME_FORMATS[currentLang] || "DD.MM.YYYY, HH:mm";
|
|
3228
|
-
};
|
|
3229
|
-
const formatDateTime = (date, customPattern) => {
|
|
3230
|
-
if (!date) return "\u2014";
|
|
3231
|
-
const pattern = customPattern || DEFAULT_DATETIME_FORMATS[currentLang] || "DD.MM.YYYY, HH:mm";
|
|
3232
|
-
return moment(date).locale(currentLang).format(pattern);
|
|
3233
|
-
};
|
|
3234
|
-
const formatDate = (date, customPattern) => {
|
|
3235
|
-
if (!date) return "\u2014";
|
|
3236
|
-
const pattern = customPattern || DEFAULT_DATE_FORMATS[currentLang] || "DD.MM.YYYY";
|
|
3237
|
-
return moment(date).locale(currentLang).format(pattern);
|
|
3238
|
-
};
|
|
3239
|
-
const formatTime = (date, customPattern) => {
|
|
3240
|
-
if (!date) return "\u2014";
|
|
3241
|
-
const pattern = customPattern || DEFAULT_TIME_FORMATS[currentLang] || "HH:mm:ss";
|
|
3242
|
-
return moment(date).locale(currentLang).format(pattern);
|
|
3243
|
-
};
|
|
3244
|
-
const formatRelativeTime = (date, withoutSuffix = false) => {
|
|
3245
|
-
if (!date) return "\u2014";
|
|
3246
|
-
return moment(date).locale(currentLang).fromNow(withoutSuffix);
|
|
3247
|
-
};
|
|
3248
|
-
const changeLanguage2 = async (lang) => {
|
|
3249
|
-
await i18n.changeLanguage(lang);
|
|
3250
|
-
};
|
|
3251
|
-
const value = useMemo3(
|
|
3252
|
-
() => ({
|
|
3253
|
-
currentLang,
|
|
3254
|
-
languages,
|
|
3255
|
-
isLoadingLangs,
|
|
3256
|
-
languagesError,
|
|
3257
|
-
changeLanguage: changeLanguage2,
|
|
3258
|
-
getDateFormat,
|
|
3259
|
-
getTimeFormat,
|
|
3260
|
-
getDateTimeFormat,
|
|
3261
|
-
formatDateTime,
|
|
3262
|
-
formatDate,
|
|
3263
|
-
formatTime,
|
|
3264
|
-
formatRelativeTime
|
|
3265
|
-
}),
|
|
3266
|
-
[currentLang, languages, isLoadingLangs, languagesError]
|
|
3267
|
-
);
|
|
3268
|
-
return /* @__PURE__ */ jsx9(LocalizationContext.Provider, { value, children });
|
|
3269
|
-
};
|
|
3270
|
-
var useLocalization = () => {
|
|
3271
|
-
const context = useContext6(LocalizationContext);
|
|
3272
|
-
if (!context) {
|
|
3273
|
-
throw new Error("useLocalization must be used within a LocalizationProvider");
|
|
3274
|
-
}
|
|
3275
|
-
return context;
|
|
3276
|
-
};
|
|
3277
|
-
|
|
3278
|
-
// src/context/ThemeProvider.tsx
|
|
3279
|
-
import { createContext as createContext7, useContext as useContext7, useMemo as useMemo4, useState as useState6, useEffect as useEffect6 } from "react";
|
|
3280
|
-
import { createTheme, ThemeProvider as MuiThemeProvider, CssBaseline, useMediaQuery } from "@mui/material";
|
|
3281
|
-
import { jsx as jsx10, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
3282
|
-
var DEFAULT_LIGHT_COLORS = {
|
|
3283
|
-
primary: "#1976d2",
|
|
3284
|
-
secondary: "#9c27b0",
|
|
3285
|
-
backgroundDefault: "#f5f5f5",
|
|
3286
|
-
backgroundPaper: "#ffffff",
|
|
3287
|
-
textPrimary: "#0f172a",
|
|
3288
|
-
textSecondary: "#475569",
|
|
3289
|
-
success: "#2e7d32",
|
|
3290
|
-
error: "#d32f2f",
|
|
3291
|
-
warning: "#ed6c02",
|
|
3292
|
-
info: "#0288d1"
|
|
3293
|
-
};
|
|
3294
|
-
var DEFAULT_DARK_COLORS = {
|
|
3295
|
-
primary: "#90caf9",
|
|
3296
|
-
secondary: "#ce93d8",
|
|
3297
|
-
backgroundDefault: "#0f172a",
|
|
3298
|
-
backgroundPaper: "#1e293b",
|
|
3299
|
-
textPrimary: "#f8fafc",
|
|
3300
|
-
textSecondary: "#94a3b8",
|
|
3301
|
-
success: "#66bb6a",
|
|
3302
|
-
error: "#f44336",
|
|
3303
|
-
warning: "#ffa726",
|
|
3304
|
-
info: "#29b6f6"
|
|
3305
|
-
};
|
|
3306
|
-
var INITIAL_THEME_CONFIG = {
|
|
3307
|
-
name: "Base MUI Theme",
|
|
3308
|
-
mode: "light",
|
|
3309
|
-
borderRadius: 12,
|
|
3310
|
-
colors: {
|
|
3311
|
-
light: DEFAULT_LIGHT_COLORS,
|
|
3312
|
-
dark: DEFAULT_DARK_COLORS
|
|
3313
|
-
},
|
|
3314
|
-
typography: {
|
|
3315
|
-
fontFamily: '"Inter", "Roboto", "Helvetica", "Arial", sans-serif',
|
|
3316
|
-
fontSize: 14,
|
|
3317
|
-
fontWeightLight: 300,
|
|
3318
|
-
fontWeightRegular: 400,
|
|
3319
|
-
fontWeightMedium: 600,
|
|
3320
|
-
fontWeightBold: 700
|
|
3321
|
-
}
|
|
3322
|
-
};
|
|
3323
|
-
var buildMuiTheme = (config) => {
|
|
3324
|
-
const currentMode = config.mode;
|
|
3325
|
-
const currentColors = config.colors?.[currentMode] || (currentMode === "light" ? DEFAULT_LIGHT_COLORS : DEFAULT_DARK_COLORS);
|
|
3326
|
-
return createTheme({
|
|
3327
|
-
palette: {
|
|
3328
|
-
mode: currentMode,
|
|
3329
|
-
primary: {
|
|
3330
|
-
main: currentColors.primary,
|
|
3331
|
-
light: currentMode === "light" ? "#63a4ff" : "#a1d2fa",
|
|
3332
|
-
dark: currentMode === "light" ? "#004ba0" : "#42a5f5"
|
|
3333
|
-
},
|
|
3334
|
-
secondary: {
|
|
3335
|
-
main: currentColors.secondary
|
|
3336
|
-
},
|
|
3337
|
-
background: {
|
|
3338
|
-
default: currentColors.backgroundDefault,
|
|
3339
|
-
paper: currentColors.backgroundPaper
|
|
3340
|
-
},
|
|
3341
|
-
text: {
|
|
3342
|
-
primary: currentColors.textPrimary,
|
|
3343
|
-
secondary: currentColors.textSecondary || (currentMode === "light" ? "#475569" : "#94a3b8")
|
|
3344
|
-
},
|
|
3345
|
-
success: { main: currentColors.success },
|
|
3346
|
-
error: { main: currentColors.error },
|
|
3347
|
-
warning: { main: currentColors.warning },
|
|
3348
|
-
info: { main: currentColors.info }
|
|
3349
|
-
},
|
|
3350
|
-
shape: {
|
|
3351
|
-
borderRadius: config.borderRadius
|
|
3352
|
-
},
|
|
3353
|
-
typography: {
|
|
3354
|
-
fontFamily: config.typography?.fontFamily || INITIAL_THEME_CONFIG.typography.fontFamily,
|
|
3355
|
-
fontSize: config.typography?.fontSize || INITIAL_THEME_CONFIG.typography.fontSize,
|
|
3356
|
-
fontWeightLight: config.typography?.fontWeightLight || INITIAL_THEME_CONFIG.typography.fontWeightLight,
|
|
3357
|
-
fontWeightRegular: config.typography?.fontWeightRegular || INITIAL_THEME_CONFIG.typography.fontWeightRegular,
|
|
3358
|
-
fontWeightMedium: config.typography?.fontWeightMedium || INITIAL_THEME_CONFIG.typography.fontWeightMedium,
|
|
3359
|
-
fontWeightBold: config.typography?.fontWeightBold || INITIAL_THEME_CONFIG.typography.fontWeightBold,
|
|
3360
|
-
h5: { fontWeight: 700, fontSize: "1.25rem" },
|
|
3361
|
-
subtitle1: { fontWeight: 600, fontSize: "0.95rem" },
|
|
3362
|
-
body2: { fontSize: "0.85rem" }
|
|
3363
|
-
},
|
|
3364
|
-
components: {
|
|
3365
|
-
MuiAutocomplete: {
|
|
3366
|
-
defaultProps: {
|
|
3367
|
-
noOptionsText: "\u041D\u0456\u0447\u043E\u0433\u043E \u043D\u0435 \u0437\u043D\u0430\u0439\u0434\u0435\u043D\u043E"
|
|
3368
|
-
}
|
|
3369
|
-
},
|
|
3370
|
-
MuiListItem: {
|
|
3371
|
-
styleOverrides: {
|
|
3372
|
-
root: {
|
|
3373
|
-
transition: "all 0.2s ease-in-out",
|
|
3374
|
-
"&:hover": {
|
|
3375
|
-
backgroundColor: currentMode === "light" ? "#f1f5f9" : "#334155"
|
|
3376
|
-
}
|
|
3377
|
-
}
|
|
3378
|
-
}
|
|
3379
|
-
},
|
|
3380
|
-
MuiListItemButton: {
|
|
3381
|
-
styleOverrides: {
|
|
3382
|
-
root: {
|
|
3383
|
-
transition: "all 0.2s ease-in-out",
|
|
3384
|
-
"&:hover": {
|
|
3385
|
-
backgroundColor: currentMode === "light" ? "#f1f5f9" : "#334155"
|
|
3386
|
-
}
|
|
3387
|
-
}
|
|
3388
|
-
}
|
|
3389
|
-
},
|
|
3390
|
-
MuiButton: {
|
|
3391
|
-
styleOverrides: {
|
|
3392
|
-
root: {
|
|
3393
|
-
textTransform: "none",
|
|
3394
|
-
fontWeight: 600,
|
|
3395
|
-
borderRadius: `${config.borderRadius}px`,
|
|
3396
|
-
padding: "10px 24px",
|
|
3397
|
-
transition: "all 0.3s cubic-bezier(0.4, 0, 0.2, 1)"
|
|
3398
|
-
}
|
|
3399
|
-
}
|
|
3400
|
-
},
|
|
3401
|
-
MuiPaper: {
|
|
3402
|
-
styleOverrides: {
|
|
3403
|
-
rounded: {
|
|
3404
|
-
borderRadius: `${config.borderRadius * 1.25}px`
|
|
3405
|
-
}
|
|
3406
|
-
}
|
|
3407
|
-
}
|
|
3408
|
-
}
|
|
3409
|
-
});
|
|
3410
|
-
};
|
|
3411
|
-
var ThemeContext = createContext7(void 0);
|
|
3412
|
-
var THEME_STORAGE_KEY = "docsua_custom_theme_config";
|
|
3413
|
-
var THEME_MODE_STORAGE_KEY = "docsua_custom_theme_mode";
|
|
3414
|
-
var ThemeProvider = ({ children }) => {
|
|
3415
|
-
const supabase = useSupabase();
|
|
3416
|
-
const { user, isAuthenticated, loading: isAuthLoading } = useAuth();
|
|
3417
|
-
const userId = user?.id;
|
|
3418
|
-
const [themeConfig, setThemeConfig] = useState6(() => {
|
|
3419
|
-
const saved = localStorage.getItem(THEME_STORAGE_KEY);
|
|
3420
|
-
if (saved) {
|
|
3421
|
-
try {
|
|
3422
|
-
return JSON.parse(saved);
|
|
3423
|
-
} catch (e) {
|
|
3424
|
-
}
|
|
3425
|
-
}
|
|
3426
|
-
return INITIAL_THEME_CONFIG;
|
|
3427
|
-
});
|
|
3428
|
-
useEffect6(() => {
|
|
3429
|
-
if (isAuthLoading) return;
|
|
3430
|
-
if (isAuthenticated && userId) {
|
|
3431
|
-
const fetchActiveTheme = async () => {
|
|
3432
|
-
try {
|
|
3433
|
-
const { data, error } = await supabase.from("user_themes").select("*").eq("user_id", userId).eq("is_active", true).maybeSingle();
|
|
3434
|
-
if (error) {
|
|
3435
|
-
console.error("\u041E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043A\u0435 \u0442\u0435\u043C\u044B \u0438\u0437 Supabase:", error.message);
|
|
3436
|
-
return;
|
|
3437
|
-
}
|
|
3438
|
-
if (data) {
|
|
3439
|
-
const activeTheme = data;
|
|
3440
|
-
const savedMode = localStorage.getItem(THEME_MODE_STORAGE_KEY);
|
|
3441
|
-
setThemeConfig({
|
|
3442
|
-
id: activeTheme.id,
|
|
3443
|
-
name: activeTheme.name || INITIAL_THEME_CONFIG.name,
|
|
3444
|
-
mode: savedMode || activeTheme.config?.mode || "light",
|
|
3445
|
-
borderRadius: activeTheme.config?.borderRadius ?? INITIAL_THEME_CONFIG.borderRadius,
|
|
3446
|
-
colors: activeTheme.config?.colors || INITIAL_THEME_CONFIG.colors,
|
|
3447
|
-
typography: activeTheme.config?.typography || INITIAL_THEME_CONFIG.typography,
|
|
3448
|
-
updatedAt: activeTheme.updated_at || void 0
|
|
3449
|
-
});
|
|
3450
|
-
}
|
|
3451
|
-
} catch (err) {
|
|
3452
|
-
console.error("\u041D\u0435\u043F\u0440\u0435\u0434\u0432\u0438\u0434\u0435\u043D\u043D\u0430\u044F \u043E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u0438 \u0437\u0430\u043F\u0440\u043E\u0441\u0435 \u0442\u0435\u043C\u044B:", err);
|
|
3453
|
-
}
|
|
3454
|
-
};
|
|
3455
|
-
fetchActiveTheme();
|
|
3456
|
-
} else {
|
|
3457
|
-
setThemeConfig(INITIAL_THEME_CONFIG);
|
|
3458
|
-
localStorage.removeItem(THEME_STORAGE_KEY);
|
|
3459
|
-
localStorage.removeItem(THEME_MODE_STORAGE_KEY);
|
|
3460
|
-
}
|
|
3461
|
-
}, [isAuthenticated, isAuthLoading, userId]);
|
|
3462
|
-
useEffect6(() => {
|
|
3463
|
-
if (isAuthenticated) {
|
|
3464
|
-
localStorage.setItem(THEME_STORAGE_KEY, JSON.stringify(themeConfig));
|
|
3465
|
-
localStorage.setItem(THEME_MODE_STORAGE_KEY, themeConfig.mode);
|
|
3466
|
-
}
|
|
3467
|
-
}, [themeConfig, isAuthenticated]);
|
|
3468
|
-
const mode = themeConfig.mode;
|
|
3469
|
-
const setMode = (newMode) => {
|
|
3470
|
-
setThemeConfig((prev) => ({ ...prev, mode: newMode }));
|
|
3471
|
-
};
|
|
3472
|
-
const toggleTheme = () => {
|
|
3473
|
-
setMode(mode === "light" ? "dark" : "light");
|
|
3474
|
-
};
|
|
3475
|
-
const theme = useMemo4(() => buildMuiTheme(themeConfig), [themeConfig]);
|
|
3476
|
-
const displayState = {
|
|
3477
|
-
isMobile: useMediaQuery(theme.breakpoints.down("sm")),
|
|
3478
|
-
isTablet: useMediaQuery(theme.breakpoints.between("sm", "md")),
|
|
3479
|
-
isDesktop: useMediaQuery(theme.breakpoints.between("md", "lg")),
|
|
3480
|
-
isWideDesktop: useMediaQuery(theme.breakpoints.between("lg", "xl")),
|
|
3481
|
-
isSuperWideDesktop: useMediaQuery(theme.breakpoints.up("xl"))
|
|
3482
|
-
};
|
|
3483
|
-
return /* @__PURE__ */ jsx10(ThemeContext.Provider, { value: { mode, toggleTheme, setMode, theme, themeConfig, setThemeConfig, displayState }, children: /* @__PURE__ */ jsxs3(MuiThemeProvider, { theme, children: [
|
|
3484
|
-
/* @__PURE__ */ jsx10(CssBaseline, {}),
|
|
3485
|
-
children
|
|
3486
|
-
] }) });
|
|
3487
|
-
};
|
|
3488
|
-
var useAppTheme = () => {
|
|
3489
|
-
const context = useContext7(ThemeContext);
|
|
3490
|
-
if (!context) {
|
|
3491
|
-
throw new Error("useAppTheme should be used within the ThemeProvider");
|
|
3492
|
-
}
|
|
3493
|
-
return context;
|
|
3494
|
-
};
|
|
3495
|
-
|
|
3496
|
-
// src/context/BreadcrumbProvider.tsx
|
|
3497
|
-
import { createContext as createContext8, useContext as useContext8, useState as useState7 } from "react";
|
|
3498
|
-
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
3499
|
-
var BreadcrumbContext = createContext8({
|
|
3500
|
-
breadcrumbTitles: {},
|
|
3501
|
-
setBreadcrumbTitle: () => {
|
|
3502
|
-
}
|
|
3503
|
-
});
|
|
3504
|
-
var BreadcrumbProvider = ({ children }) => {
|
|
3505
|
-
const [breadcrumbTitles, setBreadcrumbTitles] = useState7({});
|
|
3506
|
-
const setBreadcrumbTitle = (path, title) => {
|
|
3507
|
-
setBreadcrumbTitles((prev) => {
|
|
3508
|
-
if (prev[path] === title) return prev;
|
|
3509
|
-
return { ...prev, [path]: title };
|
|
3510
|
-
});
|
|
3511
|
-
};
|
|
3512
|
-
return /* @__PURE__ */ jsx11(BreadcrumbContext.Provider, { value: { breadcrumbTitles, setBreadcrumbTitle }, children });
|
|
3513
|
-
};
|
|
3514
|
-
var useBreadcrumb = () => useContext8(BreadcrumbContext);
|
|
3515
|
-
|
|
3516
|
-
// src/context/ToastProvider.tsx
|
|
3517
|
-
import { createContext as createContext9, useContext as useContext9, useState as useState8, useCallback as useCallback3, useMemo as useMemo5 } from "react";
|
|
3518
|
-
import { Snackbar, Alert as Alert2 } from "@mui/material";
|
|
3519
|
-
import { jsx as jsx12, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
3520
|
-
var ToastContext = createContext9(void 0);
|
|
3521
|
-
var ToastProvider = ({ children }) => {
|
|
3522
|
-
const [toast, setToast] = useState8(null);
|
|
3523
|
-
const showToast = useCallback3((text, type = "info") => {
|
|
3524
|
-
setToast({ text, type });
|
|
3525
|
-
}, []);
|
|
3526
|
-
const hideToast = useCallback3(() => {
|
|
3527
|
-
setToast(null);
|
|
3528
|
-
}, []);
|
|
3529
|
-
const contextValue = useMemo5(() => ({
|
|
3530
|
-
showToast,
|
|
3531
|
-
hideToast
|
|
3532
|
-
}), [showToast, hideToast]);
|
|
3533
|
-
return /* @__PURE__ */ jsxs4(ToastContext.Provider, { value: contextValue, children: [
|
|
3534
|
-
children,
|
|
3535
|
-
/* @__PURE__ */ jsx12(
|
|
3536
|
-
Snackbar,
|
|
3537
|
-
{
|
|
3538
|
-
open: Boolean(toast),
|
|
3539
|
-
autoHideDuration: 3500,
|
|
3540
|
-
onClose: hideToast,
|
|
3541
|
-
anchorOrigin: { vertical: "bottom", horizontal: "center" },
|
|
3542
|
-
children: /* @__PURE__ */ jsx12(
|
|
3543
|
-
Alert2,
|
|
3544
|
-
{
|
|
3545
|
-
severity: toast?.type || "info",
|
|
3546
|
-
variant: "filled",
|
|
3547
|
-
onClose: hideToast,
|
|
3548
|
-
children: toast?.text
|
|
3549
|
-
}
|
|
3550
|
-
)
|
|
3551
|
-
}
|
|
3552
|
-
)
|
|
3553
|
-
] });
|
|
3554
|
-
};
|
|
3555
|
-
var useToast = () => {
|
|
3556
|
-
const context = useContext9(ToastContext);
|
|
3557
|
-
if (!context) {
|
|
3558
|
-
throw new Error("useToast must be used within a ToastProvider");
|
|
3559
|
-
}
|
|
3560
|
-
return context;
|
|
3561
|
-
};
|
|
3562
|
-
|
|
3563
|
-
// src/context/ConfirmationProvider.tsx
|
|
3564
|
-
import { createContext as createContext10, useContext as useContext10, useState as useState9, useCallback as useCallback4 } from "react";
|
|
3565
|
-
import {
|
|
3566
|
-
Button as Button2,
|
|
3567
|
-
Dialog as Dialog2,
|
|
3568
|
-
DialogActions as DialogActions2,
|
|
3569
|
-
DialogContent as DialogContent2,
|
|
3570
|
-
DialogContentText,
|
|
3571
|
-
DialogTitle as DialogTitle2,
|
|
3572
|
-
Box as Box3
|
|
3573
|
-
} from "@mui/material";
|
|
3574
|
-
import {
|
|
3575
|
-
Error as ErrorIcon,
|
|
3576
|
-
WarningAmberOutlined as WarningIcon,
|
|
3577
|
-
InfoOutlined as InfoIcon,
|
|
3578
|
-
CheckCircleOutlined as SuccessIcon
|
|
3579
|
-
} from "@mui/icons-material";
|
|
3580
|
-
import { jsx as jsx13, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
3581
|
-
var ConfirmContext = createContext10(null);
|
|
3582
|
-
var SEVERITY_ICONS = {
|
|
3583
|
-
error: /* @__PURE__ */ jsx13(ErrorIcon, { color: "error", sx: { fontSize: 40 } }),
|
|
3584
|
-
warning: /* @__PURE__ */ jsx13(WarningIcon, { color: "warning", sx: { fontSize: 40 } }),
|
|
3585
|
-
info: /* @__PURE__ */ jsx13(InfoIcon, { color: "info", sx: { fontSize: 40 } }),
|
|
3586
|
-
success: /* @__PURE__ */ jsx13(SuccessIcon, { color: "success", sx: { fontSize: 40 } })
|
|
3587
|
-
};
|
|
3588
|
-
var ConfirmationProvider = ({ children }) => {
|
|
3589
|
-
const [open, setOpen] = useState9(false);
|
|
3590
|
-
const [options, setOptions] = useState9(null);
|
|
3591
|
-
const [resolver, setResolver] = useState9(null);
|
|
3592
|
-
const confirm = useCallback4((opts) => {
|
|
3593
|
-
setOptions(opts);
|
|
3594
|
-
setOpen(true);
|
|
3595
|
-
return new Promise((resolve) => {
|
|
3596
|
-
setResolver(() => resolve);
|
|
3597
|
-
});
|
|
3598
|
-
}, []);
|
|
3599
|
-
const handleClose = (result) => {
|
|
3600
|
-
setOpen(false);
|
|
3601
|
-
if (resolver) {
|
|
3602
|
-
resolver(result);
|
|
3603
|
-
}
|
|
3604
|
-
};
|
|
3605
|
-
const severityType = options?.type || "info";
|
|
3606
|
-
return /* @__PURE__ */ jsxs5(ConfirmContext.Provider, { value: { confirm }, children: [
|
|
3607
|
-
children,
|
|
3608
|
-
/* @__PURE__ */ jsxs5(
|
|
3609
|
-
Dialog2,
|
|
3610
|
-
{
|
|
3611
|
-
open,
|
|
3612
|
-
onClose: () => handleClose("cancel"),
|
|
3613
|
-
maxWidth: "xs",
|
|
3614
|
-
fullWidth: true,
|
|
3615
|
-
disableEnforceFocus: true,
|
|
3616
|
-
disableRestoreFocus: true,
|
|
3617
|
-
children: [
|
|
3618
|
-
/* @__PURE__ */ jsxs5(DialogTitle2, { sx: { display: "flex", alignItems: "center", gap: 1.5, pb: 1 }, children: [
|
|
3619
|
-
SEVERITY_ICONS[severityType],
|
|
3620
|
-
/* @__PURE__ */ jsx13(Box3, { component: "span", sx: { fontWeight: 600 }, children: options?.title || /* @__PURE__ */ jsx13(TranslateText, { children: "Confirmation" }) })
|
|
3621
|
-
] }),
|
|
3622
|
-
/* @__PURE__ */ jsx13(DialogContent2, { sx: { py: 2 }, dividers: true, children: /* @__PURE__ */ jsx13(DialogContentText, { color: "text.secondary", children: options?.message }) }),
|
|
3623
|
-
/* @__PURE__ */ jsxs5(DialogActions2, { sx: { pt: 2, px: 2, justifyContent: "flex-end", gap: 1 }, children: [
|
|
3624
|
-
(options?.showCancelButton ?? true) && /* @__PURE__ */ jsx13(
|
|
3625
|
-
Button2,
|
|
3626
|
-
{
|
|
3627
|
-
onClick: () => handleClose("cancel"),
|
|
3628
|
-
color: "inherit",
|
|
3629
|
-
variant: "text",
|
|
3630
|
-
children: options?.cancelText || /* @__PURE__ */ jsx13(TranslateText, { children: "Cancel" })
|
|
3631
|
-
}
|
|
3632
|
-
),
|
|
3633
|
-
options?.showNoButton && /* @__PURE__ */ jsx13(
|
|
3634
|
-
Button2,
|
|
3635
|
-
{
|
|
3636
|
-
onClick: () => handleClose("no"),
|
|
3637
|
-
color: "inherit",
|
|
3638
|
-
variant: "outlined",
|
|
3639
|
-
children: options?.noText || /* @__PURE__ */ jsx13(TranslateText, { children: "No" })
|
|
3640
|
-
}
|
|
3641
|
-
),
|
|
3642
|
-
/* @__PURE__ */ jsx13(
|
|
3643
|
-
Button2,
|
|
3644
|
-
{
|
|
3645
|
-
onClick: () => handleClose("yes"),
|
|
3646
|
-
color: options?.confirmColor || (severityType === "error" ? "error" : "primary"),
|
|
3647
|
-
variant: "contained",
|
|
3648
|
-
autoFocus: true,
|
|
3649
|
-
children: options?.confirmText || /* @__PURE__ */ jsx13(TranslateText, { children: "Yes" })
|
|
3650
|
-
}
|
|
3651
|
-
)
|
|
3652
|
-
] })
|
|
3653
|
-
]
|
|
3654
|
-
}
|
|
3655
|
-
)
|
|
3656
|
-
] });
|
|
3657
|
-
};
|
|
3658
|
-
var useConfirmation = () => {
|
|
3659
|
-
const context = useContext10(ConfirmContext);
|
|
3660
|
-
if (!context) {
|
|
3661
|
-
throw new Error("useConfirm must be used within a ConfirmProvider");
|
|
3662
|
-
}
|
|
3663
|
-
return context.confirm;
|
|
3664
|
-
};
|
|
3665
|
-
|
|
3666
|
-
// src/context/index.ts
|
|
3667
|
-
var Providers = {
|
|
3668
|
-
Supabase: SupabaseProvider,
|
|
3669
|
-
Translate: TranslateProvider,
|
|
3670
|
-
TranslationEdit: TranslationEditProvider,
|
|
3671
|
-
Localization: LocalizationProvider,
|
|
3672
|
-
Theme: ThemeProvider,
|
|
3673
|
-
Breadcrumb: BreadcrumbProvider,
|
|
3674
|
-
Toast: ToastProvider,
|
|
3675
|
-
Confirmation: ConfirmationProvider,
|
|
3676
|
-
AI: AIProvider
|
|
3677
|
-
};
|
|
3678
|
-
|
|
3679
|
-
// src/UI/components/data.display/UserStatusChipComponent.tsx
|
|
3680
|
-
import { Chip, IconButton as IconButton2 } from "@mui/material";
|
|
3681
|
-
import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";
|
|
3682
|
-
import { jsx as jsx14 } from "react/jsx-runtime";
|
|
3683
|
-
var UserStatusChipComponent = ({ overrideNamespace, state }) => {
|
|
3684
|
-
const confirm = useConfirmation();
|
|
3685
|
-
const handleShowReason = async (e) => {
|
|
3686
|
-
e.stopPropagation();
|
|
3687
|
-
if (!state.locked_reason) return;
|
|
3688
|
-
await confirm({
|
|
3689
|
-
title: /* @__PURE__ */ jsx14(TranslateText, { overrideNamespace: overrideNamespace || "system_widgets", children: "Lock Reason" }),
|
|
3690
|
-
message: state.locked_reason,
|
|
3691
|
-
type: "info",
|
|
3692
|
-
confirmText: /* @__PURE__ */ jsx14(TranslateText, { overrideNamespace: overrideNamespace || "system_widgets", children: "OK" }),
|
|
3693
|
-
showNoButton: false,
|
|
3694
|
-
showCancelButton: false
|
|
3695
|
-
});
|
|
3696
|
-
};
|
|
3697
|
-
if (state.profile_archived) {
|
|
3698
|
-
return /* @__PURE__ */ jsx14(
|
|
3699
|
-
Chip,
|
|
3700
|
-
{
|
|
3701
|
-
label: /* @__PURE__ */ jsx14(TranslateText, { overrideNamespace: overrideNamespace || "system_widgets", children: "Archived" }),
|
|
3702
|
-
color: "default",
|
|
3703
|
-
size: "small",
|
|
3704
|
-
variant: "filled"
|
|
3705
|
-
}
|
|
3706
|
-
);
|
|
3707
|
-
}
|
|
3708
|
-
if (state.profile_locked) {
|
|
3709
|
-
return /* @__PURE__ */ jsx14(
|
|
3710
|
-
Chip,
|
|
3711
|
-
{
|
|
3712
|
-
label: /* @__PURE__ */ jsx14(TranslateText, { overrideNamespace: overrideNamespace || "system_widgets", children: "System Locked" }),
|
|
3713
|
-
color: "error",
|
|
3714
|
-
size: "small",
|
|
3715
|
-
variant: "filled"
|
|
3716
|
-
}
|
|
3717
|
-
);
|
|
3718
|
-
}
|
|
3719
|
-
if (state.excluded) {
|
|
3720
|
-
return /* @__PURE__ */ jsx14(
|
|
3721
|
-
Chip,
|
|
3722
|
-
{
|
|
3723
|
-
label: /* @__PURE__ */ jsx14(TranslateText, { overrideNamespace: overrideNamespace || "system_widgets", children: "Excluded" }),
|
|
3724
|
-
size: "small"
|
|
3725
|
-
}
|
|
3726
|
-
);
|
|
3727
|
-
}
|
|
3728
|
-
if (state.locked) {
|
|
3729
|
-
return /* @__PURE__ */ jsx14(
|
|
3730
|
-
Chip,
|
|
3731
|
-
{
|
|
3732
|
-
label: /* @__PURE__ */ jsx14(TranslateText, { overrideNamespace: overrideNamespace || "system_widgets", children: "Locked" }),
|
|
3733
|
-
color: "error",
|
|
3734
|
-
size: "small",
|
|
3735
|
-
onDelete: state.locked_reason ? handleShowReason : void 0,
|
|
3736
|
-
deleteIcon: state.locked_reason ? /* @__PURE__ */ jsx14(IconButton2, { size: "small", component: "span", sx: { p: 0.2 }, children: /* @__PURE__ */ jsx14(InfoOutlinedIcon, { fontSize: "small" }) }) : void 0
|
|
3737
|
-
}
|
|
3738
|
-
);
|
|
3739
|
-
}
|
|
3740
|
-
return /* @__PURE__ */ jsx14(
|
|
3741
|
-
Chip,
|
|
3742
|
-
{
|
|
3743
|
-
label: /* @__PURE__ */ jsx14(TranslateText, { overrideNamespace: overrideNamespace || "system_widgets", children: "Active" }),
|
|
3744
|
-
color: "success",
|
|
3745
|
-
size: "small",
|
|
3746
|
-
variant: "outlined"
|
|
3747
|
-
}
|
|
3748
|
-
);
|
|
3749
|
-
};
|
|
3750
|
-
|
|
3751
|
-
// src/UI/components/data.display/UserRoleChipComponent.tsx
|
|
3752
|
-
import { Chip as Chip2 } from "@mui/material";
|
|
3753
|
-
import { jsx as jsx15 } from "react/jsx-runtime";
|
|
3754
|
-
var UserRoleChipComponent = ({ overrideNamespace, role }) => {
|
|
3755
|
-
switch (role) {
|
|
3756
|
-
case "superadmin":
|
|
3757
|
-
return /* @__PURE__ */ jsx15(
|
|
3758
|
-
Chip2,
|
|
3759
|
-
{
|
|
3760
|
-
label: /* @__PURE__ */ jsx15(TranslateText, { overrideNamespace: overrideNamespace || "system_widgets", children: "Superadministrator" }),
|
|
3761
|
-
color: "error",
|
|
3762
|
-
size: "small"
|
|
3763
|
-
}
|
|
3764
|
-
);
|
|
3765
|
-
case "admin":
|
|
3766
|
-
return /* @__PURE__ */ jsx15(
|
|
3767
|
-
Chip2,
|
|
3768
|
-
{
|
|
3769
|
-
label: /* @__PURE__ */ jsx15(TranslateText, { overrideNamespace: overrideNamespace || "system_widgets", children: "Administrator" }),
|
|
3770
|
-
color: "primary",
|
|
3771
|
-
size: "small"
|
|
3772
|
-
}
|
|
3773
|
-
);
|
|
3774
|
-
default:
|
|
3775
|
-
return /* @__PURE__ */ jsx15(
|
|
3776
|
-
Chip2,
|
|
3777
|
-
{
|
|
3778
|
-
label: /* @__PURE__ */ jsx15(TranslateText, { overrideNamespace: overrideNamespace || "system_widgets", children: "User" }),
|
|
3779
|
-
variant: "outlined",
|
|
3780
|
-
size: "small"
|
|
3781
|
-
}
|
|
3782
|
-
);
|
|
3783
|
-
}
|
|
3784
|
-
};
|
|
3785
|
-
|
|
3786
|
-
// src/UI/components/buttons/CopyClipboardButtonComponent.tsx
|
|
3787
|
-
import { useState as useState10 } from "react";
|
|
3788
|
-
import { IconButton as IconButton3 } from "@mui/material";
|
|
3789
|
-
import CheckIcon from "@mui/icons-material/Check";
|
|
3790
|
-
import CopyIcon from "@mui/icons-material/ContentCopy";
|
|
3791
|
-
import { jsx as jsx16 } from "react/jsx-runtime";
|
|
3792
|
-
var CopyClipboardButtonComponent = ({
|
|
3793
|
-
overrideNamespace,
|
|
3794
|
-
textToCopy,
|
|
3795
|
-
copyTooltipText = "Copy",
|
|
3796
|
-
copiedTooltipText = "Copied",
|
|
3797
|
-
namespace = "form_components",
|
|
3798
|
-
resetDelay = 2e3,
|
|
3799
|
-
onCopySuccess,
|
|
3800
|
-
size = "small",
|
|
3801
|
-
sx,
|
|
3802
|
-
...iconButtonProps
|
|
3803
|
-
}) => {
|
|
3804
|
-
const [copied, setCopied] = useState10(false);
|
|
3805
|
-
const handleCopy = async (e) => {
|
|
3806
|
-
e.stopPropagation();
|
|
3807
|
-
if (!textToCopy) return;
|
|
3808
|
-
try {
|
|
3809
|
-
await navigator.clipboard.writeText(textToCopy);
|
|
3810
|
-
setCopied(true);
|
|
3811
|
-
if (onCopySuccess) {
|
|
3812
|
-
onCopySuccess(textToCopy);
|
|
3813
|
-
}
|
|
3814
|
-
setTimeout(() => {
|
|
3815
|
-
setCopied(false);
|
|
3816
|
-
}, resetDelay);
|
|
3817
|
-
} catch (error) {
|
|
3818
|
-
console.error("Failed to copy text to clipboard:", error);
|
|
3819
|
-
}
|
|
3820
|
-
};
|
|
3821
|
-
return /* @__PURE__ */ jsx16(TranslatableTooltipComponent, { title: copied ? copiedTooltipText : copyTooltipText, children: /* @__PURE__ */ jsx16("span", { children: /* @__PURE__ */ jsx16(
|
|
3822
|
-
IconButton3,
|
|
3823
|
-
{
|
|
3824
|
-
size,
|
|
3825
|
-
onClick: handleCopy,
|
|
3826
|
-
disabled: !textToCopy || iconButtonProps.disabled,
|
|
3827
|
-
sx: { p: 0.25, ...sx },
|
|
3828
|
-
...iconButtonProps,
|
|
3829
|
-
children: copied ? /* @__PURE__ */ jsx16(CheckIcon, { fontSize: size === "large" ? "medium" : "small", color: "success" }) : /* @__PURE__ */ jsx16(CopyIcon, { fontSize: size === "large" ? "medium" : "small" })
|
|
3830
|
-
}
|
|
3831
|
-
) }) });
|
|
3832
|
-
};
|
|
3833
|
-
|
|
3834
|
-
export {
|
|
3835
|
-
getUserLastSeenAt,
|
|
3836
|
-
SupabaseProvider,
|
|
3837
|
-
useSupabase,
|
|
3838
|
-
useAuth,
|
|
3839
|
-
TranslationEditProvider,
|
|
3840
|
-
useTranslationEdit,
|
|
3841
|
-
translationService,
|
|
3842
|
-
AIProvider,
|
|
3843
|
-
useAI,
|
|
3844
|
-
TranslationDialog,
|
|
3845
|
-
TranslateProvider,
|
|
3846
|
-
useTranslationNamespace,
|
|
3847
|
-
TranslateText,
|
|
3848
|
-
TranslatableTooltipComponent,
|
|
3849
|
-
LocalizationProvider,
|
|
3850
|
-
useLocalization,
|
|
3851
|
-
ThemeProvider,
|
|
3852
|
-
useAppTheme,
|
|
3853
|
-
BreadcrumbProvider,
|
|
3854
|
-
useBreadcrumb,
|
|
3855
|
-
ToastProvider,
|
|
3856
|
-
useToast,
|
|
3857
|
-
ConfirmationProvider,
|
|
3858
|
-
useConfirmation,
|
|
3859
|
-
Providers,
|
|
3860
|
-
UserStatusChipComponent,
|
|
3861
|
-
UserRoleChipComponent,
|
|
3862
|
-
CopyClipboardButtonComponent
|
|
3863
|
-
};
|