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