@fkui/i18next-translate 6.40.0 → 6.41.0
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/cjs/index.js +63 -85
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +63 -85
- package/dist/esm/index.js.map +1 -1
- package/package.json +3 -3
package/dist/esm/index.js
CHANGED
|
@@ -2078,7 +2078,7 @@ const defer = () => {
|
|
|
2078
2078
|
};
|
|
2079
2079
|
const makeString = object => {
|
|
2080
2080
|
if (object == null) return '';
|
|
2081
|
-
return
|
|
2081
|
+
return String(object);
|
|
2082
2082
|
};
|
|
2083
2083
|
const copy = (a, s, t) => {
|
|
2084
2084
|
a.forEach(m => {
|
|
@@ -2086,7 +2086,7 @@ const copy = (a, s, t) => {
|
|
|
2086
2086
|
});
|
|
2087
2087
|
};
|
|
2088
2088
|
const lastOfPathSeparatorRegExp = /###/g;
|
|
2089
|
-
const cleanKey = key => key && key.
|
|
2089
|
+
const cleanKey = key => key && key.includes('###') ? key.replace(lastOfPathSeparatorRegExp, '.') : key;
|
|
2090
2090
|
const canNotTraverseDeeper = object => !object || isString(object);
|
|
2091
2091
|
const getLastOfPath = (object, path, Empty) => {
|
|
2092
2092
|
const stack = !isString(path) ? path : path.split('.');
|
|
@@ -2171,7 +2171,7 @@ const deepExtend = (target, source, overwrite) => {
|
|
|
2171
2171
|
return target;
|
|
2172
2172
|
};
|
|
2173
2173
|
const regexEscape = str => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
|
|
2174
|
-
|
|
2174
|
+
const _entityMap = {
|
|
2175
2175
|
'&': '&',
|
|
2176
2176
|
'<': '<',
|
|
2177
2177
|
'>': '>',
|
|
@@ -2210,7 +2210,7 @@ const looksLikeObjectPathRegExpCache = new RegExpCache(20);
|
|
|
2210
2210
|
const looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
|
|
2211
2211
|
nsSeparator = nsSeparator || '';
|
|
2212
2212
|
keySeparator = keySeparator || '';
|
|
2213
|
-
const possibleChars = chars.filter(c => nsSeparator.
|
|
2213
|
+
const possibleChars = chars.filter(c => !nsSeparator.includes(c) && !keySeparator.includes(c));
|
|
2214
2214
|
if (possibleChars.length === 0) return true;
|
|
2215
2215
|
const r = looksLikeObjectPathRegExpCache.getRegExp(`(${possibleChars.map(c => c === '?' ? '\\?' : c).join('|')})`);
|
|
2216
2216
|
let matched = !r.test(key);
|
|
@@ -2243,7 +2243,7 @@ const deepFind = (obj, path, keySeparator = '.') => {
|
|
|
2243
2243
|
nextPath += tokens[j];
|
|
2244
2244
|
next = current[nextPath];
|
|
2245
2245
|
if (next !== undefined) {
|
|
2246
|
-
if (['string', 'number', 'boolean'].
|
|
2246
|
+
if (['string', 'number', 'boolean'].includes(typeof next) && j < tokens.length - 1) {
|
|
2247
2247
|
continue;
|
|
2248
2248
|
}
|
|
2249
2249
|
i += j - i + 1;
|
|
@@ -2334,6 +2334,14 @@ class EventEmitter {
|
|
|
2334
2334
|
}
|
|
2335
2335
|
this.observers[event].delete(listener);
|
|
2336
2336
|
}
|
|
2337
|
+
once(event, listener) {
|
|
2338
|
+
const wrapper = (...args) => {
|
|
2339
|
+
listener(...args);
|
|
2340
|
+
this.off(event, wrapper);
|
|
2341
|
+
};
|
|
2342
|
+
this.on(event, wrapper);
|
|
2343
|
+
return this;
|
|
2344
|
+
}
|
|
2337
2345
|
emit(event, ...args) {
|
|
2338
2346
|
if (this.observers[event]) {
|
|
2339
2347
|
const cloned = Array.from(this.observers[event].entries());
|
|
@@ -2347,7 +2355,7 @@ class EventEmitter {
|
|
|
2347
2355
|
const cloned = Array.from(this.observers['*'].entries());
|
|
2348
2356
|
cloned.forEach(([observer, numTimesAdded]) => {
|
|
2349
2357
|
for (let i = 0; i < numTimesAdded; i++) {
|
|
2350
|
-
observer
|
|
2358
|
+
observer(event, ...args);
|
|
2351
2359
|
}
|
|
2352
2360
|
});
|
|
2353
2361
|
}
|
|
@@ -2370,7 +2378,7 @@ class ResourceStore extends EventEmitter {
|
|
|
2370
2378
|
}
|
|
2371
2379
|
}
|
|
2372
2380
|
addNamespaces(ns) {
|
|
2373
|
-
if (this.options.ns.
|
|
2381
|
+
if (!this.options.ns.includes(ns)) {
|
|
2374
2382
|
this.options.ns.push(ns);
|
|
2375
2383
|
}
|
|
2376
2384
|
}
|
|
@@ -2384,7 +2392,7 @@ class ResourceStore extends EventEmitter {
|
|
|
2384
2392
|
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
2385
2393
|
const ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
2386
2394
|
let path;
|
|
2387
|
-
if (lng.
|
|
2395
|
+
if (lng.includes('.')) {
|
|
2388
2396
|
path = lng.split('.');
|
|
2389
2397
|
} else {
|
|
2390
2398
|
path = [lng, ns];
|
|
@@ -2399,7 +2407,7 @@ class ResourceStore extends EventEmitter {
|
|
|
2399
2407
|
}
|
|
2400
2408
|
}
|
|
2401
2409
|
const result = getPath(this.data, path);
|
|
2402
|
-
if (!result && !ns && !key && lng.
|
|
2410
|
+
if (!result && !ns && !key && lng.includes('.')) {
|
|
2403
2411
|
lng = path[0];
|
|
2404
2412
|
ns = path[1];
|
|
2405
2413
|
key = path.slice(2).join('.');
|
|
@@ -2413,7 +2421,7 @@ class ResourceStore extends EventEmitter {
|
|
|
2413
2421
|
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
2414
2422
|
let path = [lng, ns];
|
|
2415
2423
|
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
2416
|
-
if (lng.
|
|
2424
|
+
if (lng.includes('.')) {
|
|
2417
2425
|
path = lng.split('.');
|
|
2418
2426
|
value = ns;
|
|
2419
2427
|
ns = path[1];
|
|
@@ -2437,7 +2445,7 @@ class ResourceStore extends EventEmitter {
|
|
|
2437
2445
|
skipCopy: false
|
|
2438
2446
|
}) {
|
|
2439
2447
|
let path = [lng, ns];
|
|
2440
|
-
if (lng.
|
|
2448
|
+
if (lng.includes('.')) {
|
|
2441
2449
|
path = lng.split('.');
|
|
2442
2450
|
deep = resources;
|
|
2443
2451
|
resources = ns;
|
|
@@ -2527,7 +2535,6 @@ function keysFromSelector(selector, opts) {
|
|
|
2527
2535
|
return path.join(keySeparator);
|
|
2528
2536
|
}
|
|
2529
2537
|
|
|
2530
|
-
const checkedLoadedFor = {};
|
|
2531
2538
|
const shouldHandleAsObject = res => !isString(res) && typeof res !== 'boolean' && typeof res !== 'number';
|
|
2532
2539
|
class Translator extends EventEmitter {
|
|
2533
2540
|
constructor(services, options = {}) {
|
|
@@ -2538,6 +2545,7 @@ class Translator extends EventEmitter {
|
|
|
2538
2545
|
this.options.keySeparator = '.';
|
|
2539
2546
|
}
|
|
2540
2547
|
this.logger = baseLogger.create('translator');
|
|
2548
|
+
this.checkedLoadedFor = {};
|
|
2541
2549
|
}
|
|
2542
2550
|
changeLanguage(lng) {
|
|
2543
2551
|
if (lng) this.language = lng;
|
|
@@ -2562,7 +2570,7 @@ class Translator extends EventEmitter {
|
|
|
2562
2570
|
if (nsSeparator === undefined) nsSeparator = ':';
|
|
2563
2571
|
const keySeparator = opt.keySeparator !== undefined ? opt.keySeparator : this.options.keySeparator;
|
|
2564
2572
|
let namespaces = opt.ns || this.options.defaultNS || [];
|
|
2565
|
-
const wouldCheckForNsInKey = nsSeparator && key.
|
|
2573
|
+
const wouldCheckForNsInKey = nsSeparator && key.includes(nsSeparator);
|
|
2566
2574
|
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !opt.keySeparator && !this.options.userDefinedNsSeparator && !opt.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
2567
2575
|
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
2568
2576
|
const m = key.match(this.interpolator.nestingRegexp);
|
|
@@ -2573,7 +2581,7 @@ class Translator extends EventEmitter {
|
|
|
2573
2581
|
};
|
|
2574
2582
|
}
|
|
2575
2583
|
const parts = key.split(nsSeparator);
|
|
2576
|
-
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.
|
|
2584
|
+
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.includes(parts[0])) namespaces = parts.shift();
|
|
2577
2585
|
key = parts.join(keySeparator);
|
|
2578
2586
|
}
|
|
2579
2587
|
return {
|
|
@@ -2660,7 +2668,7 @@ class Translator extends EventEmitter {
|
|
|
2660
2668
|
}
|
|
2661
2669
|
const handleAsObject = shouldHandleAsObject(resForObjHndl);
|
|
2662
2670
|
const resType = Object.prototype.toString.apply(resForObjHndl);
|
|
2663
|
-
if (handleAsObjectInI18nFormat && resForObjHndl && handleAsObject && noObject.
|
|
2671
|
+
if (handleAsObjectInI18nFormat && resForObjHndl && handleAsObject && !noObject.includes(resType) && !(isString(joinArrays) && Array.isArray(resForObjHndl))) {
|
|
2664
2672
|
if (!opt.returnObjects && !this.options.returnObjects) {
|
|
2665
2673
|
if (!this.options.returnedObjectHandler) {
|
|
2666
2674
|
this.logger.warn('accessing an object - but returnObjects options is not enabled!');
|
|
@@ -2756,7 +2764,7 @@ class Translator extends EventEmitter {
|
|
|
2756
2764
|
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
2757
2765
|
lngs.forEach(language => {
|
|
2758
2766
|
const suffixes = this.pluralResolver.getSuffixes(language, opt);
|
|
2759
|
-
if (needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.
|
|
2767
|
+
if (needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] && !suffixes.includes(`${this.options.pluralSeparator}zero`)) {
|
|
2760
2768
|
suffixes.push(`${this.options.pluralSeparator}zero`);
|
|
2761
2769
|
}
|
|
2762
2770
|
suffixes.forEach(suffix => {
|
|
@@ -2866,8 +2874,8 @@ class Translator extends EventEmitter {
|
|
|
2866
2874
|
namespaces.forEach(ns => {
|
|
2867
2875
|
if (this.isValidLookup(found)) return;
|
|
2868
2876
|
usedNS = ns;
|
|
2869
|
-
if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils?.hasLoadedNamespace && !this.utils?.hasLoadedNamespace(usedNS)) {
|
|
2870
|
-
checkedLoadedFor[`${codes[0]}-${ns}`] = true;
|
|
2877
|
+
if (!this.checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils?.hasLoadedNamespace && !this.utils?.hasLoadedNamespace(usedNS)) {
|
|
2878
|
+
this.checkedLoadedFor[`${codes[0]}-${ns}`] = true;
|
|
2871
2879
|
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!!!');
|
|
2872
2880
|
}
|
|
2873
2881
|
codes.forEach(code => {
|
|
@@ -2882,7 +2890,7 @@ class Translator extends EventEmitter {
|
|
|
2882
2890
|
const zeroSuffix = `${this.options.pluralSeparator}zero`;
|
|
2883
2891
|
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
|
|
2884
2892
|
if (needsPluralHandling) {
|
|
2885
|
-
if (opt.ordinal && pluralSuffix.
|
|
2893
|
+
if (opt.ordinal && pluralSuffix.startsWith(ordinalPrefix)) {
|
|
2886
2894
|
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
2887
2895
|
}
|
|
2888
2896
|
finalKeys.push(key + pluralSuffix);
|
|
@@ -2894,7 +2902,7 @@ class Translator extends EventEmitter {
|
|
|
2894
2902
|
const contextKey = `${key}${this.options.contextSeparator || '_'}${opt.context}`;
|
|
2895
2903
|
finalKeys.push(contextKey);
|
|
2896
2904
|
if (needsPluralHandling) {
|
|
2897
|
-
if (opt.ordinal && pluralSuffix.
|
|
2905
|
+
if (opt.ordinal && pluralSuffix.startsWith(ordinalPrefix)) {
|
|
2898
2906
|
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
2899
2907
|
}
|
|
2900
2908
|
finalKeys.push(contextKey + pluralSuffix);
|
|
@@ -2955,7 +2963,7 @@ class Translator extends EventEmitter {
|
|
|
2955
2963
|
static hasDefaultValue(options) {
|
|
2956
2964
|
const prefix = 'defaultValue';
|
|
2957
2965
|
for (const option in options) {
|
|
2958
|
-
if (Object.prototype.hasOwnProperty.call(options, option) &&
|
|
2966
|
+
if (Object.prototype.hasOwnProperty.call(options, option) && option.startsWith(prefix) && undefined !== options[option]) {
|
|
2959
2967
|
return true;
|
|
2960
2968
|
}
|
|
2961
2969
|
}
|
|
@@ -2971,7 +2979,7 @@ class LanguageUtil {
|
|
|
2971
2979
|
}
|
|
2972
2980
|
getScriptPartFromCode(code) {
|
|
2973
2981
|
code = getCleanedCode(code);
|
|
2974
|
-
if (!code || code.
|
|
2982
|
+
if (!code || !code.includes('-')) return null;
|
|
2975
2983
|
const p = code.split('-');
|
|
2976
2984
|
if (p.length === 2) return null;
|
|
2977
2985
|
p.pop();
|
|
@@ -2980,12 +2988,12 @@ class LanguageUtil {
|
|
|
2980
2988
|
}
|
|
2981
2989
|
getLanguagePartFromCode(code) {
|
|
2982
2990
|
code = getCleanedCode(code);
|
|
2983
|
-
if (!code || code.
|
|
2991
|
+
if (!code || !code.includes('-')) return code;
|
|
2984
2992
|
const p = code.split('-');
|
|
2985
2993
|
return this.formatLanguageCode(p[0]);
|
|
2986
2994
|
}
|
|
2987
2995
|
formatLanguageCode(code) {
|
|
2988
|
-
if (isString(code) && code.
|
|
2996
|
+
if (isString(code) && code.includes('-')) {
|
|
2989
2997
|
let formattedCode;
|
|
2990
2998
|
try {
|
|
2991
2999
|
formattedCode = Intl.getCanonicalLocales(code)[0];
|
|
@@ -3005,7 +3013,7 @@ class LanguageUtil {
|
|
|
3005
3013
|
if (this.options.load === 'languageOnly' || this.options.nonExplicitSupportedLngs) {
|
|
3006
3014
|
code = this.getLanguagePartFromCode(code);
|
|
3007
3015
|
}
|
|
3008
|
-
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.
|
|
3016
|
+
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.includes(code);
|
|
3009
3017
|
}
|
|
3010
3018
|
getBestMatchFromCodes(codes) {
|
|
3011
3019
|
if (!codes) return null;
|
|
@@ -3023,10 +3031,11 @@ class LanguageUtil {
|
|
|
3023
3031
|
const lngOnly = this.getLanguagePartFromCode(code);
|
|
3024
3032
|
if (this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
3025
3033
|
found = this.options.supportedLngs.find(supportedLng => {
|
|
3026
|
-
if (supportedLng === lngOnly) return
|
|
3027
|
-
if (supportedLng.
|
|
3028
|
-
if (supportedLng.
|
|
3029
|
-
if (supportedLng.
|
|
3034
|
+
if (supportedLng === lngOnly) return true;
|
|
3035
|
+
if (!supportedLng.includes('-') && !lngOnly.includes('-')) return false;
|
|
3036
|
+
if (supportedLng.includes('-') && !lngOnly.includes('-') && supportedLng.slice(0, supportedLng.indexOf('-')) === lngOnly) return true;
|
|
3037
|
+
if (supportedLng.startsWith(lngOnly) && lngOnly.length > 1) return true;
|
|
3038
|
+
return false;
|
|
3030
3039
|
});
|
|
3031
3040
|
});
|
|
3032
3041
|
}
|
|
@@ -3057,7 +3066,7 @@ class LanguageUtil {
|
|
|
3057
3066
|
this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
|
|
3058
3067
|
}
|
|
3059
3068
|
};
|
|
3060
|
-
if (isString(code) && (code.
|
|
3069
|
+
if (isString(code) && (code.includes('-') || code.includes('_'))) {
|
|
3061
3070
|
if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code));
|
|
3062
3071
|
if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code));
|
|
3063
3072
|
if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code));
|
|
@@ -3065,7 +3074,7 @@ class LanguageUtil {
|
|
|
3065
3074
|
addCode(this.formatLanguageCode(code));
|
|
3066
3075
|
}
|
|
3067
3076
|
fallbackCodes.forEach(fc => {
|
|
3068
|
-
if (codes.
|
|
3077
|
+
if (!codes.includes(fc)) addCode(this.formatLanguageCode(fc));
|
|
3069
3078
|
});
|
|
3070
3079
|
return codes;
|
|
3071
3080
|
}
|
|
@@ -3221,7 +3230,7 @@ class Interpolator {
|
|
|
3221
3230
|
let replaces;
|
|
3222
3231
|
const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
3223
3232
|
const handleFormat = key => {
|
|
3224
|
-
if (key.
|
|
3233
|
+
if (!key.includes(this.formatSeparator)) {
|
|
3225
3234
|
const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
|
|
3226
3235
|
return this.alwaysFormat ? this.format(path, undefined, lng, {
|
|
3227
3236
|
...options,
|
|
@@ -3291,7 +3300,7 @@ class Interpolator {
|
|
|
3291
3300
|
let clonedOptions;
|
|
3292
3301
|
const handleHasOptions = (key, inheritedOptions) => {
|
|
3293
3302
|
const sep = this.nestingOptionsSeparator;
|
|
3294
|
-
if (key.
|
|
3303
|
+
if (!key.includes(sep)) return key;
|
|
3295
3304
|
const c = key.split(new RegExp(`${regexEscape(sep)}[ ]*{`));
|
|
3296
3305
|
let optionsString = `{${c[1]}`;
|
|
3297
3306
|
key = c[0];
|
|
@@ -3311,7 +3320,7 @@ class Interpolator {
|
|
|
3311
3320
|
this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
|
|
3312
3321
|
return `${key}${sep}${optionsString}`;
|
|
3313
3322
|
}
|
|
3314
|
-
if (clonedOptions.defaultValue && clonedOptions.defaultValue.
|
|
3323
|
+
if (clonedOptions.defaultValue && clonedOptions.defaultValue.includes(this.prefix)) delete clonedOptions.defaultValue;
|
|
3315
3324
|
return key;
|
|
3316
3325
|
};
|
|
3317
3326
|
while (match = this.nestingRegexp.exec(str)) {
|
|
@@ -3350,13 +3359,13 @@ class Interpolator {
|
|
|
3350
3359
|
const parseFormatStr = formatStr => {
|
|
3351
3360
|
let formatName = formatStr.toLowerCase().trim();
|
|
3352
3361
|
const formatOptions = {};
|
|
3353
|
-
if (formatStr.
|
|
3362
|
+
if (formatStr.includes('(')) {
|
|
3354
3363
|
const p = formatStr.split('(');
|
|
3355
3364
|
formatName = p[0].toLowerCase().trim();
|
|
3356
|
-
const optStr = p[1].
|
|
3357
|
-
if (formatName === 'currency' && optStr.
|
|
3365
|
+
const optStr = p[1].slice(0, -1);
|
|
3366
|
+
if (formatName === 'currency' && !optStr.includes(':')) {
|
|
3358
3367
|
if (!formatOptions.currency) formatOptions.currency = optStr.trim();
|
|
3359
|
-
} else if (formatName === 'relativetime' && optStr.
|
|
3368
|
+
} else if (formatName === 'relativetime' && !optStr.includes(':')) {
|
|
3360
3369
|
if (!formatOptions.range) formatOptions.range = optStr.trim();
|
|
3361
3370
|
} else {
|
|
3362
3371
|
const opts = optStr.split(';');
|
|
@@ -3450,9 +3459,11 @@ class Formatter {
|
|
|
3450
3459
|
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
3451
3460
|
}
|
|
3452
3461
|
format(value, format, lng, options = {}) {
|
|
3462
|
+
if (!format) return value;
|
|
3463
|
+
if (value == null) return value;
|
|
3453
3464
|
const formats = format.split(this.formatSeparator);
|
|
3454
|
-
if (formats.length > 1 && formats[0].indexOf('(') > 1 && formats[0].
|
|
3455
|
-
const lastIndex = formats.findIndex(f => f.
|
|
3465
|
+
if (formats.length > 1 && formats[0].indexOf('(') > 1 && !formats[0].includes(')') && formats.find(f => f.includes(')'))) {
|
|
3466
|
+
const lastIndex = formats.findIndex(f => f.includes(')'));
|
|
3456
3467
|
formats[0] = [formats[0], ...formats.splice(1, lastIndex)].join(this.formatSeparator);
|
|
3457
3468
|
}
|
|
3458
3469
|
const result = formats.reduce((mem, f) => {
|
|
@@ -3606,7 +3617,7 @@ class Connector extends EventEmitter {
|
|
|
3606
3617
|
}
|
|
3607
3618
|
if (err && data && tried < this.maxRetries) {
|
|
3608
3619
|
setTimeout(() => {
|
|
3609
|
-
this.read
|
|
3620
|
+
this.read(lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
3610
3621
|
}, wait);
|
|
3611
3622
|
return;
|
|
3612
3623
|
}
|
|
@@ -3710,7 +3721,6 @@ const get = () => ({
|
|
|
3710
3721
|
nonExplicitSupportedLngs: false,
|
|
3711
3722
|
load: 'all',
|
|
3712
3723
|
preload: false,
|
|
3713
|
-
simplifyPluralSuffix: true,
|
|
3714
3724
|
keySeparator: '.',
|
|
3715
3725
|
nsSeparator: ':',
|
|
3716
3726
|
pluralSeparator: '_',
|
|
@@ -3747,7 +3757,6 @@ const get = () => ({
|
|
|
3747
3757
|
},
|
|
3748
3758
|
interpolation: {
|
|
3749
3759
|
escapeValue: true,
|
|
3750
|
-
format: value => value,
|
|
3751
3760
|
prefix: '{{',
|
|
3752
3761
|
suffix: '}}',
|
|
3753
3762
|
formatSeparator: ',',
|
|
@@ -3764,10 +3773,9 @@ const transformOptions = options => {
|
|
|
3764
3773
|
if (isString(options.ns)) options.ns = [options.ns];
|
|
3765
3774
|
if (isString(options.fallbackLng)) options.fallbackLng = [options.fallbackLng];
|
|
3766
3775
|
if (isString(options.fallbackNS)) options.fallbackNS = [options.fallbackNS];
|
|
3767
|
-
if (options.supportedLngs
|
|
3776
|
+
if (options.supportedLngs && !options.supportedLngs.includes('cimode')) {
|
|
3768
3777
|
options.supportedLngs = options.supportedLngs.concat(['cimode']);
|
|
3769
3778
|
}
|
|
3770
|
-
if (typeof options.initImmediate === 'boolean') options.initAsync = options.initImmediate;
|
|
3771
3779
|
return options;
|
|
3772
3780
|
};
|
|
3773
3781
|
|
|
@@ -3780,27 +3788,6 @@ const bindMemberFunctions = inst => {
|
|
|
3780
3788
|
}
|
|
3781
3789
|
});
|
|
3782
3790
|
};
|
|
3783
|
-
const SUPPORT_NOTICE_KEY = '__i18next_supportNoticeShown';
|
|
3784
|
-
const getSupportNoticeShown = () => {
|
|
3785
|
-
if (typeof globalThis !== 'undefined' && !!globalThis[SUPPORT_NOTICE_KEY]) return true;
|
|
3786
|
-
if (typeof process !== 'undefined' && process.env && process.env.I18NEXT_NO_SUPPORT_NOTICE) return true;
|
|
3787
|
-
return false;
|
|
3788
|
-
};
|
|
3789
|
-
const setSupportNoticeShown = () => {
|
|
3790
|
-
if (typeof globalThis !== 'undefined') globalThis[SUPPORT_NOTICE_KEY] = true;
|
|
3791
|
-
};
|
|
3792
|
-
const usesLocize = inst => {
|
|
3793
|
-
if (inst?.modules?.backend?.name?.indexOf('Locize') > 0) return true;
|
|
3794
|
-
if (inst?.modules?.backend?.constructor?.name?.indexOf('Locize') > 0) return true;
|
|
3795
|
-
if (inst?.options?.backend?.backends) {
|
|
3796
|
-
if (inst.options.backend.backends.some(b => b?.name?.indexOf('Locize') > 0 || b?.constructor?.name?.indexOf('Locize') > 0)) return true;
|
|
3797
|
-
}
|
|
3798
|
-
if (inst?.options?.backend?.projectId) return true;
|
|
3799
|
-
if (inst?.options?.backend?.backendOptions) {
|
|
3800
|
-
if (inst.options.backend.backendOptions.some(b => b?.projectId)) return true;
|
|
3801
|
-
}
|
|
3802
|
-
return false;
|
|
3803
|
-
};
|
|
3804
3791
|
class I18n extends EventEmitter {
|
|
3805
3792
|
constructor(options = {}, callback) {
|
|
3806
3793
|
super();
|
|
@@ -3830,7 +3817,7 @@ class I18n extends EventEmitter {
|
|
|
3830
3817
|
if (options.defaultNS == null && options.ns) {
|
|
3831
3818
|
if (isString(options.ns)) {
|
|
3832
3819
|
options.defaultNS = options.ns;
|
|
3833
|
-
} else if (options.ns.
|
|
3820
|
+
} else if (!options.ns.includes('translation')) {
|
|
3834
3821
|
options.defaultNS = options.ns[0];
|
|
3835
3822
|
}
|
|
3836
3823
|
}
|
|
@@ -3853,10 +3840,6 @@ class I18n extends EventEmitter {
|
|
|
3853
3840
|
if (typeof this.options.overloadTranslationOptionHandler !== 'function') {
|
|
3854
3841
|
this.options.overloadTranslationOptionHandler = defOpts.overloadTranslationOptionHandler;
|
|
3855
3842
|
}
|
|
3856
|
-
if (this.options.showSupportNotice !== false && !usesLocize(this) && !getSupportNoticeShown()) {
|
|
3857
|
-
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 💙');
|
|
3858
|
-
setSupportNoticeShown();
|
|
3859
|
-
}
|
|
3860
3843
|
const createClassOnDemand = ClassOrObject => {
|
|
3861
3844
|
if (!ClassOrObject) return null;
|
|
3862
3845
|
if (typeof ClassOrObject === 'function') return new ClassOrObject();
|
|
@@ -3881,14 +3864,9 @@ class I18n extends EventEmitter {
|
|
|
3881
3864
|
s.resourceStore = this.store;
|
|
3882
3865
|
s.languageUtils = lu;
|
|
3883
3866
|
s.pluralResolver = new PluralResolver(lu, {
|
|
3884
|
-
prepend: this.options.pluralSeparator
|
|
3885
|
-
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
3867
|
+
prepend: this.options.pluralSeparator
|
|
3886
3868
|
});
|
|
3887
|
-
|
|
3888
|
-
if (usingLegacyFormatFunction) {
|
|
3889
|
-
this.logger.deprecate(`init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting`);
|
|
3890
|
-
}
|
|
3891
|
-
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
|
|
3869
|
+
if (formatter) {
|
|
3892
3870
|
s.formatter = createClassOnDemand(formatter);
|
|
3893
3871
|
if (s.formatter.init) s.formatter.init(s, this.options);
|
|
3894
3872
|
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
@@ -3971,7 +3949,7 @@ class I18n extends EventEmitter {
|
|
|
3971
3949
|
const lngs = this.services.languageUtils.toResolveHierarchy(lng);
|
|
3972
3950
|
lngs.forEach(l => {
|
|
3973
3951
|
if (l === 'cimode') return;
|
|
3974
|
-
if (toLoad.
|
|
3952
|
+
if (!toLoad.includes(l)) toLoad.push(l);
|
|
3975
3953
|
});
|
|
3976
3954
|
};
|
|
3977
3955
|
if (!usedLng) {
|
|
@@ -4036,16 +4014,16 @@ class I18n extends EventEmitter {
|
|
|
4036
4014
|
}
|
|
4037
4015
|
setResolvedLanguage(l) {
|
|
4038
4016
|
if (!l || !this.languages) return;
|
|
4039
|
-
if (['cimode', 'dev'].
|
|
4017
|
+
if (['cimode', 'dev'].includes(l)) return;
|
|
4040
4018
|
for (let li = 0; li < this.languages.length; li++) {
|
|
4041
4019
|
const lngInLngs = this.languages[li];
|
|
4042
|
-
if (['cimode', 'dev'].
|
|
4020
|
+
if (['cimode', 'dev'].includes(lngInLngs)) continue;
|
|
4043
4021
|
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
4044
4022
|
this.resolvedLanguage = lngInLngs;
|
|
4045
4023
|
break;
|
|
4046
4024
|
}
|
|
4047
4025
|
}
|
|
4048
|
-
if (!this.resolvedLanguage && this.languages.
|
|
4026
|
+
if (!this.resolvedLanguage && !this.languages.includes(l) && this.store.hasLanguageSomeTranslations(l)) {
|
|
4049
4027
|
this.resolvedLanguage = l;
|
|
4050
4028
|
this.languages.unshift(l);
|
|
4051
4029
|
}
|
|
@@ -4187,7 +4165,7 @@ class I18n extends EventEmitter {
|
|
|
4187
4165
|
}
|
|
4188
4166
|
if (isString(ns)) ns = [ns];
|
|
4189
4167
|
ns.forEach(n => {
|
|
4190
|
-
if (this.options.ns.
|
|
4168
|
+
if (!this.options.ns.includes(n)) this.options.ns.push(n);
|
|
4191
4169
|
});
|
|
4192
4170
|
this.loadResources(err => {
|
|
4193
4171
|
deferred.resolve();
|
|
@@ -4199,7 +4177,7 @@ class I18n extends EventEmitter {
|
|
|
4199
4177
|
const deferred = defer();
|
|
4200
4178
|
if (isString(lngs)) lngs = [lngs];
|
|
4201
4179
|
const preloaded = this.options.preload || [];
|
|
4202
|
-
const newLngs = lngs.filter(lng => preloaded.
|
|
4180
|
+
const newLngs = lngs.filter(lng => !preloaded.includes(lng) && this.services.languageUtils.isSupportedCode(lng));
|
|
4203
4181
|
if (!newLngs.length) {
|
|
4204
4182
|
if (callback) callback();
|
|
4205
4183
|
return Promise.resolve();
|
|
@@ -4224,7 +4202,7 @@ class I18n extends EventEmitter {
|
|
|
4224
4202
|
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'];
|
|
4225
4203
|
const languageUtils = this.services?.languageUtils || new LanguageUtil(get());
|
|
4226
4204
|
if (lng.toLowerCase().indexOf('-latn') > 1) return 'ltr';
|
|
4227
|
-
return rtlLngs.
|
|
4205
|
+
return rtlLngs.includes(languageUtils.getLanguagePartFromCode(lng)) || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
|
|
4228
4206
|
}
|
|
4229
4207
|
static createInstance(options = {}, callback) {
|
|
4230
4208
|
const instance = new I18n(options, callback);
|