react-i18next 17.0.0 → 17.0.2
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/CHANGELOG.md +9 -0
- package/TransWithoutContext.d.ts +9 -3
- package/dist/amd/react-i18next.js +63 -86
- package/dist/amd/react-i18next.min.js +1 -1
- package/dist/es/package.json +1 -1
- package/dist/umd/react-i18next.js +63 -86
- package/dist/umd/react-i18next.min.js +1 -1
- package/package.json +3 -3
- package/react-i18next.js +63 -86
- package/react-i18next.min.js +1 -1
package/react-i18next.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
};
|
|
19
19
|
const makeString = object => {
|
|
20
20
|
if (object == null) return '';
|
|
21
|
-
return
|
|
21
|
+
return String(object);
|
|
22
22
|
};
|
|
23
23
|
const copy = (a, s, t) => {
|
|
24
24
|
a.forEach(m => {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
});
|
|
27
27
|
};
|
|
28
28
|
const lastOfPathSeparatorRegExp = /###/g;
|
|
29
|
-
const cleanKey = key => key && key.
|
|
29
|
+
const cleanKey = key => key && key.includes('###') ? key.replace(lastOfPathSeparatorRegExp, '.') : key;
|
|
30
30
|
const canNotTraverseDeeper = object => !object || isString$1(object);
|
|
31
31
|
const getLastOfPath = (object, path, Empty) => {
|
|
32
32
|
const stack = !isString$1(path) ? path : path.split('.');
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
return target;
|
|
112
112
|
};
|
|
113
113
|
const regexEscape = str => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
|
|
114
|
-
|
|
114
|
+
const _entityMap = {
|
|
115
115
|
'&': '&',
|
|
116
116
|
'<': '<',
|
|
117
117
|
'>': '>',
|
|
@@ -150,7 +150,7 @@
|
|
|
150
150
|
const looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
|
|
151
151
|
nsSeparator = nsSeparator || '';
|
|
152
152
|
keySeparator = keySeparator || '';
|
|
153
|
-
const possibleChars = chars.filter(c => nsSeparator.
|
|
153
|
+
const possibleChars = chars.filter(c => !nsSeparator.includes(c) && !keySeparator.includes(c));
|
|
154
154
|
if (possibleChars.length === 0) return true;
|
|
155
155
|
const r = looksLikeObjectPathRegExpCache.getRegExp(`(${possibleChars.map(c => c === '?' ? '\\?' : c).join('|')})`);
|
|
156
156
|
let matched = !r.test(key);
|
|
@@ -183,7 +183,7 @@
|
|
|
183
183
|
nextPath += tokens[j];
|
|
184
184
|
next = current[nextPath];
|
|
185
185
|
if (next !== undefined) {
|
|
186
|
-
if (['string', 'number', 'boolean'].
|
|
186
|
+
if (['string', 'number', 'boolean'].includes(typeof next) && j < tokens.length - 1) {
|
|
187
187
|
continue;
|
|
188
188
|
}
|
|
189
189
|
i += j - i + 1;
|
|
@@ -272,6 +272,14 @@
|
|
|
272
272
|
}
|
|
273
273
|
this.observers[event].delete(listener);
|
|
274
274
|
}
|
|
275
|
+
once(event, listener) {
|
|
276
|
+
const wrapper = (...args) => {
|
|
277
|
+
listener(...args);
|
|
278
|
+
this.off(event, wrapper);
|
|
279
|
+
};
|
|
280
|
+
this.on(event, wrapper);
|
|
281
|
+
return this;
|
|
282
|
+
}
|
|
275
283
|
emit(event, ...args) {
|
|
276
284
|
if (this.observers[event]) {
|
|
277
285
|
const cloned = Array.from(this.observers[event].entries());
|
|
@@ -285,7 +293,7 @@
|
|
|
285
293
|
const cloned = Array.from(this.observers['*'].entries());
|
|
286
294
|
cloned.forEach(([observer, numTimesAdded]) => {
|
|
287
295
|
for (let i = 0; i < numTimesAdded; i++) {
|
|
288
|
-
observer
|
|
296
|
+
observer(event, ...args);
|
|
289
297
|
}
|
|
290
298
|
});
|
|
291
299
|
}
|
|
@@ -307,7 +315,7 @@
|
|
|
307
315
|
}
|
|
308
316
|
}
|
|
309
317
|
addNamespaces(ns) {
|
|
310
|
-
if (this.options.ns.
|
|
318
|
+
if (!this.options.ns.includes(ns)) {
|
|
311
319
|
this.options.ns.push(ns);
|
|
312
320
|
}
|
|
313
321
|
}
|
|
@@ -321,7 +329,7 @@
|
|
|
321
329
|
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
322
330
|
const ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
323
331
|
let path;
|
|
324
|
-
if (lng.
|
|
332
|
+
if (lng.includes('.')) {
|
|
325
333
|
path = lng.split('.');
|
|
326
334
|
} else {
|
|
327
335
|
path = [lng, ns];
|
|
@@ -336,7 +344,7 @@
|
|
|
336
344
|
}
|
|
337
345
|
}
|
|
338
346
|
const result = getPath(this.data, path);
|
|
339
|
-
if (!result && !ns && !key && lng.
|
|
347
|
+
if (!result && !ns && !key && lng.includes('.')) {
|
|
340
348
|
lng = path[0];
|
|
341
349
|
ns = path[1];
|
|
342
350
|
key = path.slice(2).join('.');
|
|
@@ -350,7 +358,7 @@
|
|
|
350
358
|
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
351
359
|
let path = [lng, ns];
|
|
352
360
|
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
353
|
-
if (lng.
|
|
361
|
+
if (lng.includes('.')) {
|
|
354
362
|
path = lng.split('.');
|
|
355
363
|
value = ns;
|
|
356
364
|
ns = path[1];
|
|
@@ -374,7 +382,7 @@
|
|
|
374
382
|
skipCopy: false
|
|
375
383
|
}) {
|
|
376
384
|
let path = [lng, ns];
|
|
377
|
-
if (lng.
|
|
385
|
+
if (lng.includes('.')) {
|
|
378
386
|
path = lng.split('.');
|
|
379
387
|
deep = resources;
|
|
380
388
|
resources = ns;
|
|
@@ -461,7 +469,6 @@
|
|
|
461
469
|
}
|
|
462
470
|
return path.join(keySeparator);
|
|
463
471
|
}
|
|
464
|
-
const checkedLoadedFor = {};
|
|
465
472
|
const shouldHandleAsObject = res => !isString$1(res) && typeof res !== 'boolean' && typeof res !== 'number';
|
|
466
473
|
class Translator extends EventEmitter {
|
|
467
474
|
constructor(services, options = {}) {
|
|
@@ -472,6 +479,7 @@
|
|
|
472
479
|
this.options.keySeparator = '.';
|
|
473
480
|
}
|
|
474
481
|
this.logger = baseLogger.create('translator');
|
|
482
|
+
this.checkedLoadedFor = {};
|
|
475
483
|
}
|
|
476
484
|
changeLanguage(lng) {
|
|
477
485
|
if (lng) this.language = lng;
|
|
@@ -496,7 +504,7 @@
|
|
|
496
504
|
if (nsSeparator === undefined) nsSeparator = ':';
|
|
497
505
|
const keySeparator = opt.keySeparator !== undefined ? opt.keySeparator : this.options.keySeparator;
|
|
498
506
|
let namespaces = opt.ns || this.options.defaultNS || [];
|
|
499
|
-
const wouldCheckForNsInKey = nsSeparator && key.
|
|
507
|
+
const wouldCheckForNsInKey = nsSeparator && key.includes(nsSeparator);
|
|
500
508
|
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !opt.keySeparator && !this.options.userDefinedNsSeparator && !opt.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
501
509
|
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
502
510
|
const m = key.match(this.interpolator.nestingRegexp);
|
|
@@ -507,7 +515,7 @@
|
|
|
507
515
|
};
|
|
508
516
|
}
|
|
509
517
|
const parts = key.split(nsSeparator);
|
|
510
|
-
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.
|
|
518
|
+
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.includes(parts[0])) namespaces = parts.shift();
|
|
511
519
|
key = parts.join(keySeparator);
|
|
512
520
|
}
|
|
513
521
|
return {
|
|
@@ -594,7 +602,7 @@
|
|
|
594
602
|
}
|
|
595
603
|
const handleAsObject = shouldHandleAsObject(resForObjHndl);
|
|
596
604
|
const resType = Object.prototype.toString.apply(resForObjHndl);
|
|
597
|
-
if (handleAsObjectInI18nFormat && resForObjHndl && handleAsObject && noObject.
|
|
605
|
+
if (handleAsObjectInI18nFormat && resForObjHndl && handleAsObject && !noObject.includes(resType) && !(isString$1(joinArrays) && Array.isArray(resForObjHndl))) {
|
|
598
606
|
if (!opt.returnObjects && !this.options.returnObjects) {
|
|
599
607
|
if (!this.options.returnedObjectHandler) {
|
|
600
608
|
this.logger.warn('accessing an object - but returnObjects options is not enabled!');
|
|
@@ -690,7 +698,7 @@
|
|
|
690
698
|
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
691
699
|
lngs.forEach(language => {
|
|
692
700
|
const suffixes = this.pluralResolver.getSuffixes(language, opt);
|
|
693
|
-
if (needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.
|
|
701
|
+
if (needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] && !suffixes.includes(`${this.options.pluralSeparator}zero`)) {
|
|
694
702
|
suffixes.push(`${this.options.pluralSeparator}zero`);
|
|
695
703
|
}
|
|
696
704
|
suffixes.forEach(suffix => {
|
|
@@ -800,8 +808,8 @@
|
|
|
800
808
|
namespaces.forEach(ns => {
|
|
801
809
|
if (this.isValidLookup(found)) return;
|
|
802
810
|
usedNS = ns;
|
|
803
|
-
if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils?.hasLoadedNamespace && !this.utils?.hasLoadedNamespace(usedNS)) {
|
|
804
|
-
checkedLoadedFor[`${codes[0]}-${ns}`] = true;
|
|
811
|
+
if (!this.checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils?.hasLoadedNamespace && !this.utils?.hasLoadedNamespace(usedNS)) {
|
|
812
|
+
this.checkedLoadedFor[`${codes[0]}-${ns}`] = true;
|
|
805
813
|
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!!!');
|
|
806
814
|
}
|
|
807
815
|
codes.forEach(code => {
|
|
@@ -816,7 +824,7 @@
|
|
|
816
824
|
const zeroSuffix = `${this.options.pluralSeparator}zero`;
|
|
817
825
|
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
|
|
818
826
|
if (needsPluralHandling) {
|
|
819
|
-
if (opt.ordinal && pluralSuffix.
|
|
827
|
+
if (opt.ordinal && pluralSuffix.startsWith(ordinalPrefix)) {
|
|
820
828
|
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
821
829
|
}
|
|
822
830
|
finalKeys.push(key + pluralSuffix);
|
|
@@ -828,7 +836,7 @@
|
|
|
828
836
|
const contextKey = `${key}${this.options.contextSeparator || '_'}${opt.context}`;
|
|
829
837
|
finalKeys.push(contextKey);
|
|
830
838
|
if (needsPluralHandling) {
|
|
831
|
-
if (opt.ordinal && pluralSuffix.
|
|
839
|
+
if (opt.ordinal && pluralSuffix.startsWith(ordinalPrefix)) {
|
|
832
840
|
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
833
841
|
}
|
|
834
842
|
finalKeys.push(contextKey + pluralSuffix);
|
|
@@ -889,7 +897,7 @@
|
|
|
889
897
|
static hasDefaultValue(options) {
|
|
890
898
|
const prefix = 'defaultValue';
|
|
891
899
|
for (const option in options) {
|
|
892
|
-
if (Object.prototype.hasOwnProperty.call(options, option) &&
|
|
900
|
+
if (Object.prototype.hasOwnProperty.call(options, option) && option.startsWith(prefix) && undefined !== options[option]) {
|
|
893
901
|
return true;
|
|
894
902
|
}
|
|
895
903
|
}
|
|
@@ -904,7 +912,7 @@
|
|
|
904
912
|
}
|
|
905
913
|
getScriptPartFromCode(code) {
|
|
906
914
|
code = getCleanedCode(code);
|
|
907
|
-
if (!code || code.
|
|
915
|
+
if (!code || !code.includes('-')) return null;
|
|
908
916
|
const p = code.split('-');
|
|
909
917
|
if (p.length === 2) return null;
|
|
910
918
|
p.pop();
|
|
@@ -913,12 +921,12 @@
|
|
|
913
921
|
}
|
|
914
922
|
getLanguagePartFromCode(code) {
|
|
915
923
|
code = getCleanedCode(code);
|
|
916
|
-
if (!code || code.
|
|
924
|
+
if (!code || !code.includes('-')) return code;
|
|
917
925
|
const p = code.split('-');
|
|
918
926
|
return this.formatLanguageCode(p[0]);
|
|
919
927
|
}
|
|
920
928
|
formatLanguageCode(code) {
|
|
921
|
-
if (isString$1(code) && code.
|
|
929
|
+
if (isString$1(code) && code.includes('-')) {
|
|
922
930
|
let formattedCode;
|
|
923
931
|
try {
|
|
924
932
|
formattedCode = Intl.getCanonicalLocales(code)[0];
|
|
@@ -938,7 +946,7 @@
|
|
|
938
946
|
if (this.options.load === 'languageOnly' || this.options.nonExplicitSupportedLngs) {
|
|
939
947
|
code = this.getLanguagePartFromCode(code);
|
|
940
948
|
}
|
|
941
|
-
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.
|
|
949
|
+
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.includes(code);
|
|
942
950
|
}
|
|
943
951
|
getBestMatchFromCodes(codes) {
|
|
944
952
|
if (!codes) return null;
|
|
@@ -956,10 +964,11 @@
|
|
|
956
964
|
const lngOnly = this.getLanguagePartFromCode(code);
|
|
957
965
|
if (this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
958
966
|
found = this.options.supportedLngs.find(supportedLng => {
|
|
959
|
-
if (supportedLng === lngOnly) return
|
|
960
|
-
if (supportedLng.
|
|
961
|
-
if (supportedLng.
|
|
962
|
-
if (supportedLng.
|
|
967
|
+
if (supportedLng === lngOnly) return true;
|
|
968
|
+
if (!supportedLng.includes('-') && !lngOnly.includes('-')) return false;
|
|
969
|
+
if (supportedLng.includes('-') && !lngOnly.includes('-') && supportedLng.slice(0, supportedLng.indexOf('-')) === lngOnly) return true;
|
|
970
|
+
if (supportedLng.startsWith(lngOnly) && lngOnly.length > 1) return true;
|
|
971
|
+
return false;
|
|
963
972
|
});
|
|
964
973
|
});
|
|
965
974
|
}
|
|
@@ -990,7 +999,7 @@
|
|
|
990
999
|
this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
|
|
991
1000
|
}
|
|
992
1001
|
};
|
|
993
|
-
if (isString$1(code) && (code.
|
|
1002
|
+
if (isString$1(code) && (code.includes('-') || code.includes('_'))) {
|
|
994
1003
|
if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code));
|
|
995
1004
|
if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code));
|
|
996
1005
|
if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code));
|
|
@@ -998,7 +1007,7 @@
|
|
|
998
1007
|
addCode(this.formatLanguageCode(code));
|
|
999
1008
|
}
|
|
1000
1009
|
fallbackCodes.forEach(fc => {
|
|
1001
|
-
if (codes.
|
|
1010
|
+
if (!codes.includes(fc)) addCode(this.formatLanguageCode(fc));
|
|
1002
1011
|
});
|
|
1003
1012
|
return codes;
|
|
1004
1013
|
}
|
|
@@ -1152,7 +1161,7 @@
|
|
|
1152
1161
|
let replaces;
|
|
1153
1162
|
const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
1154
1163
|
const handleFormat = key => {
|
|
1155
|
-
if (key.
|
|
1164
|
+
if (!key.includes(this.formatSeparator)) {
|
|
1156
1165
|
const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
|
|
1157
1166
|
return this.alwaysFormat ? this.format(path, undefined, lng, {
|
|
1158
1167
|
...options,
|
|
@@ -1222,7 +1231,7 @@
|
|
|
1222
1231
|
let clonedOptions;
|
|
1223
1232
|
const handleHasOptions = (key, inheritedOptions) => {
|
|
1224
1233
|
const sep = this.nestingOptionsSeparator;
|
|
1225
|
-
if (key.
|
|
1234
|
+
if (!key.includes(sep)) return key;
|
|
1226
1235
|
const c = key.split(new RegExp(`${regexEscape(sep)}[ ]*{`));
|
|
1227
1236
|
let optionsString = `{${c[1]}`;
|
|
1228
1237
|
key = c[0];
|
|
@@ -1242,7 +1251,7 @@
|
|
|
1242
1251
|
this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
|
|
1243
1252
|
return `${key}${sep}${optionsString}`;
|
|
1244
1253
|
}
|
|
1245
|
-
if (clonedOptions.defaultValue && clonedOptions.defaultValue.
|
|
1254
|
+
if (clonedOptions.defaultValue && clonedOptions.defaultValue.includes(this.prefix)) delete clonedOptions.defaultValue;
|
|
1246
1255
|
return key;
|
|
1247
1256
|
};
|
|
1248
1257
|
while (match = this.nestingRegexp.exec(str)) {
|
|
@@ -1280,13 +1289,13 @@
|
|
|
1280
1289
|
const parseFormatStr = formatStr => {
|
|
1281
1290
|
let formatName = formatStr.toLowerCase().trim();
|
|
1282
1291
|
const formatOptions = {};
|
|
1283
|
-
if (formatStr.
|
|
1292
|
+
if (formatStr.includes('(')) {
|
|
1284
1293
|
const p = formatStr.split('(');
|
|
1285
1294
|
formatName = p[0].toLowerCase().trim();
|
|
1286
|
-
const optStr = p[1].
|
|
1287
|
-
if (formatName === 'currency' && optStr.
|
|
1295
|
+
const optStr = p[1].slice(0, -1);
|
|
1296
|
+
if (formatName === 'currency' && !optStr.includes(':')) {
|
|
1288
1297
|
if (!formatOptions.currency) formatOptions.currency = optStr.trim();
|
|
1289
|
-
} else if (formatName === 'relativetime' && optStr.
|
|
1298
|
+
} else if (formatName === 'relativetime' && !optStr.includes(':')) {
|
|
1290
1299
|
if (!formatOptions.range) formatOptions.range = optStr.trim();
|
|
1291
1300
|
} else {
|
|
1292
1301
|
const opts = optStr.split(';');
|
|
@@ -1380,9 +1389,11 @@
|
|
|
1380
1389
|
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
1381
1390
|
}
|
|
1382
1391
|
format(value, format, lng, options = {}) {
|
|
1392
|
+
if (!format) return value;
|
|
1393
|
+
if (value == null) return value;
|
|
1383
1394
|
const formats = format.split(this.formatSeparator);
|
|
1384
|
-
if (formats.length > 1 && formats[0].indexOf('(') > 1 && formats[0].
|
|
1385
|
-
const lastIndex = formats.findIndex(f => f.
|
|
1395
|
+
if (formats.length > 1 && formats[0].indexOf('(') > 1 && !formats[0].includes(')') && formats.find(f => f.includes(')'))) {
|
|
1396
|
+
const lastIndex = formats.findIndex(f => f.includes(')'));
|
|
1386
1397
|
formats[0] = [formats[0], ...formats.splice(1, lastIndex)].join(this.formatSeparator);
|
|
1387
1398
|
}
|
|
1388
1399
|
const result = formats.reduce((mem, f) => {
|
|
@@ -1535,7 +1546,7 @@
|
|
|
1535
1546
|
}
|
|
1536
1547
|
if (err && data && tried < this.maxRetries) {
|
|
1537
1548
|
setTimeout(() => {
|
|
1538
|
-
this.read
|
|
1549
|
+
this.read(lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
1539
1550
|
}, wait);
|
|
1540
1551
|
return;
|
|
1541
1552
|
}
|
|
@@ -1638,7 +1649,6 @@
|
|
|
1638
1649
|
nonExplicitSupportedLngs: false,
|
|
1639
1650
|
load: 'all',
|
|
1640
1651
|
preload: false,
|
|
1641
|
-
simplifyPluralSuffix: true,
|
|
1642
1652
|
keySeparator: '.',
|
|
1643
1653
|
nsSeparator: ':',
|
|
1644
1654
|
pluralSeparator: '_',
|
|
@@ -1675,7 +1685,6 @@
|
|
|
1675
1685
|
},
|
|
1676
1686
|
interpolation: {
|
|
1677
1687
|
escapeValue: true,
|
|
1678
|
-
format: value => value,
|
|
1679
1688
|
prefix: '{{',
|
|
1680
1689
|
suffix: '}}',
|
|
1681
1690
|
formatSeparator: ',',
|
|
@@ -1692,10 +1701,9 @@
|
|
|
1692
1701
|
if (isString$1(options.ns)) options.ns = [options.ns];
|
|
1693
1702
|
if (isString$1(options.fallbackLng)) options.fallbackLng = [options.fallbackLng];
|
|
1694
1703
|
if (isString$1(options.fallbackNS)) options.fallbackNS = [options.fallbackNS];
|
|
1695
|
-
if (options.supportedLngs
|
|
1704
|
+
if (options.supportedLngs && !options.supportedLngs.includes('cimode')) {
|
|
1696
1705
|
options.supportedLngs = options.supportedLngs.concat(['cimode']);
|
|
1697
1706
|
}
|
|
1698
|
-
if (typeof options.initImmediate === 'boolean') options.initAsync = options.initImmediate;
|
|
1699
1707
|
return options;
|
|
1700
1708
|
};
|
|
1701
1709
|
const noop = () => {};
|
|
@@ -1707,28 +1715,6 @@
|
|
|
1707
1715
|
}
|
|
1708
1716
|
});
|
|
1709
1717
|
};
|
|
1710
|
-
const SUPPORT_NOTICE_KEY = '__i18next_supportNoticeShown';
|
|
1711
|
-
const getSupportNoticeShown = () => {
|
|
1712
|
-
if (typeof globalThis !== 'undefined' && !!globalThis[SUPPORT_NOTICE_KEY]) return true;
|
|
1713
|
-
if (typeof process !== 'undefined' && process.env && process.env.I18NEXT_NO_SUPPORT_NOTICE) return true;
|
|
1714
|
-
if (typeof process !== 'undefined' && process.env && "development" === 'production') ;
|
|
1715
|
-
return false;
|
|
1716
|
-
};
|
|
1717
|
-
const setSupportNoticeShown = () => {
|
|
1718
|
-
if (typeof globalThis !== 'undefined') globalThis[SUPPORT_NOTICE_KEY] = true;
|
|
1719
|
-
};
|
|
1720
|
-
const usesLocize = inst => {
|
|
1721
|
-
if (inst?.modules?.backend?.name?.indexOf('Locize') > 0) return true;
|
|
1722
|
-
if (inst?.modules?.backend?.constructor?.name?.indexOf('Locize') > 0) return true;
|
|
1723
|
-
if (inst?.options?.backend?.backends) {
|
|
1724
|
-
if (inst.options.backend.backends.some(b => b?.name?.indexOf('Locize') > 0 || b?.constructor?.name?.indexOf('Locize') > 0)) return true;
|
|
1725
|
-
}
|
|
1726
|
-
if (inst?.options?.backend?.projectId) return true;
|
|
1727
|
-
if (inst?.options?.backend?.backendOptions) {
|
|
1728
|
-
if (inst.options.backend.backendOptions.some(b => b?.projectId)) return true;
|
|
1729
|
-
}
|
|
1730
|
-
return false;
|
|
1731
|
-
};
|
|
1732
1718
|
class I18n extends EventEmitter {
|
|
1733
1719
|
constructor(options = {}, callback) {
|
|
1734
1720
|
super();
|
|
@@ -1758,7 +1744,7 @@
|
|
|
1758
1744
|
if (options.defaultNS == null && options.ns) {
|
|
1759
1745
|
if (isString$1(options.ns)) {
|
|
1760
1746
|
options.defaultNS = options.ns;
|
|
1761
|
-
} else if (options.ns.
|
|
1747
|
+
} else if (!options.ns.includes('translation')) {
|
|
1762
1748
|
options.defaultNS = options.ns[0];
|
|
1763
1749
|
}
|
|
1764
1750
|
}
|
|
@@ -1781,10 +1767,6 @@
|
|
|
1781
1767
|
if (typeof this.options.overloadTranslationOptionHandler !== 'function') {
|
|
1782
1768
|
this.options.overloadTranslationOptionHandler = defOpts.overloadTranslationOptionHandler;
|
|
1783
1769
|
}
|
|
1784
|
-
if (this.options.showSupportNotice !== false && !usesLocize(this) && !getSupportNoticeShown()) {
|
|
1785
|
-
if (typeof console !== 'undefined' && typeof console.info !== 'undefined') console.info('🌐 i18next is made possible by our own product, Locize — consider powering your project with managed localization (AI, CDN, integrations): https://locize.com 💙');
|
|
1786
|
-
setSupportNoticeShown();
|
|
1787
|
-
}
|
|
1788
1770
|
const createClassOnDemand = ClassOrObject => {
|
|
1789
1771
|
if (!ClassOrObject) return null;
|
|
1790
1772
|
if (typeof ClassOrObject === 'function') return new ClassOrObject();
|
|
@@ -1809,14 +1791,9 @@
|
|
|
1809
1791
|
s.resourceStore = this.store;
|
|
1810
1792
|
s.languageUtils = lu;
|
|
1811
1793
|
s.pluralResolver = new PluralResolver(lu, {
|
|
1812
|
-
prepend: this.options.pluralSeparator
|
|
1813
|
-
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
1794
|
+
prepend: this.options.pluralSeparator
|
|
1814
1795
|
});
|
|
1815
|
-
|
|
1816
|
-
if (usingLegacyFormatFunction) {
|
|
1817
|
-
this.logger.deprecate(`init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting`);
|
|
1818
|
-
}
|
|
1819
|
-
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
|
|
1796
|
+
if (formatter) {
|
|
1820
1797
|
s.formatter = createClassOnDemand(formatter);
|
|
1821
1798
|
if (s.formatter.init) s.formatter.init(s, this.options);
|
|
1822
1799
|
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
@@ -1899,7 +1876,7 @@
|
|
|
1899
1876
|
const lngs = this.services.languageUtils.toResolveHierarchy(lng);
|
|
1900
1877
|
lngs.forEach(l => {
|
|
1901
1878
|
if (l === 'cimode') return;
|
|
1902
|
-
if (toLoad.
|
|
1879
|
+
if (!toLoad.includes(l)) toLoad.push(l);
|
|
1903
1880
|
});
|
|
1904
1881
|
};
|
|
1905
1882
|
if (!usedLng) {
|
|
@@ -1964,16 +1941,16 @@
|
|
|
1964
1941
|
}
|
|
1965
1942
|
setResolvedLanguage(l) {
|
|
1966
1943
|
if (!l || !this.languages) return;
|
|
1967
|
-
if (['cimode', 'dev'].
|
|
1944
|
+
if (['cimode', 'dev'].includes(l)) return;
|
|
1968
1945
|
for (let li = 0; li < this.languages.length; li++) {
|
|
1969
1946
|
const lngInLngs = this.languages[li];
|
|
1970
|
-
if (['cimode', 'dev'].
|
|
1947
|
+
if (['cimode', 'dev'].includes(lngInLngs)) continue;
|
|
1971
1948
|
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
1972
1949
|
this.resolvedLanguage = lngInLngs;
|
|
1973
1950
|
break;
|
|
1974
1951
|
}
|
|
1975
1952
|
}
|
|
1976
|
-
if (!this.resolvedLanguage && this.languages.
|
|
1953
|
+
if (!this.resolvedLanguage && !this.languages.includes(l) && this.store.hasLanguageSomeTranslations(l)) {
|
|
1977
1954
|
this.resolvedLanguage = l;
|
|
1978
1955
|
this.languages.unshift(l);
|
|
1979
1956
|
}
|
|
@@ -2115,7 +2092,7 @@
|
|
|
2115
2092
|
}
|
|
2116
2093
|
if (isString$1(ns)) ns = [ns];
|
|
2117
2094
|
ns.forEach(n => {
|
|
2118
|
-
if (this.options.ns.
|
|
2095
|
+
if (!this.options.ns.includes(n)) this.options.ns.push(n);
|
|
2119
2096
|
});
|
|
2120
2097
|
this.loadResources(err => {
|
|
2121
2098
|
deferred.resolve();
|
|
@@ -2127,7 +2104,7 @@
|
|
|
2127
2104
|
const deferred = defer();
|
|
2128
2105
|
if (isString$1(lngs)) lngs = [lngs];
|
|
2129
2106
|
const preloaded = this.options.preload || [];
|
|
2130
|
-
const newLngs = lngs.filter(lng => preloaded.
|
|
2107
|
+
const newLngs = lngs.filter(lng => !preloaded.includes(lng) && this.services.languageUtils.isSupportedCode(lng));
|
|
2131
2108
|
if (!newLngs.length) {
|
|
2132
2109
|
if (callback) callback();
|
|
2133
2110
|
return Promise.resolve();
|
|
@@ -2152,7 +2129,7 @@
|
|
|
2152
2129
|
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'];
|
|
2153
2130
|
const languageUtils = this.services?.languageUtils || new LanguageUtil(get());
|
|
2154
2131
|
if (lng.toLowerCase().indexOf('-latn') > 1) return 'ltr';
|
|
2155
|
-
return rtlLngs.
|
|
2132
|
+
return rtlLngs.includes(languageUtils.getLanguagePartFromCode(lng)) || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
|
|
2156
2133
|
}
|
|
2157
2134
|
static createInstance(options = {}, callback) {
|
|
2158
2135
|
const instance = new I18n(options, callback);
|