react-i18next 11.3.3 → 11.5.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/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ### 11.5.0
2
+
3
+ - Trans: merge option in mapAST [1120](https://github.com/i18next/react-i18next/pull/1120)
4
+
5
+ ### 11.4.0
6
+
7
+ - Add sideEffects false to package json to allow tree shaking [1097](https://github.com/i18next/react-i18next/pull/1097)
8
+
9
+ ### 11.3.5
10
+
11
+ - fix returning defaultValue for Trans component [1092](https://github.com/i18next/react-i18next/pull/1092)
12
+
13
+ ### 11.3.4
14
+
15
+ - [useTranslation] Avoid setting the new `t` function if the component is unmounted. (1051)[https://github.com/i18next/react-i18next/pull/1051]
16
+
1
17
  ### 11.3.3
2
18
 
3
19
  - fixes copying ns in useSSR
package/README.md CHANGED
@@ -73,12 +73,12 @@ Head over to the **interactive playground** at [codesandbox](https://codesandbox
73
73
  - [Building i18n with Gatsby](https://www.gatsbyjs.org/blog/2017-10-17-building-i18n-with-gatsby/) via gatsbyjs.org by Samuel Goudie
74
74
  - [Get your react.js application translated with style](https://medium.com/@jamuhl/get-your-react-js-application-translated-with-style-4ad090aefc2c) by Jan Mühlemann
75
75
  - [Translate your expo.io / react-native mobile application](https://medium.com/@jamuhl/translate-your-expo-io-react-native-mobile-application-aa220b2362d2) by Jan Mühlemann
76
- - you're welcome to share your story...
76
+ - You're welcome to share your story...
77
77
 
78
78
  ### Why i18next?
79
79
 
80
- - **Simplicity:** no need to change your webpack configuration or adding additional babel transpilers, just use create-react-app and go
81
- - **Production ready** we know there are more needs for production than just doing i18n on the clientside. So we offer wider support on [serverside](https://www.i18next.com/supported-frameworks.html) too (nodejs, php, ruby, .net, ...). **Learn once - translate everywhere**.
80
+ - **Simplicity:** no need to change your webpack configuration or add additional babel transpilers, just use create-react-app and go.
81
+ - **Production ready** we know there are more needs for production than just doing i18n on the clientside, so we offer wider support on [serverside](https://www.i18next.com/supported-frameworks.html) too (nodejs, php, ruby, .net, ...). **Learn once - translate everywhere**.
82
82
  - **Beyond i18n** comes with [locize](https://locize.com) bridging the gap between developement and translations - covering the whole translation process.
83
83
 
84
84
  <img src="https://blobscdn.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-L9iS6Wm2hynS5H9Gj7j%2F-L9iS7LlT2W7wFtJH-2n%2F-L9iSBP9U65-bHJBRSDv%2Fi18next-ecosystem.jpg?generation=1523345318122913&alt=media" alt="i18next ecossystem" width="400">
@@ -152,7 +152,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
152
152
 
153
153
  <!-- ALL-CONTRIBUTORS-LIST:END -->
154
154
 
155
- This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
155
+ This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind are welcome!
156
156
 
157
157
  ---
158
158
 
@@ -3,6 +3,8 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
3
3
  var React__default = 'default' in React ? React['default'] : React;
4
4
 
5
5
  function _typeof(obj) {
6
+ "@babel/helpers - typeof";
7
+
6
8
  if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
7
9
  _typeof = function (obj) {
8
10
  return typeof obj;
@@ -72,13 +74,13 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
72
74
  var source = arguments[i] != null ? arguments[i] : {};
73
75
 
74
76
  if (i % 2) {
75
- ownKeys(source, true).forEach(function (key) {
77
+ ownKeys(Object(source), true).forEach(function (key) {
76
78
  _defineProperty(target, key, source[key]);
77
79
  });
78
80
  } else if (Object.getOwnPropertyDescriptors) {
79
81
  Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
80
82
  } else {
81
- ownKeys(source).forEach(function (key) {
83
+ ownKeys(Object(source)).forEach(function (key) {
82
84
  Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
83
85
  });
84
86
  }
@@ -124,7 +126,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
124
126
  }
125
127
 
126
128
  function _slicedToArray(arr, i) {
127
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
129
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
128
130
  }
129
131
 
130
132
  function _arrayWithHoles(arr) {
@@ -132,10 +134,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
132
134
  }
133
135
 
134
136
  function _iterableToArrayLimit(arr, i) {
135
- if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
136
- return;
137
- }
138
-
137
+ if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
139
138
  var _arr = [];
140
139
  var _n = true;
141
140
  var _d = false;
@@ -161,8 +160,25 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
161
160
  return _arr;
162
161
  }
163
162
 
163
+ function _unsupportedIterableToArray(o, minLen) {
164
+ if (!o) return;
165
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
166
+ var n = Object.prototype.toString.call(o).slice(8, -1);
167
+ if (n === "Object" && o.constructor) n = o.constructor.name;
168
+ if (n === "Map" || n === "Set") return Array.from(n);
169
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
170
+ }
171
+
172
+ function _arrayLikeToArray(arr, len) {
173
+ if (len == null || len > arr.length) len = arr.length;
174
+
175
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
176
+
177
+ return arr2;
178
+ }
179
+
164
180
  function _nonIterableRest() {
165
- throw new TypeError("Invalid attempt to destructure non-iterable instance");
181
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
166
182
  }
167
183
 
168
184
  /**
@@ -392,14 +408,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
392
408
  useSuspense: true
393
409
  };
394
410
  var i18nInstance;
395
- var hasUsedI18nextProvider;
396
411
  var I18nContext = React__default.createContext();
397
- function usedI18nextProvider(used) {
398
- hasUsedI18nextProvider = used;
399
- }
400
- function getHasUsedI18nextProvider() {
401
- return hasUsedI18nextProvider;
402
- }
403
412
  function setDefaults() {
404
413
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
405
414
  defaultOptions = _objectSpread2({}, defaultOptions, {}, options);
@@ -407,9 +416,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
407
416
  function getDefaults() {
408
417
  return defaultOptions;
409
418
  }
410
- var ReportNamespaces =
411
- /*#__PURE__*/
412
- function () {
419
+ var ReportNamespaces = /*#__PURE__*/function () {
413
420
  function ReportNamespaces() {
414
421
  _classCallCheck(this, ReportNamespaces);
415
422
 
@@ -592,44 +599,63 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
592
599
  return Array.isArray(data) ? data : [data];
593
600
  }
594
601
 
595
- function nodesToString(startingString, children, index, i18nOptions) {
602
+ function mergeProps(source, target) {
603
+ var newTarget = _objectSpread2({}, target); // overwrite source.props when target.props already set
604
+
605
+
606
+ newTarget.props = Object.assign(source.props, target.props);
607
+ return newTarget;
608
+ }
609
+
610
+ function nodesToString(children, i18nOptions) {
596
611
  if (!children) return '';
597
- var stringNode = startingString;
612
+ var stringNode = ''; // do not use `React.Children.toArray`, will fail at object children
613
+
598
614
  var childrenArray = getAsArray(children);
599
- var keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
600
- childrenArray.forEach(function (child, i) {
601
- var elementKey = "".concat(i);
615
+ var keepArray = i18nOptions.transKeepBasicHtmlNodesFor || []; // e.g. lorem <br/> ipsum {{ messageCount, format }} dolor <strong>bold</strong> amet
602
616
 
617
+ childrenArray.forEach(function (child, childIndex) {
603
618
  if (typeof child === 'string') {
604
- stringNode = "".concat(stringNode).concat(child);
605
- } else if (hasChildren(child)) {
606
- var elementTag = keepArray.indexOf(child.type) > -1 && Object.keys(child.props).length === 1 && typeof hasChildren(child) === 'string' ? child.type : elementKey;
607
-
608
- if (child.props && child.props.i18nIsDynamicList) {
609
- // we got a dynamic list like "<ul>{['a', 'b'].map(item => ( <li key={item}>{item}</li> ))}</ul>""
610
- // the result should be "<0></0>" and not "<0><0>a</0><1>b</1></0>"
611
- stringNode = "".concat(stringNode, "<").concat(elementTag, "></").concat(elementTag, ">");
612
- } else {
613
- // regular case mapping the inner children
614
- stringNode = "".concat(stringNode, "<").concat(elementTag, ">").concat(nodesToString('', getChildren(child), i + 1, i18nOptions), "</").concat(elementTag, ">");
615
- }
619
+ // actual e.g. lorem
620
+ // expected e.g. lorem
621
+ stringNode += "".concat(child);
616
622
  } else if (React__default.isValidElement(child)) {
617
- if (keepArray.indexOf(child.type) > -1 && Object.keys(child.props).length === 0) {
618
- stringNode = "".concat(stringNode, "<").concat(child.type, "/>");
623
+ var childPropsCount = Object.keys(child.props).length;
624
+ var shouldKeepChild = keepArray.indexOf(child.type) > -1;
625
+ var childChildren = child.props.children;
626
+
627
+ if (!childChildren && shouldKeepChild && childPropsCount === 0) {
628
+ // actual e.g. lorem <br/> ipsum
629
+ // expected e.g. lorem <br/> ipsum
630
+ stringNode += "<".concat(child.type, "/>");
631
+ } else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) {
632
+ // actual e.g. lorem <hr className="test" /> ipsum
633
+ // expected e.g. lorem <0></0> ipsum
634
+ stringNode += "<".concat(childIndex, "></").concat(childIndex, ">");
635
+ } else if (child.props.i18nIsDynamicList) {
636
+ // we got a dynamic list like
637
+ // e.g. <ul i18nIsDynamicList>{['a', 'b'].map(item => ( <li key={item}>{item}</li> ))}</ul>
638
+ // expected e.g. "<0></0>", not e.g. "<0><0>a</0><1>b</1></0>"
639
+ stringNode += "<".concat(childIndex, "></").concat(childIndex, ">");
640
+ } else if (shouldKeepChild && childPropsCount === 1 && typeof childChildren === 'string') {
641
+ // actual e.g. dolor <strong>bold</strong> amet
642
+ // expected e.g. dolor <strong>bold</strong> amet
643
+ stringNode += "<".concat(child.type, ">").concat(childChildren, "</").concat(child.type, ">");
619
644
  } else {
620
- stringNode = "".concat(stringNode, "<").concat(elementKey, "></").concat(elementKey, ">");
645
+ // regular case mapping the inner children
646
+ var content = nodesToString(childChildren, i18nOptions);
647
+ stringNode += "<".concat(childIndex, ">").concat(content, "</").concat(childIndex, ">");
621
648
  }
622
649
  } else if (_typeof(child) === 'object') {
623
- var clone = _objectSpread2({}, child);
650
+ // e.g. lorem {{ value, format }} ipsum
651
+ var format = child.format,
652
+ clone = _objectWithoutProperties(child, ["format"]);
624
653
 
625
- var format = clone.format;
626
- delete clone.format;
627
654
  var keys = Object.keys(clone);
628
655
 
629
- if (format && keys.length === 1) {
630
- stringNode = "".concat(stringNode, "{{").concat(keys[0], ", ").concat(format, "}}");
631
- } else if (keys.length === 1) {
632
- stringNode = "".concat(stringNode, "{{").concat(keys[0], "}}");
656
+ if (keys.length === 1) {
657
+ var value = format ? "".concat(keys[0], ", ").concat(format) : keys[0];
658
+ stringNode += "{{".concat(value, "}}");
633
659
  } else {
634
660
  // not a valid interpolation object (can only contain one value plus format)
635
661
  warn("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.", child);
@@ -672,7 +698,10 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
672
698
  var translationContent = node.children && node.children[0] && node.children[0].content;
673
699
 
674
700
  if (node.type === 'tag') {
675
- var child = reactNodes[parseInt(node.name, 10)] || {};
701
+ var tmp = reactNodes[parseInt(node.name, 10)] || {};
702
+ var child = Object.keys(node.attrs).length !== 0 ? mergeProps({
703
+ props: node.attrs
704
+ }, tmp) : tmp;
676
705
  var isElement = React__default.isValidElement(child);
677
706
 
678
707
  if (typeof child === 'string') {
@@ -771,9 +800,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
771
800
  tFromProps = _ref.t,
772
801
  additionalProps = _objectWithoutProperties(_ref, ["children", "count", "parent", "i18nKey", "tOptions", "values", "defaults", "components", "ns", "i18n", "t"]);
773
802
 
774
- var ReactI18nContext = React.useContext(I18nContext);
775
-
776
- var _ref2 = getHasUsedI18nextProvider() ? ReactI18nContext || {} : {},
803
+ var _ref2 = React.useContext(I18nContext) || {},
777
804
  i18nFromContext = _ref2.i18n,
778
805
  defaultNSFromContext = _ref2.defaultNS;
779
806
 
@@ -788,13 +815,12 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
788
815
  return k;
789
816
  };
790
817
 
791
- var reactI18nextOptions = _objectSpread2({}, getDefaults(), {}, i18n.options && i18n.options.react);
818
+ var reactI18nextOptions = _objectSpread2({}, getDefaults(), {}, i18n.options && i18n.options.react); // prepare having a namespace
792
819
 
793
- var useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent; // prepare having a namespace
794
820
 
795
821
  var namespaces = ns || t.ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
796
822
  namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
797
- var defaultValue = defaults || nodesToString('', children, 0, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue;
823
+ var defaultValue = defaults || nodesToString(children, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue || i18nKey;
798
824
  var hashTransKey = reactI18nextOptions.hashTransKey;
799
825
  var key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
800
826
  var interpolationOverride = values ? {} : {
@@ -812,17 +838,19 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
812
838
  });
813
839
 
814
840
  var translation = key ? t(key, combinedTOpts) : defaultValue;
815
- if (!useAsParent) return renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts);
816
- return React__default.createElement(useAsParent, additionalProps, renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts));
841
+ var content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts); // allows user to pass `null` to `parent`
842
+ // and override `defaultTransParent` if is present
843
+
844
+ var useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
845
+ return useAsParent ? React__default.createElement(useAsParent, additionalProps, content) : content;
817
846
  }
818
847
 
819
848
  function useTranslation(ns) {
820
849
  var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
821
850
  // assert we have the needed i18nInstance
822
851
  var i18nFromProps = props.i18n;
823
- var ReactI18nContext = React.useContext(I18nContext);
824
852
 
825
- var _ref = getHasUsedI18nextProvider() ? ReactI18nContext || {} : {},
853
+ var _ref = React.useContext(I18nContext) || {},
826
854
  i18nFromContext = _ref.i18n,
827
855
  defaultNSFromContext = _ref.defaultNS;
828
856
 
@@ -868,20 +896,21 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
868
896
  setT = _useState2[1]; // seems we can't have functions as value -> wrap it in obj
869
897
 
870
898
 
899
+ var isMounted = React.useRef(true);
871
900
  React.useEffect(function () {
872
- var isMounted = true;
873
901
  var bindI18n = i18nOptions.bindI18n,
874
- bindI18nStore = i18nOptions.bindI18nStore; // if not ready and not using suspense load the namespaces
902
+ bindI18nStore = i18nOptions.bindI18nStore;
903
+ isMounted.current = true; // if not ready and not using suspense load the namespaces
875
904
  // in side effect and do not call resetT if unmounted
876
905
 
877
906
  if (!ready && !useSuspense) {
878
907
  loadNamespaces(i18n, namespaces, function () {
879
- if (isMounted) setT(getT());
908
+ if (isMounted.current) setT(getT());
880
909
  });
881
910
  }
882
911
 
883
912
  function boundReset() {
884
- if (isMounted) setT(getT());
913
+ if (isMounted.current) setT(getT());
885
914
  } // bind events to trigger change, like languageChanged
886
915
 
887
916
 
@@ -889,7 +918,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
889
918
  if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset); // unbinding on unmount
890
919
 
891
920
  return function () {
892
- isMounted = false;
921
+ isMounted.current = false;
893
922
  if (bindI18n && i18n) bindI18n.split(' ').forEach(function (e) {
894
923
  return i18n.off(e, boundReset);
895
924
  });
@@ -910,7 +939,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
910
939
 
911
940
  throw new Promise(function (resolve) {
912
941
  loadNamespaces(i18n, namespaces, function () {
913
- setT(getT());
942
+ if (isMounted.current) setT(getT());
914
943
  resolve();
915
944
  });
916
945
  });
@@ -978,8 +1007,7 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
978
1007
  var i18n = _ref.i18n,
979
1008
  defaultNS = _ref.defaultNS,
980
1009
  children = _ref.children;
981
- usedI18nextProvider(true);
982
- return React__default.createElement(I18nContext.Provider, {
1010
+ return React.createElement(I18nContext.Provider, {
983
1011
  value: {
984
1012
  i18n: i18n,
985
1013
  defaultNS: defaultNS
@@ -990,12 +1018,11 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
990
1018
  function useSSR(initialI18nStore, initialLanguage) {
991
1019
  var props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
992
1020
  var i18nFromProps = props.i18n;
993
- var ReactI18nContext = React.useContext(I18nContext);
994
1021
 
995
- var _ref = getHasUsedI18nextProvider() ? ReactI18nContext || {} : {},
1022
+ var _ref = React.useContext(I18nContext) || {},
996
1023
  i18nFromContext = _ref.i18n;
997
1024
 
998
- var i18n = i18nFromProps || i18nFromContext || getI18n(); // opt out if is a cloned instance, eg. created by i18next-express-middleware on request
1025
+ var i18n = i18nFromProps || i18nFromContext || getI18n(); // opt out if is a cloned instance, eg. created by i18next-http-middleware on request
999
1026
  // -> do not set initial stuff on server side
1000
1027
 
1001
1028
  if (i18n.options && i18n.options.isClone) return; // nextjs / SSR: getting data from next.js or other ssr stack
@@ -1 +1 @@
1
- define(["exports","react"],(function(e,n){"use strict";var t="default"in n?n.default:n;function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function a(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function o(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function c(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?o(t,!0).forEach((function(n){i(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):o(t).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}function s(e,n){if(null==e)return{};var t,r,a=function(e,n){if(null==e)return{};var t,r,a={},i=Object.keys(e);for(r=0;r<i.length;r++)t=i[r],n.indexOf(t)>=0||(a[t]=e[t]);return a}(e,n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)t=i[r],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(a[t]=e[t])}return a}function u(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var t=[],r=!0,a=!1,i=void 0;try{for(var o,c=e[Symbol.iterator]();!(r=(o=c.next()).done)&&(t.push(o.value),!n||t.length!==n);r=!0);}catch(e){a=!0,i=e}finally{try{r||null==c.return||c.return()}finally{if(a)throw i}}return t}(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var l={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,menuitem:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},f=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,p=/(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,d=Object.create?Object.create(null):{};function g(e,n,t,r,a){var i=n.indexOf("<",r),o=n.slice(r,-1===i?void 0:i);/^\s*$/.test(o)&&(o=" "),(!a&&i>-1&&t+e.length>=0||" "!==o)&&e.push({type:"text",content:o})}function m(e,n){switch(n.type){case"text":return e+n.content;case"tag":return e+="<"+n.name+(n.attrs?function(e){var n=[];for(var t in e)n.push(t+'="'+e[t]+'"');return n.length?" "+n.join(" "):""}(n.attrs):"")+(n.voidElement?"/>":">"),n.voidElement?e:e+n.children.reduce(m,"")+"</"+n.name+">"}}var h,y,v={parse:function(e,n){n||(n={}),n.components||(n.components=d);var t,r=[],a=-1,i=[],o={},c=!1;return e.replace(p,(function(s,u){if(c){if(s!=="</"+t.name+">")return;c=!1}var p,d="/"!==s.charAt(1),m=0===s.indexOf("\x3c!--"),h=u+s.length,y=e.charAt(h);d&&!m&&(a++,"tag"===(t=function(e){var n,t=0,r=!0,a={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return e.replace(f,(function(i){if("="===i)return r=!0,void t++;r?0===t?((l[i]||"/"===e.charAt(e.length-2))&&(a.voidElement=!0),a.name=i):(a.attrs[n]=i.replace(/^['"]|['"]$/g,""),n=void 0):(n&&(a.attrs[n]=n),n=i),t++,r=!1})),a}(s)).type&&n.components[t.name]&&(t.type="component",c=!0),t.voidElement||c||!y||"<"===y||g(t.children,e,a,h,n.ignoreWhitespace),o[t.tagName]=t,0===a&&r.push(t),(p=i[a-1])&&p.children.push(t),i[a]=t),(m||!d||t.voidElement)&&(m||a--,!c&&"<"!==y&&y&&g(p=-1===a?r:i[a].children,e,a,h,n.ignoreWhitespace))})),!r.length&&e.length&&g(r,e,0,0,n.ignoreWhitespace),r},stringify:function(e){return e.reduce((function(e,n){return e+m("",n)}),"")}},b={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},O=t.createContext();function w(){return y}function j(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b=c({},b,{},e)}function S(){return b}var E=function(){function e(){!function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this,e),this.usedNamespaces={}}var n,t,r;return n=e,(t=[{key:"addUsedNamespaces",value:function(e){var n=this;e.forEach((function(e){n.usedNamespaces[e]||(n.usedNamespaces[e]=!0)}))}},{key:"getUsedNamespaces",value:function(){return Object.keys(this.usedNamespaces)}}])&&a(n.prototype,t),r&&a(n,r),e}();function N(e){h=e}function x(){return h}var k={type:"3rdParty",init:function(e){j(e.options.react),N(e)}};function I(e){return function(n){return new Promise((function(t){var r=P();e.getInitialProps?e.getInitialProps(n).then((function(e){t(c({},e,{},r))})):t(r)}))}}function P(){var e=x(),n=e.reportNamespaces?e.reportNamespaces.getUsedNamespaces():[],t={},r={};return e.languages.forEach((function(t){r[t]={},n.forEach((function(n){r[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=r,t.initialLanguage=e.language,t}function R(){if(console&&console.warn){for(var e,n=arguments.length,t=new Array(n),r=0;r<n;r++)t[r]=arguments[r];"string"==typeof t[0]&&(t[0]="react-i18next:: ".concat(t[0])),(e=console).warn.apply(e,t)}}var C={};function T(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&C[n[0]]||("string"==typeof n[0]&&(C[n[0]]=new Date),R.apply(void 0,n))}function A(e,n,t){e.loadNamespaces(n,(function(){if(e.isInitialized)t();else{e.on("initialized",(function n(){setTimeout((function(){e.off("initialized",n)}),0),t()}))}}))}function L(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}function z(e){return e&&(e.children||e.props&&e.props.children)}function D(e){return e?e&&e.children?e.children:e.props&&e.props.children:[]}function B(e){return Array.isArray(e)?e:[e]}function V(e,n,a,i,o){if(""===n)return[];var s=i.transKeepBasicHtmlNodesFor||[],u=n&&new RegExp(s.join("|")).test(n);if(!e&&!u)return[n];var l={};!function e(n){B(n).forEach((function(n){"string"!=typeof n&&(z(n)?e(D(n)):"object"!==r(n)||t.isValidElement(n)||Object.assign(l,n))}))}(e);var f=a.services.interpolator.interpolate(n,c({},l,{},o),a.language);var p=function e(n,a){var o=B(n);return B(a).reduce((function(n,a,l){var f=a.children&&a.children[0]&&a.children[0].content;if("tag"===a.type){var p=o[parseInt(a.name,10)]||{},d=t.isValidElement(p);if("string"==typeof p)n.push(p);else if(z(p)){var g=D(p),m=e(g,a.children),h=function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((function(e){return t.isValidElement(e)}))}(g)&&0===m.length?g:m;p.dummy&&(p.children=h),n.push(t.cloneElement(p,c({},p.props,{key:l}),h))}else if(u&&"object"===r(p)&&p.dummy&&!d){var y=e(o,a.children);n.push(t.cloneElement(p,c({},p.props,{key:l}),y))}else if(Number.isNaN(parseFloat(a.name)))if(i.transSupportBasicHtmlNodes&&s.indexOf(a.name)>-1)if(a.voidElement)n.push(t.createElement(a.name,{key:"".concat(a.name,"-").concat(l)}));else{var v=e(o,a.children);n.push(t.createElement(a.name,{key:"".concat(a.name,"-").concat(l)},v))}else if(a.voidElement)n.push("<".concat(a.name," />"));else{var b=e(o,a.children);n.push("<".concat(a.name,">").concat(b,"</").concat(a.name,">"))}else if("object"!==r(p)||d)1===a.children.length&&f?n.push(t.cloneElement(p,c({},p.props,{key:l}),f)):n.push(t.cloneElement(p,c({},p.props,{key:l})));else{var O=a.children[0]?f:null;O&&n.push(O)}}else"text"===a.type&&n.push(a.content);return n}),[])}([{dummy:!0,children:e}],v.parse("<0>".concat(f,"</0>")));return D(p[0])}function K(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.i18n,a=n.useContext(O),i=w()&&a||{},o=i.i18n,s=i.defaultNS,l=r||o||x();if(l&&!l.reportNamespaces&&(l.reportNamespaces=new E),!l){T("You will need pass in an i18next instance by using initReactI18next");var f=function(e){return Array.isArray(e)?e[e.length-1]:e},p=[f,{},!1];return p.t=f,p.i18n={},p.ready=!1,p}var d=c({},S(),{},l.options.react,{},t),g=d.useSuspense,m=e||s||l.options&&l.options.defaultNS;m="string"==typeof m?[m]:m||["translation"],l.reportNamespaces.addUsedNamespaces&&l.reportNamespaces.addUsedNamespaces(m);var h=(l.isInitialized||l.initializedStoreOnce)&&m.every((function(e){return function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!n.languages||!n.languages.length)return T("i18n.languages were undefined or empty",n.languages),!0;var r=n.languages[0],a=!!n.options&&n.options.fallbackLng,i=n.languages[n.languages.length-1];if("cimode"===r.toLowerCase())return!0;var o=function(e,t){var r=n.services.backendConnector.state["".concat(e,"|").concat(t)];return-1===r||2===r};return!(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!o(n.isLanguageChangingTo,e))&&(!!n.hasResourceBundle(r,e)||(!n.services.backendConnector.backend||!(!o(r,e)||a&&!o(i,e))))}(e,l,d)}));function y(){return{t:l.getFixedT(null,"fallback"===d.nsMode?m:m[0])}}var v=u(n.useState(y()),2),b=v[0],j=v[1];n.useEffect((function(){var e=!0,n=d.bindI18n,t=d.bindI18nStore;function r(){e&&j(y())}return h||g||A(l,m,(function(){e&&j(y())})),n&&l&&l.on(n,r),t&&l&&l.store.on(t,r),function(){e=!1,n&&l&&n.split(" ").forEach((function(e){return l.off(e,r)})),t&&l&&t.split(" ").forEach((function(e){return l.store.off(e,r)}))}}),[m.join()]);var N=[b.t,l,h];if(N.t=b.t,N.i18n=l,N.ready=h,h)return N;if(!h&&!g)return N;throw new Promise((function(e){A(l,m,(function(){j(y()),e()}))}))}function U(e,t){var r=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).i18n,a=n.useContext(O),i=(w()&&a||{}).i18n,o=r||i||x();o.options&&o.options.isClone||(e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.options.ns=Object.values(e).reduce((function(e,n){return Object.keys(n).forEach((function(n){e.indexOf(n)<0&&e.push(n)})),e}),o.options.ns),o.initializedStoreOnce=!0,o.isInitialized=!0),t&&!o.initializedLanguageOnce&&(o.changeLanguage(t),o.initializedLanguageOnce=!0))}e.I18nContext=O,e.I18nextProvider=function(e){var n=e.i18n,r=e.defaultNS,a=e.children;return y=!0,t.createElement(O.Provider,{value:{i18n:n,defaultNS:r}},a)},e.Trans=function(e){var a=e.children,i=e.count,o=e.parent,u=e.i18nKey,l=e.tOptions,f=e.values,p=e.defaults,d=e.components,g=e.ns,m=e.i18n,h=e.t,y=s(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]),v=n.useContext(O),b=w()&&v||{},j=b.i18n,E=b.defaultNS,N=m||j||x();if(!N)return T("You will need pass in an i18next instance by using i18nextReactModule"),a;var k=h||N.t.bind(N)||function(e){return e},I=c({},S(),{},N.options&&N.options.react),P=void 0!==o?o:I.defaultTransParent,C=g||k.ns||E||N.options&&N.options.defaultNS;C="string"==typeof C?[C]:C||["translation"];var A=p||function e(n,a,i,o){if(!a)return"";var s=n,u=B(a),l=o.transKeepBasicHtmlNodesFor||[];return u.forEach((function(n,a){var i="".concat(a);if("string"==typeof n)s="".concat(s).concat(n);else if(z(n)){var u=l.indexOf(n.type)>-1&&1===Object.keys(n.props).length&&"string"==typeof z(n)?n.type:i;s=n.props&&n.props.i18nIsDynamicList?"".concat(s,"<").concat(u,"></").concat(u,">"):"".concat(s,"<").concat(u,">").concat(e("",D(n),a+1,o),"</").concat(u,">")}else if(t.isValidElement(n))s=l.indexOf(n.type)>-1&&0===Object.keys(n.props).length?"".concat(s,"<").concat(n.type,"/>"):"".concat(s,"<").concat(i,"></").concat(i,">");else if("object"===r(n)){var f=c({},n),p=f.format;delete f.format;var d=Object.keys(f);p&&1===d.length?s="".concat(s,"{{").concat(d[0],", ").concat(p,"}}"):1===d.length?s="".concat(s,"{{").concat(d[0],"}}"):R("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",n)}else R("Trans: the passed in value is invalid - seems you passed in a variable like {number} - please pass in variables for interpolation as full objects like {{number}}.",n)})),s}("",a,0,I)||I.transEmptyNodeValue,L=I.hashTransKey,K=u||(L?L(A):A),U=c({},l,{count:i},f,{},f?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:A,ns:C}),F=K?k(K,U):A;return P?t.createElement(P,y,V(d||a,F,N,I,U)):V(d||a,F,N,I,U)},e.Translation=function(e){var n=e.ns,t=e.children,r=u(K(n,s(e,["ns","children"])),3),a=r[0],i=r[1],o=r[2];return t(a,{i18n:i,lng:i.language},o)},e.composeInitialProps=I,e.getDefaults=S,e.getI18n=x,e.getInitialProps=P,e.initReactI18next=k,e.setDefaults=j,e.setI18n=N,e.useSSR=U,e.useTranslation=K,e.withSSR=function(){return function(e){function n(n){var r=n.initialI18nStore,a=n.initialLanguage,i=s(n,["initialI18nStore","initialLanguage"]);return U(r,a),t.createElement(e,c({},i))}return n.getInitialProps=I(e),n.displayName="withI18nextSSR(".concat(L(e),")"),n.WrappedComponent=e,n}},e.withTranslation=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function a(a){var i=a.forwardedRef,o=s(a,["forwardedRef"]),l=u(K(e,o),3),f=c({},o,{t:l[0],i18n:l[1],tReady:l[2]});return n.withRef&&i?f.ref=i:!n.withRef&&i&&(f.forwardedRef=i),t.createElement(r,f)}a.displayName="withI18nextTranslation(".concat(L(r),")"),a.WrappedComponent=r;return n.withRef?t.forwardRef((function(e,n){return t.createElement(a,Object.assign({},e,{forwardedRef:n}))})):a}},Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ define(["exports","react"],(function(e,n){"use strict";var t="default"in n?n.default:n;function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function a(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function o(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function c(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?o(Object(t),!0).forEach((function(n){i(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):o(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}function s(e,n){if(null==e)return{};var t,r,a=function(e,n){if(null==e)return{};var t,r,a={},i=Object.keys(e);for(r=0;r<i.length;r++)t=i[r],n.indexOf(t)>=0||(a[t]=e[t]);return a}(e,n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)t=i[r],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(a[t]=e[t])}return a}function u(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var t=[],r=!0,a=!1,i=void 0;try{for(var o,c=e[Symbol.iterator]();!(r=(o=c.next()).done)&&(t.push(o.value),!n||t.length!==n);r=!0);}catch(e){a=!0,i=e}finally{try{r||null==c.return||c.return()}finally{if(a)throw i}}return t}(e,n)||function(e,n){if(!e)return;if("string"==typeof e)return l(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);"Object"===t&&e.constructor&&(t=e.constructor.name);if("Map"===t||"Set"===t)return Array.from(t);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return l(e,n)}(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}var f={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,menuitem:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},p=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,d=/(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,g=Object.create?Object.create(null):{};function m(e,n,t,r,a){var i=n.indexOf("<",r),o=n.slice(r,-1===i?void 0:i);/^\s*$/.test(o)&&(o=" "),(!a&&i>-1&&t+e.length>=0||" "!==o)&&e.push({type:"text",content:o})}var y,h=function(e,n){n||(n={}),n.components||(n.components=g);var t,r=[],a=-1,i=[],o={},c=!1;return e.replace(d,(function(s,u){if(c){if(s!=="</"+t.name+">")return;c=!1}var l,d="/"!==s.charAt(1),g=0===s.indexOf("\x3c!--"),y=u+s.length,h=e.charAt(y);d&&!g&&(a++,"tag"===(t=function(e){var n,t=0,r=!0,a={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return e.replace(p,(function(i){if("="===i)return r=!0,void t++;r?0===t?((f[i]||"/"===e.charAt(e.length-2))&&(a.voidElement=!0),a.name=i):(a.attrs[n]=i.replace(/^['"]|['"]$/g,""),n=void 0):(n&&(a.attrs[n]=n),n=i),t++,r=!1})),a}(s)).type&&n.components[t.name]&&(t.type="component",c=!0),t.voidElement||c||!h||"<"===h||m(t.children,e,a,y,n.ignoreWhitespace),o[t.tagName]=t,0===a&&r.push(t),(l=i[a-1])&&l.children.push(t),i[a]=t),(g||!d||t.voidElement)&&(g||a--,!c&&"<"!==h&&h&&m(l=-1===a?r:i[a].children,e,a,y,n.ignoreWhitespace))})),!r.length&&e.length&&m(r,e,0,0,n.ignoreWhitespace),r},v={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},b=t.createContext();function O(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};v=c({},v,{},e)}function w(){return v}var j=function(){function e(){!function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this,e),this.usedNamespaces={}}var n,t,r;return n=e,(t=[{key:"addUsedNamespaces",value:function(e){var n=this;e.forEach((function(e){n.usedNamespaces[e]||(n.usedNamespaces[e]=!0)}))}},{key:"getUsedNamespaces",value:function(){return Object.keys(this.usedNamespaces)}}])&&a(n.prototype,t),r&&a(n,r),e}();function S(e){y=e}function E(){return y}var N={type:"3rdParty",init:function(e){O(e.options.react),S(e)}};function x(e){return function(n){return new Promise((function(t){var r=k();e.getInitialProps?e.getInitialProps(n).then((function(e){t(c({},e,{},r))})):t(r)}))}}function k(){var e=E(),n=e.reportNamespaces?e.reportNamespaces.getUsedNamespaces():[],t={},r={};return e.languages.forEach((function(t){r[t]={},n.forEach((function(n){r[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=r,t.initialLanguage=e.language,t}function I(){if(console&&console.warn){for(var e,n=arguments.length,t=new Array(n),r=0;r<n;r++)t[r]=arguments[r];"string"==typeof t[0]&&(t[0]="react-i18next:: ".concat(t[0])),(e=console).warn.apply(e,t)}}var P={};function R(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&P[n[0]]||("string"==typeof n[0]&&(P[n[0]]=new Date),I.apply(void 0,n))}function C(e,n,t){e.loadNamespaces(n,(function(){if(e.isInitialized)t();else{e.on("initialized",(function n(){setTimeout((function(){e.off("initialized",n)}),0),t()}))}}))}function A(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!n.languages||!n.languages.length)return R("i18n.languages were undefined or empty",n.languages),!0;var r=n.languages[0],a=!!n.options&&n.options.fallbackLng,i=n.languages[n.languages.length-1];if("cimode"===r.toLowerCase())return!0;var o=function(e,t){var r=n.services.backendConnector.state["".concat(e,"|").concat(t)];return-1===r||2===r};return!(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!o(n.isLanguageChangingTo,e))&&(!!n.hasResourceBundle(r,e)||(!n.services.backendConnector.backend||!(!o(r,e)||a&&!o(i,e))))}function T(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}function L(e){return e&&(e.children||e.props&&e.props.children)}function z(e){return e?e&&e.children?e.children:e.props&&e.props.children:[]}function D(e){return Array.isArray(e)?e:[e]}function B(e,n,a,i,o){if(""===n)return[];var s=i.transKeepBasicHtmlNodesFor||[],u=n&&new RegExp(s.join("|")).test(n);if(!e&&!u)return[n];var l={};!function e(n){D(n).forEach((function(n){"string"!=typeof n&&(L(n)?e(z(n)):"object"!==r(n)||t.isValidElement(n)||Object.assign(l,n))}))}(e);var f=a.services.interpolator.interpolate(n,c({},l,{},o),a.language);var p=function e(n,a){var o=D(n);return D(a).reduce((function(n,a,l){var f,p,d,g=a.children&&a.children[0]&&a.children[0].content;if("tag"===a.type){var m=o[parseInt(a.name,10)]||{},y=0!==Object.keys(a.attrs).length?(f={props:a.attrs},(d=c({},p=m)).props=Object.assign(f.props,p.props),d):m,h=t.isValidElement(y);if("string"==typeof y)n.push(y);else if(L(y)){var v=z(y),b=e(v,a.children),O=function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((function(e){return t.isValidElement(e)}))}(v)&&0===b.length?v:b;y.dummy&&(y.children=O),n.push(t.cloneElement(y,c({},y.props,{key:l}),O))}else if(u&&"object"===r(y)&&y.dummy&&!h){var w=e(o,a.children);n.push(t.cloneElement(y,c({},y.props,{key:l}),w))}else if(Number.isNaN(parseFloat(a.name)))if(i.transSupportBasicHtmlNodes&&s.indexOf(a.name)>-1)if(a.voidElement)n.push(t.createElement(a.name,{key:"".concat(a.name,"-").concat(l)}));else{var j=e(o,a.children);n.push(t.createElement(a.name,{key:"".concat(a.name,"-").concat(l)},j))}else if(a.voidElement)n.push("<".concat(a.name," />"));else{var S=e(o,a.children);n.push("<".concat(a.name,">").concat(S,"</").concat(a.name,">"))}else if("object"!==r(y)||h)1===a.children.length&&g?n.push(t.cloneElement(y,c({},y.props,{key:l}),g)):n.push(t.cloneElement(y,c({},y.props,{key:l})));else{var E=a.children[0]?g:null;E&&n.push(E)}}else"text"===a.type&&n.push(a.content);return n}),[])}([{dummy:!0,children:e}],h("<0>".concat(f,"</0>")));return z(p[0])}function U(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.i18n,a=n.useContext(b)||{},i=a.i18n,o=a.defaultNS,s=r||i||E();if(s&&!s.reportNamespaces&&(s.reportNamespaces=new j),!s){R("You will need pass in an i18next instance by using initReactI18next");var l=function(e){return Array.isArray(e)?e[e.length-1]:e},f=[l,{},!1];return f.t=l,f.i18n={},f.ready=!1,f}var p=c({},w(),{},s.options.react,{},t),d=p.useSuspense,g=e||o||s.options&&s.options.defaultNS;g="string"==typeof g?[g]:g||["translation"],s.reportNamespaces.addUsedNamespaces&&s.reportNamespaces.addUsedNamespaces(g);var m=(s.isInitialized||s.initializedStoreOnce)&&g.every((function(e){return A(e,s,p)}));function y(){return{t:s.getFixedT(null,"fallback"===p.nsMode?g:g[0])}}var h=n.useState(y()),v=u(h,2),O=v[0],S=v[1],N=n.useRef(!0);n.useEffect((function(){var e=p.bindI18n,n=p.bindI18nStore;function t(){N.current&&S(y())}return N.current=!0,m||d||C(s,g,(function(){N.current&&S(y())})),e&&s&&s.on(e,t),n&&s&&s.store.on(n,t),function(){N.current=!1,e&&s&&e.split(" ").forEach((function(e){return s.off(e,t)})),n&&s&&n.split(" ").forEach((function(e){return s.store.off(e,t)}))}}),[g.join()]);var x=[O.t,s,m];if(x.t=O.t,x.i18n=s,x.ready=m,m)return x;if(!m&&!d)return x;throw new Promise((function(e){C(s,g,(function(){N.current&&S(y()),e()}))}))}function V(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=r.i18n,i=n.useContext(b)||{},o=i.i18n,c=a||o||E();c.options&&c.options.isClone||(e&&!c.initializedStoreOnce&&(c.services.resourceStore.data=e,c.options.ns=Object.values(e).reduce((function(e,n){return Object.keys(n).forEach((function(n){e.indexOf(n)<0&&e.push(n)})),e}),c.options.ns),c.initializedStoreOnce=!0,c.isInitialized=!0),t&&!c.initializedLanguageOnce&&(c.changeLanguage(t),c.initializedLanguageOnce=!0))}e.I18nContext=b,e.I18nextProvider=function(e){var t=e.i18n,r=e.defaultNS,a=e.children;return n.createElement(b.Provider,{value:{i18n:t,defaultNS:r}},a)},e.Trans=function(e){var a=e.children,i=e.count,o=e.parent,u=e.i18nKey,l=e.tOptions,f=e.values,p=e.defaults,d=e.components,g=e.ns,m=e.i18n,y=e.t,h=s(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]),v=n.useContext(b)||{},O=v.i18n,j=v.defaultNS,S=m||O||E();if(!S)return R("You will need pass in an i18next instance by using i18nextReactModule"),a;var N=y||S.t.bind(S)||function(e){return e},x=c({},w(),{},S.options&&S.options.react),k=g||N.ns||j||S.options&&S.options.defaultNS;k="string"==typeof k?[k]:k||["translation"];var P=p||function e(n,a){if(!n)return"";var i="",o=D(n),c=a.transKeepBasicHtmlNodesFor||[];return o.forEach((function(n,o){if("string"==typeof n)i+="".concat(n);else if(t.isValidElement(n)){var u=Object.keys(n.props).length,l=c.indexOf(n.type)>-1,f=n.props.children;if(!f&&l&&0===u)i+="<".concat(n.type,"/>");else if(f||l&&0===u)if(n.props.i18nIsDynamicList)i+="<".concat(o,"></").concat(o,">");else if(l&&1===u&&"string"==typeof f)i+="<".concat(n.type,">").concat(f,"</").concat(n.type,">");else{var p=e(f,a);i+="<".concat(o,">").concat(p,"</").concat(o,">")}else i+="<".concat(o,"></").concat(o,">")}else if("object"===r(n)){var d=n.format,g=s(n,["format"]),m=Object.keys(g);if(1===m.length){var y=d?"".concat(m[0],", ").concat(d):m[0];i+="{{".concat(y,"}}")}else I("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",n)}else I("Trans: the passed in value is invalid - seems you passed in a variable like {number} - please pass in variables for interpolation as full objects like {{number}}.",n)})),i}(a,x)||x.transEmptyNodeValue||u,C=x.hashTransKey,A=u||(C?C(P):P),T=c({},l,{count:i},f,{},f?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:P,ns:k}),L=B(d||a,A?N(A,T):P,S,x,T),z=void 0!==o?o:x.defaultTransParent;return z?t.createElement(z,h,L):L},e.Translation=function(e){var n=e.ns,t=e.children,r=u(U(n,s(e,["ns","children"])),3),a=r[0],i=r[1],o=r[2];return t(a,{i18n:i,lng:i.language},o)},e.composeInitialProps=x,e.getDefaults=w,e.getI18n=E,e.getInitialProps=k,e.initReactI18next=N,e.setDefaults=O,e.setI18n=S,e.useSSR=V,e.useTranslation=U,e.withSSR=function(){return function(e){function n(n){var r=n.initialI18nStore,a=n.initialLanguage,i=s(n,["initialI18nStore","initialLanguage"]);return V(r,a),t.createElement(e,c({},i))}return n.getInitialProps=x(e),n.displayName="withI18nextSSR(".concat(T(e),")"),n.WrappedComponent=e,n}},e.withTranslation=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function a(a){var i=a.forwardedRef,o=s(a,["forwardedRef"]),l=u(U(e,o),3),f=c({},o,{t:l[0],i18n:l[1],tReady:l[2]});return n.withRef&&i?f.ref=i:!n.withRef&&i&&(f.forwardedRef=i),t.createElement(r,f)}a.displayName="withI18nextTranslation(".concat(T(r),")"),a.WrappedComponent=r;return n.withRef?t.forwardRef((function(e,n){return t.createElement(a,Object.assign({},e,{forwardedRef:n}))})):a}},Object.defineProperty(e,"__esModule",{value:!0})}));
@@ -1,13 +1,11 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports.I18nextProvider = I18nextProvider;
9
7
 
10
- var _react = _interopRequireDefault(require("react"));
8
+ var _react = require("react");
11
9
 
12
10
  var _context = require("./context");
13
11
 
@@ -15,8 +13,7 @@ function I18nextProvider(_ref) {
15
13
  var i18n = _ref.i18n,
16
14
  defaultNS = _ref.defaultNS,
17
15
  children = _ref.children;
18
- (0, _context.usedI18nextProvider)(true);
19
- return _react["default"].createElement(_context.I18nContext.Provider, {
16
+ return (0, _react.createElement)(_context.I18nContext.Provider, {
20
17
  value: {
21
18
  i18n: i18n,
22
19
  defaultNS: defaultNS
@@ -12,10 +12,10 @@ exports.Trans = Trans;
12
12
 
13
13
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
14
14
 
15
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
-
17
15
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
18
16
 
17
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
18
+
19
19
  var _react = _interopRequireWildcard(require("react"));
20
20
 
21
21
  var _htmlParseStringify = _interopRequireDefault(require("html-parse-stringify2"));
@@ -26,7 +26,7 @@ var _utils = require("./utils");
26
26
 
27
27
  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; }
28
28
 
29
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
29
+ 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) { (0, _defineProperty2["default"])(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; }
30
30
 
31
31
  function hasChildren(node) {
32
32
  return node && (node.children || node.props && node.props.children);
@@ -48,44 +48,62 @@ function getAsArray(data) {
48
48
  return Array.isArray(data) ? data : [data];
49
49
  }
50
50
 
51
- function nodesToString(startingString, children, index, i18nOptions) {
51
+ function mergeProps(source, target) {
52
+ var newTarget = _objectSpread({}, target); // overwrite source.props when target.props already set
53
+
54
+
55
+ newTarget.props = Object.assign(source.props, target.props);
56
+ return newTarget;
57
+ }
58
+
59
+ function nodesToString(children, i18nOptions) {
52
60
  if (!children) return '';
53
- var stringNode = startingString;
61
+ var stringNode = ''; // do not use `React.Children.toArray`, will fail at object children
62
+
54
63
  var childrenArray = getAsArray(children);
55
- var keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
56
- childrenArray.forEach(function (child, i) {
57
- var elementKey = "".concat(i);
64
+ var keepArray = i18nOptions.transKeepBasicHtmlNodesFor || []; // e.g. lorem <br/> ipsum {{ messageCount, format }} dolor <strong>bold</strong> amet
58
65
 
66
+ childrenArray.forEach(function (child, childIndex) {
59
67
  if (typeof child === 'string') {
60
- stringNode = "".concat(stringNode).concat(child);
61
- } else if (hasChildren(child)) {
62
- var elementTag = keepArray.indexOf(child.type) > -1 && Object.keys(child.props).length === 1 && typeof hasChildren(child) === 'string' ? child.type : elementKey;
63
-
64
- if (child.props && child.props.i18nIsDynamicList) {
65
- // we got a dynamic list like "<ul>{['a', 'b'].map(item => ( <li key={item}>{item}</li> ))}</ul>""
66
- // the result should be "<0></0>" and not "<0><0>a</0><1>b</1></0>"
67
- stringNode = "".concat(stringNode, "<").concat(elementTag, "></").concat(elementTag, ">");
68
- } else {
69
- // regular case mapping the inner children
70
- stringNode = "".concat(stringNode, "<").concat(elementTag, ">").concat(nodesToString('', getChildren(child), i + 1, i18nOptions), "</").concat(elementTag, ">");
71
- }
68
+ // actual e.g. lorem
69
+ // expected e.g. lorem
70
+ stringNode += "".concat(child);
72
71
  } else if (_react["default"].isValidElement(child)) {
73
- if (keepArray.indexOf(child.type) > -1 && Object.keys(child.props).length === 0) {
74
- stringNode = "".concat(stringNode, "<").concat(child.type, "/>");
72
+ var childPropsCount = Object.keys(child.props).length;
73
+ var shouldKeepChild = keepArray.indexOf(child.type) > -1;
74
+ var childChildren = child.props.children;
75
+
76
+ if (!childChildren && shouldKeepChild && childPropsCount === 0) {
77
+ // actual e.g. lorem <br/> ipsum
78
+ // expected e.g. lorem <br/> ipsum
79
+ stringNode += "<".concat(child.type, "/>");
80
+ } else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) {
81
+ // actual e.g. lorem <hr className="test" /> ipsum
82
+ // expected e.g. lorem <0></0> ipsum
83
+ stringNode += "<".concat(childIndex, "></").concat(childIndex, ">");
84
+ } else if (child.props.i18nIsDynamicList) {
85
+ // we got a dynamic list like
86
+ // e.g. <ul i18nIsDynamicList>{['a', 'b'].map(item => ( <li key={item}>{item}</li> ))}</ul>
87
+ // expected e.g. "<0></0>", not e.g. "<0><0>a</0><1>b</1></0>"
88
+ stringNode += "<".concat(childIndex, "></").concat(childIndex, ">");
89
+ } else if (shouldKeepChild && childPropsCount === 1 && typeof childChildren === 'string') {
90
+ // actual e.g. dolor <strong>bold</strong> amet
91
+ // expected e.g. dolor <strong>bold</strong> amet
92
+ stringNode += "<".concat(child.type, ">").concat(childChildren, "</").concat(child.type, ">");
75
93
  } else {
76
- stringNode = "".concat(stringNode, "<").concat(elementKey, "></").concat(elementKey, ">");
94
+ // regular case mapping the inner children
95
+ var content = nodesToString(childChildren, i18nOptions);
96
+ stringNode += "<".concat(childIndex, ">").concat(content, "</").concat(childIndex, ">");
77
97
  }
78
98
  } else if ((0, _typeof2["default"])(child) === 'object') {
79
- var clone = _objectSpread({}, child);
80
-
81
- var format = clone.format;
82
- delete clone.format;
99
+ // e.g. lorem {{ value, format }} ipsum
100
+ var format = child.format,
101
+ clone = (0, _objectWithoutProperties2["default"])(child, ["format"]);
83
102
  var keys = Object.keys(clone);
84
103
 
85
- if (format && keys.length === 1) {
86
- stringNode = "".concat(stringNode, "{{").concat(keys[0], ", ").concat(format, "}}");
87
- } else if (keys.length === 1) {
88
- stringNode = "".concat(stringNode, "{{").concat(keys[0], "}}");
104
+ if (keys.length === 1) {
105
+ var value = format ? "".concat(keys[0], ", ").concat(format) : keys[0];
106
+ stringNode += "{{".concat(value, "}}");
89
107
  } else {
90
108
  // not a valid interpolation object (can only contain one value plus format)
91
109
  (0, _utils.warn)("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.", child);
@@ -128,7 +146,10 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts) {
128
146
  var translationContent = node.children && node.children[0] && node.children[0].content;
129
147
 
130
148
  if (node.type === 'tag') {
131
- var child = reactNodes[parseInt(node.name, 10)] || {};
149
+ var tmp = reactNodes[parseInt(node.name, 10)] || {};
150
+ var child = Object.keys(node.attrs).length !== 0 ? mergeProps({
151
+ props: node.attrs
152
+ }, tmp) : tmp;
132
153
 
133
154
  var isElement = _react["default"].isValidElement(child);
134
155
 
@@ -227,9 +248,8 @@ function Trans(_ref) {
227
248
  i18nFromProps = _ref.i18n,
228
249
  tFromProps = _ref.t,
229
250
  additionalProps = (0, _objectWithoutProperties2["default"])(_ref, ["children", "count", "parent", "i18nKey", "tOptions", "values", "defaults", "components", "ns", "i18n", "t"]);
230
- var ReactI18nContext = (0, _react.useContext)(_context.I18nContext);
231
251
 
232
- var _ref2 = (0, _context.getHasUsedI18nextProvider)() ? ReactI18nContext || {} : {},
252
+ var _ref2 = (0, _react.useContext)(_context.I18nContext) || {},
233
253
  i18nFromContext = _ref2.i18n,
234
254
  defaultNSFromContext = _ref2.defaultNS;
235
255
 
@@ -244,13 +264,12 @@ function Trans(_ref) {
244
264
  return k;
245
265
  };
246
266
 
247
- var reactI18nextOptions = _objectSpread({}, (0, _context.getDefaults)(), {}, i18n.options && i18n.options.react);
267
+ var reactI18nextOptions = _objectSpread({}, (0, _context.getDefaults)(), {}, i18n.options && i18n.options.react); // prepare having a namespace
248
268
 
249
- var useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent; // prepare having a namespace
250
269
 
251
270
  var namespaces = ns || t.ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
252
271
  namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
253
- var defaultValue = defaults || nodesToString('', children, 0, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue;
272
+ var defaultValue = defaults || nodesToString(children, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue || i18nKey;
254
273
  var hashTransKey = reactI18nextOptions.hashTransKey;
255
274
  var key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
256
275
  var interpolationOverride = values ? {} : {
@@ -268,6 +287,9 @@ function Trans(_ref) {
268
287
  });
269
288
 
270
289
  var translation = key ? t(key, combinedTOpts) : defaultValue;
271
- if (!useAsParent) return renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts);
272
- return _react["default"].createElement(useAsParent, additionalProps, renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts));
290
+ var content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts); // allows user to pass `null` to `parent`
291
+ // and override `defaultTransParent` if is present
292
+
293
+ var useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
294
+ return useAsParent ? _react["default"].createElement(useAsParent, additionalProps, content) : content;
273
295
  }