i18next 21.6.16 → 21.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/cjs/i18next.js +76 -29
- package/dist/esm/i18next.bundled.js +76 -29
- package/dist/esm/i18next.js +76 -29
- package/dist/esm/package.json +1 -1
- package/dist/umd/i18next.js +76 -29
- package/dist/umd/i18next.min.js +1 -1
- package/i18next.js +76 -29
- package/i18next.min.js +1 -1
- package/index.d.ts +81 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,8 +13,8 @@ i18next is a very popular internationalization framework for browser or any othe
|
|
|
13
13
|
|
|
14
14
|
i18next provides:
|
|
15
15
|
|
|
16
|
-
- Flexible connection to [backend](https://www.i18next.com/plugins-and-utils
|
|
17
|
-
- Optional [caching](https://www.i18next.com/
|
|
16
|
+
- Flexible connection to [backend](https://www.i18next.com/overview/plugins-and-utils#backends) (loading translations via xhr, ...)
|
|
17
|
+
- Optional [caching](https://www.i18next.com/how-to/caching), user [language detection](https://www.i18next.com/overview/plugins-and-utils#language-detector), ...
|
|
18
18
|
- Proper [pluralizations](https://www.i18next.com/translation-function/plurals)
|
|
19
19
|
- Translation [context](https://www.i18next.com/translation-function/context)
|
|
20
20
|
- [Nesting](https://www.i18next.com/translation-function/nesting), [Variable replacement](https://www.i18next.com/translation-function/interpolation)
|
package/dist/cjs/i18next.js
CHANGED
|
@@ -672,6 +672,7 @@ var Translator = function (_EventEmitter) {
|
|
|
672
672
|
if (!options) options = {};
|
|
673
673
|
if (keys === undefined || keys === null) return '';
|
|
674
674
|
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
675
|
+
var returnDetails = options.returnDetails !== undefined ? options.returnDetails : this.options.returnDetails;
|
|
675
676
|
var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
676
677
|
|
|
677
678
|
var _this$extractFromKey = this.extractFromKey(keys[keys.length - 1], options),
|
|
@@ -685,7 +686,18 @@ var Translator = function (_EventEmitter) {
|
|
|
685
686
|
if (lng && lng.toLowerCase() === 'cimode') {
|
|
686
687
|
if (appendNamespaceToCIMode) {
|
|
687
688
|
var nsSeparator = options.nsSeparator || this.options.nsSeparator;
|
|
688
|
-
|
|
689
|
+
|
|
690
|
+
if (returnDetails) {
|
|
691
|
+
resolved.res = "".concat(namespace).concat(nsSeparator).concat(key);
|
|
692
|
+
return resolved;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
return "".concat(namespace).concat(nsSeparator).concat(key);
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
if (returnDetails) {
|
|
699
|
+
resolved.res = key;
|
|
700
|
+
return resolved;
|
|
689
701
|
}
|
|
690
702
|
|
|
691
703
|
return key;
|
|
@@ -707,9 +719,16 @@ var Translator = function (_EventEmitter) {
|
|
|
707
719
|
this.logger.warn('accessing an object - but returnObjects options is not enabled!');
|
|
708
720
|
}
|
|
709
721
|
|
|
710
|
-
|
|
722
|
+
var r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, _objectSpread$2(_objectSpread$2({}, options), {}, {
|
|
711
723
|
ns: namespaces
|
|
712
724
|
})) : "key '".concat(key, " (").concat(this.language, ")' returned an object instead of string.");
|
|
725
|
+
|
|
726
|
+
if (returnDetails) {
|
|
727
|
+
resolved.res = r;
|
|
728
|
+
return resolved;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
return r;
|
|
713
732
|
}
|
|
714
733
|
|
|
715
734
|
if (keySeparator) {
|
|
@@ -815,6 +834,11 @@ var Translator = function (_EventEmitter) {
|
|
|
815
834
|
}
|
|
816
835
|
}
|
|
817
836
|
|
|
837
|
+
if (returnDetails) {
|
|
838
|
+
resolved.res = res;
|
|
839
|
+
return resolved;
|
|
840
|
+
}
|
|
841
|
+
|
|
818
842
|
return res;
|
|
819
843
|
}
|
|
820
844
|
}, {
|
|
@@ -1824,13 +1848,9 @@ function _createSuper$2(Derived) { var hasNativeReflectConstruct = _isNativeRefl
|
|
|
1824
1848
|
|
|
1825
1849
|
function _isNativeReflectConstruct$2() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
1826
1850
|
|
|
1827
|
-
function
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
while (found !== -1) {
|
|
1831
|
-
arr.splice(found, 1);
|
|
1832
|
-
found = arr.indexOf(what);
|
|
1833
|
-
}
|
|
1851
|
+
function removePending(q, name) {
|
|
1852
|
+
delete q.pending[name];
|
|
1853
|
+
q.pendingCount--;
|
|
1834
1854
|
}
|
|
1835
1855
|
|
|
1836
1856
|
var Connector = function (_EventEmitter) {
|
|
@@ -1857,6 +1877,9 @@ var Connector = function (_EventEmitter) {
|
|
|
1857
1877
|
_this.languageUtils = services.languageUtils;
|
|
1858
1878
|
_this.options = options;
|
|
1859
1879
|
_this.logger = baseLogger.create('backendConnector');
|
|
1880
|
+
_this.waitingReads = [];
|
|
1881
|
+
_this.maxParallelReads = options.maxParallelReads || 10;
|
|
1882
|
+
_this.readingCalls = 0;
|
|
1860
1883
|
_this.state = {};
|
|
1861
1884
|
_this.queue = [];
|
|
1862
1885
|
|
|
@@ -1872,10 +1895,10 @@ var Connector = function (_EventEmitter) {
|
|
|
1872
1895
|
value: function queueLoad(languages, namespaces, options, callback) {
|
|
1873
1896
|
var _this2 = this;
|
|
1874
1897
|
|
|
1875
|
-
var toLoad =
|
|
1876
|
-
var pending =
|
|
1877
|
-
var toLoadLanguages =
|
|
1878
|
-
var toLoadNamespaces =
|
|
1898
|
+
var toLoad = {};
|
|
1899
|
+
var pending = {};
|
|
1900
|
+
var toLoadLanguages = {};
|
|
1901
|
+
var toLoadNamespaces = {};
|
|
1879
1902
|
languages.forEach(function (lng) {
|
|
1880
1903
|
var hasAllNamespaces = true;
|
|
1881
1904
|
namespaces.forEach(function (ns) {
|
|
@@ -1884,21 +1907,22 @@ var Connector = function (_EventEmitter) {
|
|
|
1884
1907
|
if (!options.reload && _this2.store.hasResourceBundle(lng, ns)) {
|
|
1885
1908
|
_this2.state[name] = 2;
|
|
1886
1909
|
} else if (_this2.state[name] < 0) ; else if (_this2.state[name] === 1) {
|
|
1887
|
-
if (pending
|
|
1910
|
+
if (pending[name] !== undefined) pending[name] = true;
|
|
1888
1911
|
} else {
|
|
1889
1912
|
_this2.state[name] = 1;
|
|
1890
1913
|
hasAllNamespaces = false;
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1914
|
+
pending[name] = true;
|
|
1915
|
+
toLoad[name] = true;
|
|
1916
|
+
toLoadNamespaces[ns] = true;
|
|
1894
1917
|
}
|
|
1895
1918
|
});
|
|
1896
|
-
if (!hasAllNamespaces) toLoadLanguages
|
|
1919
|
+
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
1897
1920
|
});
|
|
1898
1921
|
|
|
1899
|
-
if (toLoad.length || pending.length) {
|
|
1922
|
+
if (Object.keys(toLoad).length || Object.keys(pending).length) {
|
|
1900
1923
|
this.queue.push({
|
|
1901
1924
|
pending: pending,
|
|
1925
|
+
pendingCount: Object.keys(pending).length,
|
|
1902
1926
|
loaded: {},
|
|
1903
1927
|
errors: [],
|
|
1904
1928
|
callback: callback
|
|
@@ -1906,10 +1930,10 @@ var Connector = function (_EventEmitter) {
|
|
|
1906
1930
|
}
|
|
1907
1931
|
|
|
1908
1932
|
return {
|
|
1909
|
-
toLoad: toLoad,
|
|
1910
|
-
pending: pending,
|
|
1911
|
-
toLoadLanguages: toLoadLanguages,
|
|
1912
|
-
toLoadNamespaces: toLoadNamespaces
|
|
1933
|
+
toLoad: Object.keys(toLoad),
|
|
1934
|
+
pending: Object.keys(pending),
|
|
1935
|
+
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
1936
|
+
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
1913
1937
|
};
|
|
1914
1938
|
}
|
|
1915
1939
|
}, {
|
|
@@ -1928,16 +1952,17 @@ var Connector = function (_EventEmitter) {
|
|
|
1928
1952
|
var loaded = {};
|
|
1929
1953
|
this.queue.forEach(function (q) {
|
|
1930
1954
|
pushPath(q.loaded, [lng], ns);
|
|
1931
|
-
|
|
1955
|
+
removePending(q, name);
|
|
1932
1956
|
if (err) q.errors.push(err);
|
|
1933
1957
|
|
|
1934
|
-
if (q.
|
|
1958
|
+
if (q.pendingCount === 0 && !q.done) {
|
|
1935
1959
|
Object.keys(q.loaded).forEach(function (l) {
|
|
1936
|
-
if (!loaded[l]) loaded[l] =
|
|
1960
|
+
if (!loaded[l]) loaded[l] = {};
|
|
1961
|
+
var loadedKeys = Object.keys(loaded[l]);
|
|
1937
1962
|
|
|
1938
|
-
if (
|
|
1939
|
-
|
|
1940
|
-
if (
|
|
1963
|
+
if (loadedKeys.length) {
|
|
1964
|
+
loadedKeys.forEach(function (ns) {
|
|
1965
|
+
if (loadedKeys[ns] !== undefined) loaded[l][ns] = true;
|
|
1941
1966
|
});
|
|
1942
1967
|
}
|
|
1943
1968
|
});
|
|
@@ -1964,6 +1989,20 @@ var Connector = function (_EventEmitter) {
|
|
|
1964
1989
|
var wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 350;
|
|
1965
1990
|
var callback = arguments.length > 5 ? arguments[5] : undefined;
|
|
1966
1991
|
if (!lng.length) return callback(null, {});
|
|
1992
|
+
|
|
1993
|
+
if (this.readingCalls >= this.maxParallelReads) {
|
|
1994
|
+
this.waitingReads.push({
|
|
1995
|
+
lng: lng,
|
|
1996
|
+
ns: ns,
|
|
1997
|
+
fcName: fcName,
|
|
1998
|
+
tried: tried,
|
|
1999
|
+
wait: wait,
|
|
2000
|
+
callback: callback
|
|
2001
|
+
});
|
|
2002
|
+
return;
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
this.readingCalls++;
|
|
1967
2006
|
return this.backend[fcName](lng, ns, function (err, data) {
|
|
1968
2007
|
if (err && data && tried < 5) {
|
|
1969
2008
|
setTimeout(function () {
|
|
@@ -1972,6 +2011,14 @@ var Connector = function (_EventEmitter) {
|
|
|
1972
2011
|
return;
|
|
1973
2012
|
}
|
|
1974
2013
|
|
|
2014
|
+
_this3.readingCalls--;
|
|
2015
|
+
|
|
2016
|
+
if (_this3.waitingReads.length > 0) {
|
|
2017
|
+
var next = _this3.waitingReads.shift();
|
|
2018
|
+
|
|
2019
|
+
_this3.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
2020
|
+
}
|
|
2021
|
+
|
|
1975
2022
|
callback(err, data);
|
|
1976
2023
|
});
|
|
1977
2024
|
}
|
|
@@ -834,6 +834,7 @@ var Translator = function (_EventEmitter) {
|
|
|
834
834
|
if (!options) options = {};
|
|
835
835
|
if (keys === undefined || keys === null) return '';
|
|
836
836
|
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
837
|
+
var returnDetails = options.returnDetails !== undefined ? options.returnDetails : this.options.returnDetails;
|
|
837
838
|
var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
838
839
|
|
|
839
840
|
var _this$extractFromKey = this.extractFromKey(keys[keys.length - 1], options),
|
|
@@ -847,7 +848,18 @@ var Translator = function (_EventEmitter) {
|
|
|
847
848
|
if (lng && lng.toLowerCase() === 'cimode') {
|
|
848
849
|
if (appendNamespaceToCIMode) {
|
|
849
850
|
var nsSeparator = options.nsSeparator || this.options.nsSeparator;
|
|
850
|
-
|
|
851
|
+
|
|
852
|
+
if (returnDetails) {
|
|
853
|
+
resolved.res = "".concat(namespace).concat(nsSeparator).concat(key);
|
|
854
|
+
return resolved;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
return "".concat(namespace).concat(nsSeparator).concat(key);
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
if (returnDetails) {
|
|
861
|
+
resolved.res = key;
|
|
862
|
+
return resolved;
|
|
851
863
|
}
|
|
852
864
|
|
|
853
865
|
return key;
|
|
@@ -869,9 +881,16 @@ var Translator = function (_EventEmitter) {
|
|
|
869
881
|
this.logger.warn('accessing an object - but returnObjects options is not enabled!');
|
|
870
882
|
}
|
|
871
883
|
|
|
872
|
-
|
|
884
|
+
var r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
873
885
|
ns: namespaces
|
|
874
886
|
})) : "key '".concat(key, " (").concat(this.language, ")' returned an object instead of string.");
|
|
887
|
+
|
|
888
|
+
if (returnDetails) {
|
|
889
|
+
resolved.res = r;
|
|
890
|
+
return resolved;
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
return r;
|
|
875
894
|
}
|
|
876
895
|
|
|
877
896
|
if (keySeparator) {
|
|
@@ -977,6 +996,11 @@ var Translator = function (_EventEmitter) {
|
|
|
977
996
|
}
|
|
978
997
|
}
|
|
979
998
|
|
|
999
|
+
if (returnDetails) {
|
|
1000
|
+
resolved.res = res;
|
|
1001
|
+
return resolved;
|
|
1002
|
+
}
|
|
1003
|
+
|
|
980
1004
|
return res;
|
|
981
1005
|
}
|
|
982
1006
|
}, {
|
|
@@ -1970,13 +1994,9 @@ var Formatter = function () {
|
|
|
1970
1994
|
return Formatter;
|
|
1971
1995
|
}();
|
|
1972
1996
|
|
|
1973
|
-
function
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
while (found !== -1) {
|
|
1977
|
-
arr.splice(found, 1);
|
|
1978
|
-
found = arr.indexOf(what);
|
|
1979
|
-
}
|
|
1997
|
+
function removePending(q, name) {
|
|
1998
|
+
delete q.pending[name];
|
|
1999
|
+
q.pendingCount--;
|
|
1980
2000
|
}
|
|
1981
2001
|
|
|
1982
2002
|
var Connector = function (_EventEmitter) {
|
|
@@ -2003,6 +2023,9 @@ var Connector = function (_EventEmitter) {
|
|
|
2003
2023
|
_this.languageUtils = services.languageUtils;
|
|
2004
2024
|
_this.options = options;
|
|
2005
2025
|
_this.logger = baseLogger.create('backendConnector');
|
|
2026
|
+
_this.waitingReads = [];
|
|
2027
|
+
_this.maxParallelReads = options.maxParallelReads || 10;
|
|
2028
|
+
_this.readingCalls = 0;
|
|
2006
2029
|
_this.state = {};
|
|
2007
2030
|
_this.queue = [];
|
|
2008
2031
|
|
|
@@ -2018,10 +2041,10 @@ var Connector = function (_EventEmitter) {
|
|
|
2018
2041
|
value: function queueLoad(languages, namespaces, options, callback) {
|
|
2019
2042
|
var _this2 = this;
|
|
2020
2043
|
|
|
2021
|
-
var toLoad =
|
|
2022
|
-
var pending =
|
|
2023
|
-
var toLoadLanguages =
|
|
2024
|
-
var toLoadNamespaces =
|
|
2044
|
+
var toLoad = {};
|
|
2045
|
+
var pending = {};
|
|
2046
|
+
var toLoadLanguages = {};
|
|
2047
|
+
var toLoadNamespaces = {};
|
|
2025
2048
|
languages.forEach(function (lng) {
|
|
2026
2049
|
var hasAllNamespaces = true;
|
|
2027
2050
|
namespaces.forEach(function (ns) {
|
|
@@ -2030,21 +2053,22 @@ var Connector = function (_EventEmitter) {
|
|
|
2030
2053
|
if (!options.reload && _this2.store.hasResourceBundle(lng, ns)) {
|
|
2031
2054
|
_this2.state[name] = 2;
|
|
2032
2055
|
} else if (_this2.state[name] < 0) ; else if (_this2.state[name] === 1) {
|
|
2033
|
-
if (pending
|
|
2056
|
+
if (pending[name] !== undefined) pending[name] = true;
|
|
2034
2057
|
} else {
|
|
2035
2058
|
_this2.state[name] = 1;
|
|
2036
2059
|
hasAllNamespaces = false;
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2060
|
+
pending[name] = true;
|
|
2061
|
+
toLoad[name] = true;
|
|
2062
|
+
toLoadNamespaces[ns] = true;
|
|
2040
2063
|
}
|
|
2041
2064
|
});
|
|
2042
|
-
if (!hasAllNamespaces) toLoadLanguages
|
|
2065
|
+
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
2043
2066
|
});
|
|
2044
2067
|
|
|
2045
|
-
if (toLoad.length || pending.length) {
|
|
2068
|
+
if (Object.keys(toLoad).length || Object.keys(pending).length) {
|
|
2046
2069
|
this.queue.push({
|
|
2047
2070
|
pending: pending,
|
|
2071
|
+
pendingCount: Object.keys(pending).length,
|
|
2048
2072
|
loaded: {},
|
|
2049
2073
|
errors: [],
|
|
2050
2074
|
callback: callback
|
|
@@ -2052,10 +2076,10 @@ var Connector = function (_EventEmitter) {
|
|
|
2052
2076
|
}
|
|
2053
2077
|
|
|
2054
2078
|
return {
|
|
2055
|
-
toLoad: toLoad,
|
|
2056
|
-
pending: pending,
|
|
2057
|
-
toLoadLanguages: toLoadLanguages,
|
|
2058
|
-
toLoadNamespaces: toLoadNamespaces
|
|
2079
|
+
toLoad: Object.keys(toLoad),
|
|
2080
|
+
pending: Object.keys(pending),
|
|
2081
|
+
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
2082
|
+
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
2059
2083
|
};
|
|
2060
2084
|
}
|
|
2061
2085
|
}, {
|
|
@@ -2074,16 +2098,17 @@ var Connector = function (_EventEmitter) {
|
|
|
2074
2098
|
var loaded = {};
|
|
2075
2099
|
this.queue.forEach(function (q) {
|
|
2076
2100
|
pushPath(q.loaded, [lng], ns);
|
|
2077
|
-
|
|
2101
|
+
removePending(q, name);
|
|
2078
2102
|
if (err) q.errors.push(err);
|
|
2079
2103
|
|
|
2080
|
-
if (q.
|
|
2104
|
+
if (q.pendingCount === 0 && !q.done) {
|
|
2081
2105
|
Object.keys(q.loaded).forEach(function (l) {
|
|
2082
|
-
if (!loaded[l]) loaded[l] =
|
|
2106
|
+
if (!loaded[l]) loaded[l] = {};
|
|
2107
|
+
var loadedKeys = Object.keys(loaded[l]);
|
|
2083
2108
|
|
|
2084
|
-
if (
|
|
2085
|
-
|
|
2086
|
-
if (
|
|
2109
|
+
if (loadedKeys.length) {
|
|
2110
|
+
loadedKeys.forEach(function (ns) {
|
|
2111
|
+
if (loadedKeys[ns] !== undefined) loaded[l][ns] = true;
|
|
2087
2112
|
});
|
|
2088
2113
|
}
|
|
2089
2114
|
});
|
|
@@ -2110,6 +2135,20 @@ var Connector = function (_EventEmitter) {
|
|
|
2110
2135
|
var wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 350;
|
|
2111
2136
|
var callback = arguments.length > 5 ? arguments[5] : undefined;
|
|
2112
2137
|
if (!lng.length) return callback(null, {});
|
|
2138
|
+
|
|
2139
|
+
if (this.readingCalls >= this.maxParallelReads) {
|
|
2140
|
+
this.waitingReads.push({
|
|
2141
|
+
lng: lng,
|
|
2142
|
+
ns: ns,
|
|
2143
|
+
fcName: fcName,
|
|
2144
|
+
tried: tried,
|
|
2145
|
+
wait: wait,
|
|
2146
|
+
callback: callback
|
|
2147
|
+
});
|
|
2148
|
+
return;
|
|
2149
|
+
}
|
|
2150
|
+
|
|
2151
|
+
this.readingCalls++;
|
|
2113
2152
|
return this.backend[fcName](lng, ns, function (err, data) {
|
|
2114
2153
|
if (err && data && tried < 5) {
|
|
2115
2154
|
setTimeout(function () {
|
|
@@ -2118,6 +2157,14 @@ var Connector = function (_EventEmitter) {
|
|
|
2118
2157
|
return;
|
|
2119
2158
|
}
|
|
2120
2159
|
|
|
2160
|
+
_this3.readingCalls--;
|
|
2161
|
+
|
|
2162
|
+
if (_this3.waitingReads.length > 0) {
|
|
2163
|
+
var next = _this3.waitingReads.shift();
|
|
2164
|
+
|
|
2165
|
+
_this3.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
2166
|
+
}
|
|
2167
|
+
|
|
2121
2168
|
callback(err, data);
|
|
2122
2169
|
});
|
|
2123
2170
|
}
|
package/dist/esm/i18next.js
CHANGED
|
@@ -658,6 +658,7 @@ var Translator = function (_EventEmitter) {
|
|
|
658
658
|
if (!options) options = {};
|
|
659
659
|
if (keys === undefined || keys === null) return '';
|
|
660
660
|
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
661
|
+
var returnDetails = options.returnDetails !== undefined ? options.returnDetails : this.options.returnDetails;
|
|
661
662
|
var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
662
663
|
|
|
663
664
|
var _this$extractFromKey = this.extractFromKey(keys[keys.length - 1], options),
|
|
@@ -671,7 +672,18 @@ var Translator = function (_EventEmitter) {
|
|
|
671
672
|
if (lng && lng.toLowerCase() === 'cimode') {
|
|
672
673
|
if (appendNamespaceToCIMode) {
|
|
673
674
|
var nsSeparator = options.nsSeparator || this.options.nsSeparator;
|
|
674
|
-
|
|
675
|
+
|
|
676
|
+
if (returnDetails) {
|
|
677
|
+
resolved.res = "".concat(namespace).concat(nsSeparator).concat(key);
|
|
678
|
+
return resolved;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
return "".concat(namespace).concat(nsSeparator).concat(key);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
if (returnDetails) {
|
|
685
|
+
resolved.res = key;
|
|
686
|
+
return resolved;
|
|
675
687
|
}
|
|
676
688
|
|
|
677
689
|
return key;
|
|
@@ -693,9 +705,16 @@ var Translator = function (_EventEmitter) {
|
|
|
693
705
|
this.logger.warn('accessing an object - but returnObjects options is not enabled!');
|
|
694
706
|
}
|
|
695
707
|
|
|
696
|
-
|
|
708
|
+
var r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, _objectSpread$2(_objectSpread$2({}, options), {}, {
|
|
697
709
|
ns: namespaces
|
|
698
710
|
})) : "key '".concat(key, " (").concat(this.language, ")' returned an object instead of string.");
|
|
711
|
+
|
|
712
|
+
if (returnDetails) {
|
|
713
|
+
resolved.res = r;
|
|
714
|
+
return resolved;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
return r;
|
|
699
718
|
}
|
|
700
719
|
|
|
701
720
|
if (keySeparator) {
|
|
@@ -801,6 +820,11 @@ var Translator = function (_EventEmitter) {
|
|
|
801
820
|
}
|
|
802
821
|
}
|
|
803
822
|
|
|
823
|
+
if (returnDetails) {
|
|
824
|
+
resolved.res = res;
|
|
825
|
+
return resolved;
|
|
826
|
+
}
|
|
827
|
+
|
|
804
828
|
return res;
|
|
805
829
|
}
|
|
806
830
|
}, {
|
|
@@ -1810,13 +1834,9 @@ function _createSuper$2(Derived) { var hasNativeReflectConstruct = _isNativeRefl
|
|
|
1810
1834
|
|
|
1811
1835
|
function _isNativeReflectConstruct$2() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
1812
1836
|
|
|
1813
|
-
function
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
while (found !== -1) {
|
|
1817
|
-
arr.splice(found, 1);
|
|
1818
|
-
found = arr.indexOf(what);
|
|
1819
|
-
}
|
|
1837
|
+
function removePending(q, name) {
|
|
1838
|
+
delete q.pending[name];
|
|
1839
|
+
q.pendingCount--;
|
|
1820
1840
|
}
|
|
1821
1841
|
|
|
1822
1842
|
var Connector = function (_EventEmitter) {
|
|
@@ -1843,6 +1863,9 @@ var Connector = function (_EventEmitter) {
|
|
|
1843
1863
|
_this.languageUtils = services.languageUtils;
|
|
1844
1864
|
_this.options = options;
|
|
1845
1865
|
_this.logger = baseLogger.create('backendConnector');
|
|
1866
|
+
_this.waitingReads = [];
|
|
1867
|
+
_this.maxParallelReads = options.maxParallelReads || 10;
|
|
1868
|
+
_this.readingCalls = 0;
|
|
1846
1869
|
_this.state = {};
|
|
1847
1870
|
_this.queue = [];
|
|
1848
1871
|
|
|
@@ -1858,10 +1881,10 @@ var Connector = function (_EventEmitter) {
|
|
|
1858
1881
|
value: function queueLoad(languages, namespaces, options, callback) {
|
|
1859
1882
|
var _this2 = this;
|
|
1860
1883
|
|
|
1861
|
-
var toLoad =
|
|
1862
|
-
var pending =
|
|
1863
|
-
var toLoadLanguages =
|
|
1864
|
-
var toLoadNamespaces =
|
|
1884
|
+
var toLoad = {};
|
|
1885
|
+
var pending = {};
|
|
1886
|
+
var toLoadLanguages = {};
|
|
1887
|
+
var toLoadNamespaces = {};
|
|
1865
1888
|
languages.forEach(function (lng) {
|
|
1866
1889
|
var hasAllNamespaces = true;
|
|
1867
1890
|
namespaces.forEach(function (ns) {
|
|
@@ -1870,21 +1893,22 @@ var Connector = function (_EventEmitter) {
|
|
|
1870
1893
|
if (!options.reload && _this2.store.hasResourceBundle(lng, ns)) {
|
|
1871
1894
|
_this2.state[name] = 2;
|
|
1872
1895
|
} else if (_this2.state[name] < 0) ; else if (_this2.state[name] === 1) {
|
|
1873
|
-
if (pending
|
|
1896
|
+
if (pending[name] !== undefined) pending[name] = true;
|
|
1874
1897
|
} else {
|
|
1875
1898
|
_this2.state[name] = 1;
|
|
1876
1899
|
hasAllNamespaces = false;
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1900
|
+
pending[name] = true;
|
|
1901
|
+
toLoad[name] = true;
|
|
1902
|
+
toLoadNamespaces[ns] = true;
|
|
1880
1903
|
}
|
|
1881
1904
|
});
|
|
1882
|
-
if (!hasAllNamespaces) toLoadLanguages
|
|
1905
|
+
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
1883
1906
|
});
|
|
1884
1907
|
|
|
1885
|
-
if (toLoad.length || pending.length) {
|
|
1908
|
+
if (Object.keys(toLoad).length || Object.keys(pending).length) {
|
|
1886
1909
|
this.queue.push({
|
|
1887
1910
|
pending: pending,
|
|
1911
|
+
pendingCount: Object.keys(pending).length,
|
|
1888
1912
|
loaded: {},
|
|
1889
1913
|
errors: [],
|
|
1890
1914
|
callback: callback
|
|
@@ -1892,10 +1916,10 @@ var Connector = function (_EventEmitter) {
|
|
|
1892
1916
|
}
|
|
1893
1917
|
|
|
1894
1918
|
return {
|
|
1895
|
-
toLoad: toLoad,
|
|
1896
|
-
pending: pending,
|
|
1897
|
-
toLoadLanguages: toLoadLanguages,
|
|
1898
|
-
toLoadNamespaces: toLoadNamespaces
|
|
1919
|
+
toLoad: Object.keys(toLoad),
|
|
1920
|
+
pending: Object.keys(pending),
|
|
1921
|
+
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
1922
|
+
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
1899
1923
|
};
|
|
1900
1924
|
}
|
|
1901
1925
|
}, {
|
|
@@ -1914,16 +1938,17 @@ var Connector = function (_EventEmitter) {
|
|
|
1914
1938
|
var loaded = {};
|
|
1915
1939
|
this.queue.forEach(function (q) {
|
|
1916
1940
|
pushPath(q.loaded, [lng], ns);
|
|
1917
|
-
|
|
1941
|
+
removePending(q, name);
|
|
1918
1942
|
if (err) q.errors.push(err);
|
|
1919
1943
|
|
|
1920
|
-
if (q.
|
|
1944
|
+
if (q.pendingCount === 0 && !q.done) {
|
|
1921
1945
|
Object.keys(q.loaded).forEach(function (l) {
|
|
1922
|
-
if (!loaded[l]) loaded[l] =
|
|
1946
|
+
if (!loaded[l]) loaded[l] = {};
|
|
1947
|
+
var loadedKeys = Object.keys(loaded[l]);
|
|
1923
1948
|
|
|
1924
|
-
if (
|
|
1925
|
-
|
|
1926
|
-
if (
|
|
1949
|
+
if (loadedKeys.length) {
|
|
1950
|
+
loadedKeys.forEach(function (ns) {
|
|
1951
|
+
if (loadedKeys[ns] !== undefined) loaded[l][ns] = true;
|
|
1927
1952
|
});
|
|
1928
1953
|
}
|
|
1929
1954
|
});
|
|
@@ -1950,6 +1975,20 @@ var Connector = function (_EventEmitter) {
|
|
|
1950
1975
|
var wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 350;
|
|
1951
1976
|
var callback = arguments.length > 5 ? arguments[5] : undefined;
|
|
1952
1977
|
if (!lng.length) return callback(null, {});
|
|
1978
|
+
|
|
1979
|
+
if (this.readingCalls >= this.maxParallelReads) {
|
|
1980
|
+
this.waitingReads.push({
|
|
1981
|
+
lng: lng,
|
|
1982
|
+
ns: ns,
|
|
1983
|
+
fcName: fcName,
|
|
1984
|
+
tried: tried,
|
|
1985
|
+
wait: wait,
|
|
1986
|
+
callback: callback
|
|
1987
|
+
});
|
|
1988
|
+
return;
|
|
1989
|
+
}
|
|
1990
|
+
|
|
1991
|
+
this.readingCalls++;
|
|
1953
1992
|
return this.backend[fcName](lng, ns, function (err, data) {
|
|
1954
1993
|
if (err && data && tried < 5) {
|
|
1955
1994
|
setTimeout(function () {
|
|
@@ -1958,6 +1997,14 @@ var Connector = function (_EventEmitter) {
|
|
|
1958
1997
|
return;
|
|
1959
1998
|
}
|
|
1960
1999
|
|
|
2000
|
+
_this3.readingCalls--;
|
|
2001
|
+
|
|
2002
|
+
if (_this3.waitingReads.length > 0) {
|
|
2003
|
+
var next = _this3.waitingReads.shift();
|
|
2004
|
+
|
|
2005
|
+
_this3.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
2006
|
+
}
|
|
2007
|
+
|
|
1961
2008
|
callback(err, data);
|
|
1962
2009
|
});
|
|
1963
2010
|
}
|
package/dist/esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"21.
|
|
1
|
+
{"type":"module","version":"21.8.0"}
|