@aslaluroba/help-center-react 3.0.8 → 3.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.css +1 -1
- package/dist/index.esm.js +2229 -17
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +2229 -18
- package/dist/index.js.map +1 -1
- package/package.json +2 -4
- package/src/ui/chatbot-popup/chat-window-screen/header.tsx +4 -4
- package/src/ui/chatbot-popup/options-list-screen/header.tsx +6 -8
- package/src/ui/chatbot-popup/options-list-screen/option-card.tsx +4 -5
package/dist/index.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var React = require('react');
|
|
7
|
-
var i18next = require('i18next');
|
|
8
7
|
|
|
9
8
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
9
|
|
|
@@ -28,7 +27,6 @@ function _interopNamespace(e) {
|
|
|
28
27
|
|
|
29
28
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
30
29
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
31
|
-
var i18next__default = /*#__PURE__*/_interopDefaultLegacy(i18next);
|
|
32
30
|
|
|
33
31
|
function _OverloadYield(e, d) {
|
|
34
32
|
this.v = e, this.k = d;
|
|
@@ -3617,6 +3615,2218 @@ var Rating = /*#__PURE__*/React__namespace.forwardRef((_ref, ref) => {
|
|
|
3617
3615
|
});
|
|
3618
3616
|
Rating.displayName = 'Rating';
|
|
3619
3617
|
|
|
3618
|
+
var isString$1 = obj => typeof obj === 'string';
|
|
3619
|
+
var defer = () => {
|
|
3620
|
+
var res;
|
|
3621
|
+
var rej;
|
|
3622
|
+
var promise = new Promise((resolve, reject) => {
|
|
3623
|
+
res = resolve;
|
|
3624
|
+
rej = reject;
|
|
3625
|
+
});
|
|
3626
|
+
promise.resolve = res;
|
|
3627
|
+
promise.reject = rej;
|
|
3628
|
+
return promise;
|
|
3629
|
+
};
|
|
3630
|
+
var makeString = object => {
|
|
3631
|
+
if (object == null) return '';
|
|
3632
|
+
return '' + object;
|
|
3633
|
+
};
|
|
3634
|
+
var copy = (a, s, t) => {
|
|
3635
|
+
a.forEach(m => {
|
|
3636
|
+
if (s[m]) t[m] = s[m];
|
|
3637
|
+
});
|
|
3638
|
+
};
|
|
3639
|
+
var lastOfPathSeparatorRegExp = /###/g;
|
|
3640
|
+
var cleanKey = key => key && key.indexOf('###') > -1 ? key.replace(lastOfPathSeparatorRegExp, '.') : key;
|
|
3641
|
+
var canNotTraverseDeeper = object => !object || isString$1(object);
|
|
3642
|
+
var getLastOfPath = (object, path, Empty) => {
|
|
3643
|
+
var stack = !isString$1(path) ? path : path.split('.');
|
|
3644
|
+
var stackIndex = 0;
|
|
3645
|
+
while (stackIndex < stack.length - 1) {
|
|
3646
|
+
if (canNotTraverseDeeper(object)) return {};
|
|
3647
|
+
var key = cleanKey(stack[stackIndex]);
|
|
3648
|
+
if (!object[key] && Empty) object[key] = new Empty();
|
|
3649
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
3650
|
+
object = object[key];
|
|
3651
|
+
} else {
|
|
3652
|
+
object = {};
|
|
3653
|
+
}
|
|
3654
|
+
++stackIndex;
|
|
3655
|
+
}
|
|
3656
|
+
if (canNotTraverseDeeper(object)) return {};
|
|
3657
|
+
return {
|
|
3658
|
+
obj: object,
|
|
3659
|
+
k: cleanKey(stack[stackIndex])
|
|
3660
|
+
};
|
|
3661
|
+
};
|
|
3662
|
+
var setPath = (object, path, newValue) => {
|
|
3663
|
+
var {
|
|
3664
|
+
obj,
|
|
3665
|
+
k
|
|
3666
|
+
} = getLastOfPath(object, path, Object);
|
|
3667
|
+
if (obj !== undefined || path.length === 1) {
|
|
3668
|
+
obj[k] = newValue;
|
|
3669
|
+
return;
|
|
3670
|
+
}
|
|
3671
|
+
var e = path[path.length - 1];
|
|
3672
|
+
var p = path.slice(0, path.length - 1);
|
|
3673
|
+
var last = getLastOfPath(object, p, Object);
|
|
3674
|
+
while (last.obj === undefined && p.length) {
|
|
3675
|
+
var _last;
|
|
3676
|
+
e = "".concat(p[p.length - 1], ".").concat(e);
|
|
3677
|
+
p = p.slice(0, p.length - 1);
|
|
3678
|
+
last = getLastOfPath(object, p, Object);
|
|
3679
|
+
if ((_last = last) !== null && _last !== void 0 && _last.obj && typeof last.obj["".concat(last.k, ".").concat(e)] !== 'undefined') {
|
|
3680
|
+
last.obj = undefined;
|
|
3681
|
+
}
|
|
3682
|
+
}
|
|
3683
|
+
last.obj["".concat(last.k, ".").concat(e)] = newValue;
|
|
3684
|
+
};
|
|
3685
|
+
var pushPath = (object, path, newValue, concat) => {
|
|
3686
|
+
var {
|
|
3687
|
+
obj,
|
|
3688
|
+
k
|
|
3689
|
+
} = getLastOfPath(object, path, Object);
|
|
3690
|
+
obj[k] = obj[k] || [];
|
|
3691
|
+
obj[k].push(newValue);
|
|
3692
|
+
};
|
|
3693
|
+
var getPath = (object, path) => {
|
|
3694
|
+
var {
|
|
3695
|
+
obj,
|
|
3696
|
+
k
|
|
3697
|
+
} = getLastOfPath(object, path);
|
|
3698
|
+
if (!obj) return undefined;
|
|
3699
|
+
if (!Object.prototype.hasOwnProperty.call(obj, k)) return undefined;
|
|
3700
|
+
return obj[k];
|
|
3701
|
+
};
|
|
3702
|
+
var getPathWithDefaults = (data, defaultData, key) => {
|
|
3703
|
+
var value = getPath(data, key);
|
|
3704
|
+
if (value !== undefined) {
|
|
3705
|
+
return value;
|
|
3706
|
+
}
|
|
3707
|
+
return getPath(defaultData, key);
|
|
3708
|
+
};
|
|
3709
|
+
var deepExtend = (target, source, overwrite) => {
|
|
3710
|
+
for (var prop in source) {
|
|
3711
|
+
if (prop !== '__proto__' && prop !== 'constructor') {
|
|
3712
|
+
if (prop in target) {
|
|
3713
|
+
if (isString$1(target[prop]) || target[prop] instanceof String || isString$1(source[prop]) || source[prop] instanceof String) {
|
|
3714
|
+
if (overwrite) target[prop] = source[prop];
|
|
3715
|
+
} else {
|
|
3716
|
+
deepExtend(target[prop], source[prop], overwrite);
|
|
3717
|
+
}
|
|
3718
|
+
} else {
|
|
3719
|
+
target[prop] = source[prop];
|
|
3720
|
+
}
|
|
3721
|
+
}
|
|
3722
|
+
}
|
|
3723
|
+
return target;
|
|
3724
|
+
};
|
|
3725
|
+
var regexEscape = str => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
|
|
3726
|
+
var _entityMap = {
|
|
3727
|
+
'&': '&',
|
|
3728
|
+
'<': '<',
|
|
3729
|
+
'>': '>',
|
|
3730
|
+
'"': '"',
|
|
3731
|
+
"'": ''',
|
|
3732
|
+
'/': '/'
|
|
3733
|
+
};
|
|
3734
|
+
var escape = data => {
|
|
3735
|
+
if (isString$1(data)) {
|
|
3736
|
+
return data.replace(/[&<>"'\/]/g, s => _entityMap[s]);
|
|
3737
|
+
}
|
|
3738
|
+
return data;
|
|
3739
|
+
};
|
|
3740
|
+
class RegExpCache {
|
|
3741
|
+
constructor(capacity) {
|
|
3742
|
+
this.capacity = capacity;
|
|
3743
|
+
this.regExpMap = new Map();
|
|
3744
|
+
this.regExpQueue = [];
|
|
3745
|
+
}
|
|
3746
|
+
getRegExp(pattern) {
|
|
3747
|
+
var regExpFromCache = this.regExpMap.get(pattern);
|
|
3748
|
+
if (regExpFromCache !== undefined) {
|
|
3749
|
+
return regExpFromCache;
|
|
3750
|
+
}
|
|
3751
|
+
var regExpNew = new RegExp(pattern);
|
|
3752
|
+
if (this.regExpQueue.length === this.capacity) {
|
|
3753
|
+
this.regExpMap.delete(this.regExpQueue.shift());
|
|
3754
|
+
}
|
|
3755
|
+
this.regExpMap.set(pattern, regExpNew);
|
|
3756
|
+
this.regExpQueue.push(pattern);
|
|
3757
|
+
return regExpNew;
|
|
3758
|
+
}
|
|
3759
|
+
}
|
|
3760
|
+
var chars = [' ', ',', '?', '!', ';'];
|
|
3761
|
+
var looksLikeObjectPathRegExpCache = new RegExpCache(20);
|
|
3762
|
+
var looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
|
|
3763
|
+
nsSeparator = nsSeparator || '';
|
|
3764
|
+
keySeparator = keySeparator || '';
|
|
3765
|
+
var possibleChars = chars.filter(c => nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0);
|
|
3766
|
+
if (possibleChars.length === 0) return true;
|
|
3767
|
+
var r = looksLikeObjectPathRegExpCache.getRegExp("(".concat(possibleChars.map(c => c === '?' ? '\\?' : c).join('|'), ")"));
|
|
3768
|
+
var matched = !r.test(key);
|
|
3769
|
+
if (!matched) {
|
|
3770
|
+
var ki = key.indexOf(keySeparator);
|
|
3771
|
+
if (ki > 0 && !r.test(key.substring(0, ki))) {
|
|
3772
|
+
matched = true;
|
|
3773
|
+
}
|
|
3774
|
+
}
|
|
3775
|
+
return matched;
|
|
3776
|
+
};
|
|
3777
|
+
var deepFind = function deepFind(obj, path) {
|
|
3778
|
+
var keySeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
|
|
3779
|
+
if (!obj) return undefined;
|
|
3780
|
+
if (obj[path]) {
|
|
3781
|
+
if (!Object.prototype.hasOwnProperty.call(obj, path)) return undefined;
|
|
3782
|
+
return obj[path];
|
|
3783
|
+
}
|
|
3784
|
+
var tokens = path.split(keySeparator);
|
|
3785
|
+
var current = obj;
|
|
3786
|
+
for (var i = 0; i < tokens.length;) {
|
|
3787
|
+
if (!current || typeof current !== 'object') {
|
|
3788
|
+
return undefined;
|
|
3789
|
+
}
|
|
3790
|
+
var next = void 0;
|
|
3791
|
+
var nextPath = '';
|
|
3792
|
+
for (var j = i; j < tokens.length; ++j) {
|
|
3793
|
+
if (j !== i) {
|
|
3794
|
+
nextPath += keySeparator;
|
|
3795
|
+
}
|
|
3796
|
+
nextPath += tokens[j];
|
|
3797
|
+
next = current[nextPath];
|
|
3798
|
+
if (next !== undefined) {
|
|
3799
|
+
if (['string', 'number', 'boolean'].indexOf(typeof next) > -1 && j < tokens.length - 1) {
|
|
3800
|
+
continue;
|
|
3801
|
+
}
|
|
3802
|
+
i += j - i + 1;
|
|
3803
|
+
break;
|
|
3804
|
+
}
|
|
3805
|
+
}
|
|
3806
|
+
current = next;
|
|
3807
|
+
}
|
|
3808
|
+
return current;
|
|
3809
|
+
};
|
|
3810
|
+
var getCleanedCode = code => code === null || code === void 0 ? void 0 : code.replace('_', '-');
|
|
3811
|
+
var consoleLogger = {
|
|
3812
|
+
type: 'logger',
|
|
3813
|
+
log(args) {
|
|
3814
|
+
this.output('log', args);
|
|
3815
|
+
},
|
|
3816
|
+
warn(args) {
|
|
3817
|
+
this.output('warn', args);
|
|
3818
|
+
},
|
|
3819
|
+
error(args) {
|
|
3820
|
+
this.output('error', args);
|
|
3821
|
+
},
|
|
3822
|
+
output(type, args) {
|
|
3823
|
+
var _console, _console$apply;
|
|
3824
|
+
(_console = console) === null || _console === void 0 || (_console = _console[type]) === null || _console === void 0 || (_console$apply = _console.apply) === null || _console$apply === void 0 || _console$apply.call(_console, console, args);
|
|
3825
|
+
}
|
|
3826
|
+
};
|
|
3827
|
+
class Logger {
|
|
3828
|
+
constructor(concreteLogger) {
|
|
3829
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
3830
|
+
this.init(concreteLogger, options);
|
|
3831
|
+
}
|
|
3832
|
+
init(concreteLogger) {
|
|
3833
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
3834
|
+
this.prefix = options.prefix || 'i18next:';
|
|
3835
|
+
this.logger = concreteLogger || consoleLogger;
|
|
3836
|
+
this.options = options;
|
|
3837
|
+
this.debug = options.debug;
|
|
3838
|
+
}
|
|
3839
|
+
log() {
|
|
3840
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3841
|
+
args[_key] = arguments[_key];
|
|
3842
|
+
}
|
|
3843
|
+
return this.forward(args, 'log', '', true);
|
|
3844
|
+
}
|
|
3845
|
+
warn() {
|
|
3846
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
3847
|
+
args[_key2] = arguments[_key2];
|
|
3848
|
+
}
|
|
3849
|
+
return this.forward(args, 'warn', '', true);
|
|
3850
|
+
}
|
|
3851
|
+
error() {
|
|
3852
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
3853
|
+
args[_key3] = arguments[_key3];
|
|
3854
|
+
}
|
|
3855
|
+
return this.forward(args, 'error', '');
|
|
3856
|
+
}
|
|
3857
|
+
deprecate() {
|
|
3858
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
3859
|
+
args[_key4] = arguments[_key4];
|
|
3860
|
+
}
|
|
3861
|
+
return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
|
|
3862
|
+
}
|
|
3863
|
+
forward(args, lvl, prefix, debugOnly) {
|
|
3864
|
+
if (debugOnly && !this.debug) return null;
|
|
3865
|
+
if (isString$1(args[0])) args[0] = "".concat(prefix).concat(this.prefix, " ").concat(args[0]);
|
|
3866
|
+
return this.logger[lvl](args);
|
|
3867
|
+
}
|
|
3868
|
+
create(moduleName) {
|
|
3869
|
+
return new Logger(this.logger, _objectSpread2(_objectSpread2({}, {
|
|
3870
|
+
prefix: "".concat(this.prefix, ":").concat(moduleName, ":")
|
|
3871
|
+
}), this.options));
|
|
3872
|
+
}
|
|
3873
|
+
clone(options) {
|
|
3874
|
+
options = options || this.options;
|
|
3875
|
+
options.prefix = options.prefix || this.prefix;
|
|
3876
|
+
return new Logger(this.logger, options);
|
|
3877
|
+
}
|
|
3878
|
+
}
|
|
3879
|
+
var baseLogger = new Logger();
|
|
3880
|
+
class EventEmitter {
|
|
3881
|
+
constructor() {
|
|
3882
|
+
this.observers = {};
|
|
3883
|
+
}
|
|
3884
|
+
on(events, listener) {
|
|
3885
|
+
events.split(' ').forEach(event => {
|
|
3886
|
+
if (!this.observers[event]) this.observers[event] = new Map();
|
|
3887
|
+
var numListeners = this.observers[event].get(listener) || 0;
|
|
3888
|
+
this.observers[event].set(listener, numListeners + 1);
|
|
3889
|
+
});
|
|
3890
|
+
return this;
|
|
3891
|
+
}
|
|
3892
|
+
off(event, listener) {
|
|
3893
|
+
if (!this.observers[event]) return;
|
|
3894
|
+
if (!listener) {
|
|
3895
|
+
delete this.observers[event];
|
|
3896
|
+
return;
|
|
3897
|
+
}
|
|
3898
|
+
this.observers[event].delete(listener);
|
|
3899
|
+
}
|
|
3900
|
+
emit(event) {
|
|
3901
|
+
for (var _len5 = arguments.length, args = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
|
|
3902
|
+
args[_key5 - 1] = arguments[_key5];
|
|
3903
|
+
}
|
|
3904
|
+
if (this.observers[event]) {
|
|
3905
|
+
var cloned = Array.from(this.observers[event].entries());
|
|
3906
|
+
cloned.forEach(_ref => {
|
|
3907
|
+
var [observer, numTimesAdded] = _ref;
|
|
3908
|
+
for (var i = 0; i < numTimesAdded; i++) {
|
|
3909
|
+
observer(...args);
|
|
3910
|
+
}
|
|
3911
|
+
});
|
|
3912
|
+
}
|
|
3913
|
+
if (this.observers['*']) {
|
|
3914
|
+
var _cloned = Array.from(this.observers['*'].entries());
|
|
3915
|
+
_cloned.forEach(_ref2 => {
|
|
3916
|
+
var [observer, numTimesAdded] = _ref2;
|
|
3917
|
+
for (var i = 0; i < numTimesAdded; i++) {
|
|
3918
|
+
observer.apply(observer, [event, ...args]);
|
|
3919
|
+
}
|
|
3920
|
+
});
|
|
3921
|
+
}
|
|
3922
|
+
}
|
|
3923
|
+
}
|
|
3924
|
+
class ResourceStore extends EventEmitter {
|
|
3925
|
+
constructor(data) {
|
|
3926
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
3927
|
+
ns: ['translation'],
|
|
3928
|
+
defaultNS: 'translation'
|
|
3929
|
+
};
|
|
3930
|
+
super();
|
|
3931
|
+
this.data = data || {};
|
|
3932
|
+
this.options = options;
|
|
3933
|
+
if (this.options.keySeparator === undefined) {
|
|
3934
|
+
this.options.keySeparator = '.';
|
|
3935
|
+
}
|
|
3936
|
+
if (this.options.ignoreJSONStructure === undefined) {
|
|
3937
|
+
this.options.ignoreJSONStructure = true;
|
|
3938
|
+
}
|
|
3939
|
+
}
|
|
3940
|
+
addNamespaces(ns) {
|
|
3941
|
+
if (this.options.ns.indexOf(ns) < 0) {
|
|
3942
|
+
this.options.ns.push(ns);
|
|
3943
|
+
}
|
|
3944
|
+
}
|
|
3945
|
+
removeNamespaces(ns) {
|
|
3946
|
+
var index = this.options.ns.indexOf(ns);
|
|
3947
|
+
if (index > -1) {
|
|
3948
|
+
this.options.ns.splice(index, 1);
|
|
3949
|
+
}
|
|
3950
|
+
}
|
|
3951
|
+
getResource(lng, ns, key) {
|
|
3952
|
+
var _this$data;
|
|
3953
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
3954
|
+
var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
3955
|
+
var ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
3956
|
+
var path;
|
|
3957
|
+
if (lng.indexOf('.') > -1) {
|
|
3958
|
+
path = lng.split('.');
|
|
3959
|
+
} else {
|
|
3960
|
+
path = [lng, ns];
|
|
3961
|
+
if (key) {
|
|
3962
|
+
if (Array.isArray(key)) {
|
|
3963
|
+
path.push(...key);
|
|
3964
|
+
} else if (isString$1(key) && keySeparator) {
|
|
3965
|
+
path.push(...key.split(keySeparator));
|
|
3966
|
+
} else {
|
|
3967
|
+
path.push(key);
|
|
3968
|
+
}
|
|
3969
|
+
}
|
|
3970
|
+
}
|
|
3971
|
+
var result = getPath(this.data, path);
|
|
3972
|
+
if (!result && !ns && !key && lng.indexOf('.') > -1) {
|
|
3973
|
+
lng = path[0];
|
|
3974
|
+
ns = path[1];
|
|
3975
|
+
key = path.slice(2).join('.');
|
|
3976
|
+
}
|
|
3977
|
+
if (result || !ignoreJSONStructure || !isString$1(key)) return result;
|
|
3978
|
+
return deepFind((_this$data = this.data) === null || _this$data === void 0 || (_this$data = _this$data[lng]) === null || _this$data === void 0 ? void 0 : _this$data[ns], key, keySeparator);
|
|
3979
|
+
}
|
|
3980
|
+
addResource(lng, ns, key, value) {
|
|
3981
|
+
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
|
3982
|
+
silent: false
|
|
3983
|
+
};
|
|
3984
|
+
var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
3985
|
+
var path = [lng, ns];
|
|
3986
|
+
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
3987
|
+
if (lng.indexOf('.') > -1) {
|
|
3988
|
+
path = lng.split('.');
|
|
3989
|
+
value = ns;
|
|
3990
|
+
ns = path[1];
|
|
3991
|
+
}
|
|
3992
|
+
this.addNamespaces(ns);
|
|
3993
|
+
setPath(this.data, path, value);
|
|
3994
|
+
if (!options.silent) this.emit('added', lng, ns, key, value);
|
|
3995
|
+
}
|
|
3996
|
+
addResources(lng, ns, resources) {
|
|
3997
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
3998
|
+
silent: false
|
|
3999
|
+
};
|
|
4000
|
+
for (var m in resources) {
|
|
4001
|
+
if (isString$1(resources[m]) || Array.isArray(resources[m])) this.addResource(lng, ns, m, resources[m], {
|
|
4002
|
+
silent: true
|
|
4003
|
+
});
|
|
4004
|
+
}
|
|
4005
|
+
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
4006
|
+
}
|
|
4007
|
+
addResourceBundle(lng, ns, resources, deep, overwrite) {
|
|
4008
|
+
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {
|
|
4009
|
+
silent: false,
|
|
4010
|
+
skipCopy: false
|
|
4011
|
+
};
|
|
4012
|
+
var path = [lng, ns];
|
|
4013
|
+
if (lng.indexOf('.') > -1) {
|
|
4014
|
+
path = lng.split('.');
|
|
4015
|
+
deep = resources;
|
|
4016
|
+
resources = ns;
|
|
4017
|
+
ns = path[1];
|
|
4018
|
+
}
|
|
4019
|
+
this.addNamespaces(ns);
|
|
4020
|
+
var pack = getPath(this.data, path) || {};
|
|
4021
|
+
if (!options.skipCopy) resources = JSON.parse(JSON.stringify(resources));
|
|
4022
|
+
if (deep) {
|
|
4023
|
+
deepExtend(pack, resources, overwrite);
|
|
4024
|
+
} else {
|
|
4025
|
+
pack = _objectSpread2(_objectSpread2({}, pack), resources);
|
|
4026
|
+
}
|
|
4027
|
+
setPath(this.data, path, pack);
|
|
4028
|
+
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
4029
|
+
}
|
|
4030
|
+
removeResourceBundle(lng, ns) {
|
|
4031
|
+
if (this.hasResourceBundle(lng, ns)) {
|
|
4032
|
+
delete this.data[lng][ns];
|
|
4033
|
+
}
|
|
4034
|
+
this.removeNamespaces(ns);
|
|
4035
|
+
this.emit('removed', lng, ns);
|
|
4036
|
+
}
|
|
4037
|
+
hasResourceBundle(lng, ns) {
|
|
4038
|
+
return this.getResource(lng, ns) !== undefined;
|
|
4039
|
+
}
|
|
4040
|
+
getResourceBundle(lng, ns) {
|
|
4041
|
+
if (!ns) ns = this.options.defaultNS;
|
|
4042
|
+
return this.getResource(lng, ns);
|
|
4043
|
+
}
|
|
4044
|
+
getDataByLanguage(lng) {
|
|
4045
|
+
return this.data[lng];
|
|
4046
|
+
}
|
|
4047
|
+
hasLanguageSomeTranslations(lng) {
|
|
4048
|
+
var data = this.getDataByLanguage(lng);
|
|
4049
|
+
var n = data && Object.keys(data) || [];
|
|
4050
|
+
return !!n.find(v => data[v] && Object.keys(data[v]).length > 0);
|
|
4051
|
+
}
|
|
4052
|
+
toJSON() {
|
|
4053
|
+
return this.data;
|
|
4054
|
+
}
|
|
4055
|
+
}
|
|
4056
|
+
var postProcessor = {
|
|
4057
|
+
processors: {},
|
|
4058
|
+
addPostProcessor(module) {
|
|
4059
|
+
this.processors[module.name] = module;
|
|
4060
|
+
},
|
|
4061
|
+
handle(processors, value, key, options, translator) {
|
|
4062
|
+
processors.forEach(processor => {
|
|
4063
|
+
var _this$processors$proc, _this$processors$proc2;
|
|
4064
|
+
value = (_this$processors$proc = (_this$processors$proc2 = this.processors[processor]) === null || _this$processors$proc2 === void 0 ? void 0 : _this$processors$proc2.process(value, key, options, translator)) !== null && _this$processors$proc !== void 0 ? _this$processors$proc : value;
|
|
4065
|
+
});
|
|
4066
|
+
return value;
|
|
4067
|
+
}
|
|
4068
|
+
};
|
|
4069
|
+
var PATH_KEY = Symbol('i18next/PATH_KEY');
|
|
4070
|
+
function createProxy() {
|
|
4071
|
+
var state = [];
|
|
4072
|
+
var handler = Object.create(null);
|
|
4073
|
+
var proxy;
|
|
4074
|
+
handler.get = (target, key) => {
|
|
4075
|
+
var _proxy, _proxy$revoke;
|
|
4076
|
+
(_proxy = proxy) === null || _proxy === void 0 || (_proxy$revoke = _proxy.revoke) === null || _proxy$revoke === void 0 || _proxy$revoke.call(_proxy);
|
|
4077
|
+
if (key === PATH_KEY) return state;
|
|
4078
|
+
state.push(key);
|
|
4079
|
+
proxy = Proxy.revocable(target, handler);
|
|
4080
|
+
return proxy.proxy;
|
|
4081
|
+
};
|
|
4082
|
+
return Proxy.revocable(Object.create(null), handler).proxy;
|
|
4083
|
+
}
|
|
4084
|
+
function keysFromSelector(selector, opts) {
|
|
4085
|
+
var _opts$keySeparator;
|
|
4086
|
+
var {
|
|
4087
|
+
[PATH_KEY]: path
|
|
4088
|
+
} = selector(createProxy());
|
|
4089
|
+
return path.join((_opts$keySeparator = opts === null || opts === void 0 ? void 0 : opts.keySeparator) !== null && _opts$keySeparator !== void 0 ? _opts$keySeparator : '.');
|
|
4090
|
+
}
|
|
4091
|
+
var checkedLoadedFor = {};
|
|
4092
|
+
var shouldHandleAsObject = res => !isString$1(res) && typeof res !== 'boolean' && typeof res !== 'number';
|
|
4093
|
+
class Translator extends EventEmitter {
|
|
4094
|
+
constructor(services) {
|
|
4095
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
4096
|
+
super();
|
|
4097
|
+
copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector', 'i18nFormat', 'utils'], services, this);
|
|
4098
|
+
this.options = options;
|
|
4099
|
+
if (this.options.keySeparator === undefined) {
|
|
4100
|
+
this.options.keySeparator = '.';
|
|
4101
|
+
}
|
|
4102
|
+
this.logger = baseLogger.create('translator');
|
|
4103
|
+
}
|
|
4104
|
+
changeLanguage(lng) {
|
|
4105
|
+
if (lng) this.language = lng;
|
|
4106
|
+
}
|
|
4107
|
+
exists(key) {
|
|
4108
|
+
var o = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
4109
|
+
interpolation: {}
|
|
4110
|
+
};
|
|
4111
|
+
var opt = _objectSpread2({}, o);
|
|
4112
|
+
if (key == null) return false;
|
|
4113
|
+
var resolved = this.resolve(key, opt);
|
|
4114
|
+
return (resolved === null || resolved === void 0 ? void 0 : resolved.res) !== undefined;
|
|
4115
|
+
}
|
|
4116
|
+
extractFromKey(key, opt) {
|
|
4117
|
+
var nsSeparator = opt.nsSeparator !== undefined ? opt.nsSeparator : this.options.nsSeparator;
|
|
4118
|
+
if (nsSeparator === undefined) nsSeparator = ':';
|
|
4119
|
+
var keySeparator = opt.keySeparator !== undefined ? opt.keySeparator : this.options.keySeparator;
|
|
4120
|
+
var namespaces = opt.ns || this.options.defaultNS || [];
|
|
4121
|
+
var wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
|
|
4122
|
+
var seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !opt.keySeparator && !this.options.userDefinedNsSeparator && !opt.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
4123
|
+
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
4124
|
+
var m = key.match(this.interpolator.nestingRegexp);
|
|
4125
|
+
if (m && m.length > 0) {
|
|
4126
|
+
return {
|
|
4127
|
+
key,
|
|
4128
|
+
namespaces: isString$1(namespaces) ? [namespaces] : namespaces
|
|
4129
|
+
};
|
|
4130
|
+
}
|
|
4131
|
+
var parts = key.split(nsSeparator);
|
|
4132
|
+
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
|
|
4133
|
+
key = parts.join(keySeparator);
|
|
4134
|
+
}
|
|
4135
|
+
return {
|
|
4136
|
+
key,
|
|
4137
|
+
namespaces: isString$1(namespaces) ? [namespaces] : namespaces
|
|
4138
|
+
};
|
|
4139
|
+
}
|
|
4140
|
+
translate(keys, o, lastKey) {
|
|
4141
|
+
var opt = typeof o === 'object' ? _objectSpread2({}, o) : o;
|
|
4142
|
+
if (typeof opt !== 'object' && this.options.overloadTranslationOptionHandler) {
|
|
4143
|
+
opt = this.options.overloadTranslationOptionHandler(arguments);
|
|
4144
|
+
}
|
|
4145
|
+
if (typeof opt === 'object') opt = _objectSpread2({}, opt);
|
|
4146
|
+
if (!opt) opt = {};
|
|
4147
|
+
if (keys == null) return '';
|
|
4148
|
+
if (typeof keys === 'function') keys = keysFromSelector(keys, _objectSpread2(_objectSpread2({}, this.options), opt));
|
|
4149
|
+
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
4150
|
+
var returnDetails = opt.returnDetails !== undefined ? opt.returnDetails : this.options.returnDetails;
|
|
4151
|
+
var keySeparator = opt.keySeparator !== undefined ? opt.keySeparator : this.options.keySeparator;
|
|
4152
|
+
var {
|
|
4153
|
+
key,
|
|
4154
|
+
namespaces
|
|
4155
|
+
} = this.extractFromKey(keys[keys.length - 1], opt);
|
|
4156
|
+
var namespace = namespaces[namespaces.length - 1];
|
|
4157
|
+
var nsSeparator = opt.nsSeparator !== undefined ? opt.nsSeparator : this.options.nsSeparator;
|
|
4158
|
+
if (nsSeparator === undefined) nsSeparator = ':';
|
|
4159
|
+
var lng = opt.lng || this.language;
|
|
4160
|
+
var appendNamespaceToCIMode = opt.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
4161
|
+
if ((lng === null || lng === void 0 ? void 0 : lng.toLowerCase()) === 'cimode') {
|
|
4162
|
+
if (appendNamespaceToCIMode) {
|
|
4163
|
+
if (returnDetails) {
|
|
4164
|
+
return {
|
|
4165
|
+
res: "".concat(namespace).concat(nsSeparator).concat(key),
|
|
4166
|
+
usedKey: key,
|
|
4167
|
+
exactUsedKey: key,
|
|
4168
|
+
usedLng: lng,
|
|
4169
|
+
usedNS: namespace,
|
|
4170
|
+
usedParams: this.getUsedParamsDetails(opt)
|
|
4171
|
+
};
|
|
4172
|
+
}
|
|
4173
|
+
return "".concat(namespace).concat(nsSeparator).concat(key);
|
|
4174
|
+
}
|
|
4175
|
+
if (returnDetails) {
|
|
4176
|
+
return {
|
|
4177
|
+
res: key,
|
|
4178
|
+
usedKey: key,
|
|
4179
|
+
exactUsedKey: key,
|
|
4180
|
+
usedLng: lng,
|
|
4181
|
+
usedNS: namespace,
|
|
4182
|
+
usedParams: this.getUsedParamsDetails(opt)
|
|
4183
|
+
};
|
|
4184
|
+
}
|
|
4185
|
+
return key;
|
|
4186
|
+
}
|
|
4187
|
+
var resolved = this.resolve(keys, opt);
|
|
4188
|
+
var res = resolved === null || resolved === void 0 ? void 0 : resolved.res;
|
|
4189
|
+
var resUsedKey = (resolved === null || resolved === void 0 ? void 0 : resolved.usedKey) || key;
|
|
4190
|
+
var resExactUsedKey = (resolved === null || resolved === void 0 ? void 0 : resolved.exactUsedKey) || key;
|
|
4191
|
+
var noObject = ['[object Number]', '[object Function]', '[object RegExp]'];
|
|
4192
|
+
var joinArrays = opt.joinArrays !== undefined ? opt.joinArrays : this.options.joinArrays;
|
|
4193
|
+
var handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
4194
|
+
var needsPluralHandling = opt.count !== undefined && !isString$1(opt.count);
|
|
4195
|
+
var hasDefaultValue = Translator.hasDefaultValue(opt);
|
|
4196
|
+
var defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, opt) : '';
|
|
4197
|
+
var defaultValueSuffixOrdinalFallback = opt.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, {
|
|
4198
|
+
ordinal: false
|
|
4199
|
+
}) : '';
|
|
4200
|
+
var needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
|
|
4201
|
+
var defaultValue = needsZeroSuffixLookup && opt["defaultValue".concat(this.options.pluralSeparator, "zero")] || opt["defaultValue".concat(defaultValueSuffix)] || opt["defaultValue".concat(defaultValueSuffixOrdinalFallback)] || opt.defaultValue;
|
|
4202
|
+
var resForObjHndl = res;
|
|
4203
|
+
if (handleAsObjectInI18nFormat && !res && hasDefaultValue) {
|
|
4204
|
+
resForObjHndl = defaultValue;
|
|
4205
|
+
}
|
|
4206
|
+
var handleAsObject = shouldHandleAsObject(resForObjHndl);
|
|
4207
|
+
var resType = Object.prototype.toString.apply(resForObjHndl);
|
|
4208
|
+
if (handleAsObjectInI18nFormat && resForObjHndl && handleAsObject && noObject.indexOf(resType) < 0 && !(isString$1(joinArrays) && Array.isArray(resForObjHndl))) {
|
|
4209
|
+
if (!opt.returnObjects && !this.options.returnObjects) {
|
|
4210
|
+
if (!this.options.returnedObjectHandler) {
|
|
4211
|
+
this.logger.warn('accessing an object - but returnObjects options is not enabled!');
|
|
4212
|
+
}
|
|
4213
|
+
var r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, resForObjHndl, _objectSpread2(_objectSpread2({}, opt), {}, {
|
|
4214
|
+
ns: namespaces
|
|
4215
|
+
})) : "key '".concat(key, " (").concat(this.language, ")' returned an object instead of string.");
|
|
4216
|
+
if (returnDetails) {
|
|
4217
|
+
resolved.res = r;
|
|
4218
|
+
resolved.usedParams = this.getUsedParamsDetails(opt);
|
|
4219
|
+
return resolved;
|
|
4220
|
+
}
|
|
4221
|
+
return r;
|
|
4222
|
+
}
|
|
4223
|
+
if (keySeparator) {
|
|
4224
|
+
var resTypeIsArray = Array.isArray(resForObjHndl);
|
|
4225
|
+
var _copy = resTypeIsArray ? [] : {};
|
|
4226
|
+
var newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
4227
|
+
for (var m in resForObjHndl) {
|
|
4228
|
+
if (Object.prototype.hasOwnProperty.call(resForObjHndl, m)) {
|
|
4229
|
+
var deepKey = "".concat(newKeyToUse).concat(keySeparator).concat(m);
|
|
4230
|
+
if (hasDefaultValue && !res) {
|
|
4231
|
+
_copy[m] = this.translate(deepKey, _objectSpread2(_objectSpread2({}, opt), {}, {
|
|
4232
|
+
defaultValue: shouldHandleAsObject(defaultValue) ? defaultValue[m] : undefined
|
|
4233
|
+
}, {
|
|
4234
|
+
joinArrays: false,
|
|
4235
|
+
ns: namespaces
|
|
4236
|
+
}));
|
|
4237
|
+
} else {
|
|
4238
|
+
_copy[m] = this.translate(deepKey, _objectSpread2(_objectSpread2({}, opt), {
|
|
4239
|
+
joinArrays: false,
|
|
4240
|
+
ns: namespaces
|
|
4241
|
+
}));
|
|
4242
|
+
}
|
|
4243
|
+
if (_copy[m] === deepKey) _copy[m] = resForObjHndl[m];
|
|
4244
|
+
}
|
|
4245
|
+
}
|
|
4246
|
+
res = _copy;
|
|
4247
|
+
}
|
|
4248
|
+
} else if (handleAsObjectInI18nFormat && isString$1(joinArrays) && Array.isArray(res)) {
|
|
4249
|
+
res = res.join(joinArrays);
|
|
4250
|
+
if (res) res = this.extendTranslation(res, keys, opt, lastKey);
|
|
4251
|
+
} else {
|
|
4252
|
+
var usedDefault = false;
|
|
4253
|
+
var usedKey = false;
|
|
4254
|
+
if (!this.isValidLookup(res) && hasDefaultValue) {
|
|
4255
|
+
usedDefault = true;
|
|
4256
|
+
res = defaultValue;
|
|
4257
|
+
}
|
|
4258
|
+
if (!this.isValidLookup(res)) {
|
|
4259
|
+
usedKey = true;
|
|
4260
|
+
res = key;
|
|
4261
|
+
}
|
|
4262
|
+
var missingKeyNoValueFallbackToKey = opt.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
|
|
4263
|
+
var resForMissing = missingKeyNoValueFallbackToKey && usedKey ? undefined : res;
|
|
4264
|
+
var updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
4265
|
+
if (usedKey || usedDefault || updateMissing) {
|
|
4266
|
+
this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? defaultValue : res);
|
|
4267
|
+
if (keySeparator) {
|
|
4268
|
+
var fk = this.resolve(key, _objectSpread2(_objectSpread2({}, opt), {}, {
|
|
4269
|
+
keySeparator: false
|
|
4270
|
+
}));
|
|
4271
|
+
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.');
|
|
4272
|
+
}
|
|
4273
|
+
var lngs = [];
|
|
4274
|
+
var fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, opt.lng || this.language);
|
|
4275
|
+
if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) {
|
|
4276
|
+
for (var i = 0; i < fallbackLngs.length; i++) {
|
|
4277
|
+
lngs.push(fallbackLngs[i]);
|
|
4278
|
+
}
|
|
4279
|
+
} else if (this.options.saveMissingTo === 'all') {
|
|
4280
|
+
lngs = this.languageUtils.toResolveHierarchy(opt.lng || this.language);
|
|
4281
|
+
} else {
|
|
4282
|
+
lngs.push(opt.lng || this.language);
|
|
4283
|
+
}
|
|
4284
|
+
var send = (l, k, specificDefaultValue) => {
|
|
4285
|
+
var _this$backendConnecto;
|
|
4286
|
+
var defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
4287
|
+
if (this.options.missingKeyHandler) {
|
|
4288
|
+
this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, opt);
|
|
4289
|
+
} else if ((_this$backendConnecto = this.backendConnector) !== null && _this$backendConnecto !== void 0 && _this$backendConnecto.saveMissing) {
|
|
4290
|
+
this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, opt);
|
|
4291
|
+
}
|
|
4292
|
+
this.emit('missingKey', l, namespace, k, res);
|
|
4293
|
+
};
|
|
4294
|
+
if (this.options.saveMissing) {
|
|
4295
|
+
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
4296
|
+
lngs.forEach(language => {
|
|
4297
|
+
var suffixes = this.pluralResolver.getSuffixes(language, opt);
|
|
4298
|
+
if (needsZeroSuffixLookup && opt["defaultValue".concat(this.options.pluralSeparator, "zero")] && suffixes.indexOf("".concat(this.options.pluralSeparator, "zero")) < 0) {
|
|
4299
|
+
suffixes.push("".concat(this.options.pluralSeparator, "zero"));
|
|
4300
|
+
}
|
|
4301
|
+
suffixes.forEach(suffix => {
|
|
4302
|
+
send([language], key + suffix, opt["defaultValue".concat(suffix)] || defaultValue);
|
|
4303
|
+
});
|
|
4304
|
+
});
|
|
4305
|
+
} else {
|
|
4306
|
+
send(lngs, key, defaultValue);
|
|
4307
|
+
}
|
|
4308
|
+
}
|
|
4309
|
+
}
|
|
4310
|
+
res = this.extendTranslation(res, keys, opt, resolved, lastKey);
|
|
4311
|
+
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) {
|
|
4312
|
+
res = "".concat(namespace).concat(nsSeparator).concat(key);
|
|
4313
|
+
}
|
|
4314
|
+
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
|
|
4315
|
+
res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? "".concat(namespace).concat(nsSeparator).concat(key) : key, usedDefault ? res : undefined, opt);
|
|
4316
|
+
}
|
|
4317
|
+
}
|
|
4318
|
+
if (returnDetails) {
|
|
4319
|
+
resolved.res = res;
|
|
4320
|
+
resolved.usedParams = this.getUsedParamsDetails(opt);
|
|
4321
|
+
return resolved;
|
|
4322
|
+
}
|
|
4323
|
+
return res;
|
|
4324
|
+
}
|
|
4325
|
+
extendTranslation(res, key, opt, resolved, lastKey) {
|
|
4326
|
+
var _this$i18nFormat,
|
|
4327
|
+
_this = this;
|
|
4328
|
+
if ((_this$i18nFormat = this.i18nFormat) !== null && _this$i18nFormat !== void 0 && _this$i18nFormat.parse) {
|
|
4329
|
+
res = this.i18nFormat.parse(res, _objectSpread2(_objectSpread2({}, this.options.interpolation.defaultVariables), opt), opt.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
|
|
4330
|
+
resolved
|
|
4331
|
+
});
|
|
4332
|
+
} else if (!opt.skipInterpolation) {
|
|
4333
|
+
var _opt$interpolation;
|
|
4334
|
+
if (opt.interpolation) this.interpolator.init(_objectSpread2(_objectSpread2({}, opt), {
|
|
4335
|
+
interpolation: _objectSpread2(_objectSpread2({}, this.options.interpolation), opt.interpolation)
|
|
4336
|
+
}));
|
|
4337
|
+
var skipOnVariables = isString$1(res) && ((opt === null || opt === void 0 || (_opt$interpolation = opt.interpolation) === null || _opt$interpolation === void 0 ? void 0 : _opt$interpolation.skipOnVariables) !== undefined ? opt.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
4338
|
+
var nestBef;
|
|
4339
|
+
if (skipOnVariables) {
|
|
4340
|
+
var nb = res.match(this.interpolator.nestingRegexp);
|
|
4341
|
+
nestBef = nb && nb.length;
|
|
4342
|
+
}
|
|
4343
|
+
var data = opt.replace && !isString$1(opt.replace) ? opt.replace : opt;
|
|
4344
|
+
if (this.options.interpolation.defaultVariables) data = _objectSpread2(_objectSpread2({}, this.options.interpolation.defaultVariables), data);
|
|
4345
|
+
res = this.interpolator.interpolate(res, data, opt.lng || this.language || resolved.usedLng, opt);
|
|
4346
|
+
if (skipOnVariables) {
|
|
4347
|
+
var na = res.match(this.interpolator.nestingRegexp);
|
|
4348
|
+
var nestAft = na && na.length;
|
|
4349
|
+
if (nestBef < nestAft) opt.nest = false;
|
|
4350
|
+
}
|
|
4351
|
+
if (!opt.lng && resolved && resolved.res) opt.lng = this.language || resolved.usedLng;
|
|
4352
|
+
if (opt.nest !== false) res = this.interpolator.nest(res, function () {
|
|
4353
|
+
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
4354
|
+
args[_key6] = arguments[_key6];
|
|
4355
|
+
}
|
|
4356
|
+
if ((lastKey === null || lastKey === void 0 ? void 0 : lastKey[0]) === args[0] && !opt.context) {
|
|
4357
|
+
_this.logger.warn("It seems you are nesting recursively key: ".concat(args[0], " in key: ").concat(key[0]));
|
|
4358
|
+
return null;
|
|
4359
|
+
}
|
|
4360
|
+
return _this.translate(...args, key);
|
|
4361
|
+
}, opt);
|
|
4362
|
+
if (opt.interpolation) this.interpolator.reset();
|
|
4363
|
+
}
|
|
4364
|
+
var postProcess = opt.postProcess || this.options.postProcess;
|
|
4365
|
+
var postProcessorNames = isString$1(postProcess) ? [postProcess] : postProcess;
|
|
4366
|
+
if (res != null && postProcessorNames !== null && postProcessorNames !== void 0 && postProcessorNames.length && opt.applyPostProcessor !== false) {
|
|
4367
|
+
res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? _objectSpread2({
|
|
4368
|
+
i18nResolved: _objectSpread2(_objectSpread2({}, resolved), {}, {
|
|
4369
|
+
usedParams: this.getUsedParamsDetails(opt)
|
|
4370
|
+
})
|
|
4371
|
+
}, opt) : opt, this);
|
|
4372
|
+
}
|
|
4373
|
+
return res;
|
|
4374
|
+
}
|
|
4375
|
+
resolve(keys) {
|
|
4376
|
+
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
4377
|
+
var found;
|
|
4378
|
+
var usedKey;
|
|
4379
|
+
var exactUsedKey;
|
|
4380
|
+
var usedLng;
|
|
4381
|
+
var usedNS;
|
|
4382
|
+
if (isString$1(keys)) keys = [keys];
|
|
4383
|
+
keys.forEach(k => {
|
|
4384
|
+
if (this.isValidLookup(found)) return;
|
|
4385
|
+
var extracted = this.extractFromKey(k, opt);
|
|
4386
|
+
var key = extracted.key;
|
|
4387
|
+
usedKey = key;
|
|
4388
|
+
var namespaces = extracted.namespaces;
|
|
4389
|
+
if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
|
|
4390
|
+
var needsPluralHandling = opt.count !== undefined && !isString$1(opt.count);
|
|
4391
|
+
var needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
|
|
4392
|
+
var needsContextHandling = opt.context !== undefined && (isString$1(opt.context) || typeof opt.context === 'number') && opt.context !== '';
|
|
4393
|
+
var codes = opt.lngs ? opt.lngs : this.languageUtils.toResolveHierarchy(opt.lng || this.language, opt.fallbackLng);
|
|
4394
|
+
namespaces.forEach(ns => {
|
|
4395
|
+
var _this$utils, _this$utils2;
|
|
4396
|
+
if (this.isValidLookup(found)) return;
|
|
4397
|
+
usedNS = ns;
|
|
4398
|
+
if (!checkedLoadedFor["".concat(codes[0], "-").concat(ns)] && (_this$utils = this.utils) !== null && _this$utils !== void 0 && _this$utils.hasLoadedNamespace && !((_this$utils2 = this.utils) !== null && _this$utils2 !== void 0 && _this$utils2.hasLoadedNamespace(usedNS))) {
|
|
4399
|
+
checkedLoadedFor["".concat(codes[0], "-").concat(ns)] = true;
|
|
4400
|
+
this.logger.warn("key \"".concat(usedKey, "\" for languages \"").concat(codes.join(', '), "\" won't get resolved as namespace \"").concat(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!!!');
|
|
4401
|
+
}
|
|
4402
|
+
codes.forEach(code => {
|
|
4403
|
+
var _this$i18nFormat2;
|
|
4404
|
+
if (this.isValidLookup(found)) return;
|
|
4405
|
+
usedLng = code;
|
|
4406
|
+
var finalKeys = [key];
|
|
4407
|
+
if ((_this$i18nFormat2 = this.i18nFormat) !== null && _this$i18nFormat2 !== void 0 && _this$i18nFormat2.addLookupKeys) {
|
|
4408
|
+
this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, opt);
|
|
4409
|
+
} else {
|
|
4410
|
+
var pluralSuffix;
|
|
4411
|
+
if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, opt.count, opt);
|
|
4412
|
+
var zeroSuffix = "".concat(this.options.pluralSeparator, "zero");
|
|
4413
|
+
var ordinalPrefix = "".concat(this.options.pluralSeparator, "ordinal").concat(this.options.pluralSeparator);
|
|
4414
|
+
if (needsPluralHandling) {
|
|
4415
|
+
if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
4416
|
+
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
4417
|
+
}
|
|
4418
|
+
finalKeys.push(key + pluralSuffix);
|
|
4419
|
+
if (needsZeroSuffixLookup) {
|
|
4420
|
+
finalKeys.push(key + zeroSuffix);
|
|
4421
|
+
}
|
|
4422
|
+
}
|
|
4423
|
+
if (needsContextHandling) {
|
|
4424
|
+
var contextKey = "".concat(key).concat(this.options.contextSeparator || '_').concat(opt.context);
|
|
4425
|
+
finalKeys.push(contextKey);
|
|
4426
|
+
if (needsPluralHandling) {
|
|
4427
|
+
if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
4428
|
+
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
4429
|
+
}
|
|
4430
|
+
finalKeys.push(contextKey + pluralSuffix);
|
|
4431
|
+
if (needsZeroSuffixLookup) {
|
|
4432
|
+
finalKeys.push(contextKey + zeroSuffix);
|
|
4433
|
+
}
|
|
4434
|
+
}
|
|
4435
|
+
}
|
|
4436
|
+
}
|
|
4437
|
+
var possibleKey;
|
|
4438
|
+
while (possibleKey = finalKeys.pop()) {
|
|
4439
|
+
if (!this.isValidLookup(found)) {
|
|
4440
|
+
exactUsedKey = possibleKey;
|
|
4441
|
+
found = this.getResource(code, ns, possibleKey, opt);
|
|
4442
|
+
}
|
|
4443
|
+
}
|
|
4444
|
+
});
|
|
4445
|
+
});
|
|
4446
|
+
});
|
|
4447
|
+
return {
|
|
4448
|
+
res: found,
|
|
4449
|
+
usedKey,
|
|
4450
|
+
exactUsedKey,
|
|
4451
|
+
usedLng,
|
|
4452
|
+
usedNS
|
|
4453
|
+
};
|
|
4454
|
+
}
|
|
4455
|
+
isValidLookup(res) {
|
|
4456
|
+
return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === '');
|
|
4457
|
+
}
|
|
4458
|
+
getResource(code, ns, key) {
|
|
4459
|
+
var _this$i18nFormat3;
|
|
4460
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
4461
|
+
if ((_this$i18nFormat3 = this.i18nFormat) !== null && _this$i18nFormat3 !== void 0 && _this$i18nFormat3.getResource) return this.i18nFormat.getResource(code, ns, key, options);
|
|
4462
|
+
return this.resourceStore.getResource(code, ns, key, options);
|
|
4463
|
+
}
|
|
4464
|
+
getUsedParamsDetails() {
|
|
4465
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
4466
|
+
var optionsKeys = ['defaultValue', 'ordinal', 'context', 'replace', 'lng', 'lngs', 'fallbackLng', 'ns', 'keySeparator', 'nsSeparator', 'returnObjects', 'returnDetails', 'joinArrays', 'postProcess', 'interpolation'];
|
|
4467
|
+
var useOptionsReplaceForData = options.replace && !isString$1(options.replace);
|
|
4468
|
+
var data = useOptionsReplaceForData ? options.replace : options;
|
|
4469
|
+
if (useOptionsReplaceForData && typeof options.count !== 'undefined') {
|
|
4470
|
+
data.count = options.count;
|
|
4471
|
+
}
|
|
4472
|
+
if (this.options.interpolation.defaultVariables) {
|
|
4473
|
+
data = _objectSpread2(_objectSpread2({}, this.options.interpolation.defaultVariables), data);
|
|
4474
|
+
}
|
|
4475
|
+
if (!useOptionsReplaceForData) {
|
|
4476
|
+
data = _objectSpread2({}, data);
|
|
4477
|
+
for (var key of optionsKeys) {
|
|
4478
|
+
delete data[key];
|
|
4479
|
+
}
|
|
4480
|
+
}
|
|
4481
|
+
return data;
|
|
4482
|
+
}
|
|
4483
|
+
static hasDefaultValue(options) {
|
|
4484
|
+
var prefix = 'defaultValue';
|
|
4485
|
+
for (var option in options) {
|
|
4486
|
+
if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && undefined !== options[option]) {
|
|
4487
|
+
return true;
|
|
4488
|
+
}
|
|
4489
|
+
}
|
|
4490
|
+
return false;
|
|
4491
|
+
}
|
|
4492
|
+
}
|
|
4493
|
+
class LanguageUtil {
|
|
4494
|
+
constructor(options) {
|
|
4495
|
+
this.options = options;
|
|
4496
|
+
this.supportedLngs = this.options.supportedLngs || false;
|
|
4497
|
+
this.logger = baseLogger.create('languageUtils');
|
|
4498
|
+
}
|
|
4499
|
+
getScriptPartFromCode(code) {
|
|
4500
|
+
code = getCleanedCode(code);
|
|
4501
|
+
if (!code || code.indexOf('-') < 0) return null;
|
|
4502
|
+
var p = code.split('-');
|
|
4503
|
+
if (p.length === 2) return null;
|
|
4504
|
+
p.pop();
|
|
4505
|
+
if (p[p.length - 1].toLowerCase() === 'x') return null;
|
|
4506
|
+
return this.formatLanguageCode(p.join('-'));
|
|
4507
|
+
}
|
|
4508
|
+
getLanguagePartFromCode(code) {
|
|
4509
|
+
code = getCleanedCode(code);
|
|
4510
|
+
if (!code || code.indexOf('-') < 0) return code;
|
|
4511
|
+
var p = code.split('-');
|
|
4512
|
+
return this.formatLanguageCode(p[0]);
|
|
4513
|
+
}
|
|
4514
|
+
formatLanguageCode(code) {
|
|
4515
|
+
if (isString$1(code) && code.indexOf('-') > -1) {
|
|
4516
|
+
var formattedCode;
|
|
4517
|
+
try {
|
|
4518
|
+
formattedCode = Intl.getCanonicalLocales(code)[0];
|
|
4519
|
+
} catch (e) {}
|
|
4520
|
+
if (formattedCode && this.options.lowerCaseLng) {
|
|
4521
|
+
formattedCode = formattedCode.toLowerCase();
|
|
4522
|
+
}
|
|
4523
|
+
if (formattedCode) return formattedCode;
|
|
4524
|
+
if (this.options.lowerCaseLng) {
|
|
4525
|
+
return code.toLowerCase();
|
|
4526
|
+
}
|
|
4527
|
+
return code;
|
|
4528
|
+
}
|
|
4529
|
+
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
|
|
4530
|
+
}
|
|
4531
|
+
isSupportedCode(code) {
|
|
4532
|
+
if (this.options.load === 'languageOnly' || this.options.nonExplicitSupportedLngs) {
|
|
4533
|
+
code = this.getLanguagePartFromCode(code);
|
|
4534
|
+
}
|
|
4535
|
+
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
|
|
4536
|
+
}
|
|
4537
|
+
getBestMatchFromCodes(codes) {
|
|
4538
|
+
if (!codes) return null;
|
|
4539
|
+
var found;
|
|
4540
|
+
codes.forEach(code => {
|
|
4541
|
+
if (found) return;
|
|
4542
|
+
var cleanedLng = this.formatLanguageCode(code);
|
|
4543
|
+
if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
|
|
4544
|
+
});
|
|
4545
|
+
if (!found && this.options.supportedLngs) {
|
|
4546
|
+
codes.forEach(code => {
|
|
4547
|
+
if (found) return;
|
|
4548
|
+
var lngScOnly = this.getScriptPartFromCode(code);
|
|
4549
|
+
if (this.isSupportedCode(lngScOnly)) return found = lngScOnly;
|
|
4550
|
+
var lngOnly = this.getLanguagePartFromCode(code);
|
|
4551
|
+
if (this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
4552
|
+
found = this.options.supportedLngs.find(supportedLng => {
|
|
4553
|
+
if (supportedLng === lngOnly) return supportedLng;
|
|
4554
|
+
if (supportedLng.indexOf('-') < 0 && lngOnly.indexOf('-') < 0) return;
|
|
4555
|
+
if (supportedLng.indexOf('-') > 0 && lngOnly.indexOf('-') < 0 && supportedLng.substring(0, supportedLng.indexOf('-')) === lngOnly) return supportedLng;
|
|
4556
|
+
if (supportedLng.indexOf(lngOnly) === 0 && lngOnly.length > 1) return supportedLng;
|
|
4557
|
+
});
|
|
4558
|
+
});
|
|
4559
|
+
}
|
|
4560
|
+
if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
|
|
4561
|
+
return found;
|
|
4562
|
+
}
|
|
4563
|
+
getFallbackCodes(fallbacks, code) {
|
|
4564
|
+
if (!fallbacks) return [];
|
|
4565
|
+
if (typeof fallbacks === 'function') fallbacks = fallbacks(code);
|
|
4566
|
+
if (isString$1(fallbacks)) fallbacks = [fallbacks];
|
|
4567
|
+
if (Array.isArray(fallbacks)) return fallbacks;
|
|
4568
|
+
if (!code) return fallbacks.default || [];
|
|
4569
|
+
var found = fallbacks[code];
|
|
4570
|
+
if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
|
|
4571
|
+
if (!found) found = fallbacks[this.formatLanguageCode(code)];
|
|
4572
|
+
if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
4573
|
+
if (!found) found = fallbacks.default;
|
|
4574
|
+
return found || [];
|
|
4575
|
+
}
|
|
4576
|
+
toResolveHierarchy(code, fallbackCode) {
|
|
4577
|
+
var fallbackCodes = this.getFallbackCodes((fallbackCode === false ? [] : fallbackCode) || this.options.fallbackLng || [], code);
|
|
4578
|
+
var codes = [];
|
|
4579
|
+
var addCode = c => {
|
|
4580
|
+
if (!c) return;
|
|
4581
|
+
if (this.isSupportedCode(c)) {
|
|
4582
|
+
codes.push(c);
|
|
4583
|
+
} else {
|
|
4584
|
+
this.logger.warn("rejecting language code not found in supportedLngs: ".concat(c));
|
|
4585
|
+
}
|
|
4586
|
+
};
|
|
4587
|
+
if (isString$1(code) && (code.indexOf('-') > -1 || code.indexOf('_') > -1)) {
|
|
4588
|
+
if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code));
|
|
4589
|
+
if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code));
|
|
4590
|
+
if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code));
|
|
4591
|
+
} else if (isString$1(code)) {
|
|
4592
|
+
addCode(this.formatLanguageCode(code));
|
|
4593
|
+
}
|
|
4594
|
+
fallbackCodes.forEach(fc => {
|
|
4595
|
+
if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
|
|
4596
|
+
});
|
|
4597
|
+
return codes;
|
|
4598
|
+
}
|
|
4599
|
+
}
|
|
4600
|
+
var suffixesOrder = {
|
|
4601
|
+
zero: 0,
|
|
4602
|
+
one: 1,
|
|
4603
|
+
two: 2,
|
|
4604
|
+
few: 3,
|
|
4605
|
+
many: 4,
|
|
4606
|
+
other: 5
|
|
4607
|
+
};
|
|
4608
|
+
var dummyRule = {
|
|
4609
|
+
select: count => count === 1 ? 'one' : 'other',
|
|
4610
|
+
resolvedOptions: () => ({
|
|
4611
|
+
pluralCategories: ['one', 'other']
|
|
4612
|
+
})
|
|
4613
|
+
};
|
|
4614
|
+
class PluralResolver {
|
|
4615
|
+
constructor(languageUtils) {
|
|
4616
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
4617
|
+
this.languageUtils = languageUtils;
|
|
4618
|
+
this.options = options;
|
|
4619
|
+
this.logger = baseLogger.create('pluralResolver');
|
|
4620
|
+
this.pluralRulesCache = {};
|
|
4621
|
+
}
|
|
4622
|
+
addRule(lng, obj) {
|
|
4623
|
+
this.rules[lng] = obj;
|
|
4624
|
+
}
|
|
4625
|
+
clearCache() {
|
|
4626
|
+
this.pluralRulesCache = {};
|
|
4627
|
+
}
|
|
4628
|
+
getRule(code) {
|
|
4629
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
4630
|
+
var cleanedCode = getCleanedCode(code === 'dev' ? 'en' : code);
|
|
4631
|
+
var type = options.ordinal ? 'ordinal' : 'cardinal';
|
|
4632
|
+
var cacheKey = JSON.stringify({
|
|
4633
|
+
cleanedCode,
|
|
4634
|
+
type
|
|
4635
|
+
});
|
|
4636
|
+
if (cacheKey in this.pluralRulesCache) {
|
|
4637
|
+
return this.pluralRulesCache[cacheKey];
|
|
4638
|
+
}
|
|
4639
|
+
var rule;
|
|
4640
|
+
try {
|
|
4641
|
+
rule = new Intl.PluralRules(cleanedCode, {
|
|
4642
|
+
type
|
|
4643
|
+
});
|
|
4644
|
+
} catch (err) {
|
|
4645
|
+
if (!Intl) {
|
|
4646
|
+
this.logger.error('No Intl support, please use an Intl polyfill!');
|
|
4647
|
+
return dummyRule;
|
|
4648
|
+
}
|
|
4649
|
+
if (!code.match(/-|_/)) return dummyRule;
|
|
4650
|
+
var lngPart = this.languageUtils.getLanguagePartFromCode(code);
|
|
4651
|
+
rule = this.getRule(lngPart, options);
|
|
4652
|
+
}
|
|
4653
|
+
this.pluralRulesCache[cacheKey] = rule;
|
|
4654
|
+
return rule;
|
|
4655
|
+
}
|
|
4656
|
+
needsPlural(code) {
|
|
4657
|
+
var _rule;
|
|
4658
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
4659
|
+
var rule = this.getRule(code, options);
|
|
4660
|
+
if (!rule) rule = this.getRule('dev', options);
|
|
4661
|
+
return ((_rule = rule) === null || _rule === void 0 ? void 0 : _rule.resolvedOptions().pluralCategories.length) > 1;
|
|
4662
|
+
}
|
|
4663
|
+
getPluralFormsOfKey(code, key) {
|
|
4664
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
4665
|
+
return this.getSuffixes(code, options).map(suffix => "".concat(key).concat(suffix));
|
|
4666
|
+
}
|
|
4667
|
+
getSuffixes(code) {
|
|
4668
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
4669
|
+
var rule = this.getRule(code, options);
|
|
4670
|
+
if (!rule) rule = this.getRule('dev', options);
|
|
4671
|
+
if (!rule) return [];
|
|
4672
|
+
return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map(pluralCategory => "".concat(this.options.prepend).concat(options.ordinal ? "ordinal".concat(this.options.prepend) : '').concat(pluralCategory));
|
|
4673
|
+
}
|
|
4674
|
+
getSuffix(code, count) {
|
|
4675
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
4676
|
+
var rule = this.getRule(code, options);
|
|
4677
|
+
if (rule) {
|
|
4678
|
+
return "".concat(this.options.prepend).concat(options.ordinal ? "ordinal".concat(this.options.prepend) : '').concat(rule.select(count));
|
|
4679
|
+
}
|
|
4680
|
+
this.logger.warn("no plural rule found for: ".concat(code));
|
|
4681
|
+
return this.getSuffix('dev', count, options);
|
|
4682
|
+
}
|
|
4683
|
+
}
|
|
4684
|
+
var deepFindWithDefaults = function deepFindWithDefaults(data, defaultData, key) {
|
|
4685
|
+
var keySeparator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '.';
|
|
4686
|
+
var ignoreJSONStructure = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
4687
|
+
var path = getPathWithDefaults(data, defaultData, key);
|
|
4688
|
+
if (!path && ignoreJSONStructure && isString$1(key)) {
|
|
4689
|
+
path = deepFind(data, key, keySeparator);
|
|
4690
|
+
if (path === undefined) path = deepFind(defaultData, key, keySeparator);
|
|
4691
|
+
}
|
|
4692
|
+
return path;
|
|
4693
|
+
};
|
|
4694
|
+
var regexSafe = val => val.replace(/\$/g, '$$$$');
|
|
4695
|
+
class Interpolator {
|
|
4696
|
+
constructor() {
|
|
4697
|
+
var _options$interpolatio;
|
|
4698
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
4699
|
+
this.logger = baseLogger.create('interpolator');
|
|
4700
|
+
this.options = options;
|
|
4701
|
+
this.format = (options === null || options === void 0 || (_options$interpolatio = options.interpolation) === null || _options$interpolatio === void 0 ? void 0 : _options$interpolatio.format) || (value => value);
|
|
4702
|
+
this.init(options);
|
|
4703
|
+
}
|
|
4704
|
+
init() {
|
|
4705
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
4706
|
+
if (!options.interpolation) options.interpolation = {
|
|
4707
|
+
escapeValue: true
|
|
4708
|
+
};
|
|
4709
|
+
var {
|
|
4710
|
+
escape: escape$1,
|
|
4711
|
+
escapeValue,
|
|
4712
|
+
useRawValueToEscape,
|
|
4713
|
+
prefix,
|
|
4714
|
+
prefixEscaped,
|
|
4715
|
+
suffix,
|
|
4716
|
+
suffixEscaped,
|
|
4717
|
+
formatSeparator,
|
|
4718
|
+
unescapeSuffix,
|
|
4719
|
+
unescapePrefix,
|
|
4720
|
+
nestingPrefix,
|
|
4721
|
+
nestingPrefixEscaped,
|
|
4722
|
+
nestingSuffix,
|
|
4723
|
+
nestingSuffixEscaped,
|
|
4724
|
+
nestingOptionsSeparator,
|
|
4725
|
+
maxReplaces,
|
|
4726
|
+
alwaysFormat
|
|
4727
|
+
} = options.interpolation;
|
|
4728
|
+
this.escape = escape$1 !== undefined ? escape$1 : escape;
|
|
4729
|
+
this.escapeValue = escapeValue !== undefined ? escapeValue : true;
|
|
4730
|
+
this.useRawValueToEscape = useRawValueToEscape !== undefined ? useRawValueToEscape : false;
|
|
4731
|
+
this.prefix = prefix ? regexEscape(prefix) : prefixEscaped || '{{';
|
|
4732
|
+
this.suffix = suffix ? regexEscape(suffix) : suffixEscaped || '}}';
|
|
4733
|
+
this.formatSeparator = formatSeparator || ',';
|
|
4734
|
+
this.unescapePrefix = unescapeSuffix ? '' : unescapePrefix || '-';
|
|
4735
|
+
this.unescapeSuffix = this.unescapePrefix ? '' : unescapeSuffix || '';
|
|
4736
|
+
this.nestingPrefix = nestingPrefix ? regexEscape(nestingPrefix) : nestingPrefixEscaped || regexEscape('$t(');
|
|
4737
|
+
this.nestingSuffix = nestingSuffix ? regexEscape(nestingSuffix) : nestingSuffixEscaped || regexEscape(')');
|
|
4738
|
+
this.nestingOptionsSeparator = nestingOptionsSeparator || ',';
|
|
4739
|
+
this.maxReplaces = maxReplaces || 1000;
|
|
4740
|
+
this.alwaysFormat = alwaysFormat !== undefined ? alwaysFormat : false;
|
|
4741
|
+
this.resetRegExp();
|
|
4742
|
+
}
|
|
4743
|
+
reset() {
|
|
4744
|
+
if (this.options) this.init(this.options);
|
|
4745
|
+
}
|
|
4746
|
+
resetRegExp() {
|
|
4747
|
+
var getOrResetRegExp = (existingRegExp, pattern) => {
|
|
4748
|
+
if ((existingRegExp === null || existingRegExp === void 0 ? void 0 : existingRegExp.source) === pattern) {
|
|
4749
|
+
existingRegExp.lastIndex = 0;
|
|
4750
|
+
return existingRegExp;
|
|
4751
|
+
}
|
|
4752
|
+
return new RegExp(pattern, 'g');
|
|
4753
|
+
};
|
|
4754
|
+
this.regexp = getOrResetRegExp(this.regexp, "".concat(this.prefix, "(.+?)").concat(this.suffix));
|
|
4755
|
+
this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, "".concat(this.prefix).concat(this.unescapePrefix, "(.+?)").concat(this.unescapeSuffix).concat(this.suffix));
|
|
4756
|
+
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, "".concat(this.nestingPrefix, "((?:[^()\"']+|\"[^\"]*\"|'[^']*'|\\((?:[^()]|\"[^\"]*\"|'[^']*')*\\))*?)").concat(this.nestingSuffix));
|
|
4757
|
+
}
|
|
4758
|
+
interpolate(str, data, lng, options) {
|
|
4759
|
+
var _options$interpolatio2;
|
|
4760
|
+
var match;
|
|
4761
|
+
var value;
|
|
4762
|
+
var replaces;
|
|
4763
|
+
var defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
4764
|
+
var handleFormat = key => {
|
|
4765
|
+
if (key.indexOf(this.formatSeparator) < 0) {
|
|
4766
|
+
var path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
|
|
4767
|
+
return this.alwaysFormat ? this.format(path, undefined, lng, _objectSpread2(_objectSpread2(_objectSpread2({}, options), data), {}, {
|
|
4768
|
+
interpolationkey: key
|
|
4769
|
+
})) : path;
|
|
4770
|
+
}
|
|
4771
|
+
var p = key.split(this.formatSeparator);
|
|
4772
|
+
var k = p.shift().trim();
|
|
4773
|
+
var f = p.join(this.formatSeparator).trim();
|
|
4774
|
+
return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, _objectSpread2(_objectSpread2(_objectSpread2({}, options), data), {}, {
|
|
4775
|
+
interpolationkey: k
|
|
4776
|
+
}));
|
|
4777
|
+
};
|
|
4778
|
+
this.resetRegExp();
|
|
4779
|
+
var missingInterpolationHandler = (options === null || options === void 0 ? void 0 : options.missingInterpolationHandler) || this.options.missingInterpolationHandler;
|
|
4780
|
+
var skipOnVariables = (options === null || options === void 0 || (_options$interpolatio2 = options.interpolation) === null || _options$interpolatio2 === void 0 ? void 0 : _options$interpolatio2.skipOnVariables) !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
|
|
4781
|
+
var todos = [{
|
|
4782
|
+
regex: this.regexpUnescape,
|
|
4783
|
+
safeValue: val => regexSafe(val)
|
|
4784
|
+
}, {
|
|
4785
|
+
regex: this.regexp,
|
|
4786
|
+
safeValue: val => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
|
|
4787
|
+
}];
|
|
4788
|
+
todos.forEach(todo => {
|
|
4789
|
+
replaces = 0;
|
|
4790
|
+
while (match = todo.regex.exec(str)) {
|
|
4791
|
+
var matchedVar = match[1].trim();
|
|
4792
|
+
value = handleFormat(matchedVar);
|
|
4793
|
+
if (value === undefined) {
|
|
4794
|
+
if (typeof missingInterpolationHandler === 'function') {
|
|
4795
|
+
var temp = missingInterpolationHandler(str, match, options);
|
|
4796
|
+
value = isString$1(temp) ? temp : '';
|
|
4797
|
+
} else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
|
|
4798
|
+
value = '';
|
|
4799
|
+
} else if (skipOnVariables) {
|
|
4800
|
+
value = match[0];
|
|
4801
|
+
continue;
|
|
4802
|
+
} else {
|
|
4803
|
+
this.logger.warn("missed to pass in variable ".concat(matchedVar, " for interpolating ").concat(str));
|
|
4804
|
+
value = '';
|
|
4805
|
+
}
|
|
4806
|
+
} else if (!isString$1(value) && !this.useRawValueToEscape) {
|
|
4807
|
+
value = makeString(value);
|
|
4808
|
+
}
|
|
4809
|
+
var safeValue = todo.safeValue(value);
|
|
4810
|
+
str = str.replace(match[0], safeValue);
|
|
4811
|
+
if (skipOnVariables) {
|
|
4812
|
+
todo.regex.lastIndex += value.length;
|
|
4813
|
+
todo.regex.lastIndex -= match[0].length;
|
|
4814
|
+
} else {
|
|
4815
|
+
todo.regex.lastIndex = 0;
|
|
4816
|
+
}
|
|
4817
|
+
replaces++;
|
|
4818
|
+
if (replaces >= this.maxReplaces) {
|
|
4819
|
+
break;
|
|
4820
|
+
}
|
|
4821
|
+
}
|
|
4822
|
+
});
|
|
4823
|
+
return str;
|
|
4824
|
+
}
|
|
4825
|
+
nest(str, fc) {
|
|
4826
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
4827
|
+
var match;
|
|
4828
|
+
var value;
|
|
4829
|
+
var clonedOptions;
|
|
4830
|
+
var handleHasOptions = (key, inheritedOptions) => {
|
|
4831
|
+
var _matchedSingleQuotes$;
|
|
4832
|
+
var sep = this.nestingOptionsSeparator;
|
|
4833
|
+
if (key.indexOf(sep) < 0) return key;
|
|
4834
|
+
var c = key.split(new RegExp("".concat(sep, "[ ]*{")));
|
|
4835
|
+
var optionsString = "{".concat(c[1]);
|
|
4836
|
+
key = c[0];
|
|
4837
|
+
optionsString = this.interpolate(optionsString, clonedOptions);
|
|
4838
|
+
var matchedSingleQuotes = optionsString.match(/'/g);
|
|
4839
|
+
var matchedDoubleQuotes = optionsString.match(/"/g);
|
|
4840
|
+
if (((_matchedSingleQuotes$ = matchedSingleQuotes === null || matchedSingleQuotes === void 0 ? void 0 : matchedSingleQuotes.length) !== null && _matchedSingleQuotes$ !== void 0 ? _matchedSingleQuotes$ : 0) % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
|
|
4841
|
+
optionsString = optionsString.replace(/'/g, '"');
|
|
4842
|
+
}
|
|
4843
|
+
try {
|
|
4844
|
+
clonedOptions = JSON.parse(optionsString);
|
|
4845
|
+
if (inheritedOptions) clonedOptions = _objectSpread2(_objectSpread2({}, inheritedOptions), clonedOptions);
|
|
4846
|
+
} catch (e) {
|
|
4847
|
+
this.logger.warn("failed parsing options string in nesting for key ".concat(key), e);
|
|
4848
|
+
return "".concat(key).concat(sep).concat(optionsString);
|
|
4849
|
+
}
|
|
4850
|
+
if (clonedOptions.defaultValue && clonedOptions.defaultValue.indexOf(this.prefix) > -1) delete clonedOptions.defaultValue;
|
|
4851
|
+
return key;
|
|
4852
|
+
};
|
|
4853
|
+
while (match = this.nestingRegexp.exec(str)) {
|
|
4854
|
+
var formatters = [];
|
|
4855
|
+
clonedOptions = _objectSpread2({}, options);
|
|
4856
|
+
clonedOptions = clonedOptions.replace && !isString$1(clonedOptions.replace) ? clonedOptions.replace : clonedOptions;
|
|
4857
|
+
clonedOptions.applyPostProcessor = false;
|
|
4858
|
+
delete clonedOptions.defaultValue;
|
|
4859
|
+
var keyEndIndex = /{.*}/.test(match[1]) ? match[1].lastIndexOf('}') + 1 : match[1].indexOf(this.formatSeparator);
|
|
4860
|
+
if (keyEndIndex !== -1) {
|
|
4861
|
+
formatters = match[1].slice(keyEndIndex).split(this.formatSeparator).map(elem => elem.trim()).filter(Boolean);
|
|
4862
|
+
match[1] = match[1].slice(0, keyEndIndex);
|
|
4863
|
+
}
|
|
4864
|
+
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
4865
|
+
if (value && match[0] === str && !isString$1(value)) return value;
|
|
4866
|
+
if (!isString$1(value)) value = makeString(value);
|
|
4867
|
+
if (!value) {
|
|
4868
|
+
this.logger.warn("missed to resolve ".concat(match[1], " for nesting ").concat(str));
|
|
4869
|
+
value = '';
|
|
4870
|
+
}
|
|
4871
|
+
if (formatters.length) {
|
|
4872
|
+
value = formatters.reduce((v, f) => this.format(v, f, options.lng, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
4873
|
+
interpolationkey: match[1].trim()
|
|
4874
|
+
})), value.trim());
|
|
4875
|
+
}
|
|
4876
|
+
str = str.replace(match[0], value);
|
|
4877
|
+
this.regexp.lastIndex = 0;
|
|
4878
|
+
}
|
|
4879
|
+
return str;
|
|
4880
|
+
}
|
|
4881
|
+
}
|
|
4882
|
+
var parseFormatStr = formatStr => {
|
|
4883
|
+
var formatName = formatStr.toLowerCase().trim();
|
|
4884
|
+
var formatOptions = {};
|
|
4885
|
+
if (formatStr.indexOf('(') > -1) {
|
|
4886
|
+
var p = formatStr.split('(');
|
|
4887
|
+
formatName = p[0].toLowerCase().trim();
|
|
4888
|
+
var optStr = p[1].substring(0, p[1].length - 1);
|
|
4889
|
+
if (formatName === 'currency' && optStr.indexOf(':') < 0) {
|
|
4890
|
+
if (!formatOptions.currency) formatOptions.currency = optStr.trim();
|
|
4891
|
+
} else if (formatName === 'relativetime' && optStr.indexOf(':') < 0) {
|
|
4892
|
+
if (!formatOptions.range) formatOptions.range = optStr.trim();
|
|
4893
|
+
} else {
|
|
4894
|
+
var opts = optStr.split(';');
|
|
4895
|
+
opts.forEach(opt => {
|
|
4896
|
+
if (opt) {
|
|
4897
|
+
var [key, ...rest] = opt.split(':');
|
|
4898
|
+
var val = rest.join(':').trim().replace(/^'+|'+$/g, '');
|
|
4899
|
+
var trimmedKey = key.trim();
|
|
4900
|
+
if (!formatOptions[trimmedKey]) formatOptions[trimmedKey] = val;
|
|
4901
|
+
if (val === 'false') formatOptions[trimmedKey] = false;
|
|
4902
|
+
if (val === 'true') formatOptions[trimmedKey] = true;
|
|
4903
|
+
if (!isNaN(val)) formatOptions[trimmedKey] = parseInt(val, 10);
|
|
4904
|
+
}
|
|
4905
|
+
});
|
|
4906
|
+
}
|
|
4907
|
+
}
|
|
4908
|
+
return {
|
|
4909
|
+
formatName,
|
|
4910
|
+
formatOptions
|
|
4911
|
+
};
|
|
4912
|
+
};
|
|
4913
|
+
var createCachedFormatter = fn => {
|
|
4914
|
+
var cache = {};
|
|
4915
|
+
return (v, l, o) => {
|
|
4916
|
+
var optForCache = o;
|
|
4917
|
+
if (o && o.interpolationkey && o.formatParams && o.formatParams[o.interpolationkey] && o[o.interpolationkey]) {
|
|
4918
|
+
optForCache = _objectSpread2(_objectSpread2({}, optForCache), {}, {
|
|
4919
|
+
[o.interpolationkey]: undefined
|
|
4920
|
+
});
|
|
4921
|
+
}
|
|
4922
|
+
var key = l + JSON.stringify(optForCache);
|
|
4923
|
+
var frm = cache[key];
|
|
4924
|
+
if (!frm) {
|
|
4925
|
+
frm = fn(getCleanedCode(l), o);
|
|
4926
|
+
cache[key] = frm;
|
|
4927
|
+
}
|
|
4928
|
+
return frm(v);
|
|
4929
|
+
};
|
|
4930
|
+
};
|
|
4931
|
+
var createNonCachedFormatter = fn => (v, l, o) => fn(getCleanedCode(l), o)(v);
|
|
4932
|
+
class Formatter {
|
|
4933
|
+
constructor() {
|
|
4934
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
4935
|
+
this.logger = baseLogger.create('formatter');
|
|
4936
|
+
this.options = options;
|
|
4937
|
+
this.init(options);
|
|
4938
|
+
}
|
|
4939
|
+
init(services) {
|
|
4940
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
4941
|
+
interpolation: {}
|
|
4942
|
+
};
|
|
4943
|
+
this.formatSeparator = options.interpolation.formatSeparator || ',';
|
|
4944
|
+
var cf = options.cacheInBuiltFormats ? createCachedFormatter : createNonCachedFormatter;
|
|
4945
|
+
this.formats = {
|
|
4946
|
+
number: cf((lng, opt) => {
|
|
4947
|
+
var formatter = new Intl.NumberFormat(lng, _objectSpread2({}, opt));
|
|
4948
|
+
return val => formatter.format(val);
|
|
4949
|
+
}),
|
|
4950
|
+
currency: cf((lng, opt) => {
|
|
4951
|
+
var formatter = new Intl.NumberFormat(lng, _objectSpread2(_objectSpread2({}, opt), {}, {
|
|
4952
|
+
style: 'currency'
|
|
4953
|
+
}));
|
|
4954
|
+
return val => formatter.format(val);
|
|
4955
|
+
}),
|
|
4956
|
+
datetime: cf((lng, opt) => {
|
|
4957
|
+
var formatter = new Intl.DateTimeFormat(lng, _objectSpread2({}, opt));
|
|
4958
|
+
return val => formatter.format(val);
|
|
4959
|
+
}),
|
|
4960
|
+
relativetime: cf((lng, opt) => {
|
|
4961
|
+
var formatter = new Intl.RelativeTimeFormat(lng, _objectSpread2({}, opt));
|
|
4962
|
+
return val => formatter.format(val, opt.range || 'day');
|
|
4963
|
+
}),
|
|
4964
|
+
list: cf((lng, opt) => {
|
|
4965
|
+
var formatter = new Intl.ListFormat(lng, _objectSpread2({}, opt));
|
|
4966
|
+
return val => formatter.format(val);
|
|
4967
|
+
})
|
|
4968
|
+
};
|
|
4969
|
+
}
|
|
4970
|
+
add(name, fc) {
|
|
4971
|
+
this.formats[name.toLowerCase().trim()] = fc;
|
|
4972
|
+
}
|
|
4973
|
+
addCached(name, fc) {
|
|
4974
|
+
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
4975
|
+
}
|
|
4976
|
+
format(value, format, lng) {
|
|
4977
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
4978
|
+
var formats = format.split(this.formatSeparator);
|
|
4979
|
+
if (formats.length > 1 && formats[0].indexOf('(') > 1 && formats[0].indexOf(')') < 0 && formats.find(f => f.indexOf(')') > -1)) {
|
|
4980
|
+
var lastIndex = formats.findIndex(f => f.indexOf(')') > -1);
|
|
4981
|
+
formats[0] = [formats[0], ...formats.splice(1, lastIndex)].join(this.formatSeparator);
|
|
4982
|
+
}
|
|
4983
|
+
var result = formats.reduce((mem, f) => {
|
|
4984
|
+
var {
|
|
4985
|
+
formatName,
|
|
4986
|
+
formatOptions
|
|
4987
|
+
} = parseFormatStr(f);
|
|
4988
|
+
if (this.formats[formatName]) {
|
|
4989
|
+
var formatted = mem;
|
|
4990
|
+
try {
|
|
4991
|
+
var _options$formatParams;
|
|
4992
|
+
var valOptions = (options === null || options === void 0 || (_options$formatParams = options.formatParams) === null || _options$formatParams === void 0 ? void 0 : _options$formatParams[options.interpolationkey]) || {};
|
|
4993
|
+
var l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
|
|
4994
|
+
formatted = this.formats[formatName](mem, l, _objectSpread2(_objectSpread2(_objectSpread2({}, formatOptions), options), valOptions));
|
|
4995
|
+
} catch (error) {
|
|
4996
|
+
this.logger.warn(error);
|
|
4997
|
+
}
|
|
4998
|
+
return formatted;
|
|
4999
|
+
} else {
|
|
5000
|
+
this.logger.warn("there was no format function for ".concat(formatName));
|
|
5001
|
+
}
|
|
5002
|
+
return mem;
|
|
5003
|
+
}, value);
|
|
5004
|
+
return result;
|
|
5005
|
+
}
|
|
5006
|
+
}
|
|
5007
|
+
var removePending = (q, name) => {
|
|
5008
|
+
if (q.pending[name] !== undefined) {
|
|
5009
|
+
delete q.pending[name];
|
|
5010
|
+
q.pendingCount--;
|
|
5011
|
+
}
|
|
5012
|
+
};
|
|
5013
|
+
class Connector extends EventEmitter {
|
|
5014
|
+
constructor(backend, store, services) {
|
|
5015
|
+
var _this$backend, _this$backend$init;
|
|
5016
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
5017
|
+
super();
|
|
5018
|
+
this.backend = backend;
|
|
5019
|
+
this.store = store;
|
|
5020
|
+
this.services = services;
|
|
5021
|
+
this.languageUtils = services.languageUtils;
|
|
5022
|
+
this.options = options;
|
|
5023
|
+
this.logger = baseLogger.create('backendConnector');
|
|
5024
|
+
this.waitingReads = [];
|
|
5025
|
+
this.maxParallelReads = options.maxParallelReads || 10;
|
|
5026
|
+
this.readingCalls = 0;
|
|
5027
|
+
this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
|
|
5028
|
+
this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
|
|
5029
|
+
this.state = {};
|
|
5030
|
+
this.queue = [];
|
|
5031
|
+
(_this$backend = this.backend) === null || _this$backend === void 0 || (_this$backend$init = _this$backend.init) === null || _this$backend$init === void 0 || _this$backend$init.call(_this$backend, services, options.backend, options);
|
|
5032
|
+
}
|
|
5033
|
+
queueLoad(languages, namespaces, options, callback) {
|
|
5034
|
+
var toLoad = {};
|
|
5035
|
+
var pending = {};
|
|
5036
|
+
var toLoadLanguages = {};
|
|
5037
|
+
var toLoadNamespaces = {};
|
|
5038
|
+
languages.forEach(lng => {
|
|
5039
|
+
var hasAllNamespaces = true;
|
|
5040
|
+
namespaces.forEach(ns => {
|
|
5041
|
+
var name = "".concat(lng, "|").concat(ns);
|
|
5042
|
+
if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
|
|
5043
|
+
this.state[name] = 2;
|
|
5044
|
+
} else if (this.state[name] < 0) ;else if (this.state[name] === 1) {
|
|
5045
|
+
if (pending[name] === undefined) pending[name] = true;
|
|
5046
|
+
} else {
|
|
5047
|
+
this.state[name] = 1;
|
|
5048
|
+
hasAllNamespaces = false;
|
|
5049
|
+
if (pending[name] === undefined) pending[name] = true;
|
|
5050
|
+
if (toLoad[name] === undefined) toLoad[name] = true;
|
|
5051
|
+
if (toLoadNamespaces[ns] === undefined) toLoadNamespaces[ns] = true;
|
|
5052
|
+
}
|
|
5053
|
+
});
|
|
5054
|
+
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
5055
|
+
});
|
|
5056
|
+
if (Object.keys(toLoad).length || Object.keys(pending).length) {
|
|
5057
|
+
this.queue.push({
|
|
5058
|
+
pending,
|
|
5059
|
+
pendingCount: Object.keys(pending).length,
|
|
5060
|
+
loaded: {},
|
|
5061
|
+
errors: [],
|
|
5062
|
+
callback
|
|
5063
|
+
});
|
|
5064
|
+
}
|
|
5065
|
+
return {
|
|
5066
|
+
toLoad: Object.keys(toLoad),
|
|
5067
|
+
pending: Object.keys(pending),
|
|
5068
|
+
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
5069
|
+
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
5070
|
+
};
|
|
5071
|
+
}
|
|
5072
|
+
loaded(name, err, data) {
|
|
5073
|
+
var s = name.split('|');
|
|
5074
|
+
var lng = s[0];
|
|
5075
|
+
var ns = s[1];
|
|
5076
|
+
if (err) this.emit('failedLoading', lng, ns, err);
|
|
5077
|
+
if (!err && data) {
|
|
5078
|
+
this.store.addResourceBundle(lng, ns, data, undefined, undefined, {
|
|
5079
|
+
skipCopy: true
|
|
5080
|
+
});
|
|
5081
|
+
}
|
|
5082
|
+
this.state[name] = err ? -1 : 2;
|
|
5083
|
+
if (err && data) this.state[name] = 0;
|
|
5084
|
+
var loaded = {};
|
|
5085
|
+
this.queue.forEach(q => {
|
|
5086
|
+
pushPath(q.loaded, [lng], ns);
|
|
5087
|
+
removePending(q, name);
|
|
5088
|
+
if (err) q.errors.push(err);
|
|
5089
|
+
if (q.pendingCount === 0 && !q.done) {
|
|
5090
|
+
Object.keys(q.loaded).forEach(l => {
|
|
5091
|
+
if (!loaded[l]) loaded[l] = {};
|
|
5092
|
+
var loadedKeys = q.loaded[l];
|
|
5093
|
+
if (loadedKeys.length) {
|
|
5094
|
+
loadedKeys.forEach(n => {
|
|
5095
|
+
if (loaded[l][n] === undefined) loaded[l][n] = true;
|
|
5096
|
+
});
|
|
5097
|
+
}
|
|
5098
|
+
});
|
|
5099
|
+
q.done = true;
|
|
5100
|
+
if (q.errors.length) {
|
|
5101
|
+
q.callback(q.errors);
|
|
5102
|
+
} else {
|
|
5103
|
+
q.callback();
|
|
5104
|
+
}
|
|
5105
|
+
}
|
|
5106
|
+
});
|
|
5107
|
+
this.emit('loaded', loaded);
|
|
5108
|
+
this.queue = this.queue.filter(q => !q.done);
|
|
5109
|
+
}
|
|
5110
|
+
read(lng, ns, fcName) {
|
|
5111
|
+
var tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
5112
|
+
var wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
|
|
5113
|
+
var callback = arguments.length > 5 ? arguments[5] : undefined;
|
|
5114
|
+
if (!lng.length) return callback(null, {});
|
|
5115
|
+
if (this.readingCalls >= this.maxParallelReads) {
|
|
5116
|
+
this.waitingReads.push({
|
|
5117
|
+
lng,
|
|
5118
|
+
ns,
|
|
5119
|
+
fcName,
|
|
5120
|
+
tried,
|
|
5121
|
+
wait,
|
|
5122
|
+
callback
|
|
5123
|
+
});
|
|
5124
|
+
return;
|
|
5125
|
+
}
|
|
5126
|
+
this.readingCalls++;
|
|
5127
|
+
var resolver = (err, data) => {
|
|
5128
|
+
this.readingCalls--;
|
|
5129
|
+
if (this.waitingReads.length > 0) {
|
|
5130
|
+
var next = this.waitingReads.shift();
|
|
5131
|
+
this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
5132
|
+
}
|
|
5133
|
+
if (err && data && tried < this.maxRetries) {
|
|
5134
|
+
setTimeout(() => {
|
|
5135
|
+
this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
5136
|
+
}, wait);
|
|
5137
|
+
return;
|
|
5138
|
+
}
|
|
5139
|
+
callback(err, data);
|
|
5140
|
+
};
|
|
5141
|
+
var fc = this.backend[fcName].bind(this.backend);
|
|
5142
|
+
if (fc.length === 2) {
|
|
5143
|
+
try {
|
|
5144
|
+
var r = fc(lng, ns);
|
|
5145
|
+
if (r && typeof r.then === 'function') {
|
|
5146
|
+
r.then(data => resolver(null, data)).catch(resolver);
|
|
5147
|
+
} else {
|
|
5148
|
+
resolver(null, r);
|
|
5149
|
+
}
|
|
5150
|
+
} catch (err) {
|
|
5151
|
+
resolver(err);
|
|
5152
|
+
}
|
|
5153
|
+
return;
|
|
5154
|
+
}
|
|
5155
|
+
return fc(lng, ns, resolver);
|
|
5156
|
+
}
|
|
5157
|
+
prepareLoading(languages, namespaces) {
|
|
5158
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
5159
|
+
var callback = arguments.length > 3 ? arguments[3] : undefined;
|
|
5160
|
+
if (!this.backend) {
|
|
5161
|
+
this.logger.warn('No backend was added via i18next.use. Will not load resources.');
|
|
5162
|
+
return callback && callback();
|
|
5163
|
+
}
|
|
5164
|
+
if (isString$1(languages)) languages = this.languageUtils.toResolveHierarchy(languages);
|
|
5165
|
+
if (isString$1(namespaces)) namespaces = [namespaces];
|
|
5166
|
+
var toLoad = this.queueLoad(languages, namespaces, options, callback);
|
|
5167
|
+
if (!toLoad.toLoad.length) {
|
|
5168
|
+
if (!toLoad.pending.length) callback();
|
|
5169
|
+
return null;
|
|
5170
|
+
}
|
|
5171
|
+
toLoad.toLoad.forEach(name => {
|
|
5172
|
+
this.loadOne(name);
|
|
5173
|
+
});
|
|
5174
|
+
}
|
|
5175
|
+
load(languages, namespaces, callback) {
|
|
5176
|
+
this.prepareLoading(languages, namespaces, {}, callback);
|
|
5177
|
+
}
|
|
5178
|
+
reload(languages, namespaces, callback) {
|
|
5179
|
+
this.prepareLoading(languages, namespaces, {
|
|
5180
|
+
reload: true
|
|
5181
|
+
}, callback);
|
|
5182
|
+
}
|
|
5183
|
+
loadOne(name) {
|
|
5184
|
+
var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
5185
|
+
var s = name.split('|');
|
|
5186
|
+
var lng = s[0];
|
|
5187
|
+
var ns = s[1];
|
|
5188
|
+
this.read(lng, ns, 'read', undefined, undefined, (err, data) => {
|
|
5189
|
+
if (err) this.logger.warn("".concat(prefix, "loading namespace ").concat(ns, " for language ").concat(lng, " failed"), err);
|
|
5190
|
+
if (!err && data) this.logger.log("".concat(prefix, "loaded namespace ").concat(ns, " for language ").concat(lng), data);
|
|
5191
|
+
this.loaded(name, err, data);
|
|
5192
|
+
});
|
|
5193
|
+
}
|
|
5194
|
+
saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
|
|
5195
|
+
var _this$services, _this$services2, _this$backend2;
|
|
5196
|
+
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
5197
|
+
var clb = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : () => {};
|
|
5198
|
+
if ((_this$services = this.services) !== null && _this$services !== void 0 && (_this$services = _this$services.utils) !== null && _this$services !== void 0 && _this$services.hasLoadedNamespace && !((_this$services2 = this.services) !== null && _this$services2 !== void 0 && (_this$services2 = _this$services2.utils) !== null && _this$services2 !== void 0 && _this$services2.hasLoadedNamespace(namespace))) {
|
|
5199
|
+
this.logger.warn("did not save key \"".concat(key, "\" as the namespace \"").concat(namespace, "\" was not yet loaded"), 'This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!');
|
|
5200
|
+
return;
|
|
5201
|
+
}
|
|
5202
|
+
if (key === undefined || key === null || key === '') return;
|
|
5203
|
+
if ((_this$backend2 = this.backend) !== null && _this$backend2 !== void 0 && _this$backend2.create) {
|
|
5204
|
+
var opts = _objectSpread2(_objectSpread2({}, options), {}, {
|
|
5205
|
+
isUpdate
|
|
5206
|
+
});
|
|
5207
|
+
var fc = this.backend.create.bind(this.backend);
|
|
5208
|
+
if (fc.length < 6) {
|
|
5209
|
+
try {
|
|
5210
|
+
var r;
|
|
5211
|
+
if (fc.length === 5) {
|
|
5212
|
+
r = fc(languages, namespace, key, fallbackValue, opts);
|
|
5213
|
+
} else {
|
|
5214
|
+
r = fc(languages, namespace, key, fallbackValue);
|
|
5215
|
+
}
|
|
5216
|
+
if (r && typeof r.then === 'function') {
|
|
5217
|
+
r.then(data => clb(null, data)).catch(clb);
|
|
5218
|
+
} else {
|
|
5219
|
+
clb(null, r);
|
|
5220
|
+
}
|
|
5221
|
+
} catch (err) {
|
|
5222
|
+
clb(err);
|
|
5223
|
+
}
|
|
5224
|
+
} else {
|
|
5225
|
+
fc(languages, namespace, key, fallbackValue, clb, opts);
|
|
5226
|
+
}
|
|
5227
|
+
}
|
|
5228
|
+
if (!languages || !languages[0]) return;
|
|
5229
|
+
this.store.addResource(languages[0], namespace, key, fallbackValue);
|
|
5230
|
+
}
|
|
5231
|
+
}
|
|
5232
|
+
var get = () => ({
|
|
5233
|
+
debug: false,
|
|
5234
|
+
initAsync: true,
|
|
5235
|
+
ns: ['translation'],
|
|
5236
|
+
defaultNS: ['translation'],
|
|
5237
|
+
fallbackLng: ['dev'],
|
|
5238
|
+
fallbackNS: false,
|
|
5239
|
+
supportedLngs: false,
|
|
5240
|
+
nonExplicitSupportedLngs: false,
|
|
5241
|
+
load: 'all',
|
|
5242
|
+
preload: false,
|
|
5243
|
+
simplifyPluralSuffix: true,
|
|
5244
|
+
keySeparator: '.',
|
|
5245
|
+
nsSeparator: ':',
|
|
5246
|
+
pluralSeparator: '_',
|
|
5247
|
+
contextSeparator: '_',
|
|
5248
|
+
partialBundledLanguages: false,
|
|
5249
|
+
saveMissing: false,
|
|
5250
|
+
updateMissing: false,
|
|
5251
|
+
saveMissingTo: 'fallback',
|
|
5252
|
+
saveMissingPlurals: true,
|
|
5253
|
+
missingKeyHandler: false,
|
|
5254
|
+
missingInterpolationHandler: false,
|
|
5255
|
+
postProcess: false,
|
|
5256
|
+
postProcessPassResolved: false,
|
|
5257
|
+
returnNull: false,
|
|
5258
|
+
returnEmptyString: true,
|
|
5259
|
+
returnObjects: false,
|
|
5260
|
+
joinArrays: false,
|
|
5261
|
+
returnedObjectHandler: false,
|
|
5262
|
+
parseMissingKeyHandler: false,
|
|
5263
|
+
appendNamespaceToMissingKey: false,
|
|
5264
|
+
appendNamespaceToCIMode: false,
|
|
5265
|
+
overloadTranslationOptionHandler: args => {
|
|
5266
|
+
var ret = {};
|
|
5267
|
+
if (typeof args[1] === 'object') ret = args[1];
|
|
5268
|
+
if (isString$1(args[1])) ret.defaultValue = args[1];
|
|
5269
|
+
if (isString$1(args[2])) ret.tDescription = args[2];
|
|
5270
|
+
if (typeof args[2] === 'object' || typeof args[3] === 'object') {
|
|
5271
|
+
var options = args[3] || args[2];
|
|
5272
|
+
Object.keys(options).forEach(key => {
|
|
5273
|
+
ret[key] = options[key];
|
|
5274
|
+
});
|
|
5275
|
+
}
|
|
5276
|
+
return ret;
|
|
5277
|
+
},
|
|
5278
|
+
interpolation: {
|
|
5279
|
+
escapeValue: true,
|
|
5280
|
+
format: value => value,
|
|
5281
|
+
prefix: '{{',
|
|
5282
|
+
suffix: '}}',
|
|
5283
|
+
formatSeparator: ',',
|
|
5284
|
+
unescapePrefix: '-',
|
|
5285
|
+
nestingPrefix: '$t(',
|
|
5286
|
+
nestingSuffix: ')',
|
|
5287
|
+
nestingOptionsSeparator: ',',
|
|
5288
|
+
maxReplaces: 1000,
|
|
5289
|
+
skipOnVariables: true
|
|
5290
|
+
},
|
|
5291
|
+
cacheInBuiltFormats: true
|
|
5292
|
+
});
|
|
5293
|
+
var transformOptions = options => {
|
|
5294
|
+
var _options$supportedLng, _options$supportedLng2;
|
|
5295
|
+
if (isString$1(options.ns)) options.ns = [options.ns];
|
|
5296
|
+
if (isString$1(options.fallbackLng)) options.fallbackLng = [options.fallbackLng];
|
|
5297
|
+
if (isString$1(options.fallbackNS)) options.fallbackNS = [options.fallbackNS];
|
|
5298
|
+
if (((_options$supportedLng = options.supportedLngs) === null || _options$supportedLng === void 0 || (_options$supportedLng2 = _options$supportedLng.indexOf) === null || _options$supportedLng2 === void 0 ? void 0 : _options$supportedLng2.call(_options$supportedLng, 'cimode')) < 0) {
|
|
5299
|
+
options.supportedLngs = options.supportedLngs.concat(['cimode']);
|
|
5300
|
+
}
|
|
5301
|
+
if (typeof options.initImmediate === 'boolean') options.initAsync = options.initImmediate;
|
|
5302
|
+
return options;
|
|
5303
|
+
};
|
|
5304
|
+
var noop$1 = () => {};
|
|
5305
|
+
var bindMemberFunctions = inst => {
|
|
5306
|
+
var mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
|
|
5307
|
+
mems.forEach(mem => {
|
|
5308
|
+
if (typeof inst[mem] === 'function') {
|
|
5309
|
+
inst[mem] = inst[mem].bind(inst);
|
|
5310
|
+
}
|
|
5311
|
+
});
|
|
5312
|
+
};
|
|
5313
|
+
class I18n extends EventEmitter {
|
|
5314
|
+
constructor() {
|
|
5315
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
5316
|
+
var callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
5317
|
+
super();
|
|
5318
|
+
this.options = transformOptions(options);
|
|
5319
|
+
this.services = {};
|
|
5320
|
+
this.logger = baseLogger;
|
|
5321
|
+
this.modules = {
|
|
5322
|
+
external: []
|
|
5323
|
+
};
|
|
5324
|
+
bindMemberFunctions(this);
|
|
5325
|
+
if (callback && !this.isInitialized && !options.isClone) {
|
|
5326
|
+
if (!this.options.initAsync) {
|
|
5327
|
+
this.init(options, callback);
|
|
5328
|
+
return this;
|
|
5329
|
+
}
|
|
5330
|
+
setTimeout(() => {
|
|
5331
|
+
this.init(options, callback);
|
|
5332
|
+
}, 0);
|
|
5333
|
+
}
|
|
5334
|
+
}
|
|
5335
|
+
init() {
|
|
5336
|
+
var _this2 = this;
|
|
5337
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
5338
|
+
var callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
5339
|
+
this.isInitializing = true;
|
|
5340
|
+
if (typeof options === 'function') {
|
|
5341
|
+
callback = options;
|
|
5342
|
+
options = {};
|
|
5343
|
+
}
|
|
5344
|
+
if (options.defaultNS == null && options.ns) {
|
|
5345
|
+
if (isString$1(options.ns)) {
|
|
5346
|
+
options.defaultNS = options.ns;
|
|
5347
|
+
} else if (options.ns.indexOf('translation') < 0) {
|
|
5348
|
+
options.defaultNS = options.ns[0];
|
|
5349
|
+
}
|
|
5350
|
+
}
|
|
5351
|
+
var defOpts = get();
|
|
5352
|
+
this.options = _objectSpread2(_objectSpread2(_objectSpread2({}, defOpts), this.options), transformOptions(options));
|
|
5353
|
+
this.options.interpolation = _objectSpread2(_objectSpread2({}, defOpts.interpolation), this.options.interpolation);
|
|
5354
|
+
if (options.keySeparator !== undefined) {
|
|
5355
|
+
this.options.userDefinedKeySeparator = options.keySeparator;
|
|
5356
|
+
}
|
|
5357
|
+
if (options.nsSeparator !== undefined) {
|
|
5358
|
+
this.options.userDefinedNsSeparator = options.nsSeparator;
|
|
5359
|
+
}
|
|
5360
|
+
var createClassOnDemand = ClassOrObject => {
|
|
5361
|
+
if (!ClassOrObject) return null;
|
|
5362
|
+
if (typeof ClassOrObject === 'function') return new ClassOrObject();
|
|
5363
|
+
return ClassOrObject;
|
|
5364
|
+
};
|
|
5365
|
+
if (!this.options.isClone) {
|
|
5366
|
+
if (this.modules.logger) {
|
|
5367
|
+
baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
|
|
5368
|
+
} else {
|
|
5369
|
+
baseLogger.init(null, this.options);
|
|
5370
|
+
}
|
|
5371
|
+
var formatter;
|
|
5372
|
+
if (this.modules.formatter) {
|
|
5373
|
+
formatter = this.modules.formatter;
|
|
5374
|
+
} else {
|
|
5375
|
+
formatter = Formatter;
|
|
5376
|
+
}
|
|
5377
|
+
var lu = new LanguageUtil(this.options);
|
|
5378
|
+
this.store = new ResourceStore(this.options.resources, this.options);
|
|
5379
|
+
var s = this.services;
|
|
5380
|
+
s.logger = baseLogger;
|
|
5381
|
+
s.resourceStore = this.store;
|
|
5382
|
+
s.languageUtils = lu;
|
|
5383
|
+
s.pluralResolver = new PluralResolver(lu, {
|
|
5384
|
+
prepend: this.options.pluralSeparator,
|
|
5385
|
+
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
5386
|
+
});
|
|
5387
|
+
var usingLegacyFormatFunction = this.options.interpolation.format && this.options.interpolation.format !== defOpts.interpolation.format;
|
|
5388
|
+
if (usingLegacyFormatFunction) {
|
|
5389
|
+
this.logger.deprecate("init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting");
|
|
5390
|
+
}
|
|
5391
|
+
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
|
|
5392
|
+
s.formatter = createClassOnDemand(formatter);
|
|
5393
|
+
if (s.formatter.init) s.formatter.init(s, this.options);
|
|
5394
|
+
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
5395
|
+
}
|
|
5396
|
+
s.interpolator = new Interpolator(this.options);
|
|
5397
|
+
s.utils = {
|
|
5398
|
+
hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
|
|
5399
|
+
};
|
|
5400
|
+
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
5401
|
+
s.backendConnector.on('*', function (event) {
|
|
5402
|
+
for (var _len7 = arguments.length, args = new Array(_len7 > 1 ? _len7 - 1 : 0), _key7 = 1; _key7 < _len7; _key7++) {
|
|
5403
|
+
args[_key7 - 1] = arguments[_key7];
|
|
5404
|
+
}
|
|
5405
|
+
_this2.emit(event, ...args);
|
|
5406
|
+
});
|
|
5407
|
+
if (this.modules.languageDetector) {
|
|
5408
|
+
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
5409
|
+
if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
|
|
5410
|
+
}
|
|
5411
|
+
if (this.modules.i18nFormat) {
|
|
5412
|
+
s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
|
|
5413
|
+
if (s.i18nFormat.init) s.i18nFormat.init(this);
|
|
5414
|
+
}
|
|
5415
|
+
this.translator = new Translator(this.services, this.options);
|
|
5416
|
+
this.translator.on('*', function (event) {
|
|
5417
|
+
for (var _len8 = arguments.length, args = new Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) {
|
|
5418
|
+
args[_key8 - 1] = arguments[_key8];
|
|
5419
|
+
}
|
|
5420
|
+
_this2.emit(event, ...args);
|
|
5421
|
+
});
|
|
5422
|
+
this.modules.external.forEach(m => {
|
|
5423
|
+
if (m.init) m.init(this);
|
|
5424
|
+
});
|
|
5425
|
+
}
|
|
5426
|
+
this.format = this.options.interpolation.format;
|
|
5427
|
+
if (!callback) callback = noop$1;
|
|
5428
|
+
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
5429
|
+
var codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
5430
|
+
if (codes.length > 0 && codes[0] !== 'dev') this.options.lng = codes[0];
|
|
5431
|
+
}
|
|
5432
|
+
if (!this.services.languageDetector && !this.options.lng) {
|
|
5433
|
+
this.logger.warn('init: no languageDetector is used and no lng is defined');
|
|
5434
|
+
}
|
|
5435
|
+
var storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
|
|
5436
|
+
storeApi.forEach(fcName => {
|
|
5437
|
+
this[fcName] = function () {
|
|
5438
|
+
return _this2.store[fcName](...arguments);
|
|
5439
|
+
};
|
|
5440
|
+
});
|
|
5441
|
+
var storeApiChained = ['addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle'];
|
|
5442
|
+
storeApiChained.forEach(fcName => {
|
|
5443
|
+
this[fcName] = function () {
|
|
5444
|
+
_this2.store[fcName](...arguments);
|
|
5445
|
+
return _this2;
|
|
5446
|
+
};
|
|
5447
|
+
});
|
|
5448
|
+
var deferred = defer();
|
|
5449
|
+
var load = () => {
|
|
5450
|
+
var finish = (err, t) => {
|
|
5451
|
+
this.isInitializing = false;
|
|
5452
|
+
if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn('init: i18next is already initialized. You should call init just once!');
|
|
5453
|
+
this.isInitialized = true;
|
|
5454
|
+
if (!this.options.isClone) this.logger.log('initialized', this.options);
|
|
5455
|
+
this.emit('initialized', this.options);
|
|
5456
|
+
deferred.resolve(t);
|
|
5457
|
+
callback(err, t);
|
|
5458
|
+
};
|
|
5459
|
+
if (this.languages && !this.isInitialized) return finish(null, this.t.bind(this));
|
|
5460
|
+
this.changeLanguage(this.options.lng, finish);
|
|
5461
|
+
};
|
|
5462
|
+
if (this.options.resources || !this.options.initAsync) {
|
|
5463
|
+
load();
|
|
5464
|
+
} else {
|
|
5465
|
+
setTimeout(load, 0);
|
|
5466
|
+
}
|
|
5467
|
+
return deferred;
|
|
5468
|
+
}
|
|
5469
|
+
loadResources(language) {
|
|
5470
|
+
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop$1;
|
|
5471
|
+
var usedCallback = callback;
|
|
5472
|
+
var usedLng = isString$1(language) ? language : this.language;
|
|
5473
|
+
if (typeof language === 'function') usedCallback = language;
|
|
5474
|
+
if (!this.options.resources || this.options.partialBundledLanguages) {
|
|
5475
|
+
var _this$options$preload, _this$options$preload2;
|
|
5476
|
+
if ((usedLng === null || usedLng === void 0 ? void 0 : usedLng.toLowerCase()) === 'cimode' && (!this.options.preload || this.options.preload.length === 0)) return usedCallback();
|
|
5477
|
+
var toLoad = [];
|
|
5478
|
+
var append = lng => {
|
|
5479
|
+
if (!lng) return;
|
|
5480
|
+
if (lng === 'cimode') return;
|
|
5481
|
+
var lngs = this.services.languageUtils.toResolveHierarchy(lng);
|
|
5482
|
+
lngs.forEach(l => {
|
|
5483
|
+
if (l === 'cimode') return;
|
|
5484
|
+
if (toLoad.indexOf(l) < 0) toLoad.push(l);
|
|
5485
|
+
});
|
|
5486
|
+
};
|
|
5487
|
+
if (!usedLng) {
|
|
5488
|
+
var fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
5489
|
+
fallbacks.forEach(l => append(l));
|
|
5490
|
+
} else {
|
|
5491
|
+
append(usedLng);
|
|
5492
|
+
}
|
|
5493
|
+
(_this$options$preload = this.options.preload) === null || _this$options$preload === void 0 || (_this$options$preload2 = _this$options$preload.forEach) === null || _this$options$preload2 === void 0 || _this$options$preload2.call(_this$options$preload, l => append(l));
|
|
5494
|
+
this.services.backendConnector.load(toLoad, this.options.ns, e => {
|
|
5495
|
+
if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
|
|
5496
|
+
usedCallback(e);
|
|
5497
|
+
});
|
|
5498
|
+
} else {
|
|
5499
|
+
usedCallback(null);
|
|
5500
|
+
}
|
|
5501
|
+
}
|
|
5502
|
+
reloadResources(lngs, ns, callback) {
|
|
5503
|
+
var deferred = defer();
|
|
5504
|
+
if (typeof lngs === 'function') {
|
|
5505
|
+
callback = lngs;
|
|
5506
|
+
lngs = undefined;
|
|
5507
|
+
}
|
|
5508
|
+
if (typeof ns === 'function') {
|
|
5509
|
+
callback = ns;
|
|
5510
|
+
ns = undefined;
|
|
5511
|
+
}
|
|
5512
|
+
if (!lngs) lngs = this.languages;
|
|
5513
|
+
if (!ns) ns = this.options.ns;
|
|
5514
|
+
if (!callback) callback = noop$1;
|
|
5515
|
+
this.services.backendConnector.reload(lngs, ns, err => {
|
|
5516
|
+
deferred.resolve();
|
|
5517
|
+
callback(err);
|
|
5518
|
+
});
|
|
5519
|
+
return deferred;
|
|
5520
|
+
}
|
|
5521
|
+
use(module) {
|
|
5522
|
+
if (!module) throw new Error('You are passing an undefined module! Please check the object you are passing to i18next.use()');
|
|
5523
|
+
if (!module.type) throw new Error('You are passing a wrong module! Please check the object you are passing to i18next.use()');
|
|
5524
|
+
if (module.type === 'backend') {
|
|
5525
|
+
this.modules.backend = module;
|
|
5526
|
+
}
|
|
5527
|
+
if (module.type === 'logger' || module.log && module.warn && module.error) {
|
|
5528
|
+
this.modules.logger = module;
|
|
5529
|
+
}
|
|
5530
|
+
if (module.type === 'languageDetector') {
|
|
5531
|
+
this.modules.languageDetector = module;
|
|
5532
|
+
}
|
|
5533
|
+
if (module.type === 'i18nFormat') {
|
|
5534
|
+
this.modules.i18nFormat = module;
|
|
5535
|
+
}
|
|
5536
|
+
if (module.type === 'postProcessor') {
|
|
5537
|
+
postProcessor.addPostProcessor(module);
|
|
5538
|
+
}
|
|
5539
|
+
if (module.type === 'formatter') {
|
|
5540
|
+
this.modules.formatter = module;
|
|
5541
|
+
}
|
|
5542
|
+
if (module.type === '3rdParty') {
|
|
5543
|
+
this.modules.external.push(module);
|
|
5544
|
+
}
|
|
5545
|
+
return this;
|
|
5546
|
+
}
|
|
5547
|
+
setResolvedLanguage(l) {
|
|
5548
|
+
if (!l || !this.languages) return;
|
|
5549
|
+
if (['cimode', 'dev'].indexOf(l) > -1) return;
|
|
5550
|
+
for (var li = 0; li < this.languages.length; li++) {
|
|
5551
|
+
var lngInLngs = this.languages[li];
|
|
5552
|
+
if (['cimode', 'dev'].indexOf(lngInLngs) > -1) continue;
|
|
5553
|
+
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
5554
|
+
this.resolvedLanguage = lngInLngs;
|
|
5555
|
+
break;
|
|
5556
|
+
}
|
|
5557
|
+
}
|
|
5558
|
+
if (!this.resolvedLanguage && this.languages.indexOf(l) < 0 && this.store.hasLanguageSomeTranslations(l)) {
|
|
5559
|
+
this.resolvedLanguage = l;
|
|
5560
|
+
this.languages.unshift(l);
|
|
5561
|
+
}
|
|
5562
|
+
}
|
|
5563
|
+
changeLanguage(lng, callback) {
|
|
5564
|
+
var _this3 = this;
|
|
5565
|
+
this.isLanguageChangingTo = lng;
|
|
5566
|
+
var deferred = defer();
|
|
5567
|
+
this.emit('languageChanging', lng);
|
|
5568
|
+
var setLngProps = l => {
|
|
5569
|
+
this.language = l;
|
|
5570
|
+
this.languages = this.services.languageUtils.toResolveHierarchy(l);
|
|
5571
|
+
this.resolvedLanguage = undefined;
|
|
5572
|
+
this.setResolvedLanguage(l);
|
|
5573
|
+
};
|
|
5574
|
+
var done = (err, l) => {
|
|
5575
|
+
if (l) {
|
|
5576
|
+
if (this.isLanguageChangingTo === lng) {
|
|
5577
|
+
setLngProps(l);
|
|
5578
|
+
this.translator.changeLanguage(l);
|
|
5579
|
+
this.isLanguageChangingTo = undefined;
|
|
5580
|
+
this.emit('languageChanged', l);
|
|
5581
|
+
this.logger.log('languageChanged', l);
|
|
5582
|
+
}
|
|
5583
|
+
} else {
|
|
5584
|
+
this.isLanguageChangingTo = undefined;
|
|
5585
|
+
}
|
|
5586
|
+
deferred.resolve(function () {
|
|
5587
|
+
return _this3.t(...arguments);
|
|
5588
|
+
});
|
|
5589
|
+
if (callback) callback(err, function () {
|
|
5590
|
+
return _this3.t(...arguments);
|
|
5591
|
+
});
|
|
5592
|
+
};
|
|
5593
|
+
var setLng = lngs => {
|
|
5594
|
+
if (!lng && !lngs && this.services.languageDetector) lngs = [];
|
|
5595
|
+
var fl = isString$1(lngs) ? lngs : lngs && lngs[0];
|
|
5596
|
+
var l = this.store.hasLanguageSomeTranslations(fl) ? fl : this.services.languageUtils.getBestMatchFromCodes(isString$1(lngs) ? [lngs] : lngs);
|
|
5597
|
+
if (l) {
|
|
5598
|
+
var _this$services$langua, _this$services$langua2;
|
|
5599
|
+
if (!this.language) {
|
|
5600
|
+
setLngProps(l);
|
|
5601
|
+
}
|
|
5602
|
+
if (!this.translator.language) this.translator.changeLanguage(l);
|
|
5603
|
+
(_this$services$langua = this.services.languageDetector) === null || _this$services$langua === void 0 || (_this$services$langua2 = _this$services$langua.cacheUserLanguage) === null || _this$services$langua2 === void 0 || _this$services$langua2.call(_this$services$langua, l);
|
|
5604
|
+
}
|
|
5605
|
+
this.loadResources(l, err => {
|
|
5606
|
+
done(err, l);
|
|
5607
|
+
});
|
|
5608
|
+
};
|
|
5609
|
+
if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
|
|
5610
|
+
setLng(this.services.languageDetector.detect());
|
|
5611
|
+
} else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
|
|
5612
|
+
if (this.services.languageDetector.detect.length === 0) {
|
|
5613
|
+
this.services.languageDetector.detect().then(setLng);
|
|
5614
|
+
} else {
|
|
5615
|
+
this.services.languageDetector.detect(setLng);
|
|
5616
|
+
}
|
|
5617
|
+
} else {
|
|
5618
|
+
setLng(lng);
|
|
5619
|
+
}
|
|
5620
|
+
return deferred;
|
|
5621
|
+
}
|
|
5622
|
+
getFixedT(lng, ns, keyPrefix) {
|
|
5623
|
+
var _this4 = this;
|
|
5624
|
+
var _fixedT = function fixedT(key, opts) {
|
|
5625
|
+
var o;
|
|
5626
|
+
if (typeof opts !== 'object') {
|
|
5627
|
+
for (var _len9 = arguments.length, rest = new Array(_len9 > 2 ? _len9 - 2 : 0), _key9 = 2; _key9 < _len9; _key9++) {
|
|
5628
|
+
rest[_key9 - 2] = arguments[_key9];
|
|
5629
|
+
}
|
|
5630
|
+
o = _this4.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
5631
|
+
} else {
|
|
5632
|
+
o = _objectSpread2({}, opts);
|
|
5633
|
+
}
|
|
5634
|
+
o.lng = o.lng || _fixedT.lng;
|
|
5635
|
+
o.lngs = o.lngs || _fixedT.lngs;
|
|
5636
|
+
o.ns = o.ns || _fixedT.ns;
|
|
5637
|
+
if (o.keyPrefix !== '') o.keyPrefix = o.keyPrefix || keyPrefix || _fixedT.keyPrefix;
|
|
5638
|
+
var keySeparator = _this4.options.keySeparator || '.';
|
|
5639
|
+
var resultKey;
|
|
5640
|
+
if (o.keyPrefix && Array.isArray(key)) {
|
|
5641
|
+
resultKey = key.map(k => {
|
|
5642
|
+
if (typeof k === 'function') k = keysFromSelector(k, _objectSpread2(_objectSpread2({}, _this4.options), opts));
|
|
5643
|
+
return "".concat(o.keyPrefix).concat(keySeparator).concat(k);
|
|
5644
|
+
});
|
|
5645
|
+
} else {
|
|
5646
|
+
if (typeof key === 'function') key = keysFromSelector(key, _objectSpread2(_objectSpread2({}, _this4.options), opts));
|
|
5647
|
+
resultKey = o.keyPrefix ? "".concat(o.keyPrefix).concat(keySeparator).concat(key) : key;
|
|
5648
|
+
}
|
|
5649
|
+
return _this4.t(resultKey, o);
|
|
5650
|
+
};
|
|
5651
|
+
if (isString$1(lng)) {
|
|
5652
|
+
_fixedT.lng = lng;
|
|
5653
|
+
} else {
|
|
5654
|
+
_fixedT.lngs = lng;
|
|
5655
|
+
}
|
|
5656
|
+
_fixedT.ns = ns;
|
|
5657
|
+
_fixedT.keyPrefix = keyPrefix;
|
|
5658
|
+
return _fixedT;
|
|
5659
|
+
}
|
|
5660
|
+
t() {
|
|
5661
|
+
var _this$translator;
|
|
5662
|
+
for (var _len0 = arguments.length, args = new Array(_len0), _key0 = 0; _key0 < _len0; _key0++) {
|
|
5663
|
+
args[_key0] = arguments[_key0];
|
|
5664
|
+
}
|
|
5665
|
+
return (_this$translator = this.translator) === null || _this$translator === void 0 ? void 0 : _this$translator.translate(...args);
|
|
5666
|
+
}
|
|
5667
|
+
exists() {
|
|
5668
|
+
var _this$translator2;
|
|
5669
|
+
for (var _len1 = arguments.length, args = new Array(_len1), _key1 = 0; _key1 < _len1; _key1++) {
|
|
5670
|
+
args[_key1] = arguments[_key1];
|
|
5671
|
+
}
|
|
5672
|
+
return (_this$translator2 = this.translator) === null || _this$translator2 === void 0 ? void 0 : _this$translator2.exists(...args);
|
|
5673
|
+
}
|
|
5674
|
+
setDefaultNamespace(ns) {
|
|
5675
|
+
this.options.defaultNS = ns;
|
|
5676
|
+
}
|
|
5677
|
+
hasLoadedNamespace(ns) {
|
|
5678
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
5679
|
+
if (!this.isInitialized) {
|
|
5680
|
+
this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
|
|
5681
|
+
return false;
|
|
5682
|
+
}
|
|
5683
|
+
if (!this.languages || !this.languages.length) {
|
|
5684
|
+
this.logger.warn('hasLoadedNamespace: i18n.languages were undefined or empty', this.languages);
|
|
5685
|
+
return false;
|
|
5686
|
+
}
|
|
5687
|
+
var lng = options.lng || this.resolvedLanguage || this.languages[0];
|
|
5688
|
+
var fallbackLng = this.options ? this.options.fallbackLng : false;
|
|
5689
|
+
var lastLng = this.languages[this.languages.length - 1];
|
|
5690
|
+
if (lng.toLowerCase() === 'cimode') return true;
|
|
5691
|
+
var loadNotPending = (l, n) => {
|
|
5692
|
+
var loadState = this.services.backendConnector.state["".concat(l, "|").concat(n)];
|
|
5693
|
+
return loadState === -1 || loadState === 0 || loadState === 2;
|
|
5694
|
+
};
|
|
5695
|
+
if (options.precheck) {
|
|
5696
|
+
var preResult = options.precheck(this, loadNotPending);
|
|
5697
|
+
if (preResult !== undefined) return preResult;
|
|
5698
|
+
}
|
|
5699
|
+
if (this.hasResourceBundle(lng, ns)) return true;
|
|
5700
|
+
if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
|
|
5701
|
+
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
5702
|
+
return false;
|
|
5703
|
+
}
|
|
5704
|
+
loadNamespaces(ns, callback) {
|
|
5705
|
+
var deferred = defer();
|
|
5706
|
+
if (!this.options.ns) {
|
|
5707
|
+
if (callback) callback();
|
|
5708
|
+
return Promise.resolve();
|
|
5709
|
+
}
|
|
5710
|
+
if (isString$1(ns)) ns = [ns];
|
|
5711
|
+
ns.forEach(n => {
|
|
5712
|
+
if (this.options.ns.indexOf(n) < 0) this.options.ns.push(n);
|
|
5713
|
+
});
|
|
5714
|
+
this.loadResources(err => {
|
|
5715
|
+
deferred.resolve();
|
|
5716
|
+
if (callback) callback(err);
|
|
5717
|
+
});
|
|
5718
|
+
return deferred;
|
|
5719
|
+
}
|
|
5720
|
+
loadLanguages(lngs, callback) {
|
|
5721
|
+
var deferred = defer();
|
|
5722
|
+
if (isString$1(lngs)) lngs = [lngs];
|
|
5723
|
+
var preloaded = this.options.preload || [];
|
|
5724
|
+
var newLngs = lngs.filter(lng => preloaded.indexOf(lng) < 0 && this.services.languageUtils.isSupportedCode(lng));
|
|
5725
|
+
if (!newLngs.length) {
|
|
5726
|
+
if (callback) callback();
|
|
5727
|
+
return Promise.resolve();
|
|
5728
|
+
}
|
|
5729
|
+
this.options.preload = preloaded.concat(newLngs);
|
|
5730
|
+
this.loadResources(err => {
|
|
5731
|
+
deferred.resolve();
|
|
5732
|
+
if (callback) callback(err);
|
|
5733
|
+
});
|
|
5734
|
+
return deferred;
|
|
5735
|
+
}
|
|
5736
|
+
dir(lng) {
|
|
5737
|
+
var _this$languages, _this$services3;
|
|
5738
|
+
if (!lng) lng = this.resolvedLanguage || (((_this$languages = this.languages) === null || _this$languages === void 0 ? void 0 : _this$languages.length) > 0 ? this.languages[0] : this.language);
|
|
5739
|
+
if (!lng) return 'rtl';
|
|
5740
|
+
try {
|
|
5741
|
+
var l = new Intl.Locale(lng);
|
|
5742
|
+
if (l && l.getTextInfo) {
|
|
5743
|
+
var ti = l.getTextInfo();
|
|
5744
|
+
if (ti && ti.direction) return ti.direction;
|
|
5745
|
+
}
|
|
5746
|
+
} catch (e) {}
|
|
5747
|
+
var 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'];
|
|
5748
|
+
var languageUtils = ((_this$services3 = this.services) === null || _this$services3 === void 0 ? void 0 : _this$services3.languageUtils) || new LanguageUtil(get());
|
|
5749
|
+
if (lng.toLowerCase().indexOf('-latn') > 1) return 'ltr';
|
|
5750
|
+
return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
|
|
5751
|
+
}
|
|
5752
|
+
static createInstance() {
|
|
5753
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
5754
|
+
var callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
5755
|
+
return new I18n(options, callback);
|
|
5756
|
+
}
|
|
5757
|
+
cloneInstance() {
|
|
5758
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
5759
|
+
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop$1;
|
|
5760
|
+
var forkResourceStore = options.forkResourceStore;
|
|
5761
|
+
if (forkResourceStore) delete options.forkResourceStore;
|
|
5762
|
+
var mergedOptions = _objectSpread2(_objectSpread2(_objectSpread2({}, this.options), options), {
|
|
5763
|
+
isClone: true
|
|
5764
|
+
});
|
|
5765
|
+
var clone = new I18n(mergedOptions);
|
|
5766
|
+
if (options.debug !== undefined || options.prefix !== undefined) {
|
|
5767
|
+
clone.logger = clone.logger.clone(options);
|
|
5768
|
+
}
|
|
5769
|
+
var membersToCopy = ['store', 'services', 'language'];
|
|
5770
|
+
membersToCopy.forEach(m => {
|
|
5771
|
+
clone[m] = this[m];
|
|
5772
|
+
});
|
|
5773
|
+
clone.services = _objectSpread2({}, this.services);
|
|
5774
|
+
clone.services.utils = {
|
|
5775
|
+
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
5776
|
+
};
|
|
5777
|
+
if (forkResourceStore) {
|
|
5778
|
+
var clonedData = Object.keys(this.store.data).reduce((prev, l) => {
|
|
5779
|
+
prev[l] = _objectSpread2({}, this.store.data[l]);
|
|
5780
|
+
prev[l] = Object.keys(prev[l]).reduce((acc, n) => {
|
|
5781
|
+
acc[n] = _objectSpread2({}, prev[l][n]);
|
|
5782
|
+
return acc;
|
|
5783
|
+
}, prev[l]);
|
|
5784
|
+
return prev;
|
|
5785
|
+
}, {});
|
|
5786
|
+
clone.store = new ResourceStore(clonedData, mergedOptions);
|
|
5787
|
+
clone.services.resourceStore = clone.store;
|
|
5788
|
+
}
|
|
5789
|
+
clone.translator = new Translator(clone.services, mergedOptions);
|
|
5790
|
+
clone.translator.on('*', function (event) {
|
|
5791
|
+
for (var _len10 = arguments.length, args = new Array(_len10 > 1 ? _len10 - 1 : 0), _key10 = 1; _key10 < _len10; _key10++) {
|
|
5792
|
+
args[_key10 - 1] = arguments[_key10];
|
|
5793
|
+
}
|
|
5794
|
+
clone.emit(event, ...args);
|
|
5795
|
+
});
|
|
5796
|
+
clone.init(mergedOptions, callback);
|
|
5797
|
+
clone.translator.options = mergedOptions;
|
|
5798
|
+
clone.translator.backendConnector.services.utils = {
|
|
5799
|
+
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
5800
|
+
};
|
|
5801
|
+
return clone;
|
|
5802
|
+
}
|
|
5803
|
+
toJSON() {
|
|
5804
|
+
return {
|
|
5805
|
+
options: this.options,
|
|
5806
|
+
store: this.store,
|
|
5807
|
+
language: this.language,
|
|
5808
|
+
languages: this.languages,
|
|
5809
|
+
resolvedLanguage: this.resolvedLanguage
|
|
5810
|
+
};
|
|
5811
|
+
}
|
|
5812
|
+
}
|
|
5813
|
+
var instance = I18n.createInstance();
|
|
5814
|
+
instance.createInstance = I18n.createInstance;
|
|
5815
|
+
instance.createInstance;
|
|
5816
|
+
instance.dir;
|
|
5817
|
+
instance.init;
|
|
5818
|
+
instance.loadResources;
|
|
5819
|
+
instance.reloadResources;
|
|
5820
|
+
instance.use;
|
|
5821
|
+
instance.changeLanguage;
|
|
5822
|
+
instance.getFixedT;
|
|
5823
|
+
instance.t;
|
|
5824
|
+
instance.exists;
|
|
5825
|
+
instance.setDefaultNamespace;
|
|
5826
|
+
instance.hasLoadedNamespace;
|
|
5827
|
+
instance.loadNamespaces;
|
|
5828
|
+
instance.loadLanguages;
|
|
5829
|
+
|
|
3620
5830
|
var homeSdk$1 = {
|
|
3621
5831
|
chatTitle: "Chat with",
|
|
3622
5832
|
tryBabylAi: "Try Babyl AI for Free 🎉",
|
|
@@ -3690,8 +5900,8 @@ var ar = {
|
|
|
3690
5900
|
var defaultLanguage = "ar";
|
|
3691
5901
|
var createHelpCenterI18n = function createHelpCenterI18n() {
|
|
3692
5902
|
var lng = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultLanguage;
|
|
3693
|
-
var instance =
|
|
3694
|
-
instance.init({
|
|
5903
|
+
var instance$1 = instance.createInstance();
|
|
5904
|
+
instance$1.init({
|
|
3695
5905
|
resources: {
|
|
3696
5906
|
en: {
|
|
3697
5907
|
translation: en
|
|
@@ -3706,7 +5916,7 @@ var createHelpCenterI18n = function createHelpCenterI18n() {
|
|
|
3706
5916
|
escapeValue: false
|
|
3707
5917
|
}
|
|
3708
5918
|
});
|
|
3709
|
-
return instance;
|
|
5919
|
+
return instance$1;
|
|
3710
5920
|
};
|
|
3711
5921
|
|
|
3712
5922
|
var useLocalTranslation = () => {
|
|
@@ -32213,21 +34423,21 @@ var ChatWindowHeader = props => {
|
|
|
32213
34423
|
t,
|
|
32214
34424
|
dir
|
|
32215
34425
|
} = useLocalTranslation();
|
|
32216
|
-
var isRTL = dir === "rtl";
|
|
34426
|
+
var isRTL = String(dir) === "rtl";
|
|
32217
34427
|
return jsxRuntime.jsxs("header", {
|
|
32218
34428
|
className: "babylai-flex babylai-w-full babylai-items-center babylai-py-[18px] babylai-px-[18px] babylai-justify-between babylai-relative babylai-bg-black-white-50 dark:!babylai-bg-storm-dust-900 babylai-rounded-t-3xl",
|
|
32219
34429
|
children: [jsxRuntime.jsxs("div", {
|
|
32220
34430
|
className: "babylai-flex babylai-items-center babylai-gap-2",
|
|
32221
|
-
children: [jsxRuntime.
|
|
34431
|
+
children: [jsxRuntime.jsx(Button, {
|
|
32222
34432
|
variant: "rounded-icon",
|
|
32223
34433
|
size: "icon",
|
|
32224
34434
|
className: "babylai-bg-primary-500/10 dark:babylai-bg-storm-dust-950",
|
|
32225
34435
|
onClick: props.handleBack,
|
|
32226
|
-
children:
|
|
32227
|
-
className: "
|
|
32228
|
-
})
|
|
34436
|
+
children: jsxRuntime.jsx(ArrowRight, {
|
|
34437
|
+
className: "babylai-w-3 babylai-h-3 ".concat(isRTL ? "" : "babylai-rotate-180", " babylai-text-primary-500 dark:babylai-text-white")
|
|
34438
|
+
})
|
|
32229
34439
|
}), jsxRuntime.jsxs("div", {
|
|
32230
|
-
className: "babylai-relative
|
|
34440
|
+
className: "babylai-relative",
|
|
32231
34441
|
children: [jsxRuntime.jsx(Button, {
|
|
32232
34442
|
variant: "rounded-icon",
|
|
32233
34443
|
size: "icon",
|
|
@@ -32499,9 +34709,8 @@ var OptionsListHeader = _ref => {
|
|
|
32499
34709
|
var {
|
|
32500
34710
|
dir
|
|
32501
34711
|
} = useLocalTranslation();
|
|
32502
|
-
var isRTL = dir === "rtl";
|
|
34712
|
+
var isRTL = String(dir) === "rtl";
|
|
32503
34713
|
return jsxRuntime.jsxs("header", {
|
|
32504
|
-
dir: dir,
|
|
32505
34714
|
className: "babylai-flex babylai-w-full babylai-items-center babylai-mb-2 ".concat(!showHelpScreen ? "babylai-justify-end" : "babylai-justify-between"),
|
|
32506
34715
|
children: [jsxRuntime.jsx(Button, {
|
|
32507
34716
|
variant: "rounded-icon",
|
|
@@ -32509,20 +34718,22 @@ var OptionsListHeader = _ref => {
|
|
|
32509
34718
|
className: "!babylai-w-12 !babylai-h-12 babylai-bg-black-white-50 dark:babylai-bg-storm-dust-900 babylai-relative babylai-z-10",
|
|
32510
34719
|
onClick: handleBack,
|
|
32511
34720
|
children: showHelpScreen ? jsxRuntime.jsx(ArrowRight, {
|
|
32512
|
-
className: "".concat(isRTL ? "" : "babylai-rotate-180", " babylai-text-primary-500 babylai-w-full babylai-h-full")
|
|
34721
|
+
className: "".concat(!isRTL ? "" : "babylai-rotate-180", " babylai-text-primary-500 babylai-w-full babylai-h-full")
|
|
32513
34722
|
}) : jsxRuntime.jsx(CloseCircle, {
|
|
32514
34723
|
className: "!babylai-w-full !babylai-h-full babylai-cursor-pointer"
|
|
32515
34724
|
})
|
|
32516
34725
|
}), jsxRuntime.jsx(ThinkingLogo, {
|
|
32517
|
-
className: "babylai-w-40 babylai-h-40 babylai-text-primary-500 babylai-absolute babylai-top-0 babylai-
|
|
34726
|
+
className: "babylai-w-40 babylai-h-40 babylai-text-primary-500 babylai-absolute babylai-top-0 babylai-end-1 babylai-overflow-hidden"
|
|
32518
34727
|
})]
|
|
32519
34728
|
});
|
|
32520
34729
|
};
|
|
32521
34730
|
var OptionsListHeader$1 = OptionsListHeader;
|
|
32522
34731
|
|
|
32523
34732
|
var OptionCard = props => {
|
|
32524
|
-
var
|
|
32525
|
-
|
|
34733
|
+
var {
|
|
34734
|
+
dir
|
|
34735
|
+
} = useLocalTranslation();
|
|
34736
|
+
var isRTL = String(dir) === "rtl";
|
|
32526
34737
|
return jsxRuntime.jsxs("div", {
|
|
32527
34738
|
className: "babylai-flex babylai-items-center babylai-justify-between babylai-p-2",
|
|
32528
34739
|
children: [jsxRuntime.jsx("p", {
|
|
@@ -32533,7 +34744,7 @@ var OptionCard = props => {
|
|
|
32533
34744
|
size: "icon",
|
|
32534
34745
|
className: "babylai-text-primary-500 hover:babylai-bg-primary-100",
|
|
32535
34746
|
children: jsxRuntime.jsx(ArrowRight, {
|
|
32536
|
-
className: "babylai-w-3 babylai-h-3 ".concat(
|
|
34747
|
+
className: "babylai-w-3 babylai-h-3 ".concat(!isRTL ? "" : "babylai-rotate-180", " babylai-text-primary-500 dark:babylai-text-white")
|
|
32537
34748
|
})
|
|
32538
34749
|
})]
|
|
32539
34750
|
});
|