@spscommerce/i18n 3.12.3 → 3.15.4

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/lib/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from "./localize";
2
- export * from "./SpsLanguage";
3
- export * from "./useSpsLanguage";
1
+ export * from './localize';
2
+ export * from './SpsLanguage';
3
+ export * from './useSpsLanguage';
package/lib/index.esm.js CHANGED
@@ -44,23 +44,23 @@ function __rest(s, e) {
44
44
  return t;
45
45
  }
46
46
 
47
- function _typeof$3(obj) {
47
+ function _typeof$2(obj) {
48
48
  "@babel/helpers - typeof";
49
49
 
50
50
  if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
51
- _typeof$3 = function _typeof(obj) {
51
+ _typeof$2 = function _typeof(obj) {
52
52
  return typeof obj;
53
53
  };
54
54
  } else {
55
- _typeof$3 = function _typeof(obj) {
55
+ _typeof$2 = function _typeof(obj) {
56
56
  return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
57
57
  };
58
58
  }
59
59
 
60
- return _typeof$3(obj);
60
+ return _typeof$2(obj);
61
61
  }
62
62
 
63
- function _defineProperty$2(obj, key, value) {
63
+ function _defineProperty$1(obj, key, value) {
64
64
  if (key in obj) {
65
65
  Object.defineProperty(obj, key, {
66
66
  value: value,
@@ -87,20 +87,20 @@ function _objectSpread$3(target) {
87
87
  }
88
88
 
89
89
  ownKeys.forEach(function (key) {
90
- _defineProperty$2(target, key, source[key]);
90
+ _defineProperty$1(target, key, source[key]);
91
91
  });
92
92
  }
93
93
 
94
94
  return target;
95
95
  }
96
96
 
97
- function _classCallCheck$3(instance, Constructor) {
97
+ function _classCallCheck$1(instance, Constructor) {
98
98
  if (!(instance instanceof Constructor)) {
99
99
  throw new TypeError("Cannot call a class as a function");
100
100
  }
101
101
  }
102
102
 
103
- function _defineProperties$3(target, props) {
103
+ function _defineProperties$1(target, props) {
104
104
  for (var i = 0; i < props.length; i++) {
105
105
  var descriptor = props[i];
106
106
  descriptor.enumerable = descriptor.enumerable || false;
@@ -110,9 +110,9 @@ function _defineProperties$3(target, props) {
110
110
  }
111
111
  }
112
112
 
113
- function _createClass$3(Constructor, protoProps, staticProps) {
114
- if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
115
- if (staticProps) _defineProperties$3(Constructor, staticProps);
113
+ function _createClass$1(Constructor, protoProps, staticProps) {
114
+ if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
115
+ if (staticProps) _defineProperties$1(Constructor, staticProps);
116
116
  return Constructor;
117
117
  }
118
118
 
@@ -125,7 +125,7 @@ function _assertThisInitialized(self) {
125
125
  }
126
126
 
127
127
  function _possibleConstructorReturn(self, call) {
128
- if (call && (_typeof$3(call) === "object" || typeof call === "function")) {
128
+ if (call && (_typeof$2(call) === "object" || typeof call === "function")) {
129
129
  return call;
130
130
  }
131
131
 
@@ -183,12 +183,12 @@ var Logger = function () {
183
183
  function Logger(concreteLogger) {
184
184
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
185
185
 
186
- _classCallCheck$3(this, Logger);
186
+ _classCallCheck$1(this, Logger);
187
187
 
188
188
  this.init(concreteLogger, options);
189
189
  }
190
190
 
191
- _createClass$3(Logger, [{
191
+ _createClass$1(Logger, [{
192
192
  key: "init",
193
193
  value: function init(concreteLogger) {
194
194
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -261,12 +261,12 @@ var baseLogger = new Logger();
261
261
 
262
262
  var EventEmitter = function () {
263
263
  function EventEmitter() {
264
- _classCallCheck$3(this, EventEmitter);
264
+ _classCallCheck$1(this, EventEmitter);
265
265
 
266
266
  this.observers = {};
267
267
  }
268
268
 
269
- _createClass$3(EventEmitter, [{
269
+ _createClass$1(EventEmitter, [{
270
270
  key: "on",
271
271
  value: function on(events, listener) {
272
272
  var _this = this;
@@ -355,7 +355,12 @@ function getLastOfPath(object, path, Empty) {
355
355
  if (canNotTraverseDeeper()) return {};
356
356
  var key = cleanKey(stack.shift());
357
357
  if (!object[key] && Empty) object[key] = new Empty();
358
- object = object[key];
358
+
359
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
360
+ object = object[key];
361
+ } else {
362
+ object = {};
363
+ }
359
364
  }
360
365
 
361
366
  if (canNotTraverseDeeper()) return {};
@@ -448,7 +453,7 @@ var ResourceStore = function (_EventEmitter) {
448
453
  defaultNS: 'translation'
449
454
  };
450
455
 
451
- _classCallCheck$3(this, ResourceStore);
456
+ _classCallCheck$1(this, ResourceStore);
452
457
 
453
458
  _this = _possibleConstructorReturn(this, _getPrototypeOf(ResourceStore).call(this));
454
459
 
@@ -466,7 +471,7 @@ var ResourceStore = function (_EventEmitter) {
466
471
  return _this;
467
472
  }
468
473
 
469
- _createClass$3(ResourceStore, [{
474
+ _createClass$1(ResourceStore, [{
470
475
  key: "addNamespaces",
471
476
  value: function addNamespaces(ns) {
472
477
  if (this.options.ns.indexOf(ns) < 0) {
@@ -622,7 +627,7 @@ var Translator = function (_EventEmitter) {
622
627
 
623
628
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
624
629
 
625
- _classCallCheck$3(this, Translator);
630
+ _classCallCheck$1(this, Translator);
626
631
 
627
632
  _this = _possibleConstructorReturn(this, _getPrototypeOf(Translator).call(this));
628
633
 
@@ -641,7 +646,7 @@ var Translator = function (_EventEmitter) {
641
646
  return _this;
642
647
  }
643
648
 
644
- _createClass$3(Translator, [{
649
+ _createClass$1(Translator, [{
645
650
  key: "changeLanguage",
646
651
  value: function changeLanguage(lng) {
647
652
  if (lng) this.language = lng;
@@ -689,7 +694,7 @@ var Translator = function (_EventEmitter) {
689
694
  value: function translate(keys, options, lastKey) {
690
695
  var _this2 = this;
691
696
 
692
- if (_typeof$3(options) !== 'object' && this.options.overloadTranslationOptionHandler) {
697
+ if (_typeof$2(options) !== 'object' && this.options.overloadTranslationOptionHandler) {
693
698
  options = this.options.overloadTranslationOptionHandler(arguments);
694
699
  }
695
700
 
@@ -733,21 +738,21 @@ var Translator = function (_EventEmitter) {
733
738
 
734
739
  if (keySeparator) {
735
740
  var resTypeIsArray = resType === '[object Array]';
736
- var copy$$1 = resTypeIsArray ? [] : {};
741
+ var copy = resTypeIsArray ? [] : {};
737
742
  var newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
738
743
 
739
744
  for (var m in res) {
740
745
  if (Object.prototype.hasOwnProperty.call(res, m)) {
741
746
  var deepKey = "".concat(newKeyToUse).concat(keySeparator).concat(m);
742
- copy$$1[m] = this.translate(deepKey, _objectSpread$3({}, options, {
747
+ copy[m] = this.translate(deepKey, _objectSpread$3({}, options, {
743
748
  joinArrays: false,
744
749
  ns: namespaces
745
750
  }));
746
- if (copy$$1[m] === deepKey) copy$$1[m] = res[m];
751
+ if (copy[m] === deepKey) copy[m] = res[m];
747
752
  }
748
753
  }
749
754
 
750
- res = copy$$1;
755
+ res = copy;
751
756
  }
752
757
  } else if (handleAsObjectInI18nFormat && typeof joinArrays === 'string' && resType === '[object Array]') {
753
758
  res = res.join(joinArrays);
@@ -755,16 +760,14 @@ var Translator = function (_EventEmitter) {
755
760
  } else {
756
761
  var usedDefault = false;
757
762
  var usedKey = false;
763
+ var needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
764
+ var hasDefaultValue = Translator.hasDefaultValue(options);
765
+ var defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count) : '';
766
+ var defaultValue = options["defaultValue".concat(defaultValueSuffix)] || options.defaultValue;
758
767
 
759
- if (!this.isValidLookup(res) && options.defaultValue !== undefined) {
768
+ if (!this.isValidLookup(res) && hasDefaultValue) {
760
769
  usedDefault = true;
761
-
762
- if (options.count !== undefined) {
763
- var suffix = this.pluralResolver.getSuffix(lng, options.count);
764
- res = options["defaultValue".concat(suffix)];
765
- }
766
-
767
- if (!res) res = options.defaultValue;
770
+ res = defaultValue;
768
771
  }
769
772
 
770
773
  if (!this.isValidLookup(res)) {
@@ -772,10 +775,10 @@ var Translator = function (_EventEmitter) {
772
775
  res = key;
773
776
  }
774
777
 
775
- var updateMissing = options.defaultValue && options.defaultValue !== res && this.options.updateMissing;
778
+ var updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
776
779
 
777
780
  if (usedKey || usedDefault || updateMissing) {
778
- this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? options.defaultValue : res);
781
+ this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? defaultValue : res);
779
782
 
780
783
  if (keySeparator) {
781
784
  var fk = this.resolve(key, _objectSpread$3({}, options, {
@@ -797,29 +800,25 @@ var Translator = function (_EventEmitter) {
797
800
  lngs.push(options.lng || this.language);
798
801
  }
799
802
 
800
- var send = function send(l, k) {
803
+ var send = function send(l, k, fallbackValue) {
801
804
  if (_this2.options.missingKeyHandler) {
802
- _this2.options.missingKeyHandler(l, namespace, k, updateMissing ? options.defaultValue : res, updateMissing, options);
805
+ _this2.options.missingKeyHandler(l, namespace, k, updateMissing ? fallbackValue : res, updateMissing, options);
803
806
  } else if (_this2.backendConnector && _this2.backendConnector.saveMissing) {
804
- _this2.backendConnector.saveMissing(l, namespace, k, updateMissing ? options.defaultValue : res, updateMissing, options);
807
+ _this2.backendConnector.saveMissing(l, namespace, k, updateMissing ? fallbackValue : res, updateMissing, options);
805
808
  }
806
809
 
807
810
  _this2.emit('missingKey', l, namespace, k, res);
808
811
  };
809
812
 
810
813
  if (this.options.saveMissing) {
811
- var needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
812
-
813
814
  if (this.options.saveMissingPlurals && needsPluralHandling) {
814
- lngs.forEach(function (l) {
815
- var plurals = _this2.pluralResolver.getPluralFormsOfKey(l, key);
816
-
817
- plurals.forEach(function (p) {
818
- return send([l], p);
815
+ lngs.forEach(function (language) {
816
+ _this2.pluralResolver.getSuffixes(language).forEach(function (suffix) {
817
+ send([language], key + suffix, options["defaultValue".concat(suffix)] || defaultValue);
819
818
  });
820
819
  });
821
820
  } else {
822
- send(lngs, key);
821
+ send(lngs, key, defaultValue);
823
822
  }
824
823
  }
825
824
  }
@@ -970,6 +969,19 @@ var Translator = function (_EventEmitter) {
970
969
  if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options);
971
970
  return this.resourceStore.getResource(code, ns, key, options);
972
971
  }
972
+ }], [{
973
+ key: "hasDefaultValue",
974
+ value: function hasDefaultValue(options) {
975
+ var prefix = 'defaultValue';
976
+
977
+ for (var option in options) {
978
+ if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && undefined !== options[option]) {
979
+ return true;
980
+ }
981
+ }
982
+
983
+ return false;
984
+ }
973
985
  }]);
974
986
 
975
987
  return Translator;
@@ -981,7 +993,7 @@ function capitalize(string) {
981
993
 
982
994
  var LanguageUtil = function () {
983
995
  function LanguageUtil(options) {
984
- _classCallCheck$3(this, LanguageUtil);
996
+ _classCallCheck$1(this, LanguageUtil);
985
997
 
986
998
  this.options = options;
987
999
  this.whitelist = this.options.supportedLngs || false;
@@ -989,7 +1001,7 @@ var LanguageUtil = function () {
989
1001
  this.logger = baseLogger.create('languageUtils');
990
1002
  }
991
1003
 
992
- _createClass$3(LanguageUtil, [{
1004
+ _createClass$1(LanguageUtil, [{
993
1005
  key: "getScriptPartFromCode",
994
1006
  value: function getScriptPartFromCode(code) {
995
1007
  if (!code || code.indexOf('-') < 0) return null;
@@ -1132,7 +1144,7 @@ var LanguageUtil = function () {
1132
1144
  }();
1133
1145
 
1134
1146
  var sets = [{
1135
- lngs: ['ach', 'ak', 'am', 'arn', 'br', 'fil', 'gun', 'ln', 'mfe', 'mg', 'mi', 'oc', 'pt', 'pt-BR', 'tg', 'ti', 'tr', 'uz', 'wa'],
1147
+ lngs: ['ach', 'ak', 'am', 'arn', 'br', 'fil', 'gun', 'ln', 'mfe', 'mg', 'mi', 'oc', 'pt', 'pt-BR', 'tg', 'tl', 'ti', 'tr', 'uz', 'wa'],
1136
1148
  nr: [1, 2],
1137
1149
  fc: 1
1138
1150
  }, {
@@ -1310,7 +1322,7 @@ var PluralResolver = function () {
1310
1322
  function PluralResolver(languageUtils) {
1311
1323
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1312
1324
 
1313
- _classCallCheck$3(this, PluralResolver);
1325
+ _classCallCheck$1(this, PluralResolver);
1314
1326
 
1315
1327
  this.languageUtils = languageUtils;
1316
1328
  this.options = options;
@@ -1318,7 +1330,7 @@ var PluralResolver = function () {
1318
1330
  this.rules = createRules();
1319
1331
  }
1320
1332
 
1321
- _createClass$3(PluralResolver, [{
1333
+ _createClass$1(PluralResolver, [{
1322
1334
  key: "addRule",
1323
1335
  value: function addRule(lng, obj) {
1324
1336
  this.rules[lng] = obj;
@@ -1337,17 +1349,24 @@ var PluralResolver = function () {
1337
1349
  }, {
1338
1350
  key: "getPluralFormsOfKey",
1339
1351
  value: function getPluralFormsOfKey(code, key) {
1352
+ return this.getSuffixes(code).map(function (suffix) {
1353
+ return key + suffix;
1354
+ });
1355
+ }
1356
+ }, {
1357
+ key: "getSuffixes",
1358
+ value: function getSuffixes(code) {
1340
1359
  var _this = this;
1341
1360
 
1342
- var ret = [];
1343
1361
  var rule = this.getRule(code);
1344
- if (!rule) return ret;
1345
- rule.numbers.forEach(function (n) {
1346
- var suffix = _this.getSuffix(code, n);
1347
1362
 
1348
- ret.push("".concat(key).concat(suffix));
1363
+ if (!rule) {
1364
+ return [];
1365
+ }
1366
+
1367
+ return rule.numbers.map(function (number) {
1368
+ return _this.getSuffix(code, number);
1349
1369
  });
1350
- return ret;
1351
1370
  }
1352
1371
  }, {
1353
1372
  key: "getSuffix",
@@ -1397,7 +1416,7 @@ var Interpolator = function () {
1397
1416
  function Interpolator() {
1398
1417
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1399
1418
 
1400
- _classCallCheck$3(this, Interpolator);
1419
+ _classCallCheck$1(this, Interpolator);
1401
1420
 
1402
1421
  this.logger = baseLogger.create('interpolator');
1403
1422
  this.options = options;
@@ -1409,7 +1428,7 @@ var Interpolator = function () {
1409
1428
  this.init(options);
1410
1429
  }
1411
1430
 
1412
- _createClass$3(Interpolator, [{
1431
+ _createClass$1(Interpolator, [{
1413
1432
  key: "init",
1414
1433
  value: function init() {
1415
1434
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -1611,7 +1630,7 @@ var Connector = function (_EventEmitter) {
1611
1630
 
1612
1631
  var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1613
1632
 
1614
- _classCallCheck$3(this, Connector);
1633
+ _classCallCheck$1(this, Connector);
1615
1634
 
1616
1635
  _this = _possibleConstructorReturn(this, _getPrototypeOf(Connector).call(this));
1617
1636
 
@@ -1635,7 +1654,7 @@ var Connector = function (_EventEmitter) {
1635
1654
  return _this;
1636
1655
  }
1637
1656
 
1638
- _createClass$3(Connector, [{
1657
+ _createClass$1(Connector, [{
1639
1658
  key: "queueLoad",
1640
1659
  value: function queueLoad(languages, namespaces, options, callback) {
1641
1660
  var _this2 = this;
@@ -1861,11 +1880,11 @@ function get() {
1861
1880
  appendNamespaceToCIMode: false,
1862
1881
  overloadTranslationOptionHandler: function handle(args) {
1863
1882
  var ret = {};
1864
- if (_typeof$3(args[1]) === 'object') ret = args[1];
1883
+ if (_typeof$2(args[1]) === 'object') ret = args[1];
1865
1884
  if (typeof args[1] === 'string') ret.defaultValue = args[1];
1866
1885
  if (typeof args[2] === 'string') ret.tDescription = args[2];
1867
1886
 
1868
- if (_typeof$3(args[2]) === 'object' || _typeof$3(args[3]) === 'object') {
1887
+ if (_typeof$2(args[2]) === 'object' || _typeof$2(args[3]) === 'object') {
1869
1888
  var options = args[3] || args[2];
1870
1889
  Object.keys(options).forEach(function (key) {
1871
1890
  ret[key] = options[key];
@@ -1926,7 +1945,7 @@ var I18n = function (_EventEmitter) {
1926
1945
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1927
1946
  var callback = arguments.length > 1 ? arguments[1] : undefined;
1928
1947
 
1929
- _classCallCheck$3(this, I18n);
1948
+ _classCallCheck$1(this, I18n);
1930
1949
 
1931
1950
  _this = _possibleConstructorReturn(this, _getPrototypeOf(I18n).call(this));
1932
1951
 
@@ -1956,7 +1975,7 @@ var I18n = function (_EventEmitter) {
1956
1975
  return _this;
1957
1976
  }
1958
1977
 
1959
- _createClass$3(I18n, [{
1978
+ _createClass$1(I18n, [{
1960
1979
  key: "init",
1961
1980
  value: function init() {
1962
1981
  var _this2 = this;
@@ -2041,6 +2060,11 @@ var I18n = function (_EventEmitter) {
2041
2060
  });
2042
2061
  }
2043
2062
 
2063
+ if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
2064
+ var codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
2065
+ if (codes.length > 0 && codes[0] !== 'dev') this.options.lng = codes[0];
2066
+ }
2067
+
2044
2068
  if (!this.services.languageDetector && !this.options.lng) {
2045
2069
  this.logger.warn('init: no languageDetector is used and no lng is defined');
2046
2070
  }
@@ -2066,7 +2090,8 @@ var I18n = function (_EventEmitter) {
2066
2090
  var deferred = defer();
2067
2091
 
2068
2092
  var load = function load() {
2069
- _this2.changeLanguage(_this2.options.lng, function (err, t) {
2093
+ var finish = function finish(err, t) {
2094
+ if (_this2.isInitialized) _this2.logger.warn('init: i18next is already initialized. You should call init just once!');
2070
2095
  _this2.isInitialized = true;
2071
2096
  if (!_this2.options.isClone) _this2.logger.log('initialized', _this2.options);
2072
2097
 
@@ -2074,7 +2099,11 @@ var I18n = function (_EventEmitter) {
2074
2099
 
2075
2100
  deferred.resolve(t);
2076
2101
  callback(err, t);
2077
- });
2102
+ };
2103
+
2104
+ if (_this2.languages && _this2.options.compatibilityAPI !== 'v1' && !_this2.isInitialized) return finish(null, _this2.t.bind(_this2));
2105
+
2106
+ _this2.changeLanguage(_this2.options.lng, finish);
2078
2107
  };
2079
2108
 
2080
2109
  if (this.options.resources || !this.options.initImmediate) {
@@ -2243,7 +2272,7 @@ var I18n = function (_EventEmitter) {
2243
2272
  var fixedT = function fixedT(key, opts) {
2244
2273
  var options;
2245
2274
 
2246
- if (_typeof$3(opts) !== 'object') {
2275
+ if (_typeof$2(opts) !== 'object') {
2247
2276
  for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
2248
2277
  rest[_key3 - 2] = arguments[_key3];
2249
2278
  }
@@ -2427,27 +2456,6 @@ var I18n = function (_EventEmitter) {
2427
2456
 
2428
2457
  var i18next = new I18n();
2429
2458
 
2430
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
2431
-
2432
- function getAugmentedNamespace(n) {
2433
- if (n.__esModule) return n;
2434
- var a = Object.defineProperty({}, '__esModule', {value: true});
2435
- Object.keys(n).forEach(function (k) {
2436
- var d = Object.getOwnPropertyDescriptor(n, k);
2437
- Object.defineProperty(a, k, d.get ? d : {
2438
- enumerable: true,
2439
- get: function () {
2440
- return n[k];
2441
- }
2442
- });
2443
- });
2444
- return a;
2445
- }
2446
-
2447
- function commonjsRequire (path) {
2448
- throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
2449
- }
2450
-
2451
2459
  function _objectWithoutPropertiesLoose(source, excluded) {
2452
2460
  if (source == null) return {};
2453
2461
  var target = {};
@@ -2463,13 +2471,9 @@ function _objectWithoutPropertiesLoose(source, excluded) {
2463
2471
  return target;
2464
2472
  }
2465
2473
 
2466
- var objectWithoutPropertiesLoose$1 = _objectWithoutPropertiesLoose;
2467
-
2468
- var objectWithoutPropertiesLoose = objectWithoutPropertiesLoose$1;
2469
-
2470
2474
  function _objectWithoutProperties(source, excluded) {
2471
2475
  if (source == null) return {};
2472
- var target = objectWithoutPropertiesLoose(source, excluded);
2476
+ var target = _objectWithoutPropertiesLoose(source, excluded);
2473
2477
  var key, i;
2474
2478
 
2475
2479
  if (Object.getOwnPropertySymbols) {
@@ -2486,51 +2490,33 @@ function _objectWithoutProperties(source, excluded) {
2486
2490
  return target;
2487
2491
  }
2488
2492
 
2489
- var objectWithoutProperties = _objectWithoutProperties;
2490
-
2491
- function _typeof$1(obj) {
2492
- "@babel/helpers - typeof";
2493
-
2494
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
2495
- _typeof_1 = _typeof$1 = function _typeof(obj) {
2496
- return typeof obj;
2497
- };
2498
- } else {
2499
- _typeof_1 = _typeof$1 = function _typeof(obj) {
2500
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
2501
- };
2502
- }
2493
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
2503
2494
 
2504
- return _typeof$1(obj);
2495
+ function getAugmentedNamespace(n) {
2496
+ if (n.__esModule) return n;
2497
+ var a = Object.defineProperty({}, '__esModule', {value: true});
2498
+ Object.keys(n).forEach(function (k) {
2499
+ var d = Object.getOwnPropertyDescriptor(n, k);
2500
+ Object.defineProperty(a, k, d.get ? d : {
2501
+ enumerable: true,
2502
+ get: function () {
2503
+ return n[k];
2504
+ }
2505
+ });
2506
+ });
2507
+ return a;
2505
2508
  }
2506
2509
 
2507
- var _typeof_1 = _typeof$1;
2508
-
2509
- var _typeof$2 = _typeof_1;
2510
-
2511
- function _defineProperty$1(obj, key, value) {
2512
- if (key in obj) {
2513
- Object.defineProperty(obj, key, {
2514
- value: value,
2515
- enumerable: true,
2516
- configurable: true,
2517
- writable: true
2518
- });
2519
- } else {
2520
- obj[key] = value;
2521
- }
2522
-
2523
- return obj;
2510
+ function commonjsRequire (path) {
2511
+ throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
2524
2512
  }
2525
2513
 
2526
- var defineProperty = _defineProperty$1;
2527
-
2528
2514
  /**
2529
2515
  * This file automatically generated from `pre-publish.js`.
2530
2516
  * Do not manually edit.
2531
2517
  */
2532
2518
 
2533
- var voidElements$1 = {
2519
+ var voidElements = {
2534
2520
  "area": true,
2535
2521
  "base": true,
2536
2522
  "br": true,
@@ -2539,9 +2525,7 @@ var voidElements$1 = {
2539
2525
  "hr": true,
2540
2526
  "img": true,
2541
2527
  "input": true,
2542
- "keygen": true,
2543
2528
  "link": true,
2544
- "menuitem": true,
2545
2529
  "meta": true,
2546
2530
  "param": true,
2547
2531
  "source": true,
@@ -2549,225 +2533,17 @@ var voidElements$1 = {
2549
2533
  "wbr": true
2550
2534
  };
2551
2535
 
2552
- var attrRE = /([\w-]+)|=|(['"])([.\s\S]*?)\2/g;
2553
- var voidElements = voidElements$1;
2554
-
2555
- var parseTag$1 = function (tag) {
2556
- var i = 0;
2557
- var key;
2558
- var expectingValueAfterEquals = true;
2559
- var res = {
2560
- type: 'tag',
2561
- name: '',
2562
- voidElement: false,
2563
- attrs: {},
2564
- children: []
2565
- };
2566
-
2567
- tag.replace(attrRE, function (match) {
2568
- if (match === '=') {
2569
- expectingValueAfterEquals = true;
2570
- i++;
2571
- return;
2572
- }
2573
-
2574
- if (!expectingValueAfterEquals) {
2575
- if (key) {
2576
- res.attrs[key] = key; // boolean attribute
2577
- }
2578
- key=match;
2579
- } else {
2580
- if (i === 0) {
2581
- if (voidElements[match] || tag.charAt(tag.length - 2) === '/') {
2582
- res.voidElement = true;
2583
- }
2584
- res.name = match;
2585
- } else {
2586
- res.attrs[key] = match.replace(/^['"]|['"]$/g, '');
2587
- key=undefined;
2588
- }
2589
- }
2590
- i++;
2591
- expectingValueAfterEquals = false;
2592
- });
2593
-
2594
- return res;
2595
- };
2596
-
2597
- /*jshint -W030 */
2598
-
2599
- var tagRE = /(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g;
2600
- var parseTag = parseTag$1;
2601
- // re-used obj for quick lookups of components
2602
- var empty = Object.create ? Object.create(null) : {};
2603
- // common logic for pushing a child node onto a list
2604
- function pushTextNode(list, html, level, start, ignoreWhitespace) {
2605
- // calculate correct end of the content slice in case there's
2606
- // no tag after the text node.
2607
- var end = html.indexOf('<', start);
2608
- var content = html.slice(start, end === -1 ? undefined : end);
2609
- // if a node is nothing but whitespace, collapse it as the spec states:
2610
- // https://www.w3.org/TR/html4/struct/text.html#h-9.1
2611
- if (/^\s*$/.test(content)) {
2612
- content = ' ';
2613
- }
2614
- // don't add whitespace-only text nodes if they would be trailing text nodes
2615
- // or if they would be leading whitespace-only text nodes:
2616
- // * end > -1 indicates this is not a trailing text node
2617
- // * leading node is when level is -1 and list has length 0
2618
- if ((!ignoreWhitespace && end > -1 && level + list.length >= 0) || content !== ' ') {
2619
- list.push({
2620
- type: 'text',
2621
- content: content
2622
- });
2623
- }
2624
- }
2625
-
2626
- var parse = function parse(html, options) {
2627
- options || (options = {});
2628
- options.components || (options.components = empty);
2629
- var result = [];
2630
- var current;
2631
- var level = -1;
2632
- var arr = [];
2633
- var byTag = {};
2634
- var inComponent = false;
2635
-
2636
- html.replace(tagRE, function (tag, index) {
2637
- if (inComponent) {
2638
- if (tag !== ('</' + current.name + '>')) {
2639
- return;
2640
- } else {
2641
- inComponent = false;
2642
- }
2643
- }
2644
-
2645
- var isOpen = tag.charAt(1) !== '/';
2646
- var isComment = tag.indexOf('<!--') === 0;
2647
- var start = index + tag.length;
2648
- var nextChar = html.charAt(start);
2649
- var parent;
2650
-
2651
- if (isOpen && !isComment) {
2652
- level++;
2653
-
2654
- current = parseTag(tag);
2655
- if (current.type === 'tag' && options.components[current.name]) {
2656
- current.type = 'component';
2657
- inComponent = true;
2658
- }
2659
-
2660
- if (!current.voidElement && !inComponent && nextChar && nextChar !== '<') {
2661
- pushTextNode(current.children, html, level, start, options.ignoreWhitespace);
2662
- }
2663
-
2664
- byTag[current.tagName] = current;
2665
-
2666
- // if we're at root, push new base node
2667
- if (level === 0) {
2668
- result.push(current);
2669
- }
2670
-
2671
- parent = arr[level - 1];
2672
-
2673
- if (parent) {
2674
- parent.children.push(current);
2675
- }
2676
-
2677
- arr[level] = current;
2678
- }
2679
-
2680
- if (isComment || !isOpen || current.voidElement) {
2681
- if (!isComment) {
2682
- level--;
2683
- }
2684
- if (!inComponent && nextChar !== '<' && nextChar) {
2685
- // trailing text node
2686
- // if we're at the root, push a base text node. otherwise add as
2687
- // a child to the current node.
2688
- parent = level === -1 ? result : arr[level].children;
2689
- pushTextNode(parent, html, level, start, options.ignoreWhitespace);
2690
- }
2691
- }
2692
- });
2693
-
2694
- // If the "html" passed isn't actually html, add it as a text node.
2695
- if (!result.length && html.length) {
2696
- pushTextNode(result, html, 0, 0, options.ignoreWhitespace);
2697
- }
2698
-
2699
- return result;
2700
- };
2701
-
2702
- function attrString(attrs) {
2703
- var buff = [];
2704
- for (var key in attrs) {
2705
- buff.push(key + '="' + attrs[key] + '"');
2706
- }
2707
- if (!buff.length) {
2708
- return '';
2709
- }
2710
- return ' ' + buff.join(' ');
2711
- }
2712
-
2713
- function stringify(buff, doc) {
2714
- switch (doc.type) {
2715
- case 'text':
2716
- return buff + doc.content;
2717
- case 'tag':
2718
- buff += '<' + doc.name + (doc.attrs ? attrString(doc.attrs) : '') + (doc.voidElement ? '/>' : '>');
2719
- if (doc.voidElement) {
2720
- return buff;
2721
- }
2722
- return buff + doc.children.reduce(stringify, '') + '</' + doc.name + '>';
2723
- }
2724
- }
2725
-
2726
- var stringify_1 = function (doc) {
2727
- return doc.reduce(function (token, rootEl) {
2728
- return token + stringify('', rootEl);
2729
- }, '');
2730
- };
2731
-
2732
- var htmlParseStringify2 = {
2733
- parse: parse,
2734
- stringify: stringify_1
2735
- };
2736
-
2737
- function _classCallCheck$2(instance, Constructor) {
2738
- if (!(instance instanceof Constructor)) {
2739
- throw new TypeError("Cannot call a class as a function");
2740
- }
2741
- }
2742
-
2743
- var classCallCheck = _classCallCheck$2;
2744
-
2745
- function _defineProperties$2(target, props) {
2746
- for (var i = 0; i < props.length; i++) {
2747
- var descriptor = props[i];
2748
- descriptor.enumerable = descriptor.enumerable || false;
2749
- descriptor.configurable = true;
2750
- if ("value" in descriptor) descriptor.writable = true;
2751
- Object.defineProperty(target, descriptor.key, descriptor);
2752
- }
2753
- }
2754
-
2755
- function _createClass$2(Constructor, protoProps, staticProps) {
2756
- if (protoProps) _defineProperties$2(Constructor.prototype, protoProps);
2757
- if (staticProps) _defineProperties$2(Constructor, staticProps);
2758
- return Constructor;
2759
- }
2760
-
2761
- var createClass = _createClass$2;
2536
+ var t=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function n(n){var r={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},i=n.match(/<\/?([^\s]+?)[/\s>]/);if(i&&(r.name=i[1],(voidElements[i[1]]||"/"===n.charAt(n.length-2))&&(r.voidElement=!0),r.name.startsWith("!--"))){var s=n.indexOf("--\x3e");return {type:"comment",comment:-1!==s?n.slice(4,s):""}}for(var a=new RegExp(t),c=null;null!==(c=a.exec(n));)if(c[0].trim())if(c[1]){var o=c[1].trim(),l=[o,""];o.indexOf("=")>-1&&(l=o.split("=")),r.attrs[l[0]]=l[1],a.lastIndex--;}else c[2]&&(r.attrs[c[2]]=c[3].trim().substring(1,c[3].length-1));return r}var r=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,i=/^\s*$/,s=Object.create(null);function a(e,t){switch(t.type){case"text":return e+t.content;case"tag":return e+="<"+t.name+(t.attrs?function(e){var t=[];for(var n in e)t.push(n+'="'+e[n]+'"');return t.length?" "+t.join(" "):""}(t.attrs):"")+(t.voidElement?"/>":">"),t.voidElement?e:e+t.children.reduce(a,"")+"</"+t.name+">";case"comment":return e+"\x3c!--"+t.comment+"--\x3e"}}var c={parse:function(e,t){t||(t={}),t.components||(t.components=s);var a,c=[],o=[],l=-1,m=!1;if(0!==e.indexOf("<")){var u=e.indexOf("<");c.push({type:"text",content:-1===u?e:e.substring(0,u)});}return e.replace(r,function(r,s){if(m){if(r!=="</"+a.name+">")return;m=!1;}var u,f="/"!==r.charAt(1),h=r.startsWith("\x3c!--"),p=s+r.length,d=e.charAt(p);if(h){var v=n(r);return l<0?(c.push(v),c):((u=o[l]).children.push(v),c)}if(f&&(l++,"tag"===(a=n(r)).type&&t.components[a.name]&&(a.type="component",m=!0),a.voidElement||m||!d||"<"===d||a.children.push({type:"text",content:e.slice(p,e.indexOf("<",p))}),0===l&&c.push(a),(u=o[l-1])&&u.children.push(a),o[l]=a),(!f||a.voidElement)&&(l>-1&&(a.voidElement||a.name===r.slice(2,-1))&&(l--,a=-1===l?c:o[l]),!m&&"<"!==d&&d)){u=-1===l?c:o[l].children;var x=e.indexOf("<",p),g=e.slice(p,-1===x?void 0:x);i.test(g)&&(g=" "),(x>-1&&l+u.length>=0||" "!==g)&&u.push({type:"text",content:g});}}),c},stringify:function(e){return e.reduce(function(e,t){return e+a("",t)},"")}};
2762
2537
 
2763
- function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
2538
+ function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
2764
2539
 
2765
- function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$2(Object(source), true).forEach(function (key) { defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
2540
+ function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$2(Object(source), true).forEach(function (key) { _defineProperty$1(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
2766
2541
  var defaultOptions = {
2767
2542
  bindI18n: 'languageChanged',
2768
2543
  bindI18nStore: '',
2769
2544
  transEmptyNodeValue: '',
2770
2545
  transSupportBasicHtmlNodes: true,
2546
+ transWrapTextNodes: '',
2771
2547
  transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
2772
2548
  useSuspense: true
2773
2549
  };
@@ -2782,12 +2558,12 @@ function getDefaults$2() {
2782
2558
  }
2783
2559
  var ReportNamespaces = function () {
2784
2560
  function ReportNamespaces() {
2785
- classCallCheck(this, ReportNamespaces);
2561
+ _classCallCheck$1(this, ReportNamespaces);
2786
2562
 
2787
2563
  this.usedNamespaces = {};
2788
2564
  }
2789
2565
 
2790
- createClass(ReportNamespaces, [{
2566
+ _createClass$1(ReportNamespaces, [{
2791
2567
  key: "addUsedNamespaces",
2792
2568
  value: function addUsedNamespaces(namespaces) {
2793
2569
  var _this = this;
@@ -2883,9 +2659,12 @@ function hasLoadedNamespace(ns, i18n) {
2883
2659
  return false;
2884
2660
  }
2885
2661
 
2886
- function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
2662
+ var _excluded = ["format"],
2663
+ _excluded2 = ["children", "count", "parent", "i18nKey", "tOptions", "values", "defaults", "components", "ns", "i18n", "t"];
2887
2664
 
2888
- function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(Object(source), true).forEach(function (key) { defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
2665
+ function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
2666
+
2667
+ function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty$1(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
2889
2668
 
2890
2669
  function hasChildren(node, checkLength) {
2891
2670
  if (!node) return false;
@@ -2942,9 +2721,11 @@ function nodesToString(children, i18nOptions) {
2942
2721
  var content = nodesToString(childChildren, i18nOptions);
2943
2722
  stringNode += "<".concat(childIndex, ">").concat(content, "</").concat(childIndex, ">");
2944
2723
  }
2724
+ } else if (child === null) {
2725
+ warn("Trans: the passed in value is invalid - seems you passed in a null child.");
2945
2726
  } else if (_typeof$2(child) === 'object') {
2946
2727
  var format = child.format,
2947
- clone = objectWithoutProperties(child, ["format"]);
2728
+ clone = _objectWithoutProperties(child, _excluded);
2948
2729
 
2949
2730
  var keys = Object.keys(clone);
2950
2731
 
@@ -2978,7 +2759,7 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts) {
2978
2759
 
2979
2760
  getData(children);
2980
2761
  var interpolatedString = i18n.services.interpolator.interpolate(targetString, _objectSpread$1(_objectSpread$1({}, data), combinedTOpts), i18n.language);
2981
- var ast = htmlParseStringify2.parse("<0>".concat(interpolatedString, "</0>"));
2762
+ var ast = c.parse("<0>".concat(interpolatedString, "</0>"));
2982
2763
 
2983
2764
  function renderInner(child, node, rootReactNode) {
2984
2765
  var childs = getChildren(child);
@@ -3059,7 +2840,15 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts) {
3059
2840
  })));
3060
2841
  }
3061
2842
  } else if (node.type === 'text') {
3062
- mem.push(node.content);
2843
+ var wrapTextNodes = i18nOptions.transWrapTextNodes;
2844
+
2845
+ if (wrapTextNodes) {
2846
+ mem.push(React__default.createElement(wrapTextNodes, {
2847
+ key: "".concat(node.name, "-").concat(i)
2848
+ }, node.content));
2849
+ } else {
2850
+ mem.push(node.content);
2851
+ }
3063
2852
  }
3064
2853
 
3065
2854
  return mem;
@@ -3086,7 +2875,7 @@ function Trans(_ref) {
3086
2875
  ns = _ref.ns,
3087
2876
  i18nFromProps = _ref.i18n,
3088
2877
  tFromProps = _ref.t,
3089
- additionalProps = objectWithoutProperties(_ref, ["children", "count", "parent", "i18nKey", "tOptions", "values", "defaults", "components", "ns", "i18n", "t"]);
2878
+ additionalProps = _objectWithoutProperties(_ref, _excluded2);
3090
2879
 
3091
2880
  var _ref2 = useContext(I18nContext) || {},
3092
2881
  i18nFromContext = _ref2.i18n,
@@ -3134,17 +2923,18 @@ function _arrayWithHoles(arr) {
3134
2923
  if (Array.isArray(arr)) return arr;
3135
2924
  }
3136
2925
 
3137
- var arrayWithHoles$1 = _arrayWithHoles;
3138
-
3139
2926
  function _iterableToArrayLimit(arr, i) {
3140
- if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
2927
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
2928
+
2929
+ if (_i == null) return;
3141
2930
  var _arr = [];
3142
2931
  var _n = true;
3143
2932
  var _d = false;
3144
- var _e = undefined;
2933
+
2934
+ var _s, _e;
3145
2935
 
3146
2936
  try {
3147
- for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
2937
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
3148
2938
  _arr.push(_s.value);
3149
2939
 
3150
2940
  if (i && _arr.length === i) break;
@@ -3163,8 +2953,6 @@ function _iterableToArrayLimit(arr, i) {
3163
2953
  return _arr;
3164
2954
  }
3165
2955
 
3166
- var iterableToArrayLimit$1 = _iterableToArrayLimit;
3167
-
3168
2956
  function _arrayLikeToArray(arr, len) {
3169
2957
  if (len == null || len > arr.length) len = arr.length;
3170
2958
 
@@ -3175,44 +2963,26 @@ function _arrayLikeToArray(arr, len) {
3175
2963
  return arr2;
3176
2964
  }
3177
2965
 
3178
- var arrayLikeToArray$1 = _arrayLikeToArray;
3179
-
3180
- var arrayLikeToArray = arrayLikeToArray$1;
3181
-
3182
2966
  function _unsupportedIterableToArray(o, minLen) {
3183
2967
  if (!o) return;
3184
- if (typeof o === "string") return arrayLikeToArray(o, minLen);
2968
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
3185
2969
  var n = Object.prototype.toString.call(o).slice(8, -1);
3186
2970
  if (n === "Object" && o.constructor) n = o.constructor.name;
3187
2971
  if (n === "Map" || n === "Set") return Array.from(o);
3188
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return arrayLikeToArray(o, minLen);
2972
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
3189
2973
  }
3190
2974
 
3191
- var unsupportedIterableToArray$1 = _unsupportedIterableToArray;
3192
-
3193
2975
  function _nonIterableRest() {
3194
2976
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
3195
2977
  }
3196
2978
 
3197
- var nonIterableRest$1 = _nonIterableRest;
3198
-
3199
- var arrayWithHoles = arrayWithHoles$1;
3200
-
3201
- var iterableToArrayLimit = iterableToArrayLimit$1;
3202
-
3203
- var unsupportedIterableToArray = unsupportedIterableToArray$1;
3204
-
3205
- var nonIterableRest = nonIterableRest$1;
3206
-
3207
2979
  function _slicedToArray(arr, i) {
3208
- return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || unsupportedIterableToArray(arr, i) || nonIterableRest();
2980
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
3209
2981
  }
3210
2982
 
3211
- var slicedToArray = _slicedToArray;
2983
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
3212
2984
 
3213
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
3214
-
3215
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
2985
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty$1(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
3216
2986
  function useTranslation(ns) {
3217
2987
  var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3218
2988
  var i18nFromProps = props.i18n;
@@ -3238,6 +3008,8 @@ function useTranslation(ns) {
3238
3008
  return retNotReady;
3239
3009
  }
3240
3010
 
3011
+ if (i18n.options.react && i18n.options.react.wait !== undefined) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.');
3012
+
3241
3013
  var i18nOptions = _objectSpread(_objectSpread(_objectSpread({}, getDefaults$2()), i18n.options.react), props);
3242
3014
 
3243
3015
  var useSuspense = i18nOptions.useSuspense;
@@ -3249,13 +3021,11 @@ function useTranslation(ns) {
3249
3021
  });
3250
3022
 
3251
3023
  function getT() {
3252
- return {
3253
- t: i18n.getFixedT(null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0])
3254
- };
3024
+ return i18n.getFixedT(null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0]);
3255
3025
  }
3256
3026
 
3257
- var _useState = useState(getT()),
3258
- _useState2 = slicedToArray(_useState, 2),
3027
+ var _useState = useState(getT),
3028
+ _useState2 = _slicedToArray(_useState, 2),
3259
3029
  t = _useState2[0],
3260
3030
  setT = _useState2[1];
3261
3031
 
@@ -3267,12 +3037,12 @@ function useTranslation(ns) {
3267
3037
 
3268
3038
  if (!ready && !useSuspense) {
3269
3039
  loadNamespaces(i18n, namespaces, function () {
3270
- if (isMounted.current) setT(getT());
3040
+ if (isMounted.current) setT(getT);
3271
3041
  });
3272
3042
  }
3273
3043
 
3274
3044
  function boundReset() {
3275
- if (isMounted.current) setT(getT());
3045
+ if (isMounted.current) setT(getT);
3276
3046
  }
3277
3047
 
3278
3048
  if (bindI18n && i18n) i18n.on(bindI18n, boundReset);
@@ -3286,9 +3056,17 @@ function useTranslation(ns) {
3286
3056
  return i18n.store.off(e, boundReset);
3287
3057
  });
3288
3058
  };
3289
- }, [namespaces.join()]);
3290
- var ret = [t.t, i18n, ready];
3291
- ret.t = t.t;
3059
+ }, [i18n, namespaces.join()]);
3060
+ var isInitial = useRef(true);
3061
+ useEffect(function () {
3062
+ if (isMounted.current && !isInitial.current) {
3063
+ setT(getT);
3064
+ }
3065
+
3066
+ isInitial.current = false;
3067
+ }, [i18n]);
3068
+ var ret = [t, i18n, ready];
3069
+ ret.t = t;
3292
3070
  ret.i18n = i18n;
3293
3071
  ret.ready = ready;
3294
3072
  if (ready) return ret;
@@ -3300,6 +3078,8 @@ function useTranslation(ns) {
3300
3078
  });
3301
3079
  }
3302
3080
 
3081
+ function _typeof$1(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$1 = function _typeof(obj) { return typeof obj; }; } else { _typeof$1 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$1(obj); }
3082
+
3303
3083
  var arr$1 = [];
3304
3084
  var each$1 = arr$1.forEach;
3305
3085
  var slice$1 = arr$1.slice;
@@ -3313,9 +3093,14 @@ function defaults$1(obj) {
3313
3093
  });
3314
3094
  return obj;
3315
3095
  }
3096
+ function hasXMLHttpRequest() {
3097
+ return typeof XMLHttpRequest === 'function' || (typeof XMLHttpRequest === "undefined" ? "undefined" : _typeof$1(XMLHttpRequest)) === 'object';
3098
+ }
3316
3099
 
3317
3100
  var getFetch$1 = {exports: {}};
3318
3101
 
3102
+ var nodePonyfill = {exports: {}};
3103
+
3319
3104
  // Based on https://github.com/tmpvar/jsdom/blob/aa85b2abf07766ff7bf5c1f6daafb3726f2f2db5/lib/jsdom/living/blob.js
3320
3105
 
3321
3106
  // fix for "Readable" isn't a named export issue
@@ -4957,6 +4742,31 @@ var lib = /*#__PURE__*/Object.freeze({
4957
4742
 
4958
4743
  var require$$0 = /*@__PURE__*/getAugmentedNamespace(lib);
4959
4744
 
4745
+ (function (module, exports) {
4746
+ const nodeFetch = require$$0;
4747
+ const realFetch = nodeFetch.default || nodeFetch;
4748
+
4749
+ const fetch = function (url, options) {
4750
+ // Support schemaless URIs on the server for parity with the browser.
4751
+ // Ex: //github.com/ -> https://github.com/
4752
+ if (/^\/\//.test(url)) {
4753
+ url = 'https:' + url;
4754
+ }
4755
+ return realFetch.call(this, url, options)
4756
+ };
4757
+
4758
+ fetch.ponyfill = true;
4759
+
4760
+ module.exports = exports = fetch;
4761
+ exports.fetch = fetch;
4762
+ exports.Headers = nodeFetch.Headers;
4763
+ exports.Request = nodeFetch.Request;
4764
+ exports.Response = nodeFetch.Response;
4765
+
4766
+ // Needed for TypeScript consumers without esModuleInterop.
4767
+ exports.default = fetch;
4768
+ }(nodePonyfill, nodePonyfill.exports));
4769
+
4960
4770
  (function (module, exports) {
4961
4771
  var fetchApi;
4962
4772
  if (typeof fetch === 'function') {
@@ -4968,7 +4778,7 @@ if (typeof fetch === 'function') {
4968
4778
  }
4969
4779
 
4970
4780
  if (typeof commonjsRequire !== 'undefined' && (typeof window === 'undefined' || typeof window.document === 'undefined')) {
4971
- var f = fetchApi || require$$0;
4781
+ var f = fetchApi || nodePonyfill.exports;
4972
4782
  if (f.default) f = f.default;
4973
4783
  exports.default = f;
4974
4784
  module.exports = exports.default;
@@ -4994,7 +4804,7 @@ if (typeof fetch === 'function') {
4994
4804
 
4995
4805
  var XmlHttpRequestApi;
4996
4806
 
4997
- if (typeof XMLHttpRequest === 'function') {
4807
+ if (hasXMLHttpRequest) {
4998
4808
  if (typeof global !== 'undefined' && global.XMLHttpRequest) {
4999
4809
  XmlHttpRequestApi = global.XMLHttpRequest;
5000
4810
  } else if (typeof window !== 'undefined' && window.XMLHttpRequest) {
@@ -5122,16 +4932,16 @@ var request = function request(options, url, payload, callback) {
5122
4932
  return requestWithFetch(options, url, payload, callback);
5123
4933
  }
5124
4934
 
5125
- if (typeof XMLHttpRequest === 'function' || typeof ActiveXObject === 'function') {
4935
+ if (hasXMLHttpRequest || typeof ActiveXObject === 'function') {
5126
4936
  return requestWithXmlHttpRequest(options, url, payload, callback);
5127
4937
  }
5128
4938
  };
5129
4939
 
5130
- function _classCallCheck$1(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4940
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5131
4941
 
5132
- function _defineProperties$1(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
4942
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
5133
4943
 
5134
- function _createClass$1(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$1(Constructor.prototype, protoProps); if (staticProps) _defineProperties$1(Constructor, staticProps); return Constructor; }
4944
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
5135
4945
 
5136
4946
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5137
4947
 
@@ -5167,7 +4977,7 @@ var Backend = function () {
5167
4977
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
5168
4978
  var allOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
5169
4979
 
5170
- _classCallCheck$1(this, Backend);
4980
+ _classCallCheck(this, Backend);
5171
4981
 
5172
4982
  this.services = services;
5173
4983
  this.options = options;
@@ -5176,7 +4986,7 @@ var Backend = function () {
5176
4986
  this.init(services, options, allOptions);
5177
4987
  }
5178
4988
 
5179
- _createClass$1(Backend, [{
4989
+ _createClass(Backend, [{
5180
4990
  key: "init",
5181
4991
  value: function init(services) {
5182
4992
  var _this = this;
@@ -5187,7 +4997,7 @@ var Backend = function () {
5187
4997
  this.options = defaults$1(options, this.options || {}, getDefaults$1());
5188
4998
  this.allOptions = allOptions;
5189
4999
 
5190
- if (this.options.reloadInterval) {
5000
+ if (this.services && this.options.reloadInterval) {
5191
5001
  setInterval(function () {
5192
5002
  return _this.reload();
5193
5003
  }, this.options.reloadInterval);
@@ -5229,9 +5039,9 @@ var Backend = function () {
5229
5039
  var _this2 = this;
5230
5040
 
5231
5041
  this.options.request(this.options, url, undefined, function (err, res) {
5232
- if (res && (res.status >= 500 && res.status < 600 || !res.status)) return callback('failed loading ' + url, true);
5233
- if (res && res.status >= 400 && res.status < 500) return callback('failed loading ' + url, false);
5234
- if (!res && err && err.message && err.message.indexOf('Failed to fetch') > -1) return callback('failed loading ' + url, true);
5042
+ if (res && (res.status >= 500 && res.status < 600 || !res.status)) return callback('failed loading ' + url + '; status code: ' + res.status, true);
5043
+ if (res && res.status >= 400 && res.status < 500) return callback('failed loading ' + url + '; status code: ' + res.status, false);
5044
+ if (!res && err && err.message && err.message.indexOf('Failed to fetch') > -1) return callback('failed loading ' + url + ': ' + err.message, true);
5235
5045
  if (err) return callback(err, false);
5236
5046
  var ret, parseErr;
5237
5047
 
@@ -5251,19 +5061,36 @@ var Backend = function () {
5251
5061
  }
5252
5062
  }, {
5253
5063
  key: "create",
5254
- value: function create(languages, namespace, key, fallbackValue) {
5064
+ value: function create(languages, namespace, key, fallbackValue, callback) {
5255
5065
  var _this3 = this;
5256
5066
 
5257
5067
  if (!this.options.addPath) return;
5258
5068
  if (typeof languages === 'string') languages = [languages];
5259
5069
  var payload = this.options.parsePayload(namespace, key, fallbackValue);
5070
+ var finished = 0;
5071
+ var dataArray = [];
5072
+ var resArray = [];
5260
5073
  languages.forEach(function (lng) {
5261
- var url = _this3.services.interpolator.interpolate(_this3.options.addPath, {
5074
+ var addPath = _this3.options.addPath;
5075
+
5076
+ if (typeof _this3.options.addPath === 'function') {
5077
+ addPath = _this3.options.addPath(lng, namespace);
5078
+ }
5079
+
5080
+ var url = _this3.services.interpolator.interpolate(addPath, {
5262
5081
  lng: lng,
5263
5082
  ns: namespace
5264
5083
  });
5265
5084
 
5266
- _this3.options.request(_this3.options, url, payload, function (data, res) {});
5085
+ _this3.options.request(_this3.options, url, payload, function (data, res) {
5086
+ finished += 1;
5087
+ dataArray.push(data);
5088
+ resArray.push(res);
5089
+
5090
+ if (finished === languages.length) {
5091
+ if (callback) callback(dataArray, resArray);
5092
+ }
5093
+ });
5267
5094
  });
5268
5095
  }
5269
5096
  }, {
@@ -5307,28 +5134,6 @@ var Backend = function () {
5307
5134
 
5308
5135
  Backend.type = 'backend';
5309
5136
 
5310
- function _classCallCheck(instance, Constructor) {
5311
- if (!(instance instanceof Constructor)) {
5312
- throw new TypeError("Cannot call a class as a function");
5313
- }
5314
- }
5315
-
5316
- function _defineProperties(target, props) {
5317
- for (var i = 0; i < props.length; i++) {
5318
- var descriptor = props[i];
5319
- descriptor.enumerable = descriptor.enumerable || false;
5320
- descriptor.configurable = true;
5321
- if ("value" in descriptor) descriptor.writable = true;
5322
- Object.defineProperty(target, descriptor.key, descriptor);
5323
- }
5324
- }
5325
-
5326
- function _createClass(Constructor, protoProps, staticProps) {
5327
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
5328
- if (staticProps) _defineProperties(Constructor, staticProps);
5329
- return Constructor;
5330
- }
5331
-
5332
5137
  var arr = [];
5333
5138
  var each = arr.forEach;
5334
5139
  var slice = arr.slice;
@@ -5659,14 +5464,14 @@ function () {
5659
5464
  function Browser(services) {
5660
5465
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
5661
5466
 
5662
- _classCallCheck(this, Browser);
5467
+ _classCallCheck$1(this, Browser);
5663
5468
 
5664
5469
  this.type = 'languageDetector';
5665
5470
  this.detectors = {};
5666
5471
  this.init(services, options);
5667
5472
  }
5668
5473
 
5669
- _createClass(Browser, [{
5474
+ _createClass$1(Browser, [{
5670
5475
  key: "init",
5671
5476
  value: function init(services) {
5672
5477
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -5732,26 +5537,26 @@ function localize(_a) {
5732
5537
  var detectorConfig = _a.detectorConfig, translationPath = _a.translationPath, i18nConfig = __rest(_a, ["detectorConfig", "translationPath"]);
5733
5538
  var detectionObject = detectorConfig || {
5734
5539
  // order and from where user language should be detected
5735
- order: ["querystring", "cookie", "localStorage"],
5540
+ order: ['querystring', 'cookie', 'localStorage'],
5736
5541
  // keys or params to lookup language from
5737
- lookupQuerystring: "lang",
5738
- lookupCookie: "lang",
5739
- lookupSessionStorage: "lang",
5740
- lookupLocalStorage: "lang",
5542
+ lookupQuerystring: 'lang',
5543
+ lookupCookie: 'lang',
5544
+ lookupSessionStorage: 'lang',
5545
+ lookupLocalStorage: 'lang',
5741
5546
  // cache user language on
5742
- caches: ["localStorage", "cookie"],
5743
- excludeCacheFor: ["cimode"],
5547
+ caches: ['localStorage', 'cookie'],
5548
+ excludeCacheFor: ['cimode'],
5744
5549
  // optional set cookie options, reference:[MDN Set-Cookie docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie)
5745
- cookieOptions: { path: "/", sameSite: "strict" },
5550
+ cookieOptions: { path: '/', sameSite: 'strict' },
5746
5551
  };
5747
- var transPath = translationPath || "/locales/{{lng}}/{{ns}}.json";
5748
- var mergedConfig = __assign({ fallbackLng: "en-US", debug: true, keySeparator: ".", backend: {
5552
+ var transPath = translationPath || '/locales/{{lng}}/{{ns}}.json';
5553
+ var mergedConfig = __assign({ fallbackLng: 'en-US', debug: true, keySeparator: '.', backend: {
5749
5554
  // this is the path to your translation files
5750
5555
  // this can also take an absolute path as well as the current relative path
5751
5556
  // relative path currently points to public/locales
5752
5557
  loadPath: transPath,
5753
5558
  }, interpolation: {
5754
- escapeValue: false,
5559
+ escapeValue: false, // React takes care of interpolation for us
5755
5560
  }, detection: detectionObject }, i18nConfig);
5756
5561
  i18next.use(Backend) // used for loading external translation files
5757
5562
  .use(Browser) // used to detect langage via cookie, local storage, or query param
@@ -5765,8 +5570,8 @@ function SpsLanguage(_a) {
5765
5570
  }
5766
5571
 
5767
5572
  function useSpsLanguage(ns, options) {
5768
- if (ns === void 0) { ns = "translation"; }
5769
- return useTranslation([ns, "design-system"], options);
5573
+ if (ns === void 0) { ns = 'translation'; }
5574
+ return useTranslation([ns, 'design-system'], options);
5770
5575
  }
5771
5576
 
5772
5577
  export { SpsLanguage, localize, useSpsLanguage };