@aidc-toolkit/gs1 0.9.7-beta → 0.9.8-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2312 -128
- package/dist/index.d.cts +646 -6
- package/dist/index.d.ts +646 -6
- package/dist/index.js +2286 -105
- package/package.json +5 -4
- package/src/check.ts +24 -9
- package/src/idkey.ts +50 -99
- package/src/index.ts +2 -2
- package/src/locale/en/{locale_strings.ts → locale-strings.ts} +2 -0
- package/src/locale/fr/{locale_strings.ts → locale-strings.ts} +2 -0
- package/src/locale/i18n.ts +39 -6
- package/src/locale/i18next.d.ts +5 -3
- package/test/check.test.ts +9 -8
- package/test/idkey.test.ts +5 -4
- /package/src/{character_set.ts → character-set.ts} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -58,17 +58,2222 @@ __export(src_exports, {
|
|
|
58
58
|
fiveDigitPriceWeightCheckDigit: () => fiveDigitPriceWeightCheckDigit,
|
|
59
59
|
fourDigitPriceWeightCheckDigit: () => fourDigitPriceWeightCheckDigit,
|
|
60
60
|
gs1NS: () => gs1NS,
|
|
61
|
+
gs1Resources: () => gs1Resources,
|
|
61
62
|
hasValidCheckCharacterPair: () => hasValidCheckCharacterPair,
|
|
62
|
-
hasValidCheckDigit: () => hasValidCheckDigit
|
|
63
|
+
hasValidCheckDigit: () => hasValidCheckDigit,
|
|
64
|
+
i18nGS1Init: () => i18nGS1Init,
|
|
65
|
+
i18nextGS1: () => i18nextGS1
|
|
63
66
|
});
|
|
64
67
|
module.exports = __toCommonJS(src_exports);
|
|
65
68
|
|
|
66
69
|
// src/locale/i18n.ts
|
|
67
70
|
var import_core = require("@aidc-toolkit/core");
|
|
71
|
+
var import_utility = require("@aidc-toolkit/utility");
|
|
68
72
|
|
|
69
|
-
//
|
|
73
|
+
// node_modules/i18next/dist/esm/i18next.js
|
|
74
|
+
var isString = (obj) => typeof obj === "string";
|
|
75
|
+
var defer = () => {
|
|
76
|
+
let res;
|
|
77
|
+
let rej;
|
|
78
|
+
const promise = new Promise((resolve, reject) => {
|
|
79
|
+
res = resolve;
|
|
80
|
+
rej = reject;
|
|
81
|
+
});
|
|
82
|
+
promise.resolve = res;
|
|
83
|
+
promise.reject = rej;
|
|
84
|
+
return promise;
|
|
85
|
+
};
|
|
86
|
+
var makeString = (object) => {
|
|
87
|
+
if (object == null) return "";
|
|
88
|
+
return "" + object;
|
|
89
|
+
};
|
|
90
|
+
var copy = (a, s, t2) => {
|
|
91
|
+
a.forEach((m) => {
|
|
92
|
+
if (s[m]) t2[m] = s[m];
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
var lastOfPathSeparatorRegExp = /###/g;
|
|
96
|
+
var cleanKey = (key) => key && key.indexOf("###") > -1 ? key.replace(lastOfPathSeparatorRegExp, ".") : key;
|
|
97
|
+
var canNotTraverseDeeper = (object) => !object || isString(object);
|
|
98
|
+
var getLastOfPath = (object, path, Empty) => {
|
|
99
|
+
const stack = !isString(path) ? path : path.split(".");
|
|
100
|
+
let stackIndex = 0;
|
|
101
|
+
while (stackIndex < stack.length - 1) {
|
|
102
|
+
if (canNotTraverseDeeper(object)) return {};
|
|
103
|
+
const key = cleanKey(stack[stackIndex]);
|
|
104
|
+
if (!object[key] && Empty) object[key] = new Empty();
|
|
105
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
106
|
+
object = object[key];
|
|
107
|
+
} else {
|
|
108
|
+
object = {};
|
|
109
|
+
}
|
|
110
|
+
++stackIndex;
|
|
111
|
+
}
|
|
112
|
+
if (canNotTraverseDeeper(object)) return {};
|
|
113
|
+
return {
|
|
114
|
+
obj: object,
|
|
115
|
+
k: cleanKey(stack[stackIndex])
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
var setPath = (object, path, newValue) => {
|
|
119
|
+
const {
|
|
120
|
+
obj,
|
|
121
|
+
k
|
|
122
|
+
} = getLastOfPath(object, path, Object);
|
|
123
|
+
if (obj !== void 0 || path.length === 1) {
|
|
124
|
+
obj[k] = newValue;
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
let e = path[path.length - 1];
|
|
128
|
+
let p = path.slice(0, path.length - 1);
|
|
129
|
+
let last = getLastOfPath(object, p, Object);
|
|
130
|
+
while (last.obj === void 0 && p.length) {
|
|
131
|
+
e = `${p[p.length - 1]}.${e}`;
|
|
132
|
+
p = p.slice(0, p.length - 1);
|
|
133
|
+
last = getLastOfPath(object, p, Object);
|
|
134
|
+
if (last?.obj && typeof last.obj[`${last.k}.${e}`] !== "undefined") {
|
|
135
|
+
last.obj = void 0;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
last.obj[`${last.k}.${e}`] = newValue;
|
|
139
|
+
};
|
|
140
|
+
var pushPath = (object, path, newValue, concat) => {
|
|
141
|
+
const {
|
|
142
|
+
obj,
|
|
143
|
+
k
|
|
144
|
+
} = getLastOfPath(object, path, Object);
|
|
145
|
+
obj[k] = obj[k] || [];
|
|
146
|
+
obj[k].push(newValue);
|
|
147
|
+
};
|
|
148
|
+
var getPath = (object, path) => {
|
|
149
|
+
const {
|
|
150
|
+
obj,
|
|
151
|
+
k
|
|
152
|
+
} = getLastOfPath(object, path);
|
|
153
|
+
if (!obj) return void 0;
|
|
154
|
+
return obj[k];
|
|
155
|
+
};
|
|
156
|
+
var getPathWithDefaults = (data, defaultData, key) => {
|
|
157
|
+
const value = getPath(data, key);
|
|
158
|
+
if (value !== void 0) {
|
|
159
|
+
return value;
|
|
160
|
+
}
|
|
161
|
+
return getPath(defaultData, key);
|
|
162
|
+
};
|
|
163
|
+
var deepExtend = (target, source, overwrite) => {
|
|
164
|
+
for (const prop in source) {
|
|
165
|
+
if (prop !== "__proto__" && prop !== "constructor") {
|
|
166
|
+
if (prop in target) {
|
|
167
|
+
if (isString(target[prop]) || target[prop] instanceof String || isString(source[prop]) || source[prop] instanceof String) {
|
|
168
|
+
if (overwrite) target[prop] = source[prop];
|
|
169
|
+
} else {
|
|
170
|
+
deepExtend(target[prop], source[prop], overwrite);
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
target[prop] = source[prop];
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return target;
|
|
178
|
+
};
|
|
179
|
+
var regexEscape = (str) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
|
180
|
+
var _entityMap = {
|
|
181
|
+
"&": "&",
|
|
182
|
+
"<": "<",
|
|
183
|
+
">": ">",
|
|
184
|
+
'"': """,
|
|
185
|
+
"'": "'",
|
|
186
|
+
"/": "/"
|
|
187
|
+
};
|
|
188
|
+
var escape = (data) => {
|
|
189
|
+
if (isString(data)) {
|
|
190
|
+
return data.replace(/[&<>"'\/]/g, (s) => _entityMap[s]);
|
|
191
|
+
}
|
|
192
|
+
return data;
|
|
193
|
+
};
|
|
194
|
+
var RegExpCache = class {
|
|
195
|
+
constructor(capacity) {
|
|
196
|
+
this.capacity = capacity;
|
|
197
|
+
this.regExpMap = /* @__PURE__ */ new Map();
|
|
198
|
+
this.regExpQueue = [];
|
|
199
|
+
}
|
|
200
|
+
getRegExp(pattern) {
|
|
201
|
+
const regExpFromCache = this.regExpMap.get(pattern);
|
|
202
|
+
if (regExpFromCache !== void 0) {
|
|
203
|
+
return regExpFromCache;
|
|
204
|
+
}
|
|
205
|
+
const regExpNew = new RegExp(pattern);
|
|
206
|
+
if (this.regExpQueue.length === this.capacity) {
|
|
207
|
+
this.regExpMap.delete(this.regExpQueue.shift());
|
|
208
|
+
}
|
|
209
|
+
this.regExpMap.set(pattern, regExpNew);
|
|
210
|
+
this.regExpQueue.push(pattern);
|
|
211
|
+
return regExpNew;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
var chars = [" ", ",", "?", "!", ";"];
|
|
215
|
+
var looksLikeObjectPathRegExpCache = new RegExpCache(20);
|
|
216
|
+
var looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
|
|
217
|
+
nsSeparator = nsSeparator || "";
|
|
218
|
+
keySeparator = keySeparator || "";
|
|
219
|
+
const possibleChars = chars.filter((c) => nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0);
|
|
220
|
+
if (possibleChars.length === 0) return true;
|
|
221
|
+
const r = looksLikeObjectPathRegExpCache.getRegExp(`(${possibleChars.map((c) => c === "?" ? "\\?" : c).join("|")})`);
|
|
222
|
+
let matched = !r.test(key);
|
|
223
|
+
if (!matched) {
|
|
224
|
+
const ki = key.indexOf(keySeparator);
|
|
225
|
+
if (ki > 0 && !r.test(key.substring(0, ki))) {
|
|
226
|
+
matched = true;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return matched;
|
|
230
|
+
};
|
|
231
|
+
var deepFind = function(obj, path) {
|
|
232
|
+
let keySeparator = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : ".";
|
|
233
|
+
if (!obj) return void 0;
|
|
234
|
+
if (obj[path]) return obj[path];
|
|
235
|
+
const tokens = path.split(keySeparator);
|
|
236
|
+
let current = obj;
|
|
237
|
+
for (let i = 0; i < tokens.length; ) {
|
|
238
|
+
if (!current || typeof current !== "object") {
|
|
239
|
+
return void 0;
|
|
240
|
+
}
|
|
241
|
+
let next;
|
|
242
|
+
let nextPath = "";
|
|
243
|
+
for (let j = i; j < tokens.length; ++j) {
|
|
244
|
+
if (j !== i) {
|
|
245
|
+
nextPath += keySeparator;
|
|
246
|
+
}
|
|
247
|
+
nextPath += tokens[j];
|
|
248
|
+
next = current[nextPath];
|
|
249
|
+
if (next !== void 0) {
|
|
250
|
+
if (["string", "number", "boolean"].indexOf(typeof next) > -1 && j < tokens.length - 1) {
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
i += j - i + 1;
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
current = next;
|
|
258
|
+
}
|
|
259
|
+
return current;
|
|
260
|
+
};
|
|
261
|
+
var getCleanedCode = (code) => code?.replace("_", "-");
|
|
262
|
+
var consoleLogger = {
|
|
263
|
+
type: "logger",
|
|
264
|
+
log(args) {
|
|
265
|
+
this.output("log", args);
|
|
266
|
+
},
|
|
267
|
+
warn(args) {
|
|
268
|
+
this.output("warn", args);
|
|
269
|
+
},
|
|
270
|
+
error(args) {
|
|
271
|
+
this.output("error", args);
|
|
272
|
+
},
|
|
273
|
+
output(type, args) {
|
|
274
|
+
console?.[type]?.apply?.(console, args);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
var Logger = class _Logger {
|
|
278
|
+
constructor(concreteLogger) {
|
|
279
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
280
|
+
this.init(concreteLogger, options);
|
|
281
|
+
}
|
|
282
|
+
init(concreteLogger) {
|
|
283
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
284
|
+
this.prefix = options.prefix || "i18next:";
|
|
285
|
+
this.logger = concreteLogger || consoleLogger;
|
|
286
|
+
this.options = options;
|
|
287
|
+
this.debug = options.debug;
|
|
288
|
+
}
|
|
289
|
+
log() {
|
|
290
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
291
|
+
args[_key] = arguments[_key];
|
|
292
|
+
}
|
|
293
|
+
return this.forward(args, "log", "", true);
|
|
294
|
+
}
|
|
295
|
+
warn() {
|
|
296
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
297
|
+
args[_key2] = arguments[_key2];
|
|
298
|
+
}
|
|
299
|
+
return this.forward(args, "warn", "", true);
|
|
300
|
+
}
|
|
301
|
+
error() {
|
|
302
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
303
|
+
args[_key3] = arguments[_key3];
|
|
304
|
+
}
|
|
305
|
+
return this.forward(args, "error", "");
|
|
306
|
+
}
|
|
307
|
+
deprecate() {
|
|
308
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
309
|
+
args[_key4] = arguments[_key4];
|
|
310
|
+
}
|
|
311
|
+
return this.forward(args, "warn", "WARNING DEPRECATED: ", true);
|
|
312
|
+
}
|
|
313
|
+
forward(args, lvl, prefix, debugOnly) {
|
|
314
|
+
if (debugOnly && !this.debug) return null;
|
|
315
|
+
if (isString(args[0])) args[0] = `${prefix}${this.prefix} ${args[0]}`;
|
|
316
|
+
return this.logger[lvl](args);
|
|
317
|
+
}
|
|
318
|
+
create(moduleName) {
|
|
319
|
+
return new _Logger(this.logger, {
|
|
320
|
+
...{
|
|
321
|
+
prefix: `${this.prefix}:${moduleName}:`
|
|
322
|
+
},
|
|
323
|
+
...this.options
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
clone(options) {
|
|
327
|
+
options = options || this.options;
|
|
328
|
+
options.prefix = options.prefix || this.prefix;
|
|
329
|
+
return new _Logger(this.logger, options);
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
var baseLogger = new Logger();
|
|
333
|
+
var EventEmitter = class {
|
|
334
|
+
constructor() {
|
|
335
|
+
this.observers = {};
|
|
336
|
+
}
|
|
337
|
+
on(events, listener) {
|
|
338
|
+
events.split(" ").forEach((event) => {
|
|
339
|
+
if (!this.observers[event]) this.observers[event] = /* @__PURE__ */ new Map();
|
|
340
|
+
const numListeners = this.observers[event].get(listener) || 0;
|
|
341
|
+
this.observers[event].set(listener, numListeners + 1);
|
|
342
|
+
});
|
|
343
|
+
return this;
|
|
344
|
+
}
|
|
345
|
+
off(event, listener) {
|
|
346
|
+
if (!this.observers[event]) return;
|
|
347
|
+
if (!listener) {
|
|
348
|
+
delete this.observers[event];
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
this.observers[event].delete(listener);
|
|
352
|
+
}
|
|
353
|
+
emit(event) {
|
|
354
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
355
|
+
args[_key - 1] = arguments[_key];
|
|
356
|
+
}
|
|
357
|
+
if (this.observers[event]) {
|
|
358
|
+
const cloned = Array.from(this.observers[event].entries());
|
|
359
|
+
cloned.forEach((_ref) => {
|
|
360
|
+
let [observer, numTimesAdded] = _ref;
|
|
361
|
+
for (let i = 0; i < numTimesAdded; i++) {
|
|
362
|
+
observer(...args);
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
if (this.observers["*"]) {
|
|
367
|
+
const cloned = Array.from(this.observers["*"].entries());
|
|
368
|
+
cloned.forEach((_ref2) => {
|
|
369
|
+
let [observer, numTimesAdded] = _ref2;
|
|
370
|
+
for (let i = 0; i < numTimesAdded; i++) {
|
|
371
|
+
observer.apply(observer, [event, ...args]);
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
var ResourceStore = class extends EventEmitter {
|
|
378
|
+
constructor(data) {
|
|
379
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
|
|
380
|
+
ns: ["translation"],
|
|
381
|
+
defaultNS: "translation"
|
|
382
|
+
};
|
|
383
|
+
super();
|
|
384
|
+
this.data = data || {};
|
|
385
|
+
this.options = options;
|
|
386
|
+
if (this.options.keySeparator === void 0) {
|
|
387
|
+
this.options.keySeparator = ".";
|
|
388
|
+
}
|
|
389
|
+
if (this.options.ignoreJSONStructure === void 0) {
|
|
390
|
+
this.options.ignoreJSONStructure = true;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
addNamespaces(ns) {
|
|
394
|
+
if (this.options.ns.indexOf(ns) < 0) {
|
|
395
|
+
this.options.ns.push(ns);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
removeNamespaces(ns) {
|
|
399
|
+
const index = this.options.ns.indexOf(ns);
|
|
400
|
+
if (index > -1) {
|
|
401
|
+
this.options.ns.splice(index, 1);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
getResource(lng, ns, key) {
|
|
405
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
406
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
407
|
+
const ignoreJSONStructure = options.ignoreJSONStructure !== void 0 ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
408
|
+
let path;
|
|
409
|
+
if (lng.indexOf(".") > -1) {
|
|
410
|
+
path = lng.split(".");
|
|
411
|
+
} else {
|
|
412
|
+
path = [lng, ns];
|
|
413
|
+
if (key) {
|
|
414
|
+
if (Array.isArray(key)) {
|
|
415
|
+
path.push(...key);
|
|
416
|
+
} else if (isString(key) && keySeparator) {
|
|
417
|
+
path.push(...key.split(keySeparator));
|
|
418
|
+
} else {
|
|
419
|
+
path.push(key);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
const result = getPath(this.data, path);
|
|
424
|
+
if (!result && !ns && !key && lng.indexOf(".") > -1) {
|
|
425
|
+
lng = path[0];
|
|
426
|
+
ns = path[1];
|
|
427
|
+
key = path.slice(2).join(".");
|
|
428
|
+
}
|
|
429
|
+
if (result || !ignoreJSONStructure || !isString(key)) return result;
|
|
430
|
+
return deepFind(this.data?.[lng]?.[ns], key, keySeparator);
|
|
431
|
+
}
|
|
432
|
+
addResource(lng, ns, key, value) {
|
|
433
|
+
let options = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : {
|
|
434
|
+
silent: false
|
|
435
|
+
};
|
|
436
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
437
|
+
let path = [lng, ns];
|
|
438
|
+
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
439
|
+
if (lng.indexOf(".") > -1) {
|
|
440
|
+
path = lng.split(".");
|
|
441
|
+
value = ns;
|
|
442
|
+
ns = path[1];
|
|
443
|
+
}
|
|
444
|
+
this.addNamespaces(ns);
|
|
445
|
+
setPath(this.data, path, value);
|
|
446
|
+
if (!options.silent) this.emit("added", lng, ns, key, value);
|
|
447
|
+
}
|
|
448
|
+
addResources(lng, ns, resources) {
|
|
449
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {
|
|
450
|
+
silent: false
|
|
451
|
+
};
|
|
452
|
+
for (const m in resources) {
|
|
453
|
+
if (isString(resources[m]) || Array.isArray(resources[m])) this.addResource(lng, ns, m, resources[m], {
|
|
454
|
+
silent: true
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
if (!options.silent) this.emit("added", lng, ns, resources);
|
|
458
|
+
}
|
|
459
|
+
addResourceBundle(lng, ns, resources, deep, overwrite) {
|
|
460
|
+
let options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {
|
|
461
|
+
silent: false,
|
|
462
|
+
skipCopy: false
|
|
463
|
+
};
|
|
464
|
+
let path = [lng, ns];
|
|
465
|
+
if (lng.indexOf(".") > -1) {
|
|
466
|
+
path = lng.split(".");
|
|
467
|
+
deep = resources;
|
|
468
|
+
resources = ns;
|
|
469
|
+
ns = path[1];
|
|
470
|
+
}
|
|
471
|
+
this.addNamespaces(ns);
|
|
472
|
+
let pack = getPath(this.data, path) || {};
|
|
473
|
+
if (!options.skipCopy) resources = JSON.parse(JSON.stringify(resources));
|
|
474
|
+
if (deep) {
|
|
475
|
+
deepExtend(pack, resources, overwrite);
|
|
476
|
+
} else {
|
|
477
|
+
pack = {
|
|
478
|
+
...pack,
|
|
479
|
+
...resources
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
setPath(this.data, path, pack);
|
|
483
|
+
if (!options.silent) this.emit("added", lng, ns, resources);
|
|
484
|
+
}
|
|
485
|
+
removeResourceBundle(lng, ns) {
|
|
486
|
+
if (this.hasResourceBundle(lng, ns)) {
|
|
487
|
+
delete this.data[lng][ns];
|
|
488
|
+
}
|
|
489
|
+
this.removeNamespaces(ns);
|
|
490
|
+
this.emit("removed", lng, ns);
|
|
491
|
+
}
|
|
492
|
+
hasResourceBundle(lng, ns) {
|
|
493
|
+
return this.getResource(lng, ns) !== void 0;
|
|
494
|
+
}
|
|
495
|
+
getResourceBundle(lng, ns) {
|
|
496
|
+
if (!ns) ns = this.options.defaultNS;
|
|
497
|
+
return this.getResource(lng, ns);
|
|
498
|
+
}
|
|
499
|
+
getDataByLanguage(lng) {
|
|
500
|
+
return this.data[lng];
|
|
501
|
+
}
|
|
502
|
+
hasLanguageSomeTranslations(lng) {
|
|
503
|
+
const data = this.getDataByLanguage(lng);
|
|
504
|
+
const n = data && Object.keys(data) || [];
|
|
505
|
+
return !!n.find((v) => data[v] && Object.keys(data[v]).length > 0);
|
|
506
|
+
}
|
|
507
|
+
toJSON() {
|
|
508
|
+
return this.data;
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
var postProcessor = {
|
|
512
|
+
processors: {},
|
|
513
|
+
addPostProcessor(module2) {
|
|
514
|
+
this.processors[module2.name] = module2;
|
|
515
|
+
},
|
|
516
|
+
handle(processors, value, key, options, translator) {
|
|
517
|
+
processors.forEach((processor) => {
|
|
518
|
+
value = this.processors[processor]?.process(value, key, options, translator) ?? value;
|
|
519
|
+
});
|
|
520
|
+
return value;
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
var checkedLoadedFor = {};
|
|
524
|
+
var Translator = class _Translator extends EventEmitter {
|
|
525
|
+
constructor(services) {
|
|
526
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
527
|
+
super();
|
|
528
|
+
copy(["resourceStore", "languageUtils", "pluralResolver", "interpolator", "backendConnector", "i18nFormat", "utils"], services, this);
|
|
529
|
+
this.options = options;
|
|
530
|
+
if (this.options.keySeparator === void 0) {
|
|
531
|
+
this.options.keySeparator = ".";
|
|
532
|
+
}
|
|
533
|
+
this.logger = baseLogger.create("translator");
|
|
534
|
+
}
|
|
535
|
+
changeLanguage(lng) {
|
|
536
|
+
if (lng) this.language = lng;
|
|
537
|
+
}
|
|
538
|
+
exists(key) {
|
|
539
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
|
|
540
|
+
interpolation: {}
|
|
541
|
+
};
|
|
542
|
+
if (key === void 0 || key === null) {
|
|
543
|
+
return false;
|
|
544
|
+
}
|
|
545
|
+
const resolved = this.resolve(key, options);
|
|
546
|
+
return resolved?.res !== void 0;
|
|
547
|
+
}
|
|
548
|
+
extractFromKey(key, options) {
|
|
549
|
+
let nsSeparator = options.nsSeparator !== void 0 ? options.nsSeparator : this.options.nsSeparator;
|
|
550
|
+
if (nsSeparator === void 0) nsSeparator = ":";
|
|
551
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
552
|
+
let namespaces = options.ns || this.options.defaultNS || [];
|
|
553
|
+
const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
|
|
554
|
+
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
555
|
+
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
556
|
+
const m = key.match(this.interpolator.nestingRegexp);
|
|
557
|
+
if (m && m.length > 0) {
|
|
558
|
+
return {
|
|
559
|
+
key,
|
|
560
|
+
namespaces: isString(namespaces) ? [namespaces] : namespaces
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
const parts = key.split(nsSeparator);
|
|
564
|
+
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
|
|
565
|
+
key = parts.join(keySeparator);
|
|
566
|
+
}
|
|
567
|
+
return {
|
|
568
|
+
key,
|
|
569
|
+
namespaces: isString(namespaces) ? [namespaces] : namespaces
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
translate(keys, options, lastKey) {
|
|
573
|
+
if (typeof options !== "object" && this.options.overloadTranslationOptionHandler) {
|
|
574
|
+
options = this.options.overloadTranslationOptionHandler(arguments);
|
|
575
|
+
}
|
|
576
|
+
if (typeof options === "object") options = {
|
|
577
|
+
...options
|
|
578
|
+
};
|
|
579
|
+
if (!options) options = {};
|
|
580
|
+
if (keys === void 0 || keys === null) return "";
|
|
581
|
+
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
582
|
+
const returnDetails = options.returnDetails !== void 0 ? options.returnDetails : this.options.returnDetails;
|
|
583
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
584
|
+
const {
|
|
585
|
+
key,
|
|
586
|
+
namespaces
|
|
587
|
+
} = this.extractFromKey(keys[keys.length - 1], options);
|
|
588
|
+
const namespace = namespaces[namespaces.length - 1];
|
|
589
|
+
const lng = options.lng || this.language;
|
|
590
|
+
const appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
591
|
+
if (lng?.toLowerCase() === "cimode") {
|
|
592
|
+
if (appendNamespaceToCIMode) {
|
|
593
|
+
const nsSeparator = options.nsSeparator || this.options.nsSeparator;
|
|
594
|
+
if (returnDetails) {
|
|
595
|
+
return {
|
|
596
|
+
res: `${namespace}${nsSeparator}${key}`,
|
|
597
|
+
usedKey: key,
|
|
598
|
+
exactUsedKey: key,
|
|
599
|
+
usedLng: lng,
|
|
600
|
+
usedNS: namespace,
|
|
601
|
+
usedParams: this.getUsedParamsDetails(options)
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
return `${namespace}${nsSeparator}${key}`;
|
|
605
|
+
}
|
|
606
|
+
if (returnDetails) {
|
|
607
|
+
return {
|
|
608
|
+
res: key,
|
|
609
|
+
usedKey: key,
|
|
610
|
+
exactUsedKey: key,
|
|
611
|
+
usedLng: lng,
|
|
612
|
+
usedNS: namespace,
|
|
613
|
+
usedParams: this.getUsedParamsDetails(options)
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
return key;
|
|
617
|
+
}
|
|
618
|
+
const resolved = this.resolve(keys, options);
|
|
619
|
+
let res = resolved?.res;
|
|
620
|
+
const resUsedKey = resolved?.usedKey || key;
|
|
621
|
+
const resExactUsedKey = resolved?.exactUsedKey || key;
|
|
622
|
+
const resType = Object.prototype.toString.apply(res);
|
|
623
|
+
const noObject = ["[object Number]", "[object Function]", "[object RegExp]"];
|
|
624
|
+
const joinArrays = options.joinArrays !== void 0 ? options.joinArrays : this.options.joinArrays;
|
|
625
|
+
const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
626
|
+
const handleAsObject = !isString(res) && typeof res !== "boolean" && typeof res !== "number";
|
|
627
|
+
if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(isString(joinArrays) && Array.isArray(res))) {
|
|
628
|
+
if (!options.returnObjects && !this.options.returnObjects) {
|
|
629
|
+
if (!this.options.returnedObjectHandler) {
|
|
630
|
+
this.logger.warn("accessing an object - but returnObjects options is not enabled!");
|
|
631
|
+
}
|
|
632
|
+
const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, {
|
|
633
|
+
...options,
|
|
634
|
+
ns: namespaces
|
|
635
|
+
}) : `key '${key} (${this.language})' returned an object instead of string.`;
|
|
636
|
+
if (returnDetails) {
|
|
637
|
+
resolved.res = r;
|
|
638
|
+
resolved.usedParams = this.getUsedParamsDetails(options);
|
|
639
|
+
return resolved;
|
|
640
|
+
}
|
|
641
|
+
return r;
|
|
642
|
+
}
|
|
643
|
+
if (keySeparator) {
|
|
644
|
+
const resTypeIsArray = Array.isArray(res);
|
|
645
|
+
const copy2 = resTypeIsArray ? [] : {};
|
|
646
|
+
const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
647
|
+
for (const m in res) {
|
|
648
|
+
if (Object.prototype.hasOwnProperty.call(res, m)) {
|
|
649
|
+
const deepKey = `${newKeyToUse}${keySeparator}${m}`;
|
|
650
|
+
copy2[m] = this.translate(deepKey, {
|
|
651
|
+
...options,
|
|
652
|
+
...{
|
|
653
|
+
joinArrays: false,
|
|
654
|
+
ns: namespaces
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
if (copy2[m] === deepKey) copy2[m] = res[m];
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
res = copy2;
|
|
661
|
+
}
|
|
662
|
+
} else if (handleAsObjectInI18nFormat && isString(joinArrays) && Array.isArray(res)) {
|
|
663
|
+
res = res.join(joinArrays);
|
|
664
|
+
if (res) res = this.extendTranslation(res, keys, options, lastKey);
|
|
665
|
+
} else {
|
|
666
|
+
let usedDefault = false;
|
|
667
|
+
let usedKey = false;
|
|
668
|
+
const needsPluralHandling = options.count !== void 0 && !isString(options.count);
|
|
669
|
+
const hasDefaultValue = _Translator.hasDefaultValue(options);
|
|
670
|
+
const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : "";
|
|
671
|
+
const defaultValueSuffixOrdinalFallback = options.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, {
|
|
672
|
+
ordinal: false
|
|
673
|
+
}) : "";
|
|
674
|
+
const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0;
|
|
675
|
+
const defaultValue = needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] || options[`defaultValue${defaultValueSuffix}`] || options[`defaultValue${defaultValueSuffixOrdinalFallback}`] || options.defaultValue;
|
|
676
|
+
if (!this.isValidLookup(res) && hasDefaultValue) {
|
|
677
|
+
usedDefault = true;
|
|
678
|
+
res = defaultValue;
|
|
679
|
+
}
|
|
680
|
+
if (!this.isValidLookup(res)) {
|
|
681
|
+
usedKey = true;
|
|
682
|
+
res = key;
|
|
683
|
+
}
|
|
684
|
+
const missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
|
|
685
|
+
const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? void 0 : res;
|
|
686
|
+
const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
687
|
+
if (usedKey || usedDefault || updateMissing) {
|
|
688
|
+
this.logger.log(updateMissing ? "updateKey" : "missingKey", lng, namespace, key, updateMissing ? defaultValue : res);
|
|
689
|
+
if (keySeparator) {
|
|
690
|
+
const fk = this.resolve(key, {
|
|
691
|
+
...options,
|
|
692
|
+
keySeparator: false
|
|
693
|
+
});
|
|
694
|
+
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.");
|
|
695
|
+
}
|
|
696
|
+
let lngs = [];
|
|
697
|
+
const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
|
|
698
|
+
if (this.options.saveMissingTo === "fallback" && fallbackLngs && fallbackLngs[0]) {
|
|
699
|
+
for (let i = 0; i < fallbackLngs.length; i++) {
|
|
700
|
+
lngs.push(fallbackLngs[i]);
|
|
701
|
+
}
|
|
702
|
+
} else if (this.options.saveMissingTo === "all") {
|
|
703
|
+
lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
|
|
704
|
+
} else {
|
|
705
|
+
lngs.push(options.lng || this.language);
|
|
706
|
+
}
|
|
707
|
+
const send = (l, k, specificDefaultValue) => {
|
|
708
|
+
const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
709
|
+
if (this.options.missingKeyHandler) {
|
|
710
|
+
this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
711
|
+
} else if (this.backendConnector?.saveMissing) {
|
|
712
|
+
this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
713
|
+
}
|
|
714
|
+
this.emit("missingKey", l, namespace, k, res);
|
|
715
|
+
};
|
|
716
|
+
if (this.options.saveMissing) {
|
|
717
|
+
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
718
|
+
lngs.forEach((language) => {
|
|
719
|
+
const suffixes = this.pluralResolver.getSuffixes(language, options);
|
|
720
|
+
if (needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.indexOf(`${this.options.pluralSeparator}zero`) < 0) {
|
|
721
|
+
suffixes.push(`${this.options.pluralSeparator}zero`);
|
|
722
|
+
}
|
|
723
|
+
suffixes.forEach((suffix) => {
|
|
724
|
+
send([language], key + suffix, options[`defaultValue${suffix}`] || defaultValue);
|
|
725
|
+
});
|
|
726
|
+
});
|
|
727
|
+
} else {
|
|
728
|
+
send(lngs, key, defaultValue);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
res = this.extendTranslation(res, keys, options, resolved, lastKey);
|
|
733
|
+
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
|
|
734
|
+
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
|
|
735
|
+
res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : void 0);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
if (returnDetails) {
|
|
739
|
+
resolved.res = res;
|
|
740
|
+
resolved.usedParams = this.getUsedParamsDetails(options);
|
|
741
|
+
return resolved;
|
|
742
|
+
}
|
|
743
|
+
return res;
|
|
744
|
+
}
|
|
745
|
+
extendTranslation(res, key, options, resolved, lastKey) {
|
|
746
|
+
var _this = this;
|
|
747
|
+
if (this.i18nFormat?.parse) {
|
|
748
|
+
res = this.i18nFormat.parse(res, {
|
|
749
|
+
...this.options.interpolation.defaultVariables,
|
|
750
|
+
...options
|
|
751
|
+
}, options.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
|
|
752
|
+
resolved
|
|
753
|
+
});
|
|
754
|
+
} else if (!options.skipInterpolation) {
|
|
755
|
+
if (options.interpolation) this.interpolator.init({
|
|
756
|
+
...options,
|
|
757
|
+
...{
|
|
758
|
+
interpolation: {
|
|
759
|
+
...this.options.interpolation,
|
|
760
|
+
...options.interpolation
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
});
|
|
764
|
+
const skipOnVariables = isString(res) && (options?.interpolation?.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
765
|
+
let nestBef;
|
|
766
|
+
if (skipOnVariables) {
|
|
767
|
+
const nb = res.match(this.interpolator.nestingRegexp);
|
|
768
|
+
nestBef = nb && nb.length;
|
|
769
|
+
}
|
|
770
|
+
let data = options.replace && !isString(options.replace) ? options.replace : options;
|
|
771
|
+
if (this.options.interpolation.defaultVariables) data = {
|
|
772
|
+
...this.options.interpolation.defaultVariables,
|
|
773
|
+
...data
|
|
774
|
+
};
|
|
775
|
+
res = this.interpolator.interpolate(res, data, options.lng || this.language || resolved.usedLng, options);
|
|
776
|
+
if (skipOnVariables) {
|
|
777
|
+
const na = res.match(this.interpolator.nestingRegexp);
|
|
778
|
+
const nestAft = na && na.length;
|
|
779
|
+
if (nestBef < nestAft) options.nest = false;
|
|
780
|
+
}
|
|
781
|
+
if (!options.lng && resolved && resolved.res) options.lng = this.language || resolved.usedLng;
|
|
782
|
+
if (options.nest !== false) res = this.interpolator.nest(res, function() {
|
|
783
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
784
|
+
args[_key] = arguments[_key];
|
|
785
|
+
}
|
|
786
|
+
if (lastKey?.[0] === args[0] && !options.context) {
|
|
787
|
+
_this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
|
|
788
|
+
return null;
|
|
789
|
+
}
|
|
790
|
+
return _this.translate(...args, key);
|
|
791
|
+
}, options);
|
|
792
|
+
if (options.interpolation) this.interpolator.reset();
|
|
793
|
+
}
|
|
794
|
+
const postProcess = options.postProcess || this.options.postProcess;
|
|
795
|
+
const postProcessorNames = isString(postProcess) ? [postProcess] : postProcess;
|
|
796
|
+
if (res !== void 0 && res !== null && postProcessorNames?.length && options.applyPostProcessor !== false) {
|
|
797
|
+
res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
|
|
798
|
+
i18nResolved: {
|
|
799
|
+
...resolved,
|
|
800
|
+
usedParams: this.getUsedParamsDetails(options)
|
|
801
|
+
},
|
|
802
|
+
...options
|
|
803
|
+
} : options, this);
|
|
804
|
+
}
|
|
805
|
+
return res;
|
|
806
|
+
}
|
|
807
|
+
resolve(keys) {
|
|
808
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
809
|
+
let found;
|
|
810
|
+
let usedKey;
|
|
811
|
+
let exactUsedKey;
|
|
812
|
+
let usedLng;
|
|
813
|
+
let usedNS;
|
|
814
|
+
if (isString(keys)) keys = [keys];
|
|
815
|
+
keys.forEach((k) => {
|
|
816
|
+
if (this.isValidLookup(found)) return;
|
|
817
|
+
const extracted = this.extractFromKey(k, options);
|
|
818
|
+
const key = extracted.key;
|
|
819
|
+
usedKey = key;
|
|
820
|
+
let namespaces = extracted.namespaces;
|
|
821
|
+
if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
|
|
822
|
+
const needsPluralHandling = options.count !== void 0 && !isString(options.count);
|
|
823
|
+
const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0;
|
|
824
|
+
const needsContextHandling = options.context !== void 0 && (isString(options.context) || typeof options.context === "number") && options.context !== "";
|
|
825
|
+
const codes = options.lngs ? options.lngs : this.languageUtils.toResolveHierarchy(options.lng || this.language, options.fallbackLng);
|
|
826
|
+
namespaces.forEach((ns) => {
|
|
827
|
+
if (this.isValidLookup(found)) return;
|
|
828
|
+
usedNS = ns;
|
|
829
|
+
if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils?.hasLoadedNamespace && !this.utils?.hasLoadedNamespace(usedNS)) {
|
|
830
|
+
checkedLoadedFor[`${codes[0]}-${ns}`] = true;
|
|
831
|
+
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!!!");
|
|
832
|
+
}
|
|
833
|
+
codes.forEach((code) => {
|
|
834
|
+
if (this.isValidLookup(found)) return;
|
|
835
|
+
usedLng = code;
|
|
836
|
+
const finalKeys = [key];
|
|
837
|
+
if (this.i18nFormat?.addLookupKeys) {
|
|
838
|
+
this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
|
|
839
|
+
} else {
|
|
840
|
+
let pluralSuffix;
|
|
841
|
+
if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, options.count, options);
|
|
842
|
+
const zeroSuffix = `${this.options.pluralSeparator}zero`;
|
|
843
|
+
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
|
|
844
|
+
if (needsPluralHandling) {
|
|
845
|
+
finalKeys.push(key + pluralSuffix);
|
|
846
|
+
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
847
|
+
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
848
|
+
}
|
|
849
|
+
if (needsZeroSuffixLookup) {
|
|
850
|
+
finalKeys.push(key + zeroSuffix);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
if (needsContextHandling) {
|
|
854
|
+
const contextKey = `${key}${this.options.contextSeparator}${options.context}`;
|
|
855
|
+
finalKeys.push(contextKey);
|
|
856
|
+
if (needsPluralHandling) {
|
|
857
|
+
finalKeys.push(contextKey + pluralSuffix);
|
|
858
|
+
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
859
|
+
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
860
|
+
}
|
|
861
|
+
if (needsZeroSuffixLookup) {
|
|
862
|
+
finalKeys.push(contextKey + zeroSuffix);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
let possibleKey;
|
|
868
|
+
while (possibleKey = finalKeys.pop()) {
|
|
869
|
+
if (!this.isValidLookup(found)) {
|
|
870
|
+
exactUsedKey = possibleKey;
|
|
871
|
+
found = this.getResource(code, ns, possibleKey, options);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
});
|
|
875
|
+
});
|
|
876
|
+
});
|
|
877
|
+
return {
|
|
878
|
+
res: found,
|
|
879
|
+
usedKey,
|
|
880
|
+
exactUsedKey,
|
|
881
|
+
usedLng,
|
|
882
|
+
usedNS
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
isValidLookup(res) {
|
|
886
|
+
return res !== void 0 && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === "");
|
|
887
|
+
}
|
|
888
|
+
getResource(code, ns, key) {
|
|
889
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
890
|
+
if (this.i18nFormat?.getResource) return this.i18nFormat.getResource(code, ns, key, options);
|
|
891
|
+
return this.resourceStore.getResource(code, ns, key, options);
|
|
892
|
+
}
|
|
893
|
+
getUsedParamsDetails() {
|
|
894
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
895
|
+
const optionsKeys = ["defaultValue", "ordinal", "context", "replace", "lng", "lngs", "fallbackLng", "ns", "keySeparator", "nsSeparator", "returnObjects", "returnDetails", "joinArrays", "postProcess", "interpolation"];
|
|
896
|
+
const useOptionsReplaceForData = options.replace && !isString(options.replace);
|
|
897
|
+
let data = useOptionsReplaceForData ? options.replace : options;
|
|
898
|
+
if (useOptionsReplaceForData && typeof options.count !== "undefined") {
|
|
899
|
+
data.count = options.count;
|
|
900
|
+
}
|
|
901
|
+
if (this.options.interpolation.defaultVariables) {
|
|
902
|
+
data = {
|
|
903
|
+
...this.options.interpolation.defaultVariables,
|
|
904
|
+
...data
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
if (!useOptionsReplaceForData) {
|
|
908
|
+
data = {
|
|
909
|
+
...data
|
|
910
|
+
};
|
|
911
|
+
for (const key of optionsKeys) {
|
|
912
|
+
delete data[key];
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
return data;
|
|
916
|
+
}
|
|
917
|
+
static hasDefaultValue(options) {
|
|
918
|
+
const prefix = "defaultValue";
|
|
919
|
+
for (const option in options) {
|
|
920
|
+
if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && void 0 !== options[option]) {
|
|
921
|
+
return true;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
return false;
|
|
925
|
+
}
|
|
926
|
+
};
|
|
927
|
+
var LanguageUtil = class {
|
|
928
|
+
constructor(options) {
|
|
929
|
+
this.options = options;
|
|
930
|
+
this.supportedLngs = this.options.supportedLngs || false;
|
|
931
|
+
this.logger = baseLogger.create("languageUtils");
|
|
932
|
+
}
|
|
933
|
+
getScriptPartFromCode(code) {
|
|
934
|
+
code = getCleanedCode(code);
|
|
935
|
+
if (!code || code.indexOf("-") < 0) return null;
|
|
936
|
+
const p = code.split("-");
|
|
937
|
+
if (p.length === 2) return null;
|
|
938
|
+
p.pop();
|
|
939
|
+
if (p[p.length - 1].toLowerCase() === "x") return null;
|
|
940
|
+
return this.formatLanguageCode(p.join("-"));
|
|
941
|
+
}
|
|
942
|
+
getLanguagePartFromCode(code) {
|
|
943
|
+
code = getCleanedCode(code);
|
|
944
|
+
if (!code || code.indexOf("-") < 0) return code;
|
|
945
|
+
const p = code.split("-");
|
|
946
|
+
return this.formatLanguageCode(p[0]);
|
|
947
|
+
}
|
|
948
|
+
formatLanguageCode(code) {
|
|
949
|
+
if (isString(code) && code.indexOf("-") > -1) {
|
|
950
|
+
let formattedCode;
|
|
951
|
+
try {
|
|
952
|
+
formattedCode = Intl.getCanonicalLocales(code)[0];
|
|
953
|
+
} catch (e) {
|
|
954
|
+
}
|
|
955
|
+
if (formattedCode && this.options.lowerCaseLng) {
|
|
956
|
+
formattedCode = formattedCode.toLowerCase();
|
|
957
|
+
}
|
|
958
|
+
if (formattedCode) return formattedCode;
|
|
959
|
+
if (this.options.lowerCaseLng) {
|
|
960
|
+
return code.toLowerCase();
|
|
961
|
+
}
|
|
962
|
+
return code;
|
|
963
|
+
}
|
|
964
|
+
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
|
|
965
|
+
}
|
|
966
|
+
isSupportedCode(code) {
|
|
967
|
+
if (this.options.load === "languageOnly" || this.options.nonExplicitSupportedLngs) {
|
|
968
|
+
code = this.getLanguagePartFromCode(code);
|
|
969
|
+
}
|
|
970
|
+
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
|
|
971
|
+
}
|
|
972
|
+
getBestMatchFromCodes(codes) {
|
|
973
|
+
if (!codes) return null;
|
|
974
|
+
let found;
|
|
975
|
+
codes.forEach((code) => {
|
|
976
|
+
if (found) return;
|
|
977
|
+
const cleanedLng = this.formatLanguageCode(code);
|
|
978
|
+
if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
|
|
979
|
+
});
|
|
980
|
+
if (!found && this.options.supportedLngs) {
|
|
981
|
+
codes.forEach((code) => {
|
|
982
|
+
if (found) return;
|
|
983
|
+
const lngOnly = this.getLanguagePartFromCode(code);
|
|
984
|
+
if (this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
985
|
+
found = this.options.supportedLngs.find((supportedLng) => {
|
|
986
|
+
if (supportedLng === lngOnly) return supportedLng;
|
|
987
|
+
if (supportedLng.indexOf("-") < 0 && lngOnly.indexOf("-") < 0) return;
|
|
988
|
+
if (supportedLng.indexOf("-") > 0 && lngOnly.indexOf("-") < 0 && supportedLng.substring(0, supportedLng.indexOf("-")) === lngOnly) return supportedLng;
|
|
989
|
+
if (supportedLng.indexOf(lngOnly) === 0 && lngOnly.length > 1) return supportedLng;
|
|
990
|
+
});
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
|
|
994
|
+
return found;
|
|
995
|
+
}
|
|
996
|
+
getFallbackCodes(fallbacks, code) {
|
|
997
|
+
if (!fallbacks) return [];
|
|
998
|
+
if (typeof fallbacks === "function") fallbacks = fallbacks(code);
|
|
999
|
+
if (isString(fallbacks)) fallbacks = [fallbacks];
|
|
1000
|
+
if (Array.isArray(fallbacks)) return fallbacks;
|
|
1001
|
+
if (!code) return fallbacks.default || [];
|
|
1002
|
+
let found = fallbacks[code];
|
|
1003
|
+
if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
|
|
1004
|
+
if (!found) found = fallbacks[this.formatLanguageCode(code)];
|
|
1005
|
+
if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
1006
|
+
if (!found) found = fallbacks.default;
|
|
1007
|
+
return found || [];
|
|
1008
|
+
}
|
|
1009
|
+
toResolveHierarchy(code, fallbackCode) {
|
|
1010
|
+
const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
|
|
1011
|
+
const codes = [];
|
|
1012
|
+
const addCode = (c) => {
|
|
1013
|
+
if (!c) return;
|
|
1014
|
+
if (this.isSupportedCode(c)) {
|
|
1015
|
+
codes.push(c);
|
|
1016
|
+
} else {
|
|
1017
|
+
this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
|
|
1018
|
+
}
|
|
1019
|
+
};
|
|
1020
|
+
if (isString(code) && (code.indexOf("-") > -1 || code.indexOf("_") > -1)) {
|
|
1021
|
+
if (this.options.load !== "languageOnly") addCode(this.formatLanguageCode(code));
|
|
1022
|
+
if (this.options.load !== "languageOnly" && this.options.load !== "currentOnly") addCode(this.getScriptPartFromCode(code));
|
|
1023
|
+
if (this.options.load !== "currentOnly") addCode(this.getLanguagePartFromCode(code));
|
|
1024
|
+
} else if (isString(code)) {
|
|
1025
|
+
addCode(this.formatLanguageCode(code));
|
|
1026
|
+
}
|
|
1027
|
+
fallbackCodes.forEach((fc) => {
|
|
1028
|
+
if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
|
|
1029
|
+
});
|
|
1030
|
+
return codes;
|
|
1031
|
+
}
|
|
1032
|
+
};
|
|
1033
|
+
var suffixesOrder = {
|
|
1034
|
+
zero: 0,
|
|
1035
|
+
one: 1,
|
|
1036
|
+
two: 2,
|
|
1037
|
+
few: 3,
|
|
1038
|
+
many: 4,
|
|
1039
|
+
other: 5
|
|
1040
|
+
};
|
|
1041
|
+
var dummyRule = {
|
|
1042
|
+
select: (count) => count === 1 ? "one" : "other",
|
|
1043
|
+
resolvedOptions: () => ({
|
|
1044
|
+
pluralCategories: ["one", "other"]
|
|
1045
|
+
})
|
|
1046
|
+
};
|
|
1047
|
+
var PluralResolver = class {
|
|
1048
|
+
constructor(languageUtils) {
|
|
1049
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1050
|
+
this.languageUtils = languageUtils;
|
|
1051
|
+
this.options = options;
|
|
1052
|
+
this.logger = baseLogger.create("pluralResolver");
|
|
1053
|
+
this.pluralRulesCache = {};
|
|
1054
|
+
}
|
|
1055
|
+
addRule(lng, obj) {
|
|
1056
|
+
this.rules[lng] = obj;
|
|
1057
|
+
}
|
|
1058
|
+
clearCache() {
|
|
1059
|
+
this.pluralRulesCache = {};
|
|
1060
|
+
}
|
|
1061
|
+
getRule(code) {
|
|
1062
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1063
|
+
const cleanedCode = getCleanedCode(code === "dev" ? "en" : code);
|
|
1064
|
+
const type = options.ordinal ? "ordinal" : "cardinal";
|
|
1065
|
+
const cacheKey = JSON.stringify({
|
|
1066
|
+
cleanedCode,
|
|
1067
|
+
type
|
|
1068
|
+
});
|
|
1069
|
+
if (cacheKey in this.pluralRulesCache) {
|
|
1070
|
+
return this.pluralRulesCache[cacheKey];
|
|
1071
|
+
}
|
|
1072
|
+
let rule;
|
|
1073
|
+
try {
|
|
1074
|
+
rule = new Intl.PluralRules(cleanedCode, {
|
|
1075
|
+
type
|
|
1076
|
+
});
|
|
1077
|
+
} catch (err) {
|
|
1078
|
+
if (!Intl) {
|
|
1079
|
+
this.logger.error("No Intl support, please use an Intl polyfill!");
|
|
1080
|
+
return dummyRule;
|
|
1081
|
+
}
|
|
1082
|
+
if (!code.match(/-|_/)) return dummyRule;
|
|
1083
|
+
const lngPart = this.languageUtils.getLanguagePartFromCode(code);
|
|
1084
|
+
rule = this.getRule(lngPart, options);
|
|
1085
|
+
}
|
|
1086
|
+
this.pluralRulesCache[cacheKey] = rule;
|
|
1087
|
+
return rule;
|
|
1088
|
+
}
|
|
1089
|
+
needsPlural(code) {
|
|
1090
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1091
|
+
let rule = this.getRule(code, options);
|
|
1092
|
+
if (!rule) rule = this.getRule("dev", options);
|
|
1093
|
+
return rule?.resolvedOptions().pluralCategories.length > 1;
|
|
1094
|
+
}
|
|
1095
|
+
getPluralFormsOfKey(code, key) {
|
|
1096
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1097
|
+
return this.getSuffixes(code, options).map((suffix) => `${key}${suffix}`);
|
|
1098
|
+
}
|
|
1099
|
+
getSuffixes(code) {
|
|
1100
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1101
|
+
let rule = this.getRule(code, options);
|
|
1102
|
+
if (!rule) rule = this.getRule("dev", options);
|
|
1103
|
+
if (!rule) return [];
|
|
1104
|
+
return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map((pluralCategory) => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${pluralCategory}`);
|
|
1105
|
+
}
|
|
1106
|
+
getSuffix(code, count) {
|
|
1107
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1108
|
+
const rule = this.getRule(code, options);
|
|
1109
|
+
if (rule) {
|
|
1110
|
+
return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${rule.select(count)}`;
|
|
1111
|
+
}
|
|
1112
|
+
this.logger.warn(`no plural rule found for: ${code}`);
|
|
1113
|
+
return this.getSuffix("dev", count, options);
|
|
1114
|
+
}
|
|
1115
|
+
};
|
|
1116
|
+
var deepFindWithDefaults = function(data, defaultData, key) {
|
|
1117
|
+
let keySeparator = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : ".";
|
|
1118
|
+
let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : true;
|
|
1119
|
+
let path = getPathWithDefaults(data, defaultData, key);
|
|
1120
|
+
if (!path && ignoreJSONStructure && isString(key)) {
|
|
1121
|
+
path = deepFind(data, key, keySeparator);
|
|
1122
|
+
if (path === void 0) path = deepFind(defaultData, key, keySeparator);
|
|
1123
|
+
}
|
|
1124
|
+
return path;
|
|
1125
|
+
};
|
|
1126
|
+
var regexSafe = (val) => val.replace(/\$/g, "$$$$");
|
|
1127
|
+
var Interpolator = class {
|
|
1128
|
+
constructor() {
|
|
1129
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1130
|
+
this.logger = baseLogger.create("interpolator");
|
|
1131
|
+
this.options = options;
|
|
1132
|
+
this.format = options?.interpolation?.format || ((value) => value);
|
|
1133
|
+
this.init(options);
|
|
1134
|
+
}
|
|
1135
|
+
init() {
|
|
1136
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1137
|
+
if (!options.interpolation) options.interpolation = {
|
|
1138
|
+
escapeValue: true
|
|
1139
|
+
};
|
|
1140
|
+
const {
|
|
1141
|
+
escape: escape$1,
|
|
1142
|
+
escapeValue,
|
|
1143
|
+
useRawValueToEscape,
|
|
1144
|
+
prefix,
|
|
1145
|
+
prefixEscaped,
|
|
1146
|
+
suffix,
|
|
1147
|
+
suffixEscaped,
|
|
1148
|
+
formatSeparator,
|
|
1149
|
+
unescapeSuffix,
|
|
1150
|
+
unescapePrefix,
|
|
1151
|
+
nestingPrefix,
|
|
1152
|
+
nestingPrefixEscaped,
|
|
1153
|
+
nestingSuffix,
|
|
1154
|
+
nestingSuffixEscaped,
|
|
1155
|
+
nestingOptionsSeparator,
|
|
1156
|
+
maxReplaces,
|
|
1157
|
+
alwaysFormat
|
|
1158
|
+
} = options.interpolation;
|
|
1159
|
+
this.escape = escape$1 !== void 0 ? escape$1 : escape;
|
|
1160
|
+
this.escapeValue = escapeValue !== void 0 ? escapeValue : true;
|
|
1161
|
+
this.useRawValueToEscape = useRawValueToEscape !== void 0 ? useRawValueToEscape : false;
|
|
1162
|
+
this.prefix = prefix ? regexEscape(prefix) : prefixEscaped || "{{";
|
|
1163
|
+
this.suffix = suffix ? regexEscape(suffix) : suffixEscaped || "}}";
|
|
1164
|
+
this.formatSeparator = formatSeparator || ",";
|
|
1165
|
+
this.unescapePrefix = unescapeSuffix ? "" : unescapePrefix || "-";
|
|
1166
|
+
this.unescapeSuffix = this.unescapePrefix ? "" : unescapeSuffix || "";
|
|
1167
|
+
this.nestingPrefix = nestingPrefix ? regexEscape(nestingPrefix) : nestingPrefixEscaped || regexEscape("$t(");
|
|
1168
|
+
this.nestingSuffix = nestingSuffix ? regexEscape(nestingSuffix) : nestingSuffixEscaped || regexEscape(")");
|
|
1169
|
+
this.nestingOptionsSeparator = nestingOptionsSeparator || ",";
|
|
1170
|
+
this.maxReplaces = maxReplaces || 1e3;
|
|
1171
|
+
this.alwaysFormat = alwaysFormat !== void 0 ? alwaysFormat : false;
|
|
1172
|
+
this.resetRegExp();
|
|
1173
|
+
}
|
|
1174
|
+
reset() {
|
|
1175
|
+
if (this.options) this.init(this.options);
|
|
1176
|
+
}
|
|
1177
|
+
resetRegExp() {
|
|
1178
|
+
const getOrResetRegExp = (existingRegExp, pattern) => {
|
|
1179
|
+
if (existingRegExp?.source === pattern) {
|
|
1180
|
+
existingRegExp.lastIndex = 0;
|
|
1181
|
+
return existingRegExp;
|
|
1182
|
+
}
|
|
1183
|
+
return new RegExp(pattern, "g");
|
|
1184
|
+
};
|
|
1185
|
+
this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
|
|
1186
|
+
this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
|
|
1187
|
+
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}(.+?)${this.nestingSuffix}`);
|
|
1188
|
+
}
|
|
1189
|
+
interpolate(str, data, lng, options) {
|
|
1190
|
+
let match;
|
|
1191
|
+
let value;
|
|
1192
|
+
let replaces;
|
|
1193
|
+
const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
1194
|
+
const handleFormat = (key) => {
|
|
1195
|
+
if (key.indexOf(this.formatSeparator) < 0) {
|
|
1196
|
+
const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
|
|
1197
|
+
return this.alwaysFormat ? this.format(path, void 0, lng, {
|
|
1198
|
+
...options,
|
|
1199
|
+
...data,
|
|
1200
|
+
interpolationkey: key
|
|
1201
|
+
}) : path;
|
|
1202
|
+
}
|
|
1203
|
+
const p = key.split(this.formatSeparator);
|
|
1204
|
+
const k = p.shift().trim();
|
|
1205
|
+
const f = p.join(this.formatSeparator).trim();
|
|
1206
|
+
return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
|
|
1207
|
+
...options,
|
|
1208
|
+
...data,
|
|
1209
|
+
interpolationkey: k
|
|
1210
|
+
});
|
|
1211
|
+
};
|
|
1212
|
+
this.resetRegExp();
|
|
1213
|
+
const missingInterpolationHandler = options?.missingInterpolationHandler || this.options.missingInterpolationHandler;
|
|
1214
|
+
const skipOnVariables = options?.interpolation?.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
|
|
1215
|
+
const todos = [{
|
|
1216
|
+
regex: this.regexpUnescape,
|
|
1217
|
+
safeValue: (val) => regexSafe(val)
|
|
1218
|
+
}, {
|
|
1219
|
+
regex: this.regexp,
|
|
1220
|
+
safeValue: (val) => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
|
|
1221
|
+
}];
|
|
1222
|
+
todos.forEach((todo) => {
|
|
1223
|
+
replaces = 0;
|
|
1224
|
+
while (match = todo.regex.exec(str)) {
|
|
1225
|
+
const matchedVar = match[1].trim();
|
|
1226
|
+
value = handleFormat(matchedVar);
|
|
1227
|
+
if (value === void 0) {
|
|
1228
|
+
if (typeof missingInterpolationHandler === "function") {
|
|
1229
|
+
const temp = missingInterpolationHandler(str, match, options);
|
|
1230
|
+
value = isString(temp) ? temp : "";
|
|
1231
|
+
} else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
|
|
1232
|
+
value = "";
|
|
1233
|
+
} else if (skipOnVariables) {
|
|
1234
|
+
value = match[0];
|
|
1235
|
+
continue;
|
|
1236
|
+
} else {
|
|
1237
|
+
this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
|
|
1238
|
+
value = "";
|
|
1239
|
+
}
|
|
1240
|
+
} else if (!isString(value) && !this.useRawValueToEscape) {
|
|
1241
|
+
value = makeString(value);
|
|
1242
|
+
}
|
|
1243
|
+
const safeValue = todo.safeValue(value);
|
|
1244
|
+
str = str.replace(match[0], safeValue);
|
|
1245
|
+
if (skipOnVariables) {
|
|
1246
|
+
todo.regex.lastIndex += value.length;
|
|
1247
|
+
todo.regex.lastIndex -= match[0].length;
|
|
1248
|
+
} else {
|
|
1249
|
+
todo.regex.lastIndex = 0;
|
|
1250
|
+
}
|
|
1251
|
+
replaces++;
|
|
1252
|
+
if (replaces >= this.maxReplaces) {
|
|
1253
|
+
break;
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
});
|
|
1257
|
+
return str;
|
|
1258
|
+
}
|
|
1259
|
+
nest(str, fc) {
|
|
1260
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1261
|
+
let match;
|
|
1262
|
+
let value;
|
|
1263
|
+
let clonedOptions;
|
|
1264
|
+
const handleHasOptions = (key, inheritedOptions) => {
|
|
1265
|
+
const sep = this.nestingOptionsSeparator;
|
|
1266
|
+
if (key.indexOf(sep) < 0) return key;
|
|
1267
|
+
const c = key.split(new RegExp(`${sep}[ ]*{`));
|
|
1268
|
+
let optionsString = `{${c[1]}`;
|
|
1269
|
+
key = c[0];
|
|
1270
|
+
optionsString = this.interpolate(optionsString, clonedOptions);
|
|
1271
|
+
const matchedSingleQuotes = optionsString.match(/'/g);
|
|
1272
|
+
const matchedDoubleQuotes = optionsString.match(/"/g);
|
|
1273
|
+
if ((matchedSingleQuotes?.length ?? 0) % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
|
|
1274
|
+
optionsString = optionsString.replace(/'/g, '"');
|
|
1275
|
+
}
|
|
1276
|
+
try {
|
|
1277
|
+
clonedOptions = JSON.parse(optionsString);
|
|
1278
|
+
if (inheritedOptions) clonedOptions = {
|
|
1279
|
+
...inheritedOptions,
|
|
1280
|
+
...clonedOptions
|
|
1281
|
+
};
|
|
1282
|
+
} catch (e) {
|
|
1283
|
+
this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
|
|
1284
|
+
return `${key}${sep}${optionsString}`;
|
|
1285
|
+
}
|
|
1286
|
+
if (clonedOptions.defaultValue && clonedOptions.defaultValue.indexOf(this.prefix) > -1) delete clonedOptions.defaultValue;
|
|
1287
|
+
return key;
|
|
1288
|
+
};
|
|
1289
|
+
while (match = this.nestingRegexp.exec(str)) {
|
|
1290
|
+
let formatters = [];
|
|
1291
|
+
clonedOptions = {
|
|
1292
|
+
...options
|
|
1293
|
+
};
|
|
1294
|
+
clonedOptions = clonedOptions.replace && !isString(clonedOptions.replace) ? clonedOptions.replace : clonedOptions;
|
|
1295
|
+
clonedOptions.applyPostProcessor = false;
|
|
1296
|
+
delete clonedOptions.defaultValue;
|
|
1297
|
+
let doReduce = false;
|
|
1298
|
+
if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
|
|
1299
|
+
const r = match[1].split(this.formatSeparator).map((elem) => elem.trim());
|
|
1300
|
+
match[1] = r.shift();
|
|
1301
|
+
formatters = r;
|
|
1302
|
+
doReduce = true;
|
|
1303
|
+
}
|
|
1304
|
+
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
1305
|
+
if (value && match[0] === str && !isString(value)) return value;
|
|
1306
|
+
if (!isString(value)) value = makeString(value);
|
|
1307
|
+
if (!value) {
|
|
1308
|
+
this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
|
|
1309
|
+
value = "";
|
|
1310
|
+
}
|
|
1311
|
+
if (doReduce) {
|
|
1312
|
+
value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
|
|
1313
|
+
...options,
|
|
1314
|
+
interpolationkey: match[1].trim()
|
|
1315
|
+
}), value.trim());
|
|
1316
|
+
}
|
|
1317
|
+
str = str.replace(match[0], value);
|
|
1318
|
+
this.regexp.lastIndex = 0;
|
|
1319
|
+
}
|
|
1320
|
+
return str;
|
|
1321
|
+
}
|
|
1322
|
+
};
|
|
1323
|
+
var parseFormatStr = (formatStr) => {
|
|
1324
|
+
let formatName = formatStr.toLowerCase().trim();
|
|
1325
|
+
const formatOptions = {};
|
|
1326
|
+
if (formatStr.indexOf("(") > -1) {
|
|
1327
|
+
const p = formatStr.split("(");
|
|
1328
|
+
formatName = p[0].toLowerCase().trim();
|
|
1329
|
+
const optStr = p[1].substring(0, p[1].length - 1);
|
|
1330
|
+
if (formatName === "currency" && optStr.indexOf(":") < 0) {
|
|
1331
|
+
if (!formatOptions.currency) formatOptions.currency = optStr.trim();
|
|
1332
|
+
} else if (formatName === "relativetime" && optStr.indexOf(":") < 0) {
|
|
1333
|
+
if (!formatOptions.range) formatOptions.range = optStr.trim();
|
|
1334
|
+
} else {
|
|
1335
|
+
const opts = optStr.split(";");
|
|
1336
|
+
opts.forEach((opt) => {
|
|
1337
|
+
if (opt) {
|
|
1338
|
+
const [key, ...rest] = opt.split(":");
|
|
1339
|
+
const val = rest.join(":").trim().replace(/^'+|'+$/g, "");
|
|
1340
|
+
const trimmedKey = key.trim();
|
|
1341
|
+
if (!formatOptions[trimmedKey]) formatOptions[trimmedKey] = val;
|
|
1342
|
+
if (val === "false") formatOptions[trimmedKey] = false;
|
|
1343
|
+
if (val === "true") formatOptions[trimmedKey] = true;
|
|
1344
|
+
if (!isNaN(val)) formatOptions[trimmedKey] = parseInt(val, 10);
|
|
1345
|
+
}
|
|
1346
|
+
});
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
return {
|
|
1350
|
+
formatName,
|
|
1351
|
+
formatOptions
|
|
1352
|
+
};
|
|
1353
|
+
};
|
|
1354
|
+
var createCachedFormatter = (fn) => {
|
|
1355
|
+
const cache = {};
|
|
1356
|
+
return (val, lng, options) => {
|
|
1357
|
+
let optForCache = options;
|
|
1358
|
+
if (options && options.interpolationkey && options.formatParams && options.formatParams[options.interpolationkey] && options[options.interpolationkey]) {
|
|
1359
|
+
optForCache = {
|
|
1360
|
+
...optForCache,
|
|
1361
|
+
[options.interpolationkey]: void 0
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
const key = lng + JSON.stringify(optForCache);
|
|
1365
|
+
let formatter = cache[key];
|
|
1366
|
+
if (!formatter) {
|
|
1367
|
+
formatter = fn(getCleanedCode(lng), options);
|
|
1368
|
+
cache[key] = formatter;
|
|
1369
|
+
}
|
|
1370
|
+
return formatter(val);
|
|
1371
|
+
};
|
|
1372
|
+
};
|
|
1373
|
+
var Formatter = class {
|
|
1374
|
+
constructor() {
|
|
1375
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1376
|
+
this.logger = baseLogger.create("formatter");
|
|
1377
|
+
this.options = options;
|
|
1378
|
+
this.formats = {
|
|
1379
|
+
number: createCachedFormatter((lng, opt) => {
|
|
1380
|
+
const formatter = new Intl.NumberFormat(lng, {
|
|
1381
|
+
...opt
|
|
1382
|
+
});
|
|
1383
|
+
return (val) => formatter.format(val);
|
|
1384
|
+
}),
|
|
1385
|
+
currency: createCachedFormatter((lng, opt) => {
|
|
1386
|
+
const formatter = new Intl.NumberFormat(lng, {
|
|
1387
|
+
...opt,
|
|
1388
|
+
style: "currency"
|
|
1389
|
+
});
|
|
1390
|
+
return (val) => formatter.format(val);
|
|
1391
|
+
}),
|
|
1392
|
+
datetime: createCachedFormatter((lng, opt) => {
|
|
1393
|
+
const formatter = new Intl.DateTimeFormat(lng, {
|
|
1394
|
+
...opt
|
|
1395
|
+
});
|
|
1396
|
+
return (val) => formatter.format(val);
|
|
1397
|
+
}),
|
|
1398
|
+
relativetime: createCachedFormatter((lng, opt) => {
|
|
1399
|
+
const formatter = new Intl.RelativeTimeFormat(lng, {
|
|
1400
|
+
...opt
|
|
1401
|
+
});
|
|
1402
|
+
return (val) => formatter.format(val, opt.range || "day");
|
|
1403
|
+
}),
|
|
1404
|
+
list: createCachedFormatter((lng, opt) => {
|
|
1405
|
+
const formatter = new Intl.ListFormat(lng, {
|
|
1406
|
+
...opt
|
|
1407
|
+
});
|
|
1408
|
+
return (val) => formatter.format(val);
|
|
1409
|
+
})
|
|
1410
|
+
};
|
|
1411
|
+
this.init(options);
|
|
1412
|
+
}
|
|
1413
|
+
init(services) {
|
|
1414
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
|
|
1415
|
+
interpolation: {}
|
|
1416
|
+
};
|
|
1417
|
+
this.formatSeparator = options.interpolation.formatSeparator || ",";
|
|
1418
|
+
}
|
|
1419
|
+
add(name, fc) {
|
|
1420
|
+
this.formats[name.toLowerCase().trim()] = fc;
|
|
1421
|
+
}
|
|
1422
|
+
addCached(name, fc) {
|
|
1423
|
+
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
1424
|
+
}
|
|
1425
|
+
format(value, format, lng) {
|
|
1426
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
1427
|
+
const formats = format.split(this.formatSeparator);
|
|
1428
|
+
if (formats.length > 1 && formats[0].indexOf("(") > 1 && formats[0].indexOf(")") < 0 && formats.find((f) => f.indexOf(")") > -1)) {
|
|
1429
|
+
const lastIndex = formats.findIndex((f) => f.indexOf(")") > -1);
|
|
1430
|
+
formats[0] = [formats[0], ...formats.splice(1, lastIndex)].join(this.formatSeparator);
|
|
1431
|
+
}
|
|
1432
|
+
const result = formats.reduce((mem, f) => {
|
|
1433
|
+
const {
|
|
1434
|
+
formatName,
|
|
1435
|
+
formatOptions
|
|
1436
|
+
} = parseFormatStr(f);
|
|
1437
|
+
if (this.formats[formatName]) {
|
|
1438
|
+
let formatted = mem;
|
|
1439
|
+
try {
|
|
1440
|
+
const valOptions = options?.formatParams?.[options.interpolationkey] || {};
|
|
1441
|
+
const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
|
|
1442
|
+
formatted = this.formats[formatName](mem, l, {
|
|
1443
|
+
...formatOptions,
|
|
1444
|
+
...options,
|
|
1445
|
+
...valOptions
|
|
1446
|
+
});
|
|
1447
|
+
} catch (error) {
|
|
1448
|
+
this.logger.warn(error);
|
|
1449
|
+
}
|
|
1450
|
+
return formatted;
|
|
1451
|
+
} else {
|
|
1452
|
+
this.logger.warn(`there was no format function for ${formatName}`);
|
|
1453
|
+
}
|
|
1454
|
+
return mem;
|
|
1455
|
+
}, value);
|
|
1456
|
+
return result;
|
|
1457
|
+
}
|
|
1458
|
+
};
|
|
1459
|
+
var removePending = (q, name) => {
|
|
1460
|
+
if (q.pending[name] !== void 0) {
|
|
1461
|
+
delete q.pending[name];
|
|
1462
|
+
q.pendingCount--;
|
|
1463
|
+
}
|
|
1464
|
+
};
|
|
1465
|
+
var Connector = class extends EventEmitter {
|
|
1466
|
+
constructor(backend, store, services) {
|
|
1467
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
1468
|
+
super();
|
|
1469
|
+
this.backend = backend;
|
|
1470
|
+
this.store = store;
|
|
1471
|
+
this.services = services;
|
|
1472
|
+
this.languageUtils = services.languageUtils;
|
|
1473
|
+
this.options = options;
|
|
1474
|
+
this.logger = baseLogger.create("backendConnector");
|
|
1475
|
+
this.waitingReads = [];
|
|
1476
|
+
this.maxParallelReads = options.maxParallelReads || 10;
|
|
1477
|
+
this.readingCalls = 0;
|
|
1478
|
+
this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
|
|
1479
|
+
this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
|
|
1480
|
+
this.state = {};
|
|
1481
|
+
this.queue = [];
|
|
1482
|
+
this.backend?.init?.(services, options.backend, options);
|
|
1483
|
+
}
|
|
1484
|
+
queueLoad(languages, namespaces, options, callback) {
|
|
1485
|
+
const toLoad = {};
|
|
1486
|
+
const pending = {};
|
|
1487
|
+
const toLoadLanguages = {};
|
|
1488
|
+
const toLoadNamespaces = {};
|
|
1489
|
+
languages.forEach((lng) => {
|
|
1490
|
+
let hasAllNamespaces = true;
|
|
1491
|
+
namespaces.forEach((ns) => {
|
|
1492
|
+
const name = `${lng}|${ns}`;
|
|
1493
|
+
if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
|
|
1494
|
+
this.state[name] = 2;
|
|
1495
|
+
} else if (this.state[name] < 0) ;
|
|
1496
|
+
else if (this.state[name] === 1) {
|
|
1497
|
+
if (pending[name] === void 0) pending[name] = true;
|
|
1498
|
+
} else {
|
|
1499
|
+
this.state[name] = 1;
|
|
1500
|
+
hasAllNamespaces = false;
|
|
1501
|
+
if (pending[name] === void 0) pending[name] = true;
|
|
1502
|
+
if (toLoad[name] === void 0) toLoad[name] = true;
|
|
1503
|
+
if (toLoadNamespaces[ns] === void 0) toLoadNamespaces[ns] = true;
|
|
1504
|
+
}
|
|
1505
|
+
});
|
|
1506
|
+
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
1507
|
+
});
|
|
1508
|
+
if (Object.keys(toLoad).length || Object.keys(pending).length) {
|
|
1509
|
+
this.queue.push({
|
|
1510
|
+
pending,
|
|
1511
|
+
pendingCount: Object.keys(pending).length,
|
|
1512
|
+
loaded: {},
|
|
1513
|
+
errors: [],
|
|
1514
|
+
callback
|
|
1515
|
+
});
|
|
1516
|
+
}
|
|
1517
|
+
return {
|
|
1518
|
+
toLoad: Object.keys(toLoad),
|
|
1519
|
+
pending: Object.keys(pending),
|
|
1520
|
+
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
1521
|
+
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
1522
|
+
};
|
|
1523
|
+
}
|
|
1524
|
+
loaded(name, err, data) {
|
|
1525
|
+
const s = name.split("|");
|
|
1526
|
+
const lng = s[0];
|
|
1527
|
+
const ns = s[1];
|
|
1528
|
+
if (err) this.emit("failedLoading", lng, ns, err);
|
|
1529
|
+
if (!err && data) {
|
|
1530
|
+
this.store.addResourceBundle(lng, ns, data, void 0, void 0, {
|
|
1531
|
+
skipCopy: true
|
|
1532
|
+
});
|
|
1533
|
+
}
|
|
1534
|
+
this.state[name] = err ? -1 : 2;
|
|
1535
|
+
if (err && data) this.state[name] = 0;
|
|
1536
|
+
const loaded = {};
|
|
1537
|
+
this.queue.forEach((q) => {
|
|
1538
|
+
pushPath(q.loaded, [lng], ns);
|
|
1539
|
+
removePending(q, name);
|
|
1540
|
+
if (err) q.errors.push(err);
|
|
1541
|
+
if (q.pendingCount === 0 && !q.done) {
|
|
1542
|
+
Object.keys(q.loaded).forEach((l) => {
|
|
1543
|
+
if (!loaded[l]) loaded[l] = {};
|
|
1544
|
+
const loadedKeys = q.loaded[l];
|
|
1545
|
+
if (loadedKeys.length) {
|
|
1546
|
+
loadedKeys.forEach((n) => {
|
|
1547
|
+
if (loaded[l][n] === void 0) loaded[l][n] = true;
|
|
1548
|
+
});
|
|
1549
|
+
}
|
|
1550
|
+
});
|
|
1551
|
+
q.done = true;
|
|
1552
|
+
if (q.errors.length) {
|
|
1553
|
+
q.callback(q.errors);
|
|
1554
|
+
} else {
|
|
1555
|
+
q.callback();
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
});
|
|
1559
|
+
this.emit("loaded", loaded);
|
|
1560
|
+
this.queue = this.queue.filter((q) => !q.done);
|
|
1561
|
+
}
|
|
1562
|
+
read(lng, ns, fcName) {
|
|
1563
|
+
let tried = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0;
|
|
1564
|
+
let wait = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : this.retryTimeout;
|
|
1565
|
+
let callback = arguments.length > 5 ? arguments[5] : void 0;
|
|
1566
|
+
if (!lng.length) return callback(null, {});
|
|
1567
|
+
if (this.readingCalls >= this.maxParallelReads) {
|
|
1568
|
+
this.waitingReads.push({
|
|
1569
|
+
lng,
|
|
1570
|
+
ns,
|
|
1571
|
+
fcName,
|
|
1572
|
+
tried,
|
|
1573
|
+
wait,
|
|
1574
|
+
callback
|
|
1575
|
+
});
|
|
1576
|
+
return;
|
|
1577
|
+
}
|
|
1578
|
+
this.readingCalls++;
|
|
1579
|
+
const resolver = (err, data) => {
|
|
1580
|
+
this.readingCalls--;
|
|
1581
|
+
if (this.waitingReads.length > 0) {
|
|
1582
|
+
const next = this.waitingReads.shift();
|
|
1583
|
+
this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
1584
|
+
}
|
|
1585
|
+
if (err && data && tried < this.maxRetries) {
|
|
1586
|
+
setTimeout(() => {
|
|
1587
|
+
this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
1588
|
+
}, wait);
|
|
1589
|
+
return;
|
|
1590
|
+
}
|
|
1591
|
+
callback(err, data);
|
|
1592
|
+
};
|
|
1593
|
+
const fc = this.backend[fcName].bind(this.backend);
|
|
1594
|
+
if (fc.length === 2) {
|
|
1595
|
+
try {
|
|
1596
|
+
const r = fc(lng, ns);
|
|
1597
|
+
if (r && typeof r.then === "function") {
|
|
1598
|
+
r.then((data) => resolver(null, data)).catch(resolver);
|
|
1599
|
+
} else {
|
|
1600
|
+
resolver(null, r);
|
|
1601
|
+
}
|
|
1602
|
+
} catch (err) {
|
|
1603
|
+
resolver(err);
|
|
1604
|
+
}
|
|
1605
|
+
return;
|
|
1606
|
+
}
|
|
1607
|
+
return fc(lng, ns, resolver);
|
|
1608
|
+
}
|
|
1609
|
+
prepareLoading(languages, namespaces) {
|
|
1610
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1611
|
+
let callback = arguments.length > 3 ? arguments[3] : void 0;
|
|
1612
|
+
if (!this.backend) {
|
|
1613
|
+
this.logger.warn("No backend was added via i18next.use. Will not load resources.");
|
|
1614
|
+
return callback && callback();
|
|
1615
|
+
}
|
|
1616
|
+
if (isString(languages)) languages = this.languageUtils.toResolveHierarchy(languages);
|
|
1617
|
+
if (isString(namespaces)) namespaces = [namespaces];
|
|
1618
|
+
const toLoad = this.queueLoad(languages, namespaces, options, callback);
|
|
1619
|
+
if (!toLoad.toLoad.length) {
|
|
1620
|
+
if (!toLoad.pending.length) callback();
|
|
1621
|
+
return null;
|
|
1622
|
+
}
|
|
1623
|
+
toLoad.toLoad.forEach((name) => {
|
|
1624
|
+
this.loadOne(name);
|
|
1625
|
+
});
|
|
1626
|
+
}
|
|
1627
|
+
load(languages, namespaces, callback) {
|
|
1628
|
+
this.prepareLoading(languages, namespaces, {}, callback);
|
|
1629
|
+
}
|
|
1630
|
+
reload(languages, namespaces, callback) {
|
|
1631
|
+
this.prepareLoading(languages, namespaces, {
|
|
1632
|
+
reload: true
|
|
1633
|
+
}, callback);
|
|
1634
|
+
}
|
|
1635
|
+
loadOne(name) {
|
|
1636
|
+
let prefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
|
|
1637
|
+
const s = name.split("|");
|
|
1638
|
+
const lng = s[0];
|
|
1639
|
+
const ns = s[1];
|
|
1640
|
+
this.read(lng, ns, "read", void 0, void 0, (err, data) => {
|
|
1641
|
+
if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
|
|
1642
|
+
if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
|
|
1643
|
+
this.loaded(name, err, data);
|
|
1644
|
+
});
|
|
1645
|
+
}
|
|
1646
|
+
saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
|
|
1647
|
+
let options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {};
|
|
1648
|
+
let clb = arguments.length > 6 && arguments[6] !== void 0 ? arguments[6] : () => {
|
|
1649
|
+
};
|
|
1650
|
+
if (this.services?.utils?.hasLoadedNamespace && !this.services?.utils?.hasLoadedNamespace(namespace)) {
|
|
1651
|
+
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!!!");
|
|
1652
|
+
return;
|
|
1653
|
+
}
|
|
1654
|
+
if (key === void 0 || key === null || key === "") return;
|
|
1655
|
+
if (this.backend?.create) {
|
|
1656
|
+
const opts = {
|
|
1657
|
+
...options,
|
|
1658
|
+
isUpdate
|
|
1659
|
+
};
|
|
1660
|
+
const fc = this.backend.create.bind(this.backend);
|
|
1661
|
+
if (fc.length < 6) {
|
|
1662
|
+
try {
|
|
1663
|
+
let r;
|
|
1664
|
+
if (fc.length === 5) {
|
|
1665
|
+
r = fc(languages, namespace, key, fallbackValue, opts);
|
|
1666
|
+
} else {
|
|
1667
|
+
r = fc(languages, namespace, key, fallbackValue);
|
|
1668
|
+
}
|
|
1669
|
+
if (r && typeof r.then === "function") {
|
|
1670
|
+
r.then((data) => clb(null, data)).catch(clb);
|
|
1671
|
+
} else {
|
|
1672
|
+
clb(null, r);
|
|
1673
|
+
}
|
|
1674
|
+
} catch (err) {
|
|
1675
|
+
clb(err);
|
|
1676
|
+
}
|
|
1677
|
+
} else {
|
|
1678
|
+
fc(languages, namespace, key, fallbackValue, clb, opts);
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
if (!languages || !languages[0]) return;
|
|
1682
|
+
this.store.addResource(languages[0], namespace, key, fallbackValue);
|
|
1683
|
+
}
|
|
1684
|
+
};
|
|
1685
|
+
var get = () => ({
|
|
1686
|
+
debug: false,
|
|
1687
|
+
initAsync: true,
|
|
1688
|
+
ns: ["translation"],
|
|
1689
|
+
defaultNS: ["translation"],
|
|
1690
|
+
fallbackLng: ["dev"],
|
|
1691
|
+
fallbackNS: false,
|
|
1692
|
+
supportedLngs: false,
|
|
1693
|
+
nonExplicitSupportedLngs: false,
|
|
1694
|
+
load: "all",
|
|
1695
|
+
preload: false,
|
|
1696
|
+
simplifyPluralSuffix: true,
|
|
1697
|
+
keySeparator: ".",
|
|
1698
|
+
nsSeparator: ":",
|
|
1699
|
+
pluralSeparator: "_",
|
|
1700
|
+
contextSeparator: "_",
|
|
1701
|
+
partialBundledLanguages: false,
|
|
1702
|
+
saveMissing: false,
|
|
1703
|
+
updateMissing: false,
|
|
1704
|
+
saveMissingTo: "fallback",
|
|
1705
|
+
saveMissingPlurals: true,
|
|
1706
|
+
missingKeyHandler: false,
|
|
1707
|
+
missingInterpolationHandler: false,
|
|
1708
|
+
postProcess: false,
|
|
1709
|
+
postProcessPassResolved: false,
|
|
1710
|
+
returnNull: false,
|
|
1711
|
+
returnEmptyString: true,
|
|
1712
|
+
returnObjects: false,
|
|
1713
|
+
joinArrays: false,
|
|
1714
|
+
returnedObjectHandler: false,
|
|
1715
|
+
parseMissingKeyHandler: false,
|
|
1716
|
+
appendNamespaceToMissingKey: false,
|
|
1717
|
+
appendNamespaceToCIMode: false,
|
|
1718
|
+
overloadTranslationOptionHandler: (args) => {
|
|
1719
|
+
let ret = {};
|
|
1720
|
+
if (typeof args[1] === "object") ret = args[1];
|
|
1721
|
+
if (isString(args[1])) ret.defaultValue = args[1];
|
|
1722
|
+
if (isString(args[2])) ret.tDescription = args[2];
|
|
1723
|
+
if (typeof args[2] === "object" || typeof args[3] === "object") {
|
|
1724
|
+
const options = args[3] || args[2];
|
|
1725
|
+
Object.keys(options).forEach((key) => {
|
|
1726
|
+
ret[key] = options[key];
|
|
1727
|
+
});
|
|
1728
|
+
}
|
|
1729
|
+
return ret;
|
|
1730
|
+
},
|
|
1731
|
+
interpolation: {
|
|
1732
|
+
escapeValue: true,
|
|
1733
|
+
format: (value) => value,
|
|
1734
|
+
prefix: "{{",
|
|
1735
|
+
suffix: "}}",
|
|
1736
|
+
formatSeparator: ",",
|
|
1737
|
+
unescapePrefix: "-",
|
|
1738
|
+
nestingPrefix: "$t(",
|
|
1739
|
+
nestingSuffix: ")",
|
|
1740
|
+
nestingOptionsSeparator: ",",
|
|
1741
|
+
maxReplaces: 1e3,
|
|
1742
|
+
skipOnVariables: true
|
|
1743
|
+
}
|
|
1744
|
+
});
|
|
1745
|
+
var transformOptions = (options) => {
|
|
1746
|
+
if (isString(options.ns)) options.ns = [options.ns];
|
|
1747
|
+
if (isString(options.fallbackLng)) options.fallbackLng = [options.fallbackLng];
|
|
1748
|
+
if (isString(options.fallbackNS)) options.fallbackNS = [options.fallbackNS];
|
|
1749
|
+
if (options.supportedLngs?.indexOf?.("cimode") < 0) {
|
|
1750
|
+
options.supportedLngs = options.supportedLngs.concat(["cimode"]);
|
|
1751
|
+
}
|
|
1752
|
+
if (typeof options.initImmediate === "boolean") options.initAsync = options.initImmediate;
|
|
1753
|
+
return options;
|
|
1754
|
+
};
|
|
1755
|
+
var noop = () => {
|
|
1756
|
+
};
|
|
1757
|
+
var bindMemberFunctions = (inst) => {
|
|
1758
|
+
const mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
|
|
1759
|
+
mems.forEach((mem) => {
|
|
1760
|
+
if (typeof inst[mem] === "function") {
|
|
1761
|
+
inst[mem] = inst[mem].bind(inst);
|
|
1762
|
+
}
|
|
1763
|
+
});
|
|
1764
|
+
};
|
|
1765
|
+
var I18n = class _I18n extends EventEmitter {
|
|
1766
|
+
constructor() {
|
|
1767
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1768
|
+
let callback = arguments.length > 1 ? arguments[1] : void 0;
|
|
1769
|
+
super();
|
|
1770
|
+
this.options = transformOptions(options);
|
|
1771
|
+
this.services = {};
|
|
1772
|
+
this.logger = baseLogger;
|
|
1773
|
+
this.modules = {
|
|
1774
|
+
external: []
|
|
1775
|
+
};
|
|
1776
|
+
bindMemberFunctions(this);
|
|
1777
|
+
if (callback && !this.isInitialized && !options.isClone) {
|
|
1778
|
+
if (!this.options.initAsync) {
|
|
1779
|
+
this.init(options, callback);
|
|
1780
|
+
return this;
|
|
1781
|
+
}
|
|
1782
|
+
setTimeout(() => {
|
|
1783
|
+
this.init(options, callback);
|
|
1784
|
+
}, 0);
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
init() {
|
|
1788
|
+
var _this = this;
|
|
1789
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1790
|
+
let callback = arguments.length > 1 ? arguments[1] : void 0;
|
|
1791
|
+
this.isInitializing = true;
|
|
1792
|
+
if (typeof options === "function") {
|
|
1793
|
+
callback = options;
|
|
1794
|
+
options = {};
|
|
1795
|
+
}
|
|
1796
|
+
if (!options.defaultNS && options.defaultNS !== false && options.ns) {
|
|
1797
|
+
if (isString(options.ns)) {
|
|
1798
|
+
options.defaultNS = options.ns;
|
|
1799
|
+
} else if (options.ns.indexOf("translation") < 0) {
|
|
1800
|
+
options.defaultNS = options.ns[0];
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
const defOpts = get();
|
|
1804
|
+
this.options = {
|
|
1805
|
+
...defOpts,
|
|
1806
|
+
...this.options,
|
|
1807
|
+
...transformOptions(options)
|
|
1808
|
+
};
|
|
1809
|
+
this.options.interpolation = {
|
|
1810
|
+
...defOpts.interpolation,
|
|
1811
|
+
...this.options.interpolation
|
|
1812
|
+
};
|
|
1813
|
+
if (options.keySeparator !== void 0) {
|
|
1814
|
+
this.options.userDefinedKeySeparator = options.keySeparator;
|
|
1815
|
+
}
|
|
1816
|
+
if (options.nsSeparator !== void 0) {
|
|
1817
|
+
this.options.userDefinedNsSeparator = options.nsSeparator;
|
|
1818
|
+
}
|
|
1819
|
+
const createClassOnDemand = (ClassOrObject) => {
|
|
1820
|
+
if (!ClassOrObject) return null;
|
|
1821
|
+
if (typeof ClassOrObject === "function") return new ClassOrObject();
|
|
1822
|
+
return ClassOrObject;
|
|
1823
|
+
};
|
|
1824
|
+
if (!this.options.isClone) {
|
|
1825
|
+
if (this.modules.logger) {
|
|
1826
|
+
baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
|
|
1827
|
+
} else {
|
|
1828
|
+
baseLogger.init(null, this.options);
|
|
1829
|
+
}
|
|
1830
|
+
let formatter;
|
|
1831
|
+
if (this.modules.formatter) {
|
|
1832
|
+
formatter = this.modules.formatter;
|
|
1833
|
+
} else {
|
|
1834
|
+
formatter = Formatter;
|
|
1835
|
+
}
|
|
1836
|
+
const lu = new LanguageUtil(this.options);
|
|
1837
|
+
this.store = new ResourceStore(this.options.resources, this.options);
|
|
1838
|
+
const s = this.services;
|
|
1839
|
+
s.logger = baseLogger;
|
|
1840
|
+
s.resourceStore = this.store;
|
|
1841
|
+
s.languageUtils = lu;
|
|
1842
|
+
s.pluralResolver = new PluralResolver(lu, {
|
|
1843
|
+
prepend: this.options.pluralSeparator,
|
|
1844
|
+
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
1845
|
+
});
|
|
1846
|
+
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
|
|
1847
|
+
s.formatter = createClassOnDemand(formatter);
|
|
1848
|
+
s.formatter.init(s, this.options);
|
|
1849
|
+
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
1850
|
+
}
|
|
1851
|
+
s.interpolator = new Interpolator(this.options);
|
|
1852
|
+
s.utils = {
|
|
1853
|
+
hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
|
|
1854
|
+
};
|
|
1855
|
+
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
1856
|
+
s.backendConnector.on("*", function(event) {
|
|
1857
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1858
|
+
args[_key - 1] = arguments[_key];
|
|
1859
|
+
}
|
|
1860
|
+
_this.emit(event, ...args);
|
|
1861
|
+
});
|
|
1862
|
+
if (this.modules.languageDetector) {
|
|
1863
|
+
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
1864
|
+
if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
|
|
1865
|
+
}
|
|
1866
|
+
if (this.modules.i18nFormat) {
|
|
1867
|
+
s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
|
|
1868
|
+
if (s.i18nFormat.init) s.i18nFormat.init(this);
|
|
1869
|
+
}
|
|
1870
|
+
this.translator = new Translator(this.services, this.options);
|
|
1871
|
+
this.translator.on("*", function(event) {
|
|
1872
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
1873
|
+
args[_key2 - 1] = arguments[_key2];
|
|
1874
|
+
}
|
|
1875
|
+
_this.emit(event, ...args);
|
|
1876
|
+
});
|
|
1877
|
+
this.modules.external.forEach((m) => {
|
|
1878
|
+
if (m.init) m.init(this);
|
|
1879
|
+
});
|
|
1880
|
+
}
|
|
1881
|
+
this.format = this.options.interpolation.format;
|
|
1882
|
+
if (!callback) callback = noop;
|
|
1883
|
+
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
1884
|
+
const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
1885
|
+
if (codes.length > 0 && codes[0] !== "dev") this.options.lng = codes[0];
|
|
1886
|
+
}
|
|
1887
|
+
if (!this.services.languageDetector && !this.options.lng) {
|
|
1888
|
+
this.logger.warn("init: no languageDetector is used and no lng is defined");
|
|
1889
|
+
}
|
|
1890
|
+
const storeApi = ["getResource", "hasResourceBundle", "getResourceBundle", "getDataByLanguage"];
|
|
1891
|
+
storeApi.forEach((fcName) => {
|
|
1892
|
+
this[fcName] = function() {
|
|
1893
|
+
return _this.store[fcName](...arguments);
|
|
1894
|
+
};
|
|
1895
|
+
});
|
|
1896
|
+
const storeApiChained = ["addResource", "addResources", "addResourceBundle", "removeResourceBundle"];
|
|
1897
|
+
storeApiChained.forEach((fcName) => {
|
|
1898
|
+
this[fcName] = function() {
|
|
1899
|
+
_this.store[fcName](...arguments);
|
|
1900
|
+
return _this;
|
|
1901
|
+
};
|
|
1902
|
+
});
|
|
1903
|
+
const deferred = defer();
|
|
1904
|
+
const load = () => {
|
|
1905
|
+
const finish = (err, t2) => {
|
|
1906
|
+
this.isInitializing = false;
|
|
1907
|
+
if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn("init: i18next is already initialized. You should call init just once!");
|
|
1908
|
+
this.isInitialized = true;
|
|
1909
|
+
if (!this.options.isClone) this.logger.log("initialized", this.options);
|
|
1910
|
+
this.emit("initialized", this.options);
|
|
1911
|
+
deferred.resolve(t2);
|
|
1912
|
+
callback(err, t2);
|
|
1913
|
+
};
|
|
1914
|
+
if (this.languages && !this.isInitialized) return finish(null, this.t.bind(this));
|
|
1915
|
+
this.changeLanguage(this.options.lng, finish);
|
|
1916
|
+
};
|
|
1917
|
+
if (this.options.resources || !this.options.initAsync) {
|
|
1918
|
+
load();
|
|
1919
|
+
} else {
|
|
1920
|
+
setTimeout(load, 0);
|
|
1921
|
+
}
|
|
1922
|
+
return deferred;
|
|
1923
|
+
}
|
|
1924
|
+
loadResources(language) {
|
|
1925
|
+
let callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
1926
|
+
let usedCallback = callback;
|
|
1927
|
+
const usedLng = isString(language) ? language : this.language;
|
|
1928
|
+
if (typeof language === "function") usedCallback = language;
|
|
1929
|
+
if (!this.options.resources || this.options.partialBundledLanguages) {
|
|
1930
|
+
if (usedLng?.toLowerCase() === "cimode" && (!this.options.preload || this.options.preload.length === 0)) return usedCallback();
|
|
1931
|
+
const toLoad = [];
|
|
1932
|
+
const append = (lng) => {
|
|
1933
|
+
if (!lng) return;
|
|
1934
|
+
if (lng === "cimode") return;
|
|
1935
|
+
const lngs = this.services.languageUtils.toResolveHierarchy(lng);
|
|
1936
|
+
lngs.forEach((l) => {
|
|
1937
|
+
if (l === "cimode") return;
|
|
1938
|
+
if (toLoad.indexOf(l) < 0) toLoad.push(l);
|
|
1939
|
+
});
|
|
1940
|
+
};
|
|
1941
|
+
if (!usedLng) {
|
|
1942
|
+
const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
1943
|
+
fallbacks.forEach((l) => append(l));
|
|
1944
|
+
} else {
|
|
1945
|
+
append(usedLng);
|
|
1946
|
+
}
|
|
1947
|
+
this.options.preload?.forEach?.((l) => append(l));
|
|
1948
|
+
this.services.backendConnector.load(toLoad, this.options.ns, (e) => {
|
|
1949
|
+
if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
|
|
1950
|
+
usedCallback(e);
|
|
1951
|
+
});
|
|
1952
|
+
} else {
|
|
1953
|
+
usedCallback(null);
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
reloadResources(lngs, ns, callback) {
|
|
1957
|
+
const deferred = defer();
|
|
1958
|
+
if (typeof lngs === "function") {
|
|
1959
|
+
callback = lngs;
|
|
1960
|
+
lngs = void 0;
|
|
1961
|
+
}
|
|
1962
|
+
if (typeof ns === "function") {
|
|
1963
|
+
callback = ns;
|
|
1964
|
+
ns = void 0;
|
|
1965
|
+
}
|
|
1966
|
+
if (!lngs) lngs = this.languages;
|
|
1967
|
+
if (!ns) ns = this.options.ns;
|
|
1968
|
+
if (!callback) callback = noop;
|
|
1969
|
+
this.services.backendConnector.reload(lngs, ns, (err) => {
|
|
1970
|
+
deferred.resolve();
|
|
1971
|
+
callback(err);
|
|
1972
|
+
});
|
|
1973
|
+
return deferred;
|
|
1974
|
+
}
|
|
1975
|
+
use(module2) {
|
|
1976
|
+
if (!module2) throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");
|
|
1977
|
+
if (!module2.type) throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");
|
|
1978
|
+
if (module2.type === "backend") {
|
|
1979
|
+
this.modules.backend = module2;
|
|
1980
|
+
}
|
|
1981
|
+
if (module2.type === "logger" || module2.log && module2.warn && module2.error) {
|
|
1982
|
+
this.modules.logger = module2;
|
|
1983
|
+
}
|
|
1984
|
+
if (module2.type === "languageDetector") {
|
|
1985
|
+
this.modules.languageDetector = module2;
|
|
1986
|
+
}
|
|
1987
|
+
if (module2.type === "i18nFormat") {
|
|
1988
|
+
this.modules.i18nFormat = module2;
|
|
1989
|
+
}
|
|
1990
|
+
if (module2.type === "postProcessor") {
|
|
1991
|
+
postProcessor.addPostProcessor(module2);
|
|
1992
|
+
}
|
|
1993
|
+
if (module2.type === "formatter") {
|
|
1994
|
+
this.modules.formatter = module2;
|
|
1995
|
+
}
|
|
1996
|
+
if (module2.type === "3rdParty") {
|
|
1997
|
+
this.modules.external.push(module2);
|
|
1998
|
+
}
|
|
1999
|
+
return this;
|
|
2000
|
+
}
|
|
2001
|
+
setResolvedLanguage(l) {
|
|
2002
|
+
if (!l || !this.languages) return;
|
|
2003
|
+
if (["cimode", "dev"].indexOf(l) > -1) return;
|
|
2004
|
+
for (let li = 0; li < this.languages.length; li++) {
|
|
2005
|
+
const lngInLngs = this.languages[li];
|
|
2006
|
+
if (["cimode", "dev"].indexOf(lngInLngs) > -1) continue;
|
|
2007
|
+
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
2008
|
+
this.resolvedLanguage = lngInLngs;
|
|
2009
|
+
break;
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
changeLanguage(lng, callback) {
|
|
2014
|
+
var _this2 = this;
|
|
2015
|
+
this.isLanguageChangingTo = lng;
|
|
2016
|
+
const deferred = defer();
|
|
2017
|
+
this.emit("languageChanging", lng);
|
|
2018
|
+
const setLngProps = (l) => {
|
|
2019
|
+
this.language = l;
|
|
2020
|
+
this.languages = this.services.languageUtils.toResolveHierarchy(l);
|
|
2021
|
+
this.resolvedLanguage = void 0;
|
|
2022
|
+
this.setResolvedLanguage(l);
|
|
2023
|
+
};
|
|
2024
|
+
const done = (err, l) => {
|
|
2025
|
+
if (l) {
|
|
2026
|
+
setLngProps(l);
|
|
2027
|
+
this.translator.changeLanguage(l);
|
|
2028
|
+
this.isLanguageChangingTo = void 0;
|
|
2029
|
+
this.emit("languageChanged", l);
|
|
2030
|
+
this.logger.log("languageChanged", l);
|
|
2031
|
+
} else {
|
|
2032
|
+
this.isLanguageChangingTo = void 0;
|
|
2033
|
+
}
|
|
2034
|
+
deferred.resolve(function() {
|
|
2035
|
+
return _this2.t(...arguments);
|
|
2036
|
+
});
|
|
2037
|
+
if (callback) callback(err, function() {
|
|
2038
|
+
return _this2.t(...arguments);
|
|
2039
|
+
});
|
|
2040
|
+
};
|
|
2041
|
+
const setLng = (lngs) => {
|
|
2042
|
+
if (!lng && !lngs && this.services.languageDetector) lngs = [];
|
|
2043
|
+
const l = isString(lngs) ? lngs : this.services.languageUtils.getBestMatchFromCodes(lngs);
|
|
2044
|
+
if (l) {
|
|
2045
|
+
if (!this.language) {
|
|
2046
|
+
setLngProps(l);
|
|
2047
|
+
}
|
|
2048
|
+
if (!this.translator.language) this.translator.changeLanguage(l);
|
|
2049
|
+
this.services.languageDetector?.cacheUserLanguage?.(l);
|
|
2050
|
+
}
|
|
2051
|
+
this.loadResources(l, (err) => {
|
|
2052
|
+
done(err, l);
|
|
2053
|
+
});
|
|
2054
|
+
};
|
|
2055
|
+
if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
|
|
2056
|
+
setLng(this.services.languageDetector.detect());
|
|
2057
|
+
} else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
|
|
2058
|
+
if (this.services.languageDetector.detect.length === 0) {
|
|
2059
|
+
this.services.languageDetector.detect().then(setLng);
|
|
2060
|
+
} else {
|
|
2061
|
+
this.services.languageDetector.detect(setLng);
|
|
2062
|
+
}
|
|
2063
|
+
} else {
|
|
2064
|
+
setLng(lng);
|
|
2065
|
+
}
|
|
2066
|
+
return deferred;
|
|
2067
|
+
}
|
|
2068
|
+
getFixedT(lng, ns, keyPrefix) {
|
|
2069
|
+
var _this3 = this;
|
|
2070
|
+
const fixedT = function(key, opts) {
|
|
2071
|
+
let options;
|
|
2072
|
+
if (typeof opts !== "object") {
|
|
2073
|
+
for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
2074
|
+
rest[_key3 - 2] = arguments[_key3];
|
|
2075
|
+
}
|
|
2076
|
+
options = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
2077
|
+
} else {
|
|
2078
|
+
options = {
|
|
2079
|
+
...opts
|
|
2080
|
+
};
|
|
2081
|
+
}
|
|
2082
|
+
options.lng = options.lng || fixedT.lng;
|
|
2083
|
+
options.lngs = options.lngs || fixedT.lngs;
|
|
2084
|
+
options.ns = options.ns || fixedT.ns;
|
|
2085
|
+
if (options.keyPrefix !== "") options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
|
|
2086
|
+
const keySeparator = _this3.options.keySeparator || ".";
|
|
2087
|
+
let resultKey;
|
|
2088
|
+
if (options.keyPrefix && Array.isArray(key)) {
|
|
2089
|
+
resultKey = key.map((k) => `${options.keyPrefix}${keySeparator}${k}`);
|
|
2090
|
+
} else {
|
|
2091
|
+
resultKey = options.keyPrefix ? `${options.keyPrefix}${keySeparator}${key}` : key;
|
|
2092
|
+
}
|
|
2093
|
+
return _this3.t(resultKey, options);
|
|
2094
|
+
};
|
|
2095
|
+
if (isString(lng)) {
|
|
2096
|
+
fixedT.lng = lng;
|
|
2097
|
+
} else {
|
|
2098
|
+
fixedT.lngs = lng;
|
|
2099
|
+
}
|
|
2100
|
+
fixedT.ns = ns;
|
|
2101
|
+
fixedT.keyPrefix = keyPrefix;
|
|
2102
|
+
return fixedT;
|
|
2103
|
+
}
|
|
2104
|
+
t() {
|
|
2105
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
2106
|
+
args[_key4] = arguments[_key4];
|
|
2107
|
+
}
|
|
2108
|
+
return this.translator?.translate(...args);
|
|
2109
|
+
}
|
|
2110
|
+
exists() {
|
|
2111
|
+
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
2112
|
+
args[_key5] = arguments[_key5];
|
|
2113
|
+
}
|
|
2114
|
+
return this.translator?.exists(...args);
|
|
2115
|
+
}
|
|
2116
|
+
setDefaultNamespace(ns) {
|
|
2117
|
+
this.options.defaultNS = ns;
|
|
2118
|
+
}
|
|
2119
|
+
hasLoadedNamespace(ns) {
|
|
2120
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
2121
|
+
if (!this.isInitialized) {
|
|
2122
|
+
this.logger.warn("hasLoadedNamespace: i18next was not initialized", this.languages);
|
|
2123
|
+
return false;
|
|
2124
|
+
}
|
|
2125
|
+
if (!this.languages || !this.languages.length) {
|
|
2126
|
+
this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty", this.languages);
|
|
2127
|
+
return false;
|
|
2128
|
+
}
|
|
2129
|
+
const lng = options.lng || this.resolvedLanguage || this.languages[0];
|
|
2130
|
+
const fallbackLng = this.options ? this.options.fallbackLng : false;
|
|
2131
|
+
const lastLng = this.languages[this.languages.length - 1];
|
|
2132
|
+
if (lng.toLowerCase() === "cimode") return true;
|
|
2133
|
+
const loadNotPending = (l, n) => {
|
|
2134
|
+
const loadState = this.services.backendConnector.state[`${l}|${n}`];
|
|
2135
|
+
return loadState === -1 || loadState === 0 || loadState === 2;
|
|
2136
|
+
};
|
|
2137
|
+
if (options.precheck) {
|
|
2138
|
+
const preResult = options.precheck(this, loadNotPending);
|
|
2139
|
+
if (preResult !== void 0) return preResult;
|
|
2140
|
+
}
|
|
2141
|
+
if (this.hasResourceBundle(lng, ns)) return true;
|
|
2142
|
+
if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
|
|
2143
|
+
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
2144
|
+
return false;
|
|
2145
|
+
}
|
|
2146
|
+
loadNamespaces(ns, callback) {
|
|
2147
|
+
const deferred = defer();
|
|
2148
|
+
if (!this.options.ns) {
|
|
2149
|
+
if (callback) callback();
|
|
2150
|
+
return Promise.resolve();
|
|
2151
|
+
}
|
|
2152
|
+
if (isString(ns)) ns = [ns];
|
|
2153
|
+
ns.forEach((n) => {
|
|
2154
|
+
if (this.options.ns.indexOf(n) < 0) this.options.ns.push(n);
|
|
2155
|
+
});
|
|
2156
|
+
this.loadResources((err) => {
|
|
2157
|
+
deferred.resolve();
|
|
2158
|
+
if (callback) callback(err);
|
|
2159
|
+
});
|
|
2160
|
+
return deferred;
|
|
2161
|
+
}
|
|
2162
|
+
loadLanguages(lngs, callback) {
|
|
2163
|
+
const deferred = defer();
|
|
2164
|
+
if (isString(lngs)) lngs = [lngs];
|
|
2165
|
+
const preloaded = this.options.preload || [];
|
|
2166
|
+
const newLngs = lngs.filter((lng) => preloaded.indexOf(lng) < 0 && this.services.languageUtils.isSupportedCode(lng));
|
|
2167
|
+
if (!newLngs.length) {
|
|
2168
|
+
if (callback) callback();
|
|
2169
|
+
return Promise.resolve();
|
|
2170
|
+
}
|
|
2171
|
+
this.options.preload = preloaded.concat(newLngs);
|
|
2172
|
+
this.loadResources((err) => {
|
|
2173
|
+
deferred.resolve();
|
|
2174
|
+
if (callback) callback(err);
|
|
2175
|
+
});
|
|
2176
|
+
return deferred;
|
|
2177
|
+
}
|
|
2178
|
+
dir(lng) {
|
|
2179
|
+
if (!lng) lng = this.resolvedLanguage || (this.languages?.length > 0 ? this.languages[0] : this.language);
|
|
2180
|
+
if (!lng) return "rtl";
|
|
2181
|
+
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"];
|
|
2182
|
+
const languageUtils = this.services?.languageUtils || new LanguageUtil(get());
|
|
2183
|
+
return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf("-arab") > 1 ? "rtl" : "ltr";
|
|
2184
|
+
}
|
|
2185
|
+
static createInstance() {
|
|
2186
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
2187
|
+
let callback = arguments.length > 1 ? arguments[1] : void 0;
|
|
2188
|
+
return new _I18n(options, callback);
|
|
2189
|
+
}
|
|
2190
|
+
cloneInstance() {
|
|
2191
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
2192
|
+
let callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
2193
|
+
const forkResourceStore = options.forkResourceStore;
|
|
2194
|
+
if (forkResourceStore) delete options.forkResourceStore;
|
|
2195
|
+
const mergedOptions = {
|
|
2196
|
+
...this.options,
|
|
2197
|
+
...options,
|
|
2198
|
+
...{
|
|
2199
|
+
isClone: true
|
|
2200
|
+
}
|
|
2201
|
+
};
|
|
2202
|
+
const clone = new _I18n(mergedOptions);
|
|
2203
|
+
if (options.debug !== void 0 || options.prefix !== void 0) {
|
|
2204
|
+
clone.logger = clone.logger.clone(options);
|
|
2205
|
+
}
|
|
2206
|
+
const membersToCopy = ["store", "services", "language"];
|
|
2207
|
+
membersToCopy.forEach((m) => {
|
|
2208
|
+
clone[m] = this[m];
|
|
2209
|
+
});
|
|
2210
|
+
clone.services = {
|
|
2211
|
+
...this.services
|
|
2212
|
+
};
|
|
2213
|
+
clone.services.utils = {
|
|
2214
|
+
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2215
|
+
};
|
|
2216
|
+
if (forkResourceStore) {
|
|
2217
|
+
const clonedData = Object.keys(this.store.data).reduce((prev, l) => {
|
|
2218
|
+
prev[l] = {
|
|
2219
|
+
...this.store.data[l]
|
|
2220
|
+
};
|
|
2221
|
+
return Object.keys(prev[l]).reduce((acc, n) => {
|
|
2222
|
+
acc[n] = {
|
|
2223
|
+
...prev[l][n]
|
|
2224
|
+
};
|
|
2225
|
+
return acc;
|
|
2226
|
+
}, {});
|
|
2227
|
+
}, {});
|
|
2228
|
+
clone.store = new ResourceStore(clonedData, mergedOptions);
|
|
2229
|
+
clone.services.resourceStore = clone.store;
|
|
2230
|
+
}
|
|
2231
|
+
clone.translator = new Translator(clone.services, mergedOptions);
|
|
2232
|
+
clone.translator.on("*", function(event) {
|
|
2233
|
+
for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
|
|
2234
|
+
args[_key6 - 1] = arguments[_key6];
|
|
2235
|
+
}
|
|
2236
|
+
clone.emit(event, ...args);
|
|
2237
|
+
});
|
|
2238
|
+
clone.init(mergedOptions, callback);
|
|
2239
|
+
clone.translator.options = mergedOptions;
|
|
2240
|
+
clone.translator.backendConnector.services.utils = {
|
|
2241
|
+
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2242
|
+
};
|
|
2243
|
+
return clone;
|
|
2244
|
+
}
|
|
2245
|
+
toJSON() {
|
|
2246
|
+
return {
|
|
2247
|
+
options: this.options,
|
|
2248
|
+
store: this.store,
|
|
2249
|
+
language: this.language,
|
|
2250
|
+
languages: this.languages,
|
|
2251
|
+
resolvedLanguage: this.resolvedLanguage
|
|
2252
|
+
};
|
|
2253
|
+
}
|
|
2254
|
+
};
|
|
2255
|
+
var instance = I18n.createInstance();
|
|
2256
|
+
instance.createInstance = I18n.createInstance;
|
|
2257
|
+
var createInstance = instance.createInstance;
|
|
2258
|
+
var dir = instance.dir;
|
|
2259
|
+
var init = instance.init;
|
|
2260
|
+
var loadResources = instance.loadResources;
|
|
2261
|
+
var reloadResources = instance.reloadResources;
|
|
2262
|
+
var use = instance.use;
|
|
2263
|
+
var changeLanguage = instance.changeLanguage;
|
|
2264
|
+
var getFixedT = instance.getFixedT;
|
|
2265
|
+
var t = instance.t;
|
|
2266
|
+
var exists = instance.exists;
|
|
2267
|
+
var setDefaultNamespace = instance.setDefaultNamespace;
|
|
2268
|
+
var hasLoadedNamespace = instance.hasLoadedNamespace;
|
|
2269
|
+
var loadNamespaces = instance.loadNamespaces;
|
|
2270
|
+
var loadLanguages = instance.loadLanguages;
|
|
2271
|
+
|
|
2272
|
+
// src/locale/en/locale-strings.ts
|
|
70
2273
|
var localeStrings = {
|
|
71
2274
|
Check: {
|
|
2275
|
+
lengthOfStringForPriceOrWeightMustBeExactly: "Length {{length}} of string for price or weight sum must be exactly {{exactLength}}",
|
|
2276
|
+
priceOrWeightComponent: "price or weight",
|
|
72
2277
|
lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "Length {{length}} of string for check character pair must be less than or equal to {{maximumLength}}"
|
|
73
2278
|
},
|
|
74
2279
|
IdentificationKey: {
|
|
@@ -102,9 +2307,11 @@ var localeStrings = {
|
|
|
102
2307
|
}
|
|
103
2308
|
};
|
|
104
2309
|
|
|
105
|
-
// src/locale/fr/
|
|
2310
|
+
// src/locale/fr/locale-strings.ts
|
|
106
2311
|
var localeStrings2 = {
|
|
107
2312
|
Check: {
|
|
2313
|
+
lengthOfStringForPriceOrWeightMustBeExactly: "La longueur {{longueur}} de la cha\xEEne pour le prix ou la somme du poids doit \xEAtre exactement {{exactLength}}",
|
|
2314
|
+
priceOrWeightComponent: "prix ou poids",
|
|
108
2315
|
lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo: "La longueur {{length}} de la cha\xEEne pour la paire de caract\xE8res de v\xE9rification doit \xEAtre inf\xE9rieure ou \xE9gale \xE0 {{maximum Length}}"
|
|
109
2316
|
},
|
|
110
2317
|
IdentificationKey: {
|
|
@@ -141,13 +2348,23 @@ var localeStrings2 = {
|
|
|
141
2348
|
// src/locale/i18n.ts
|
|
142
2349
|
var gs1NS = "aidct_gs1";
|
|
143
2350
|
(0, import_core.i18nAssertValidResources)(localeStrings, "fr", localeStrings2);
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
2351
|
+
var gs1Resources = {
|
|
2352
|
+
en: {
|
|
2353
|
+
aidct_gs1: localeStrings
|
|
2354
|
+
},
|
|
2355
|
+
fr: {
|
|
2356
|
+
aidct_gs1: localeStrings2
|
|
2357
|
+
}
|
|
2358
|
+
};
|
|
2359
|
+
var i18nextGS1 = instance.createInstance();
|
|
2360
|
+
async function i18nGS1Init(environment, debug = false) {
|
|
2361
|
+
await (0, import_utility.i18nUtilityInit)(environment, debug);
|
|
2362
|
+
await (0, import_core.i18nCoreInit)(i18nextGS1, environment, debug, gs1NS, import_utility.utilityResources, gs1Resources);
|
|
2363
|
+
}
|
|
147
2364
|
|
|
148
|
-
// src/
|
|
149
|
-
var
|
|
150
|
-
var AI82_CREATOR = new
|
|
2365
|
+
// src/character-set.ts
|
|
2366
|
+
var import_utility2 = require("@aidc-toolkit/utility");
|
|
2367
|
+
var AI82_CREATOR = new import_utility2.CharacterSetCreator([
|
|
151
2368
|
"!",
|
|
152
2369
|
'"',
|
|
153
2370
|
"%",
|
|
@@ -230,8 +2447,8 @@ var AI82_CREATOR = new import_utility.CharacterSetCreator([
|
|
|
230
2447
|
"x",
|
|
231
2448
|
"y",
|
|
232
2449
|
"z"
|
|
233
|
-
],
|
|
234
|
-
var AI39_CREATOR = new
|
|
2450
|
+
], import_utility2.Exclusion.AllNumeric);
|
|
2451
|
+
var AI39_CREATOR = new import_utility2.CharacterSetCreator([
|
|
235
2452
|
"#",
|
|
236
2453
|
"-",
|
|
237
2454
|
"/",
|
|
@@ -271,10 +2488,10 @@ var AI39_CREATOR = new import_utility.CharacterSetCreator([
|
|
|
271
2488
|
"X",
|
|
272
2489
|
"Y",
|
|
273
2490
|
"Z"
|
|
274
|
-
],
|
|
2491
|
+
], import_utility2.Exclusion.AllNumeric);
|
|
275
2492
|
|
|
276
2493
|
// src/check.ts
|
|
277
|
-
var
|
|
2494
|
+
var import_utility3 = require("@aidc-toolkit/utility");
|
|
278
2495
|
var THREE_WEIGHT_RESULTS = [
|
|
279
2496
|
0,
|
|
280
2497
|
3,
|
|
@@ -337,37 +2554,49 @@ var INVERSE_FIVE_MINUS_WEIGHT_RESULTS = [
|
|
|
337
2554
|
];
|
|
338
2555
|
function checkDigitSum(exchangeWeights, s) {
|
|
339
2556
|
let weight3 = (s.length + Number(exchangeWeights)) % 2 === 0;
|
|
340
|
-
return
|
|
2557
|
+
return import_utility3.NUMERIC_CREATOR.characterIndexes(s).reduce((accumulator, characterIndex, index) => {
|
|
341
2558
|
if (characterIndex === void 0) {
|
|
342
|
-
throw new RangeError(
|
|
2559
|
+
throw new RangeError(i18nextGS1.t("CharacterSetValidator.invalidCharacterAtPosition", {
|
|
2560
|
+
ns: import_utility3.utilityNS,
|
|
2561
|
+
c: s.charAt(index),
|
|
2562
|
+
position: index + 1
|
|
2563
|
+
}));
|
|
343
2564
|
}
|
|
344
2565
|
weight3 = !weight3;
|
|
345
2566
|
return accumulator + (weight3 ? THREE_WEIGHT_RESULTS[characterIndex] : characterIndex);
|
|
346
2567
|
}, 0);
|
|
347
2568
|
}
|
|
348
2569
|
function checkDigit(s) {
|
|
349
|
-
return
|
|
2570
|
+
return import_utility3.NUMERIC_CREATOR.character(9 - (checkDigitSum(false, s) + 9) % 10);
|
|
350
2571
|
}
|
|
351
2572
|
function hasValidCheckDigit(s) {
|
|
352
2573
|
return checkDigitSum(true, s) % 10 === 0;
|
|
353
2574
|
}
|
|
354
2575
|
function priceWeightSum(weightsResults, s) {
|
|
355
2576
|
if (s.length !== weightsResults.length) {
|
|
356
|
-
throw new RangeError(
|
|
2577
|
+
throw new RangeError(i18nextGS1.t("Check.lengthOfStringForPriceOrWeightMustBeExactly", {
|
|
2578
|
+
length: s.length,
|
|
2579
|
+
exactLength: weightsResults.length
|
|
2580
|
+
}));
|
|
357
2581
|
}
|
|
358
|
-
const characterIndexes =
|
|
2582
|
+
const characterIndexes = import_utility3.NUMERIC_CREATOR.characterIndexes(s);
|
|
359
2583
|
return characterIndexes.reduce((accumulator, characterIndex, index) => {
|
|
360
2584
|
if (characterIndex === void 0) {
|
|
361
|
-
throw new RangeError(
|
|
2585
|
+
throw new RangeError(i18nextGS1.t("CharacterSetValidator.invalidCharacterAtPositionOfComponent", {
|
|
2586
|
+
ns: import_utility3.utilityNS,
|
|
2587
|
+
c: s.charAt(index),
|
|
2588
|
+
position: index + 1,
|
|
2589
|
+
component: i18nextGS1.t("Check.priceOrWeightComponent")
|
|
2590
|
+
}));
|
|
362
2591
|
}
|
|
363
2592
|
return accumulator + weightsResults[index][characterIndex];
|
|
364
2593
|
}, 0);
|
|
365
2594
|
}
|
|
366
2595
|
function fourDigitPriceWeightCheckDigit(s) {
|
|
367
|
-
return
|
|
2596
|
+
return import_utility3.NUMERIC_CREATOR.character(priceWeightSum([TWO_MINUS_WEIGHT_RESULTS, TWO_MINUS_WEIGHT_RESULTS, THREE_WEIGHT_RESULTS, FIVE_MINUS_WEIGHT_RESULTS], s) * 3 % 10);
|
|
368
2597
|
}
|
|
369
2598
|
function fiveDigitPriceWeightCheckDigit(s) {
|
|
370
|
-
return
|
|
2599
|
+
return import_utility3.NUMERIC_CREATOR.character(INVERSE_FIVE_MINUS_WEIGHT_RESULTS[9 - (priceWeightSum([FIVE_PLUS_WEIGHT_RESULTS, TWO_MINUS_WEIGHT_RESULTS, FIVE_MINUS_WEIGHT_RESULTS, FIVE_PLUS_WEIGHT_RESULTS, TWO_MINUS_WEIGHT_RESULTS], s) + 9) % 10]);
|
|
371
2600
|
}
|
|
372
2601
|
var CHECK_CHARACTER_WEIGHTS = [
|
|
373
2602
|
107,
|
|
@@ -436,15 +2665,18 @@ var CHECK_CHARACTERS = [
|
|
|
436
2665
|
function checkCharacterPair(s) {
|
|
437
2666
|
const weightIndexStart = CHECK_CHARACTER_WEIGHTS.length - s.length;
|
|
438
2667
|
if (weightIndexStart < 0) {
|
|
439
|
-
throw new RangeError(
|
|
440
|
-
ns: gs1NS,
|
|
2668
|
+
throw new RangeError(i18nextGS1.t("Check.lengthOfStringForCheckCharacterPairMustBeLessThanOrEqualTo", {
|
|
441
2669
|
length: s.length,
|
|
442
2670
|
maximumLength: CHECK_CHARACTER_WEIGHTS.length
|
|
443
2671
|
}));
|
|
444
2672
|
}
|
|
445
2673
|
const checkCharacterPairSum = AI82_CREATOR.characterIndexes(s).reduce((accumulator, characterIndex, index) => {
|
|
446
2674
|
if (characterIndex === void 0) {
|
|
447
|
-
throw new RangeError(
|
|
2675
|
+
throw new RangeError(i18nextGS1.t("CharacterSetValidator.invalidCharacterAtPosition", {
|
|
2676
|
+
ns: import_utility3.utilityNS,
|
|
2677
|
+
c: s.charAt(index),
|
|
2678
|
+
position: index + 1
|
|
2679
|
+
}));
|
|
448
2680
|
}
|
|
449
2681
|
return accumulator + characterIndex * CHECK_CHARACTER_WEIGHTS[weightIndexStart + index];
|
|
450
2682
|
}, 0) % 1021;
|
|
@@ -457,7 +2689,7 @@ function hasValidCheckCharacterPair(s) {
|
|
|
457
2689
|
}
|
|
458
2690
|
|
|
459
2691
|
// src/idkey.ts
|
|
460
|
-
var
|
|
2692
|
+
var import_utility4 = require("@aidc-toolkit/utility");
|
|
461
2693
|
var import_ts_mixer = require("ts-mixer");
|
|
462
2694
|
var IdentificationKeyType = /* @__PURE__ */ ((IdentificationKeyType2) => {
|
|
463
2695
|
IdentificationKeyType2["GTIN"] = "GTIN";
|
|
@@ -488,7 +2720,7 @@ var ContentCharacterSet = /* @__PURE__ */ ((ContentCharacterSet2) => {
|
|
|
488
2720
|
})(ContentCharacterSet || {});
|
|
489
2721
|
var AbstractIdentificationKeyValidator = class _AbstractIdentificationKeyValidator {
|
|
490
2722
|
static CHARACTER_SET_CREATORS = [
|
|
491
|
-
|
|
2723
|
+
import_utility4.NUMERIC_CREATOR,
|
|
492
2724
|
AI82_CREATOR,
|
|
493
2725
|
AI39_CREATOR
|
|
494
2726
|
];
|
|
@@ -656,16 +2888,13 @@ var AbstractNumericIdentificationKeyValidator = class extends AbstractIdentifica
|
|
|
656
2888
|
super.validatePrefix(identificationKey.substring(this._prefixPosition), validation?.positionOffset === void 0 ? this._prefixPosition : validation.positionOffset + this._prefixPosition);
|
|
657
2889
|
}
|
|
658
2890
|
if (identificationKey.length !== this.length) {
|
|
659
|
-
throw new RangeError(
|
|
660
|
-
ns: gs1NS,
|
|
2891
|
+
throw new RangeError(i18nextGS1.t("IdentificationKey.identificationKeyTypeLength", {
|
|
661
2892
|
identificationKeyType: this.identificationKeyType,
|
|
662
2893
|
length: this.length
|
|
663
2894
|
}));
|
|
664
2895
|
}
|
|
665
2896
|
if (!hasValidCheckDigit(this.padIdentificationKey(identificationKey, validation))) {
|
|
666
|
-
throw new RangeError(
|
|
667
|
-
ns: gs1NS
|
|
668
|
-
}));
|
|
2897
|
+
throw new RangeError(i18nextGS1.t("IdentificationKey.invalidCheckDigit"));
|
|
669
2898
|
}
|
|
670
2899
|
}
|
|
671
2900
|
};
|
|
@@ -735,7 +2964,7 @@ var GTINValidator = class _GTINValidator extends AbstractNumericIdentificationKe
|
|
|
735
2964
|
* GTIN-12.
|
|
736
2965
|
*/
|
|
737
2966
|
static zeroExpand(zeroSuppressedGTIN12) {
|
|
738
|
-
|
|
2967
|
+
import_utility4.NUMERIC_CREATOR.validate(zeroSuppressedGTIN12, _GTINValidator.ZERO_SUPPRESSED_GTIN12_VALIDATION);
|
|
739
2968
|
const d = Array.from(zeroSuppressedGTIN12);
|
|
740
2969
|
let gtin12;
|
|
741
2970
|
if (d[0] === "0") {
|
|
@@ -750,9 +2979,7 @@ var GTINValidator = class _GTINValidator extends AbstractNumericIdentificationKe
|
|
|
750
2979
|
}
|
|
751
2980
|
}
|
|
752
2981
|
if (gtin12 === void 0) {
|
|
753
|
-
throw new RangeError(
|
|
754
|
-
ns: gs1NS
|
|
755
|
-
}));
|
|
2982
|
+
throw new RangeError(i18nextGS1.t("IdentificationKey.invalidZeroSuppressedGTIN12"));
|
|
756
2983
|
}
|
|
757
2984
|
GTIN12_VALIDATOR.validate(gtin12);
|
|
758
2985
|
return gtin12;
|
|
@@ -772,9 +2999,7 @@ var GTINValidator = class _GTINValidator extends AbstractNumericIdentificationKe
|
|
|
772
2999
|
switch (gtin.length) {
|
|
773
3000
|
case 13 /* GTIN13 */:
|
|
774
3001
|
if (gtin.startsWith("0")) {
|
|
775
|
-
throw new RangeError(
|
|
776
|
-
ns: gs1NS
|
|
777
|
-
}));
|
|
3002
|
+
throw new RangeError(i18nextGS1.t("IdentificationKey.invalidGTIN13AtRetail"));
|
|
778
3003
|
}
|
|
779
3004
|
PrefixManager.validatePrefix(0 /* GS1CompanyPrefix */, false, false, gtin, true, true);
|
|
780
3005
|
gtinLevelRestriction = 0 /* Any */;
|
|
@@ -796,19 +3021,13 @@ var GTINValidator = class _GTINValidator extends AbstractNumericIdentificationKe
|
|
|
796
3021
|
gtinLevelRestriction = 2 /* OtherThanRetailConsumer */;
|
|
797
3022
|
break;
|
|
798
3023
|
default:
|
|
799
|
-
throw new RangeError(
|
|
800
|
-
ns: gs1NS
|
|
801
|
-
}));
|
|
3024
|
+
throw new RangeError(i18nextGS1.t("IdentificationKey.invalidGTINLength"));
|
|
802
3025
|
}
|
|
803
3026
|
if (!hasValidCheckDigit(lengthValidatedGTIN)) {
|
|
804
|
-
throw new RangeError(
|
|
805
|
-
ns: gs1NS
|
|
806
|
-
}));
|
|
3027
|
+
throw new RangeError(i18nextGS1.t("IdentificationKey.invalidCheckDigit"));
|
|
807
3028
|
}
|
|
808
3029
|
if (gtinLevel !== 0 /* Any */ && gtinLevelRestriction !== 0 /* Any */ && gtinLevelRestriction !== gtinLevel) {
|
|
809
|
-
throw new RangeError(
|
|
810
|
-
ns: gs1NS
|
|
811
|
-
}));
|
|
3030
|
+
throw new RangeError(i18nextGS1.t(gtinLevel === 1 /* RetailConsumer */ ? "IdentificationKey.invalidGTINAtRetail" : "IdentificationKey.invalidGTINAtOtherThanRetail"));
|
|
812
3031
|
}
|
|
813
3032
|
}
|
|
814
3033
|
/**
|
|
@@ -819,9 +3038,7 @@ var GTINValidator = class _GTINValidator extends AbstractNumericIdentificationKe
|
|
|
819
3038
|
*/
|
|
820
3039
|
static validateGTIN14(gtin14) {
|
|
821
3040
|
if (gtin14.length !== 14 /* GTIN14 */) {
|
|
822
|
-
throw new RangeError(
|
|
823
|
-
ns: gs1NS
|
|
824
|
-
}));
|
|
3041
|
+
throw new RangeError(i18nextGS1.t("IdentificationKey.invalidGTIN14Length"));
|
|
825
3042
|
}
|
|
826
3043
|
GTINCreator.validateAny(gtin14);
|
|
827
3044
|
}
|
|
@@ -882,9 +3099,7 @@ var SerializableNumericIdentificationKeyValidator = class _SerializableNumericId
|
|
|
882
3099
|
this._serialComponentValidation = {
|
|
883
3100
|
minimumLength: 1,
|
|
884
3101
|
maximumLength: serialComponentLength,
|
|
885
|
-
component: () =>
|
|
886
|
-
ns: gs1NS
|
|
887
|
-
})
|
|
3102
|
+
component: () => i18nextGS1.t("IdentificationKey.serialComponent")
|
|
888
3103
|
};
|
|
889
3104
|
this._serialComponentCreator = _SerializableNumericIdentificationKeyValidator.creatorFor(serialComponentCharacterSet);
|
|
890
3105
|
}
|
|
@@ -926,14 +3141,12 @@ var NonNumericIdentificationKeyValidator = class _NonNumericIdentificationKeyVal
|
|
|
926
3141
|
/**
|
|
927
3142
|
* Validator to ensure that an identification key (minus check character pair) is not all numeric.
|
|
928
3143
|
*/
|
|
929
|
-
static NOT_ALL_NUMERIC_VALIDATOR = new class extends
|
|
3144
|
+
static NOT_ALL_NUMERIC_VALIDATOR = new class extends import_utility4.RegExpValidator {
|
|
930
3145
|
/**
|
|
931
3146
|
* @inheritDoc
|
|
932
3147
|
*/
|
|
933
3148
|
createErrorMessage(_s) {
|
|
934
|
-
return
|
|
935
|
-
ns: gs1NS
|
|
936
|
-
});
|
|
3149
|
+
return i18nextGS1.t("IdentificationKey.referenceCantBeAllNumeric");
|
|
937
3150
|
}
|
|
938
3151
|
}(/\D/);
|
|
939
3152
|
/**
|
|
@@ -983,11 +3196,9 @@ var NonNumericIdentificationKeyValidator = class _NonNumericIdentificationKeyVal
|
|
|
983
3196
|
positionOffset: validation?.positionOffset
|
|
984
3197
|
});
|
|
985
3198
|
} else if (!hasValidCheckCharacterPair(this.padIdentificationKey(identificationKey, validation))) {
|
|
986
|
-
throw new RangeError(
|
|
987
|
-
ns: gs1NS
|
|
988
|
-
}));
|
|
3199
|
+
throw new RangeError(i18nextGS1.t("IdentificationKey.invalidCheckCharacterPair"));
|
|
989
3200
|
}
|
|
990
|
-
if (validation?.exclusion ===
|
|
3201
|
+
if (validation?.exclusion === import_utility4.Exclusion.AllNumeric) {
|
|
991
3202
|
_NonNumericIdentificationKeyValidator.NOT_ALL_NUMERIC_VALIDATOR.validate(partialIdentificationKey);
|
|
992
3203
|
}
|
|
993
3204
|
}
|
|
@@ -1075,7 +3286,7 @@ var AbstractNumericIdentificationKeyCreator = class _AbstractNumericIdentificati
|
|
|
1075
3286
|
*/
|
|
1076
3287
|
init(prefixManager, prefix) {
|
|
1077
3288
|
super.init(prefixManager, prefix, 1);
|
|
1078
|
-
this._capacity = Number(
|
|
3289
|
+
this._capacity = Number(import_utility4.CharacterSetCreator.powerOf10(this.referenceLength));
|
|
1079
3290
|
}
|
|
1080
3291
|
/**
|
|
1081
3292
|
* @inheritDoc
|
|
@@ -1112,7 +3323,7 @@ var AbstractNumericIdentificationKeyCreator = class _AbstractNumericIdentificati
|
|
|
1112
3323
|
* @inheritDoc
|
|
1113
3324
|
*/
|
|
1114
3325
|
create(valueOrValues, sparse = false) {
|
|
1115
|
-
return
|
|
3326
|
+
return import_utility4.NUMERIC_CREATOR.create(this.referenceLength, valueOrValues, import_utility4.Exclusion.None, sparse ? this.tweak : void 0, (reference) => this.buildIdentificationKey(reference));
|
|
1116
3327
|
}
|
|
1117
3328
|
/**
|
|
1118
3329
|
* Create all identification keys from a partial identification key. Call is recursive until remaining reference
|
|
@@ -1139,18 +3350,18 @@ var AbstractNumericIdentificationKeyCreator = class _AbstractNumericIdentificati
|
|
|
1139
3350
|
*/
|
|
1140
3351
|
static *createAllPartial(partialIdentificationKey, remainingReferenceLength, extensionWeight, weight, partialCheckDigitSum) {
|
|
1141
3352
|
if (remainingReferenceLength === 0) {
|
|
1142
|
-
yield partialIdentificationKey +
|
|
3353
|
+
yield partialIdentificationKey + import_utility4.NUMERIC_CREATOR.character(9 - (partialCheckDigitSum + 9) % 10);
|
|
1143
3354
|
} else {
|
|
1144
3355
|
const nextRemainingReferenceLength = remainingReferenceLength - 1;
|
|
1145
3356
|
let nextPartialCheckDigitSum = partialCheckDigitSum;
|
|
1146
3357
|
if (extensionWeight !== 0) {
|
|
1147
|
-
for (const c of
|
|
3358
|
+
for (const c of import_utility4.NUMERIC_CREATOR.characterSet) {
|
|
1148
3359
|
yield* _AbstractNumericIdentificationKeyCreator.createAllPartial(c + partialIdentificationKey, nextRemainingReferenceLength, 0, weight, nextPartialCheckDigitSum);
|
|
1149
3360
|
nextPartialCheckDigitSum += extensionWeight;
|
|
1150
3361
|
}
|
|
1151
3362
|
} else {
|
|
1152
3363
|
const nextWeight = 4 - weight;
|
|
1153
|
-
for (const c of
|
|
3364
|
+
for (const c of import_utility4.NUMERIC_CREATOR.characterSet) {
|
|
1154
3365
|
yield* _AbstractNumericIdentificationKeyCreator.createAllPartial(partialIdentificationKey + c, nextRemainingReferenceLength, 0, nextWeight, nextPartialCheckDigitSum);
|
|
1155
3366
|
nextPartialCheckDigitSum += weight;
|
|
1156
3367
|
}
|
|
@@ -1163,9 +3374,14 @@ var AbstractNumericIdentificationKeyCreator = class _AbstractNumericIdentificati
|
|
|
1163
3374
|
createAll() {
|
|
1164
3375
|
const hasExtensionDigit = this.leaderType === 2 /* ExtensionDigit */;
|
|
1165
3376
|
const prefix = this.prefix;
|
|
3377
|
+
const length = this.length;
|
|
1166
3378
|
const referenceLength = this.referenceLength;
|
|
1167
3379
|
const startWeight = 3 - 2 * ((referenceLength + 1 - Number(hasExtensionDigit)) % 2);
|
|
1168
|
-
return
|
|
3380
|
+
return {
|
|
3381
|
+
[Symbol.iterator]() {
|
|
3382
|
+
return _AbstractNumericIdentificationKeyCreator.createAllPartial(prefix, referenceLength, hasExtensionDigit ? 3 - 2 * length % 2 : 0, startWeight, checkDigitSum(startWeight === 3, prefix));
|
|
3383
|
+
}
|
|
3384
|
+
};
|
|
1169
3385
|
}
|
|
1170
3386
|
};
|
|
1171
3387
|
var GTINCreator = class _GTINCreator extends (0, import_ts_mixer.Mixin)(GTINValidator, AbstractNumericIdentificationKeyCreator) {
|
|
@@ -1175,9 +3391,7 @@ var GTINCreator = class _GTINCreator extends (0, import_ts_mixer.Mixin)(GTINVali
|
|
|
1175
3391
|
static REQUIRED_INDICATOR_DIGIT_VALIDATION = {
|
|
1176
3392
|
minimumLength: 1,
|
|
1177
3393
|
maximumLength: 1,
|
|
1178
|
-
component: () =>
|
|
1179
|
-
ns: gs1NS
|
|
1180
|
-
})
|
|
3394
|
+
component: () => i18nextGS1.t("IdentificationKey.indicatorDigit")
|
|
1181
3395
|
};
|
|
1182
3396
|
/**
|
|
1183
3397
|
* Validation parameters for optional indicator digit.
|
|
@@ -1185,9 +3399,7 @@ var GTINCreator = class _GTINCreator extends (0, import_ts_mixer.Mixin)(GTINVali
|
|
|
1185
3399
|
static OPTIONAL_INDICATOR_DIGIT_VALIDATION = {
|
|
1186
3400
|
minimumLength: 0,
|
|
1187
3401
|
maximumLength: 1,
|
|
1188
|
-
component: () =>
|
|
1189
|
-
ns: gs1NS
|
|
1190
|
-
})
|
|
3402
|
+
component: () => i18nextGS1.t("IdentificationKey.indicatorDigit")
|
|
1191
3403
|
};
|
|
1192
3404
|
/**
|
|
1193
3405
|
* Constructor. Called internally by {@link PrefixManager.gtinCreator}; should not be called by other code.
|
|
@@ -1225,8 +3437,8 @@ var GTINCreator = class _GTINCreator extends (0, import_ts_mixer.Mixin)(GTINVali
|
|
|
1225
3437
|
* GTIN-14(s).
|
|
1226
3438
|
*/
|
|
1227
3439
|
createGTIN14(indicatorDigit, valueOrValues, sparse = false) {
|
|
1228
|
-
|
|
1229
|
-
return
|
|
3440
|
+
import_utility4.NUMERIC_CREATOR.validate(indicatorDigit, _GTINCreator.REQUIRED_INDICATOR_DIGIT_VALIDATION);
|
|
3441
|
+
return import_utility4.NUMERIC_CREATOR.create(13 /* GTIN13 */ - this.prefixManager.gs1CompanyPrefix.length - 1, valueOrValues, import_utility4.Exclusion.None, sparse ? this.tweak : void 0, (reference) => {
|
|
1230
3442
|
const partialIdentificationKey = indicatorDigit + this.prefixManager.gs1CompanyPrefix + reference;
|
|
1231
3443
|
return partialIdentificationKey + checkDigit(partialIdentificationKey);
|
|
1232
3444
|
});
|
|
@@ -1256,9 +3468,7 @@ var GTINCreator = class _GTINCreator extends (0, import_ts_mixer.Mixin)(GTINVali
|
|
|
1256
3468
|
}
|
|
1257
3469
|
}
|
|
1258
3470
|
if (zeroSuppressedGTIN12 === void 0) {
|
|
1259
|
-
throw new RangeError(
|
|
1260
|
-
ns: gs1NS
|
|
1261
|
-
}));
|
|
3471
|
+
throw new RangeError(i18nextGS1.t("IdentificationKey.invalidZeroSuppressibleGTIN12"));
|
|
1262
3472
|
}
|
|
1263
3473
|
return zeroSuppressedGTIN12;
|
|
1264
3474
|
}
|
|
@@ -1276,7 +3486,7 @@ var GTINCreator = class _GTINCreator extends (0, import_ts_mixer.Mixin)(GTINVali
|
|
|
1276
3486
|
*/
|
|
1277
3487
|
static convertToGTIN14(indicatorDigit, gtin) {
|
|
1278
3488
|
_GTINCreator.validateAny(gtin);
|
|
1279
|
-
|
|
3489
|
+
import_utility4.NUMERIC_CREATOR.validate(indicatorDigit, _GTINCreator.OPTIONAL_INDICATOR_DIGIT_VALIDATION);
|
|
1280
3490
|
const gtinLength = gtin.length;
|
|
1281
3491
|
let gtin14 = "0".repeat(14 /* GTIN14 */ - gtinLength) + gtin;
|
|
1282
3492
|
if (indicatorDigit.length !== 0 && indicatorDigit !== gtin14.charAt(0)) {
|
|
@@ -1310,9 +3520,7 @@ var GTINCreator = class _GTINCreator extends (0, import_ts_mixer.Mixin)(GTINVali
|
|
|
1310
3520
|
} else if (!gtin.startsWith("000000")) {
|
|
1311
3521
|
normalizedGTIN = gtin.substring(5);
|
|
1312
3522
|
} else {
|
|
1313
|
-
throw new RangeError(
|
|
1314
|
-
ns: gs1NS
|
|
1315
|
-
}));
|
|
3523
|
+
throw new RangeError(i18nextGS1.t("IdentificationKey.invalidZeroSuppressedGTIN12AsGTIN13"));
|
|
1316
3524
|
}
|
|
1317
3525
|
break;
|
|
1318
3526
|
case 12 /* GTIN12 */:
|
|
@@ -1335,15 +3543,11 @@ var GTINCreator = class _GTINCreator extends (0, import_ts_mixer.Mixin)(GTINVali
|
|
|
1335
3543
|
} else if (!gtin.startsWith("0000000")) {
|
|
1336
3544
|
normalizedGTIN = gtin.substring(6);
|
|
1337
3545
|
} else {
|
|
1338
|
-
throw new RangeError(
|
|
1339
|
-
ns: gs1NS
|
|
1340
|
-
}));
|
|
3546
|
+
throw new RangeError(i18nextGS1.t("IdentificationKey.invalidZeroSuppressedGTIN12AsGTIN14"));
|
|
1341
3547
|
}
|
|
1342
3548
|
break;
|
|
1343
3549
|
default:
|
|
1344
|
-
throw new RangeError(
|
|
1345
|
-
ns: gs1NS
|
|
1346
|
-
}));
|
|
3550
|
+
throw new RangeError(i18nextGS1.t("IdentificationKey.invalidGTINLength"));
|
|
1347
3551
|
}
|
|
1348
3552
|
_GTINCreator.validateAny(normalizedGTIN);
|
|
1349
3553
|
return normalizedGTIN;
|
|
@@ -1418,7 +3622,7 @@ var SerializableNumericIdentificationKeyCreator = class extends (0, import_ts_mi
|
|
|
1418
3622
|
if (typeof serialComponentOrComponents !== "object") {
|
|
1419
3623
|
result = validateAndConcatenate(serialComponentOrComponents);
|
|
1420
3624
|
} else {
|
|
1421
|
-
result =
|
|
3625
|
+
result = (0, import_utility4.transformIterable)(serialComponentOrComponents, validateAndConcatenate);
|
|
1422
3626
|
}
|
|
1423
3627
|
return result;
|
|
1424
3628
|
}
|
|
@@ -1489,9 +3693,7 @@ var NonNumericIdentificationKeyCreator = class extends (0, import_ts_mixer.Mixin
|
|
|
1489
3693
|
minimumLength: 1,
|
|
1490
3694
|
// Maximum reference length has to account for prefix and check character pair.
|
|
1491
3695
|
maximumLength: this.referenceLength,
|
|
1492
|
-
component: () =>
|
|
1493
|
-
ns: gs1NS
|
|
1494
|
-
})
|
|
3696
|
+
component: () => i18nextGS1.t("IdentificationKey.reference")
|
|
1495
3697
|
};
|
|
1496
3698
|
}
|
|
1497
3699
|
/**
|
|
@@ -1523,7 +3725,7 @@ var NonNumericIdentificationKeyCreator = class extends (0, import_ts_mixer.Mixin
|
|
|
1523
3725
|
if (typeof referenceOrReferences !== "object") {
|
|
1524
3726
|
result = validateAndCreate(referenceOrReferences);
|
|
1525
3727
|
} else {
|
|
1526
|
-
result =
|
|
3728
|
+
result = (0, import_utility4.transformIterable)(referenceOrReferences, validateAndCreate);
|
|
1527
3729
|
}
|
|
1528
3730
|
return result;
|
|
1529
3731
|
}
|
|
@@ -1563,9 +3765,7 @@ var PrefixManager = class _PrefixManager {
|
|
|
1563
3765
|
static GS1_COMPANY_PREFIX_VALIDATION = {
|
|
1564
3766
|
minimumLength: _PrefixManager.GS1_COMPANY_PREFIX_MINIMUM_LENGTH,
|
|
1565
3767
|
maximumLength: _PrefixManager.GS1_COMPANY_PREFIX_MAXIMUM_LENGTH,
|
|
1566
|
-
component: () =>
|
|
1567
|
-
ns: gs1NS
|
|
1568
|
-
})
|
|
3768
|
+
component: () => i18nextGS1.t("Prefix.gs1CompanyPrefix")
|
|
1569
3769
|
};
|
|
1570
3770
|
/**
|
|
1571
3771
|
* Validation parameters for U.P.C. Company Prefix expressed as GS1 Company Prefix.
|
|
@@ -1573,9 +3773,7 @@ var PrefixManager = class _PrefixManager {
|
|
|
1573
3773
|
static UPC_COMPANY_PREFIX_AS_GS1_COMPANY_PREFIX_VALIDATION = {
|
|
1574
3774
|
minimumLength: _PrefixManager.UPC_COMPANY_PREFIX_MINIMUM_LENGTH + 1,
|
|
1575
3775
|
maximumLength: _PrefixManager.UPC_COMPANY_PREFIX_MAXIMUM_LENGTH + 1,
|
|
1576
|
-
component: () =>
|
|
1577
|
-
ns: gs1NS
|
|
1578
|
-
})
|
|
3776
|
+
component: () => i18nextGS1.t("Prefix.gs1CompanyPrefix")
|
|
1579
3777
|
};
|
|
1580
3778
|
/**
|
|
1581
3779
|
* Validation parameters for GS1-8 Prefix expressed as GS1 Company Prefix.
|
|
@@ -1583,9 +3781,7 @@ var PrefixManager = class _PrefixManager {
|
|
|
1583
3781
|
static GS1_8_PREFIX_AS_GS1_COMPANY_PREFIX_VALIDATION = {
|
|
1584
3782
|
minimumLength: _PrefixManager.GS1_8_PREFIX_MINIMUM_LENGTH + 5,
|
|
1585
3783
|
maximumLength: _PrefixManager.GS1_8_PREFIX_MAXIMUM_LENGTH + 5,
|
|
1586
|
-
component: () =>
|
|
1587
|
-
ns: gs1NS
|
|
1588
|
-
})
|
|
3784
|
+
component: () => i18nextGS1.t("Prefix.gs1CompanyPrefix")
|
|
1589
3785
|
};
|
|
1590
3786
|
/**
|
|
1591
3787
|
* Validation parameters for U.P.C. Company Prefix.
|
|
@@ -1593,9 +3789,7 @@ var PrefixManager = class _PrefixManager {
|
|
|
1593
3789
|
static UPC_COMPANY_PREFIX_VALIDATION = {
|
|
1594
3790
|
minimumLength: _PrefixManager.UPC_COMPANY_PREFIX_MINIMUM_LENGTH,
|
|
1595
3791
|
maximumLength: _PrefixManager.UPC_COMPANY_PREFIX_MAXIMUM_LENGTH,
|
|
1596
|
-
component: () =>
|
|
1597
|
-
ns: gs1NS
|
|
1598
|
-
})
|
|
3792
|
+
component: () => i18nextGS1.t("Prefix.upcCompanyPrefix")
|
|
1599
3793
|
};
|
|
1600
3794
|
/**
|
|
1601
3795
|
* Validation parameters for GS1-8 Prefix.
|
|
@@ -1603,9 +3797,7 @@ var PrefixManager = class _PrefixManager {
|
|
|
1603
3797
|
static GS1_8_PREFIX_VALIDATION = {
|
|
1604
3798
|
minimumLength: _PrefixManager.GS1_8_PREFIX_MINIMUM_LENGTH,
|
|
1605
3799
|
maximumLength: _PrefixManager.GS1_8_PREFIX_MAXIMUM_LENGTH,
|
|
1606
|
-
component: () =>
|
|
1607
|
-
ns: gs1NS
|
|
1608
|
-
})
|
|
3800
|
+
component: () => i18nextGS1.t("Prefix.gs18Prefix")
|
|
1609
3801
|
};
|
|
1610
3802
|
/**
|
|
1611
3803
|
* Creator tweak factors. Different numeric identification key types have different tweak factors so that sparse
|
|
@@ -1805,37 +3997,27 @@ var PrefixManager = class _PrefixManager {
|
|
|
1805
3997
|
baseValidation = _PrefixManager.GS1_COMPANY_PREFIX_VALIDATION;
|
|
1806
3998
|
} else if (!prefix.startsWith("00000")) {
|
|
1807
3999
|
if (!allowUPCCompanyPrefix) {
|
|
1808
|
-
throw new RangeError(
|
|
1809
|
-
ns: gs1NS
|
|
1810
|
-
}));
|
|
4000
|
+
throw new RangeError(i18nextGS1.t("Prefix.gs1CompanyPrefixCantStartWith0"));
|
|
1811
4001
|
}
|
|
1812
4002
|
baseValidation = _PrefixManager.UPC_COMPANY_PREFIX_AS_GS1_COMPANY_PREFIX_VALIDATION;
|
|
1813
4003
|
} else if (!prefix.startsWith("000000")) {
|
|
1814
4004
|
if (!allowGS18Prefix) {
|
|
1815
|
-
throw new RangeError(
|
|
1816
|
-
ns: gs1NS
|
|
1817
|
-
}));
|
|
4005
|
+
throw new RangeError(i18nextGS1.t("Prefix.gs1CompanyPrefixCantStartWith00000"));
|
|
1818
4006
|
}
|
|
1819
4007
|
baseValidation = _PrefixManager.GS1_8_PREFIX_AS_GS1_COMPANY_PREFIX_VALIDATION;
|
|
1820
4008
|
} else {
|
|
1821
|
-
throw new RangeError(
|
|
1822
|
-
ns: gs1NS
|
|
1823
|
-
}));
|
|
4009
|
+
throw new RangeError(i18nextGS1.t("Prefix.gs1CompanyPrefixCantStartWith000000"));
|
|
1824
4010
|
}
|
|
1825
4011
|
break;
|
|
1826
4012
|
case 1 /* UPCCompanyPrefix */:
|
|
1827
4013
|
if (prefix.startsWith("0000")) {
|
|
1828
|
-
throw new RangeError(
|
|
1829
|
-
ns: gs1NS
|
|
1830
|
-
}));
|
|
4014
|
+
throw new RangeError(i18nextGS1.t("Prefix.upcCompanyPrefixCantStartWith0000"));
|
|
1831
4015
|
}
|
|
1832
4016
|
baseValidation = _PrefixManager.UPC_COMPANY_PREFIX_VALIDATION;
|
|
1833
4017
|
break;
|
|
1834
4018
|
case 2 /* GS18Prefix */:
|
|
1835
4019
|
if (prefix.startsWith("0")) {
|
|
1836
|
-
throw new RangeError(
|
|
1837
|
-
ns: gs1NS
|
|
1838
|
-
}));
|
|
4020
|
+
throw new RangeError(i18nextGS1.t("Prefix.gs18PrefixCantStartWith0"));
|
|
1839
4021
|
}
|
|
1840
4022
|
baseValidation = _PrefixManager.GS1_8_PREFIX_VALIDATION;
|
|
1841
4023
|
break;
|
|
@@ -1845,9 +4027,9 @@ var PrefixManager = class _PrefixManager {
|
|
|
1845
4027
|
positionOffset
|
|
1846
4028
|
};
|
|
1847
4029
|
if (!isFromIdentificationKey) {
|
|
1848
|
-
|
|
4030
|
+
import_utility4.NUMERIC_CREATOR.validate(prefix, mergedValidation);
|
|
1849
4031
|
} else if (!isNumericIdentificationKey) {
|
|
1850
|
-
|
|
4032
|
+
import_utility4.NUMERIC_CREATOR.validate(prefix.substring(0, Math.min(mergedValidation.minimumLength, prefix.length - 1)), mergedValidation);
|
|
1851
4033
|
}
|
|
1852
4034
|
}
|
|
1853
4035
|
/**
|
|
@@ -1866,8 +4048,7 @@ var PrefixManager = class _PrefixManager {
|
|
|
1866
4048
|
let creator = this._identificationKeyCreatorsMap.get(identificationKeyType);
|
|
1867
4049
|
if (creator === void 0) {
|
|
1868
4050
|
if (this.prefixType === 2 /* GS18Prefix */ && identificationKeyType !== "GTIN" /* GTIN */) {
|
|
1869
|
-
throw new RangeError(
|
|
1870
|
-
ns: gs1NS,
|
|
4051
|
+
throw new RangeError(i18nextGS1.t("Prefix.identificationKeyTypeNotSupportedByGS18Prefix", {
|
|
1871
4052
|
identificationKeyType
|
|
1872
4053
|
}));
|
|
1873
4054
|
}
|
|
@@ -2040,6 +4221,9 @@ var PrefixManager = class _PrefixManager {
|
|
|
2040
4221
|
fiveDigitPriceWeightCheckDigit,
|
|
2041
4222
|
fourDigitPriceWeightCheckDigit,
|
|
2042
4223
|
gs1NS,
|
|
4224
|
+
gs1Resources,
|
|
2043
4225
|
hasValidCheckCharacterPair,
|
|
2044
|
-
hasValidCheckDigit
|
|
4226
|
+
hasValidCheckDigit,
|
|
4227
|
+
i18nGS1Init,
|
|
4228
|
+
i18nextGS1
|
|
2045
4229
|
});
|