i18next 24.2.2 → 25.0.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/README.md +1 -1
- package/dist/cjs/i18next.js +99 -95
- package/dist/esm/i18next.bundled.js +99 -95
- package/dist/esm/i18next.js +99 -95
- package/dist/esm/package.json +1 -1
- package/dist/umd/i18next.js +99 -95
- package/dist/umd/i18next.min.js +1 -1
- package/i18next.js +99 -95
- package/i18next.min.js +1 -1
- package/package.json +8 -8
package/dist/umd/i18next.js
CHANGED
|
@@ -488,13 +488,13 @@
|
|
|
488
488
|
const resolved = this.resolve(key, options);
|
|
489
489
|
return resolved?.res !== undefined;
|
|
490
490
|
}
|
|
491
|
-
extractFromKey(key,
|
|
492
|
-
let nsSeparator =
|
|
491
|
+
extractFromKey(key, opt) {
|
|
492
|
+
let nsSeparator = opt.nsSeparator !== undefined ? opt.nsSeparator : this.options.nsSeparator;
|
|
493
493
|
if (nsSeparator === undefined) nsSeparator = ':';
|
|
494
|
-
const keySeparator =
|
|
495
|
-
let namespaces =
|
|
494
|
+
const keySeparator = opt.keySeparator !== undefined ? opt.keySeparator : this.options.keySeparator;
|
|
495
|
+
let namespaces = opt.ns || this.options.defaultNS || [];
|
|
496
496
|
const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
|
|
497
|
-
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !
|
|
497
|
+
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !opt.keySeparator && !this.options.userDefinedNsSeparator && !opt.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
498
498
|
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
499
499
|
const m = key.match(this.interpolator.nestingRegexp);
|
|
500
500
|
if (m && m.length > 0) {
|
|
@@ -512,28 +512,28 @@
|
|
|
512
512
|
namespaces: isString(namespaces) ? [namespaces] : namespaces
|
|
513
513
|
};
|
|
514
514
|
}
|
|
515
|
-
translate(keys,
|
|
516
|
-
if (typeof
|
|
517
|
-
|
|
515
|
+
translate(keys, opt, lastKey) {
|
|
516
|
+
if (typeof opt !== 'object' && this.options.overloadTranslationOptionHandler) {
|
|
517
|
+
opt = this.options.overloadTranslationOptionHandler(arguments);
|
|
518
518
|
}
|
|
519
|
-
if (typeof options === 'object')
|
|
520
|
-
...
|
|
519
|
+
if (typeof options === 'object') opt = {
|
|
520
|
+
...opt
|
|
521
521
|
};
|
|
522
|
-
if (!
|
|
522
|
+
if (!opt) opt = {};
|
|
523
523
|
if (keys == null) return '';
|
|
524
524
|
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
525
|
-
const returnDetails =
|
|
526
|
-
const keySeparator =
|
|
525
|
+
const returnDetails = opt.returnDetails !== undefined ? opt.returnDetails : this.options.returnDetails;
|
|
526
|
+
const keySeparator = opt.keySeparator !== undefined ? opt.keySeparator : this.options.keySeparator;
|
|
527
527
|
const {
|
|
528
528
|
key,
|
|
529
529
|
namespaces
|
|
530
|
-
} = this.extractFromKey(keys[keys.length - 1],
|
|
530
|
+
} = this.extractFromKey(keys[keys.length - 1], opt);
|
|
531
531
|
const namespace = namespaces[namespaces.length - 1];
|
|
532
|
-
const lng =
|
|
533
|
-
const appendNamespaceToCIMode =
|
|
532
|
+
const lng = opt.lng || this.language;
|
|
533
|
+
const appendNamespaceToCIMode = opt.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
534
534
|
if (lng?.toLowerCase() === 'cimode') {
|
|
535
535
|
if (appendNamespaceToCIMode) {
|
|
536
|
-
const nsSeparator =
|
|
536
|
+
const nsSeparator = opt.nsSeparator || this.options.nsSeparator;
|
|
537
537
|
if (returnDetails) {
|
|
538
538
|
return {
|
|
539
539
|
res: `${namespace}${nsSeparator}${key}`,
|
|
@@ -541,7 +541,7 @@
|
|
|
541
541
|
exactUsedKey: key,
|
|
542
542
|
usedLng: lng,
|
|
543
543
|
usedNS: namespace,
|
|
544
|
-
usedParams: this.getUsedParamsDetails(
|
|
544
|
+
usedParams: this.getUsedParamsDetails(opt)
|
|
545
545
|
};
|
|
546
546
|
}
|
|
547
547
|
return `${namespace}${nsSeparator}${key}`;
|
|
@@ -553,26 +553,26 @@
|
|
|
553
553
|
exactUsedKey: key,
|
|
554
554
|
usedLng: lng,
|
|
555
555
|
usedNS: namespace,
|
|
556
|
-
usedParams: this.getUsedParamsDetails(
|
|
556
|
+
usedParams: this.getUsedParamsDetails(opt)
|
|
557
557
|
};
|
|
558
558
|
}
|
|
559
559
|
return key;
|
|
560
560
|
}
|
|
561
|
-
const resolved = this.resolve(keys,
|
|
561
|
+
const resolved = this.resolve(keys, opt);
|
|
562
562
|
let res = resolved?.res;
|
|
563
563
|
const resUsedKey = resolved?.usedKey || key;
|
|
564
564
|
const resExactUsedKey = resolved?.exactUsedKey || key;
|
|
565
565
|
const noObject = ['[object Number]', '[object Function]', '[object RegExp]'];
|
|
566
|
-
const joinArrays =
|
|
566
|
+
const joinArrays = opt.joinArrays !== undefined ? opt.joinArrays : this.options.joinArrays;
|
|
567
567
|
const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
568
|
-
const needsPluralHandling =
|
|
569
|
-
const hasDefaultValue = Translator.hasDefaultValue(
|
|
570
|
-
const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng,
|
|
571
|
-
const defaultValueSuffixOrdinalFallback =
|
|
568
|
+
const needsPluralHandling = opt.count !== undefined && !isString(opt.count);
|
|
569
|
+
const hasDefaultValue = Translator.hasDefaultValue(opt);
|
|
570
|
+
const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, opt) : '';
|
|
571
|
+
const defaultValueSuffixOrdinalFallback = opt.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, {
|
|
572
572
|
ordinal: false
|
|
573
573
|
}) : '';
|
|
574
|
-
const needsZeroSuffixLookup = needsPluralHandling && !
|
|
575
|
-
const defaultValue = needsZeroSuffixLookup &&
|
|
574
|
+
const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
|
|
575
|
+
const defaultValue = needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] || opt[`defaultValue${defaultValueSuffix}`] || opt[`defaultValue${defaultValueSuffixOrdinalFallback}`] || opt.defaultValue;
|
|
576
576
|
let resForObjHndl = res;
|
|
577
577
|
if (handleAsObjectInI18nFormat && !res && hasDefaultValue) {
|
|
578
578
|
resForObjHndl = defaultValue;
|
|
@@ -580,17 +580,17 @@
|
|
|
580
580
|
const handleAsObject = shouldHandleAsObject(resForObjHndl);
|
|
581
581
|
const resType = Object.prototype.toString.apply(resForObjHndl);
|
|
582
582
|
if (handleAsObjectInI18nFormat && resForObjHndl && handleAsObject && noObject.indexOf(resType) < 0 && !(isString(joinArrays) && Array.isArray(resForObjHndl))) {
|
|
583
|
-
if (!
|
|
583
|
+
if (!opt.returnObjects && !this.options.returnObjects) {
|
|
584
584
|
if (!this.options.returnedObjectHandler) {
|
|
585
585
|
this.logger.warn('accessing an object - but returnObjects options is not enabled!');
|
|
586
586
|
}
|
|
587
587
|
const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, resForObjHndl, {
|
|
588
|
-
...
|
|
588
|
+
...opt,
|
|
589
589
|
ns: namespaces
|
|
590
590
|
}) : `key '${key} (${this.language})' returned an object instead of string.`;
|
|
591
591
|
if (returnDetails) {
|
|
592
592
|
resolved.res = r;
|
|
593
|
-
resolved.usedParams = this.getUsedParamsDetails(
|
|
593
|
+
resolved.usedParams = this.getUsedParamsDetails(opt);
|
|
594
594
|
return resolved;
|
|
595
595
|
}
|
|
596
596
|
return r;
|
|
@@ -604,7 +604,7 @@
|
|
|
604
604
|
const deepKey = `${newKeyToUse}${keySeparator}${m}`;
|
|
605
605
|
if (hasDefaultValue && !res) {
|
|
606
606
|
copy[m] = this.translate(deepKey, {
|
|
607
|
-
...
|
|
607
|
+
...opt,
|
|
608
608
|
defaultValue: shouldHandleAsObject(defaultValue) ? defaultValue[m] : undefined,
|
|
609
609
|
...{
|
|
610
610
|
joinArrays: false,
|
|
@@ -613,7 +613,7 @@
|
|
|
613
613
|
});
|
|
614
614
|
} else {
|
|
615
615
|
copy[m] = this.translate(deepKey, {
|
|
616
|
-
...
|
|
616
|
+
...opt,
|
|
617
617
|
...{
|
|
618
618
|
joinArrays: false,
|
|
619
619
|
ns: namespaces
|
|
@@ -627,7 +627,7 @@
|
|
|
627
627
|
}
|
|
628
628
|
} else if (handleAsObjectInI18nFormat && isString(joinArrays) && Array.isArray(res)) {
|
|
629
629
|
res = res.join(joinArrays);
|
|
630
|
-
if (res) res = this.extendTranslation(res, keys,
|
|
630
|
+
if (res) res = this.extendTranslation(res, keys, opt, lastKey);
|
|
631
631
|
} else {
|
|
632
632
|
let usedDefault = false;
|
|
633
633
|
let usedKey = false;
|
|
@@ -639,47 +639,47 @@
|
|
|
639
639
|
usedKey = true;
|
|
640
640
|
res = key;
|
|
641
641
|
}
|
|
642
|
-
const missingKeyNoValueFallbackToKey =
|
|
642
|
+
const missingKeyNoValueFallbackToKey = opt.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
|
|
643
643
|
const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? undefined : res;
|
|
644
644
|
const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
645
645
|
if (usedKey || usedDefault || updateMissing) {
|
|
646
646
|
this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? defaultValue : res);
|
|
647
647
|
if (keySeparator) {
|
|
648
648
|
const fk = this.resolve(key, {
|
|
649
|
-
...
|
|
649
|
+
...opt,
|
|
650
650
|
keySeparator: false
|
|
651
651
|
});
|
|
652
652
|
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.');
|
|
653
653
|
}
|
|
654
654
|
let lngs = [];
|
|
655
|
-
const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng,
|
|
655
|
+
const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, opt.lng || this.language);
|
|
656
656
|
if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) {
|
|
657
657
|
for (let i = 0; i < fallbackLngs.length; i++) {
|
|
658
658
|
lngs.push(fallbackLngs[i]);
|
|
659
659
|
}
|
|
660
660
|
} else if (this.options.saveMissingTo === 'all') {
|
|
661
|
-
lngs = this.languageUtils.toResolveHierarchy(
|
|
661
|
+
lngs = this.languageUtils.toResolveHierarchy(opt.lng || this.language);
|
|
662
662
|
} else {
|
|
663
|
-
lngs.push(
|
|
663
|
+
lngs.push(opt.lng || this.language);
|
|
664
664
|
}
|
|
665
665
|
const send = (l, k, specificDefaultValue) => {
|
|
666
666
|
const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
667
667
|
if (this.options.missingKeyHandler) {
|
|
668
|
-
this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing,
|
|
668
|
+
this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, opt);
|
|
669
669
|
} else if (this.backendConnector?.saveMissing) {
|
|
670
|
-
this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing,
|
|
670
|
+
this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, opt);
|
|
671
671
|
}
|
|
672
672
|
this.emit('missingKey', l, namespace, k, res);
|
|
673
673
|
};
|
|
674
674
|
if (this.options.saveMissing) {
|
|
675
675
|
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
676
676
|
lngs.forEach(language => {
|
|
677
|
-
const suffixes = this.pluralResolver.getSuffixes(language,
|
|
678
|
-
if (needsZeroSuffixLookup &&
|
|
677
|
+
const suffixes = this.pluralResolver.getSuffixes(language, opt);
|
|
678
|
+
if (needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.indexOf(`${this.options.pluralSeparator}zero`) < 0) {
|
|
679
679
|
suffixes.push(`${this.options.pluralSeparator}zero`);
|
|
680
680
|
}
|
|
681
681
|
suffixes.forEach(suffix => {
|
|
682
|
-
send([language], key + suffix,
|
|
682
|
+
send([language], key + suffix, opt[`defaultValue${suffix}`] || defaultValue);
|
|
683
683
|
});
|
|
684
684
|
});
|
|
685
685
|
} else {
|
|
@@ -687,7 +687,7 @@
|
|
|
687
687
|
}
|
|
688
688
|
}
|
|
689
689
|
}
|
|
690
|
-
res = this.extendTranslation(res, keys,
|
|
690
|
+
res = this.extendTranslation(res, keys, opt, resolved, lastKey);
|
|
691
691
|
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
|
|
692
692
|
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
|
|
693
693
|
res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : undefined);
|
|
@@ -695,75 +695,75 @@
|
|
|
695
695
|
}
|
|
696
696
|
if (returnDetails) {
|
|
697
697
|
resolved.res = res;
|
|
698
|
-
resolved.usedParams = this.getUsedParamsDetails(
|
|
698
|
+
resolved.usedParams = this.getUsedParamsDetails(opt);
|
|
699
699
|
return resolved;
|
|
700
700
|
}
|
|
701
701
|
return res;
|
|
702
702
|
}
|
|
703
|
-
extendTranslation(res, key,
|
|
703
|
+
extendTranslation(res, key, opt, resolved, lastKey) {
|
|
704
704
|
var _this = this;
|
|
705
705
|
if (this.i18nFormat?.parse) {
|
|
706
706
|
res = this.i18nFormat.parse(res, {
|
|
707
707
|
...this.options.interpolation.defaultVariables,
|
|
708
|
-
...
|
|
709
|
-
},
|
|
708
|
+
...opt
|
|
709
|
+
}, opt.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
|
|
710
710
|
resolved
|
|
711
711
|
});
|
|
712
|
-
} else if (!
|
|
713
|
-
if (
|
|
714
|
-
...
|
|
712
|
+
} else if (!opt.skipInterpolation) {
|
|
713
|
+
if (opt.interpolation) this.interpolator.init({
|
|
714
|
+
...opt,
|
|
715
715
|
...{
|
|
716
716
|
interpolation: {
|
|
717
717
|
...this.options.interpolation,
|
|
718
|
-
...
|
|
718
|
+
...opt.interpolation
|
|
719
719
|
}
|
|
720
720
|
}
|
|
721
721
|
});
|
|
722
|
-
const skipOnVariables = isString(res) && (
|
|
722
|
+
const skipOnVariables = isString(res) && (opt?.interpolation?.skipOnVariables !== undefined ? opt.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
723
723
|
let nestBef;
|
|
724
724
|
if (skipOnVariables) {
|
|
725
725
|
const nb = res.match(this.interpolator.nestingRegexp);
|
|
726
726
|
nestBef = nb && nb.length;
|
|
727
727
|
}
|
|
728
|
-
let data =
|
|
728
|
+
let data = opt.replace && !isString(opt.replace) ? opt.replace : opt;
|
|
729
729
|
if (this.options.interpolation.defaultVariables) data = {
|
|
730
730
|
...this.options.interpolation.defaultVariables,
|
|
731
731
|
...data
|
|
732
732
|
};
|
|
733
|
-
res = this.interpolator.interpolate(res, data,
|
|
733
|
+
res = this.interpolator.interpolate(res, data, opt.lng || this.language || resolved.usedLng, opt);
|
|
734
734
|
if (skipOnVariables) {
|
|
735
735
|
const na = res.match(this.interpolator.nestingRegexp);
|
|
736
736
|
const nestAft = na && na.length;
|
|
737
|
-
if (nestBef < nestAft)
|
|
737
|
+
if (nestBef < nestAft) opt.nest = false;
|
|
738
738
|
}
|
|
739
|
-
if (!
|
|
740
|
-
if (
|
|
739
|
+
if (!opt.lng && resolved && resolved.res) opt.lng = this.language || resolved.usedLng;
|
|
740
|
+
if (opt.nest !== false) res = this.interpolator.nest(res, function () {
|
|
741
741
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
742
742
|
args[_key] = arguments[_key];
|
|
743
743
|
}
|
|
744
|
-
if (lastKey?.[0] === args[0] && !
|
|
744
|
+
if (lastKey?.[0] === args[0] && !opt.context) {
|
|
745
745
|
_this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
|
|
746
746
|
return null;
|
|
747
747
|
}
|
|
748
748
|
return _this.translate(...args, key);
|
|
749
|
-
},
|
|
750
|
-
if (
|
|
749
|
+
}, opt);
|
|
750
|
+
if (opt.interpolation) this.interpolator.reset();
|
|
751
751
|
}
|
|
752
|
-
const postProcess =
|
|
752
|
+
const postProcess = opt.postProcess || this.options.postProcess;
|
|
753
753
|
const postProcessorNames = isString(postProcess) ? [postProcess] : postProcess;
|
|
754
|
-
if (res != null && postProcessorNames?.length &&
|
|
754
|
+
if (res != null && postProcessorNames?.length && opt.applyPostProcessor !== false) {
|
|
755
755
|
res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
|
|
756
756
|
i18nResolved: {
|
|
757
757
|
...resolved,
|
|
758
|
-
usedParams: this.getUsedParamsDetails(
|
|
758
|
+
usedParams: this.getUsedParamsDetails(opt)
|
|
759
759
|
},
|
|
760
|
-
...
|
|
761
|
-
} :
|
|
760
|
+
...opt
|
|
761
|
+
} : opt, this);
|
|
762
762
|
}
|
|
763
763
|
return res;
|
|
764
764
|
}
|
|
765
765
|
resolve(keys) {
|
|
766
|
-
let
|
|
766
|
+
let opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
767
767
|
let found;
|
|
768
768
|
let usedKey;
|
|
769
769
|
let exactUsedKey;
|
|
@@ -772,15 +772,15 @@
|
|
|
772
772
|
if (isString(keys)) keys = [keys];
|
|
773
773
|
keys.forEach(k => {
|
|
774
774
|
if (this.isValidLookup(found)) return;
|
|
775
|
-
const extracted = this.extractFromKey(k,
|
|
775
|
+
const extracted = this.extractFromKey(k, opt);
|
|
776
776
|
const key = extracted.key;
|
|
777
777
|
usedKey = key;
|
|
778
778
|
let namespaces = extracted.namespaces;
|
|
779
779
|
if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
|
|
780
|
-
const needsPluralHandling =
|
|
781
|
-
const needsZeroSuffixLookup = needsPluralHandling && !
|
|
782
|
-
const needsContextHandling =
|
|
783
|
-
const codes =
|
|
780
|
+
const needsPluralHandling = opt.count !== undefined && !isString(opt.count);
|
|
781
|
+
const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
|
|
782
|
+
const needsContextHandling = opt.context !== undefined && (isString(opt.context) || typeof opt.context === 'number') && opt.context !== '';
|
|
783
|
+
const codes = opt.lngs ? opt.lngs : this.languageUtils.toResolveHierarchy(opt.lng || this.language, opt.fallbackLng);
|
|
784
784
|
namespaces.forEach(ns => {
|
|
785
785
|
if (this.isValidLookup(found)) return;
|
|
786
786
|
usedNS = ns;
|
|
@@ -793,15 +793,15 @@
|
|
|
793
793
|
usedLng = code;
|
|
794
794
|
const finalKeys = [key];
|
|
795
795
|
if (this.i18nFormat?.addLookupKeys) {
|
|
796
|
-
this.i18nFormat.addLookupKeys(finalKeys, key, code, ns,
|
|
796
|
+
this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, opt);
|
|
797
797
|
} else {
|
|
798
798
|
let pluralSuffix;
|
|
799
|
-
if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code,
|
|
799
|
+
if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, opt.count, opt);
|
|
800
800
|
const zeroSuffix = `${this.options.pluralSeparator}zero`;
|
|
801
801
|
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
|
|
802
802
|
if (needsPluralHandling) {
|
|
803
803
|
finalKeys.push(key + pluralSuffix);
|
|
804
|
-
if (
|
|
804
|
+
if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
805
805
|
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
806
806
|
}
|
|
807
807
|
if (needsZeroSuffixLookup) {
|
|
@@ -809,11 +809,11 @@
|
|
|
809
809
|
}
|
|
810
810
|
}
|
|
811
811
|
if (needsContextHandling) {
|
|
812
|
-
const contextKey = `${key}${this.options.contextSeparator}${
|
|
812
|
+
const contextKey = `${key}${this.options.contextSeparator}${opt.context}`;
|
|
813
813
|
finalKeys.push(contextKey);
|
|
814
814
|
if (needsPluralHandling) {
|
|
815
815
|
finalKeys.push(contextKey + pluralSuffix);
|
|
816
|
-
if (
|
|
816
|
+
if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
817
817
|
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
818
818
|
}
|
|
819
819
|
if (needsZeroSuffixLookup) {
|
|
@@ -826,7 +826,7 @@
|
|
|
826
826
|
while (possibleKey = finalKeys.pop()) {
|
|
827
827
|
if (!this.isValidLookup(found)) {
|
|
828
828
|
exactUsedKey = possibleKey;
|
|
829
|
-
found = this.getResource(code, ns, possibleKey,
|
|
829
|
+
found = this.getResource(code, ns, possibleKey, opt);
|
|
830
830
|
}
|
|
831
831
|
}
|
|
832
832
|
});
|
|
@@ -938,6 +938,8 @@
|
|
|
938
938
|
if (!found && this.options.supportedLngs) {
|
|
939
939
|
codes.forEach(code => {
|
|
940
940
|
if (found) return;
|
|
941
|
+
const lngScOnly = this.getScriptPartFromCode(code);
|
|
942
|
+
if (this.isSupportedCode(lngScOnly)) return found = lngScOnly;
|
|
941
943
|
const lngOnly = this.getLanguagePartFromCode(code);
|
|
942
944
|
if (this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
943
945
|
found = this.options.supportedLngs.find(supportedLng => {
|
|
@@ -1984,11 +1986,13 @@
|
|
|
1984
1986
|
};
|
|
1985
1987
|
const done = (err, l) => {
|
|
1986
1988
|
if (l) {
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1989
|
+
if (this.isLanguageChangingTo === lng) {
|
|
1990
|
+
setLngProps(l);
|
|
1991
|
+
this.translator.changeLanguage(l);
|
|
1992
|
+
this.isLanguageChangingTo = undefined;
|
|
1993
|
+
this.emit('languageChanged', l);
|
|
1994
|
+
this.logger.log('languageChanged', l);
|
|
1995
|
+
}
|
|
1992
1996
|
} else {
|
|
1993
1997
|
this.isLanguageChangingTo = undefined;
|
|
1994
1998
|
}
|
|
@@ -2001,7 +2005,7 @@
|
|
|
2001
2005
|
};
|
|
2002
2006
|
const setLng = lngs => {
|
|
2003
2007
|
if (!lng && !lngs && this.services.languageDetector) lngs = [];
|
|
2004
|
-
const l = isString(lngs) ? lngs :
|
|
2008
|
+
const l = this.services.languageUtils.getBestMatchFromCodes(isString(lngs) ? [lngs] : lngs);
|
|
2005
2009
|
if (l) {
|
|
2006
2010
|
if (!this.language) {
|
|
2007
2011
|
setLngProps(l);
|
|
@@ -2029,29 +2033,29 @@
|
|
|
2029
2033
|
getFixedT(lng, ns, keyPrefix) {
|
|
2030
2034
|
var _this3 = this;
|
|
2031
2035
|
const fixedT = function (key, opts) {
|
|
2032
|
-
let
|
|
2036
|
+
let o;
|
|
2033
2037
|
if (typeof opts !== 'object') {
|
|
2034
2038
|
for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
2035
2039
|
rest[_key3 - 2] = arguments[_key3];
|
|
2036
2040
|
}
|
|
2037
|
-
|
|
2041
|
+
o = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
2038
2042
|
} else {
|
|
2039
|
-
|
|
2043
|
+
o = {
|
|
2040
2044
|
...opts
|
|
2041
2045
|
};
|
|
2042
2046
|
}
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
if (
|
|
2047
|
+
o.lng = o.lng || fixedT.lng;
|
|
2048
|
+
o.lngs = o.lngs || fixedT.lngs;
|
|
2049
|
+
o.ns = o.ns || fixedT.ns;
|
|
2050
|
+
if (o.keyPrefix !== '') o.keyPrefix = o.keyPrefix || keyPrefix || fixedT.keyPrefix;
|
|
2047
2051
|
const keySeparator = _this3.options.keySeparator || '.';
|
|
2048
2052
|
let resultKey;
|
|
2049
|
-
if (
|
|
2050
|
-
resultKey = key.map(k => `${
|
|
2053
|
+
if (o.keyPrefix && Array.isArray(key)) {
|
|
2054
|
+
resultKey = key.map(k => `${o.keyPrefix}${keySeparator}${k}`);
|
|
2051
2055
|
} else {
|
|
2052
|
-
resultKey =
|
|
2056
|
+
resultKey = o.keyPrefix ? `${o.keyPrefix}${keySeparator}${key}` : key;
|
|
2053
2057
|
}
|
|
2054
|
-
return _this3.t(resultKey,
|
|
2058
|
+
return _this3.t(resultKey, o);
|
|
2055
2059
|
};
|
|
2056
2060
|
if (isString(lng)) {
|
|
2057
2061
|
fixedT.lng = lng;
|