react-i18next 11.8.15 → 11.9.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,7 @@
1
+ ### 11.9.0
2
+
3
+ - typescript/icu macro: add new syntax for interpolation of complex types [1316](https://github.com/i18next/react-i18next/pull/1316) -> [docs for template usage](https://react.i18next.com/misc/using-with-icu-format#tagged-template-for-icu)
4
+
1
5
  ### 11.8.15
2
6
 
3
7
  - ignore null children in Trans component [1307](https://github.com/i18next/react-i18next/issues/1307)
package/README.md CHANGED
@@ -18,10 +18,10 @@
18
18
 
19
19
  ### IMPORTANT:
20
20
 
21
- Master Branch is the new v10 using hooks.
21
+ Master Branch is the newest version using hooks (>= v10).
22
22
 
23
23
  ```bash
24
- $ v10.0.0
24
+ $ >=v10.0.0
25
25
  npm i react-i18next
26
26
  ```
27
27
 
@@ -37,6 +37,7 @@ npm i react-i18next@legacy
37
37
  ### Documentation
38
38
 
39
39
  The documentation is published on [react.i18next.com](https://react.i18next.com)
40
+ The general i18next documentation is published on [www.i18next.com](https://www.i18next.com)
40
41
 
41
42
  ### What will my code look like?
42
43
 
@@ -102,10 +103,16 @@ $ npm install react-i18next
102
103
 
103
104
  - If you don't use a module loader it will be added to `window.reactI18next`
104
105
 
106
+ ### Do you like to read a more complete step by step tutorial?
107
+
108
+ [Here](https://dev.to/adrai/how-to-properly-internationalize-a-react-application-using-i18next-3hdb) you'll find a simple tutorial on how to best use react-i18next.
109
+ Some basics of i18next and some cool possibilities on how to optimize your localization workflow.
110
+
105
111
  ### Examples
106
112
 
107
113
  - [Example react](https://github.com/i18next/react-i18next/tree/master/example/react)
108
114
  - [Example react with typescript 4.1+](https://github.com/i18next/react-i18next/tree/master/example/react-typescript4.1)
115
+ - [Example locize.com](https://github.com/i18next/react-i18next/tree/master/example/locize)
109
116
 
110
117
  #### v9 samples
111
118
 
@@ -117,7 +124,7 @@ $ npm install react-i18next
117
124
  - [Example razzle](https://github.com/i18next/react-i18next/tree/master/example/v9.x.x/razzle-ssr)
118
125
  - [Example hashbase / beaker browser](https://github.com/i18next/react-i18next/tree/master/example/v9.x.x/dat)
119
126
  - [Example storybook](https://github.com/i18next/react-i18next/tree/master/example/v9.x.x/storybook)
120
- - [Example locize.com](https://github.com/i18next/react-i18next/tree/master/example/v9.x.x/locize-example)
127
+ - [Example locize.com](https://github.com/i18next/react-i18next/tree/master/example/v9.x.x/locize)
121
128
  - [Example test with jest](https://github.com/i18next/react-i18next/tree/master/example/v9.x.x/test-jest)
122
129
 
123
130
  ### Requirements
@@ -921,17 +921,42 @@ define(['exports', 'react'], function (exports, React) { 'use strict';
921
921
  };
922
922
  }
923
923
 
924
+ var date = function date() {
925
+ return '';
926
+ };
927
+ var time = function time() {
928
+ return '';
929
+ };
930
+ var number = function number() {
931
+ return '';
932
+ };
933
+ var select = function select() {
934
+ return '';
935
+ };
936
+ var plural = function plural() {
937
+ return '';
938
+ };
939
+ var selectOrdinal = function selectOrdinal() {
940
+ return '';
941
+ };
942
+
924
943
  exports.I18nContext = I18nContext;
925
944
  exports.I18nextProvider = I18nextProvider;
926
945
  exports.Trans = Trans;
927
946
  exports.Translation = Translation;
928
947
  exports.composeInitialProps = composeInitialProps;
948
+ exports.date = date;
929
949
  exports.getDefaults = getDefaults;
930
950
  exports.getI18n = getI18n;
931
951
  exports.getInitialProps = getInitialProps;
932
952
  exports.initReactI18next = initReactI18next;
953
+ exports.number = number;
954
+ exports.plural = plural;
955
+ exports.select = select;
956
+ exports.selectOrdinal = selectOrdinal;
933
957
  exports.setDefaults = setDefaults;
934
958
  exports.setI18n = setI18n;
959
+ exports.time = time;
935
960
  exports.useSSR = useSSR;
936
961
  exports.useTranslation = useTranslation;
937
962
  exports.withSSR = withSSR;
@@ -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 i(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 a(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 s(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){a(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 c(e,n){if(null==e)return{};var t,r,i=function(e,n){if(null==e)return{};var t,r,i={},a=Object.keys(e);for(r=0;r<a.length;r++)t=a[r],n.indexOf(t)>=0||(i[t]=e[t]);return i}(e,n);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)t=a[r],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(i[t]=e[t])}return i}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,i=!1,a=void 0;try{for(var o,s=e[Symbol.iterator]();!(r=(o=s.next()).done)&&(t.push(o.value),!n||t.length!==n);r=!0);}catch(e){i=!0,a=e}finally{try{r||null==s.return||s.return()}finally{if(i)throw a}}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(e);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,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},p=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function d(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(f[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var r=e.indexOf("--\x3e");return{type:"comment",comment:-1!==r?e.slice(4,r):""}}for(var i=new RegExp(p),a=null;null!==(a=i.exec(e));)if(a[0].trim())if(a[1]){var o=a[1].trim(),s=[o,""];o.indexOf("=")>-1&&(s=o.split("=")),n.attrs[s[0]]=s[1],i.lastIndex--}else a[2]&&(n.attrs[a[2]]=a[3].trim().substring(1,a[3].length-1));return n}var m=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,g=/^\s*$/,h=Object.create(null);var y,v=function(e,n){n||(n={}),n.components||(n.components=h);var t,r=[],i=[],a=-1,o=!1;if(0!==e.indexOf("<")){var s=e.indexOf("<");r.push({type:"text",content:-1===s?e:e.substring(0,s)})}return e.replace(m,(function(s,c){if(o){if(s!=="</"+t.name+">")return;o=!1}var u,l="/"!==s.charAt(1),f=s.startsWith("\x3c!--"),p=c+s.length,m=e.charAt(p);if(f){var h=d(s);return a<0?(r.push(h),r):((u=i[a]).children.push(h),r)}if(l&&(a++,"tag"===(t=d(s)).type&&n.components[t.name]&&(t.type="component",o=!0),t.voidElement||o||!m||"<"===m||t.children.push({type:"text",content:e.slice(p,e.indexOf("<",p))}),0===a&&r.push(t),(u=i[a-1])&&u.children.push(t),i[a]=t),(!l||t.voidElement)&&(a>-1&&(t.voidElement||t.name===s.slice(2,-1))&&(a--,t=-1===a?r:i[a]),!o&&"<"!==m&&m)){u=-1===a?r:i[a].children;var y=e.indexOf("<",p),v=e.slice(p,-1===y?void 0:y);g.test(v)&&(v=" "),(y>-1&&a+u.length>=0||" "!==v)&&u.push({type:"text",content:v})}})),r},b={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},O=t.createContext();function w(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b=s(s({},b),e)}function j(){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)}}])&&i(n.prototype,t),r&&i(n,r),e}();function S(e){y=e}function x(){return y}var N={type:"3rdParty",init:function(e){w(e.options.react),S(e)}};function I(e){return function(n){return new Promise((function(t){var r=k();e.getInitialProps?e.getInitialProps(n).then((function(e){t(s(s({},e),r))})):t(r)}))}}function k(){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 P(){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 R={};function C(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&R[n[0]]||("string"==typeof n[0]&&(R[n[0]]=new Date),P.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 T(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!n.languages||!n.languages.length)return C("i18n.languages were undefined or empty",n.languages),!0;var r=n.languages[0],i=!!n.options&&n.options.fallbackLng,a=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)||i&&!o(a,e))))}function z(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}function L(e,n){if(!e)return!1;var t=e.props?e.props.children:e.children;return n?t.length>0:!!t}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 U(e,n,i,a,o){if(""===n)return[];var c=a.transKeepBasicHtmlNodesFor||[],u=n&&new RegExp(c.join("|")).test(n);if(!e&&!u)return[n];var l={};!function e(n){B(n).forEach((function(n){"string"!=typeof n&&(L(n)?e(D(n)):"object"!==r(n)||t.isValidElement(n)||Object.assign(l,n))}))}(e);var f=i.services.interpolator.interpolate(n,s(s({},l),o),i.language),p=v("<0>".concat(f,"</0>"));function d(e,n,r){var i=D(e),a=g(i,n.children,r);return function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((function(e){return t.isValidElement(e)}))}(i)&&0===a.length?i:a}function m(e,n,r,i,a){e.dummy&&(e.children=n),r.push(t.cloneElement(e,s(s({},e.props),{},{key:i}),a?void 0:n))}function g(n,i,o){var l=B(n);return B(i).reduce((function(n,i,f){var p,h,y,v=i.children&&i.children[0]&&i.children[0].content;if("tag"===i.type){var b=l[parseInt(i.name,10)];!b&&1===o.length&&o[0][i.name]&&(b=o[0][i.name]),b||(b={});var O=0!==Object.keys(i.attrs).length?(p={props:i.attrs},(y=s({},h=b)).props=Object.assign(p.props,h.props),y):b,w=t.isValidElement(O),j=w&&L(i,!0)&&!i.voidElement,E=u&&"object"===r(O)&&O.dummy&&!w,S="object"===r(e)&&null!==e&&Object.hasOwnProperty.call(e,i.name);if("string"==typeof O)n.push(O);else if(L(O)||j){m(O,d(O,i,o),n,f)}else if(E){var x=g(l,i.children,o);n.push(t.cloneElement(O,s(s({},O.props),{},{key:f}),x))}else if(Number.isNaN(parseFloat(i.name))){if(S)m(O,d(O,i,o),n,f,i.voidElement);else if(a.transSupportBasicHtmlNodes&&c.indexOf(i.name)>-1)if(i.voidElement)n.push(t.createElement(i.name,{key:"".concat(i.name,"-").concat(f)}));else{var N=g(l,i.children,o);n.push(t.createElement(i.name,{key:"".concat(i.name,"-").concat(f)},N))}else if(i.voidElement)n.push("<".concat(i.name," />"));else{var I=g(l,i.children,o);n.push("<".concat(i.name,">").concat(I,"</").concat(i.name,">"))}}else if("object"!==r(O)||w)1===i.children.length&&v?n.push(t.cloneElement(O,s(s({},O.props),{},{key:f}),v)):n.push(t.cloneElement(O,s(s({},O.props),{},{key:f})));else{var k=i.children[0]?v:null;k&&n.push(k)}}else"text"===i.type&&n.push(i.content);return n}),[])}return D(g([{dummy:!0,children:e}],p,B(e||[]))[0])}function V(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.i18n,i=n.useContext(O)||{},a=i.i18n,o=i.defaultNS,c=r||a||x();if(c&&!c.reportNamespaces&&(c.reportNamespaces=new E),!c){C("You will need to 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}c.options.react&&void 0!==c.options.react.wait&&C("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");var p=s(s(s({},j()),c.options.react),t),d=p.useSuspense,m=e||o||c.options&&c.options.defaultNS;m="string"==typeof m?[m]:m||["translation"],c.reportNamespaces.addUsedNamespaces&&c.reportNamespaces.addUsedNamespaces(m);var g=(c.isInitialized||c.initializedStoreOnce)&&m.every((function(e){return T(e,c,p)}));function h(){return c.getFixedT(null,"fallback"===p.nsMode?m:m[0])}var y=n.useState(h),v=u(y,2),b=v[0],w=v[1],S=n.useRef(!0);n.useEffect((function(){var e=p.bindI18n,n=p.bindI18nStore;function t(){S.current&&w(h)}return S.current=!0,g||d||A(c,m,(function(){S.current&&w(h)})),e&&c&&c.on(e,t),n&&c&&c.store.on(n,t),function(){S.current=!1,e&&c&&e.split(" ").forEach((function(e){return c.off(e,t)})),n&&c&&n.split(" ").forEach((function(e){return c.store.off(e,t)}))}}),[c,m.join()]);var N=n.useRef(!0);n.useEffect((function(){S.current&&!N.current&&w(h),N.current=!1}),[c]);var I=[b,c,g];if(I.t=b,I.i18n=c,I.ready=g,g)return I;if(!g&&!d)return I;throw new Promise((function(e){A(c,m,(function(){e()}))}))}function K(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=r.i18n,a=n.useContext(O)||{},o=a.i18n,s=i||o||x();s.options&&s.options.isClone||(e&&!s.initializedStoreOnce&&(s.services.resourceStore.data=e,s.options.ns=Object.values(e).reduce((function(e,n){return Object.keys(n).forEach((function(n){e.indexOf(n)<0&&e.push(n)})),e}),s.options.ns),s.initializedStoreOnce=!0,s.isInitialized=!0),t&&!s.initializedLanguageOnce&&(s.changeLanguage(t),s.initializedLanguageOnce=!0))}e.I18nContext=O,e.I18nextProvider=function(e){var t=e.i18n,r=e.defaultNS,i=e.children,a=n.useMemo((function(){return{i18n:t,defaultNS:r}}),[t,r]);return n.createElement(O.Provider,{value:a},i)},e.Trans=function(e){var i=e.children,a=e.count,o=e.parent,u=e.i18nKey,l=e.tOptions,f=void 0===l?{}:l,p=e.values,d=e.defaults,m=e.components,g=e.ns,h=e.i18n,y=e.t,v=c(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]),b=n.useContext(O)||{},w=b.i18n,E=b.defaultNS,S=h||w||x();if(!S)return C("You will need to pass in an i18next instance by using i18nextReactModule"),i;var N=y||S.t.bind(S)||function(e){return e},I=s(s({},j()),S.options&&S.options.react),k=g||N.ns||E||S.options&&S.options.defaultNS;k="string"==typeof k?[k]:k||["translation"];var R=d||function e(n,i){if(!n)return"";var a="",o=B(n),s=i.transKeepBasicHtmlNodesFor||[];return o.forEach((function(n,o){if("string"==typeof n)a+="".concat(n);else if(t.isValidElement(n)){var u=Object.keys(n.props).length,l=s.indexOf(n.type)>-1,f=n.props.children;if(!f&&l&&0===u)a+="<".concat(n.type,"/>");else if(f||l&&0===u)if(n.props.i18nIsDynamicList)a+="<".concat(o,"></").concat(o,">");else if(l&&1===u&&"string"==typeof f)a+="<".concat(n.type,">").concat(f,"</").concat(n.type,">");else{var p=e(f,i);a+="<".concat(o,">").concat(p,"</").concat(o,">")}else a+="<".concat(o,"></").concat(o,">")}else if(null===n)P("Trans: the passed in value is invalid - seems you passed in a null child.");else if("object"===r(n)){var d=n.format,m=c(n,["format"]),g=Object.keys(m);if(1===g.length){var h=d?"".concat(g[0],", ").concat(d):g[0];a+="{{".concat(h,"}}")}else P("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",n)}else P("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)})),a}(i,I)||I.transEmptyNodeValue||u,A=I.hashTransKey,T=u||(A?A(R):R),z=p?f.interpolation:{interpolation:s(s({},f.interpolation),{},{prefix:"#$?",suffix:"?$#"})},L=s(s(s(s({},f),{},{count:a},p),z),{},{defaultValue:R,ns:k}),D=U(m||i,T?N(T,L):R,S,I,L),V=void 0!==o?o:I.defaultTransParent;return V?t.createElement(V,v,D):D},e.Translation=function(e){var n=e.ns,t=e.children,r=u(V(n,c(e,["ns","children"])),3),i=r[0],a=r[1],o=r[2];return t(i,{i18n:a,lng:a.language},o)},e.composeInitialProps=I,e.getDefaults=j,e.getI18n=x,e.getInitialProps=k,e.initReactI18next=N,e.setDefaults=w,e.setI18n=S,e.useSSR=K,e.useTranslation=V,e.withSSR=function(){return function(e){function n(n){var r=n.initialI18nStore,i=n.initialLanguage,a=c(n,["initialI18nStore","initialLanguage"]);return K(r,i),t.createElement(e,s({},a))}return n.getInitialProps=I(e),n.displayName="withI18nextSSR(".concat(z(e),")"),n.WrappedComponent=e,n}},e.withTranslation=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function i(i){var a=i.forwardedRef,o=c(i,["forwardedRef"]),l=u(V(e,o),3),f=l[0],p=l[1],d=l[2],m=s(s({},o),{},{t:f,i18n:p,tReady:d});return n.withRef&&a?m.ref=a:!n.withRef&&a&&(m.forwardedRef=a),t.createElement(r,m)}i.displayName="withI18nextTranslation(".concat(z(r),")"),i.WrappedComponent=r;return n.withRef?t.forwardRef((function(e,n){return t.createElement(i,Object.assign({},e,{forwardedRef:n}))})):i}},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 i(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 a(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){a(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,i=function(e,n){if(null==e)return{};var t,r,i={},a=Object.keys(e);for(r=0;r<a.length;r++)t=a[r],n.indexOf(t)>=0||(i[t]=e[t]);return i}(e,n);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)t=a[r],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(i[t]=e[t])}return i}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,i=!1,a=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){i=!0,a=e}finally{try{r||null==c.return||c.return()}finally{if(i)throw a}}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(e);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,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},p=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function d(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(f[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var r=e.indexOf("--\x3e");return{type:"comment",comment:-1!==r?e.slice(4,r):""}}for(var i=new RegExp(p),a=null;null!==(a=i.exec(e));)if(a[0].trim())if(a[1]){var o=a[1].trim(),c=[o,""];o.indexOf("=")>-1&&(c=o.split("=")),n.attrs[c[0]]=c[1],i.lastIndex--}else a[2]&&(n.attrs[a[2]]=a[3].trim().substring(1,a[3].length-1));return n}var m=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,g=/^\s*$/,h=Object.create(null);var y,v=function(e,n){n||(n={}),n.components||(n.components=h);var t,r=[],i=[],a=-1,o=!1;if(0!==e.indexOf("<")){var c=e.indexOf("<");r.push({type:"text",content:-1===c?e:e.substring(0,c)})}return e.replace(m,(function(c,s){if(o){if(c!=="</"+t.name+">")return;o=!1}var u,l="/"!==c.charAt(1),f=c.startsWith("\x3c!--"),p=s+c.length,m=e.charAt(p);if(f){var h=d(c);return a<0?(r.push(h),r):((u=i[a]).children.push(h),r)}if(l&&(a++,"tag"===(t=d(c)).type&&n.components[t.name]&&(t.type="component",o=!0),t.voidElement||o||!m||"<"===m||t.children.push({type:"text",content:e.slice(p,e.indexOf("<",p))}),0===a&&r.push(t),(u=i[a-1])&&u.children.push(t),i[a]=t),(!l||t.voidElement)&&(a>-1&&(t.voidElement||t.name===c.slice(2,-1))&&(a--,t=-1===a?r:i[a]),!o&&"<"!==m&&m)){u=-1===a?r:i[a].children;var y=e.indexOf("<",p),v=e.slice(p,-1===y?void 0:y);g.test(v)&&(v=" "),(y>-1&&a+u.length>=0||" "!==v)&&u.push({type:"text",content:v})}})),r},b={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},O=t.createContext();function w(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b=c(c({},b),e)}function j(){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)}}])&&i(n.prototype,t),r&&i(n,r),e}();function S(e){y=e}function x(){return y}var N={type:"3rdParty",init:function(e){w(e.options.react),S(e)}};function I(e){return function(n){return new Promise((function(t){var r=k();e.getInitialProps?e.getInitialProps(n).then((function(e){t(c(c({},e),r))})):t(r)}))}}function k(){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 P(){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 R={};function C(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&R[n[0]]||("string"==typeof n[0]&&(R[n[0]]=new Date),P.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 T(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!n.languages||!n.languages.length)return C("i18n.languages were undefined or empty",n.languages),!0;var r=n.languages[0],i=!!n.options&&n.options.fallbackLng,a=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)||i&&!o(a,e))))}function z(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}function L(e,n){if(!e)return!1;var t=e.props?e.props.children:e.children;return n?t.length>0:!!t}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 U(e,n,i,a,o){if(""===n)return[];var s=a.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&&(L(n)?e(D(n)):"object"!==r(n)||t.isValidElement(n)||Object.assign(l,n))}))}(e);var f=i.services.interpolator.interpolate(n,c(c({},l),o),i.language),p=v("<0>".concat(f,"</0>"));function d(e,n,r){var i=D(e),a=g(i,n.children,r);return function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((function(e){return t.isValidElement(e)}))}(i)&&0===a.length?i:a}function m(e,n,r,i,a){e.dummy&&(e.children=n),r.push(t.cloneElement(e,c(c({},e.props),{},{key:i}),a?void 0:n))}function g(n,i,o){var l=B(n);return B(i).reduce((function(n,i,f){var p,h,y,v=i.children&&i.children[0]&&i.children[0].content;if("tag"===i.type){var b=l[parseInt(i.name,10)];!b&&1===o.length&&o[0][i.name]&&(b=o[0][i.name]),b||(b={});var O=0!==Object.keys(i.attrs).length?(p={props:i.attrs},(y=c({},h=b)).props=Object.assign(p.props,h.props),y):b,w=t.isValidElement(O),j=w&&L(i,!0)&&!i.voidElement,E=u&&"object"===r(O)&&O.dummy&&!w,S="object"===r(e)&&null!==e&&Object.hasOwnProperty.call(e,i.name);if("string"==typeof O)n.push(O);else if(L(O)||j){m(O,d(O,i,o),n,f)}else if(E){var x=g(l,i.children,o);n.push(t.cloneElement(O,c(c({},O.props),{},{key:f}),x))}else if(Number.isNaN(parseFloat(i.name))){if(S)m(O,d(O,i,o),n,f,i.voidElement);else if(a.transSupportBasicHtmlNodes&&s.indexOf(i.name)>-1)if(i.voidElement)n.push(t.createElement(i.name,{key:"".concat(i.name,"-").concat(f)}));else{var N=g(l,i.children,o);n.push(t.createElement(i.name,{key:"".concat(i.name,"-").concat(f)},N))}else if(i.voidElement)n.push("<".concat(i.name," />"));else{var I=g(l,i.children,o);n.push("<".concat(i.name,">").concat(I,"</").concat(i.name,">"))}}else if("object"!==r(O)||w)1===i.children.length&&v?n.push(t.cloneElement(O,c(c({},O.props),{},{key:f}),v)):n.push(t.cloneElement(O,c(c({},O.props),{},{key:f})));else{var k=i.children[0]?v:null;k&&n.push(k)}}else"text"===i.type&&n.push(i.content);return n}),[])}return D(g([{dummy:!0,children:e}],p,B(e||[]))[0])}function V(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.i18n,i=n.useContext(O)||{},a=i.i18n,o=i.defaultNS,s=r||a||x();if(s&&!s.reportNamespaces&&(s.reportNamespaces=new E),!s){C("You will need to 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}s.options.react&&void 0!==s.options.react.wait&&C("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");var p=c(c(c({},j()),s.options.react),t),d=p.useSuspense,m=e||o||s.options&&s.options.defaultNS;m="string"==typeof m?[m]:m||["translation"],s.reportNamespaces.addUsedNamespaces&&s.reportNamespaces.addUsedNamespaces(m);var g=(s.isInitialized||s.initializedStoreOnce)&&m.every((function(e){return T(e,s,p)}));function h(){return s.getFixedT(null,"fallback"===p.nsMode?m:m[0])}var y=n.useState(h),v=u(y,2),b=v[0],w=v[1],S=n.useRef(!0);n.useEffect((function(){var e=p.bindI18n,n=p.bindI18nStore;function t(){S.current&&w(h)}return S.current=!0,g||d||A(s,m,(function(){S.current&&w(h)})),e&&s&&s.on(e,t),n&&s&&s.store.on(n,t),function(){S.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)}))}}),[s,m.join()]);var N=n.useRef(!0);n.useEffect((function(){S.current&&!N.current&&w(h),N.current=!1}),[s]);var I=[b,s,g];if(I.t=b,I.i18n=s,I.ready=g,g)return I;if(!g&&!d)return I;throw new Promise((function(e){A(s,m,(function(){e()}))}))}function K(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=r.i18n,a=n.useContext(O)||{},o=a.i18n,c=i||o||x();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=O,e.I18nextProvider=function(e){var t=e.i18n,r=e.defaultNS,i=e.children,a=n.useMemo((function(){return{i18n:t,defaultNS:r}}),[t,r]);return n.createElement(O.Provider,{value:a},i)},e.Trans=function(e){var i=e.children,a=e.count,o=e.parent,u=e.i18nKey,l=e.tOptions,f=void 0===l?{}:l,p=e.values,d=e.defaults,m=e.components,g=e.ns,h=e.i18n,y=e.t,v=s(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]),b=n.useContext(O)||{},w=b.i18n,E=b.defaultNS,S=h||w||x();if(!S)return C("You will need to pass in an i18next instance by using i18nextReactModule"),i;var N=y||S.t.bind(S)||function(e){return e},I=c(c({},j()),S.options&&S.options.react),k=g||N.ns||E||S.options&&S.options.defaultNS;k="string"==typeof k?[k]:k||["translation"];var R=d||function e(n,i){if(!n)return"";var a="",o=B(n),c=i.transKeepBasicHtmlNodesFor||[];return o.forEach((function(n,o){if("string"==typeof n)a+="".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)a+="<".concat(n.type,"/>");else if(f||l&&0===u)if(n.props.i18nIsDynamicList)a+="<".concat(o,"></").concat(o,">");else if(l&&1===u&&"string"==typeof f)a+="<".concat(n.type,">").concat(f,"</").concat(n.type,">");else{var p=e(f,i);a+="<".concat(o,">").concat(p,"</").concat(o,">")}else a+="<".concat(o,"></").concat(o,">")}else if(null===n)P("Trans: the passed in value is invalid - seems you passed in a null child.");else if("object"===r(n)){var d=n.format,m=s(n,["format"]),g=Object.keys(m);if(1===g.length){var h=d?"".concat(g[0],", ").concat(d):g[0];a+="{{".concat(h,"}}")}else P("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",n)}else P("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)})),a}(i,I)||I.transEmptyNodeValue||u,A=I.hashTransKey,T=u||(A?A(R):R),z=p?f.interpolation:{interpolation:c(c({},f.interpolation),{},{prefix:"#$?",suffix:"?$#"})},L=c(c(c(c({},f),{},{count:a},p),z),{},{defaultValue:R,ns:k}),D=U(m||i,T?N(T,L):R,S,I,L),V=void 0!==o?o:I.defaultTransParent;return V?t.createElement(V,v,D):D},e.Translation=function(e){var n=e.ns,t=e.children,r=u(V(n,s(e,["ns","children"])),3),i=r[0],a=r[1],o=r[2];return t(i,{i18n:a,lng:a.language},o)},e.composeInitialProps=I,e.date=function(){return""},e.getDefaults=j,e.getI18n=x,e.getInitialProps=k,e.initReactI18next=N,e.number=function(){return""},e.plural=function(){return""},e.select=function(){return""},e.selectOrdinal=function(){return""},e.setDefaults=w,e.setI18n=S,e.time=function(){return""},e.useSSR=K,e.useTranslation=V,e.withSSR=function(){return function(e){function n(n){var r=n.initialI18nStore,i=n.initialLanguage,a=s(n,["initialI18nStore","initialLanguage"]);return K(r,i),t.createElement(e,c({},a))}return n.getInitialProps=I(e),n.displayName="withI18nextSSR(".concat(z(e),")"),n.WrappedComponent=e,n}},e.withTranslation=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function i(i){var a=i.forwardedRef,o=s(i,["forwardedRef"]),l=u(V(e,o),3),f=l[0],p=l[1],d=l[2],m=c(c({},o),{},{t:f,i18n:p,tReady:d});return n.withRef&&a?m.ref=a:!n.withRef&&a&&(m.forwardedRef=a),t.createElement(r,m)}i.displayName="withI18nextTranslation(".concat(z(r),")"),i.WrappedComponent=r;return n.withRef?t.forwardRef((function(e,n){return t.createElement(i,Object.assign({},e,{forwardedRef:n}))})):i}},Object.defineProperty(e,"__esModule",{value:!0})}));
@@ -93,6 +93,7 @@ Object.defineProperty(exports, "getInitialProps", {
93
93
  return _context.getInitialProps;
94
94
  }
95
95
  });
96
+ exports.selectOrdinal = exports.plural = exports.select = exports.number = exports.time = exports.date = void 0;
96
97
 
97
98
  var _Trans = require("./Trans");
98
99
 
@@ -108,4 +109,40 @@ var _withSSR = require("./withSSR");
108
109
 
109
110
  var _useSSR = require("./useSSR");
110
111
 
111
- var _context = require("./context");
112
+ var _context = require("./context");
113
+
114
+ var date = function date() {
115
+ return '';
116
+ };
117
+
118
+ exports.date = date;
119
+
120
+ var time = function time() {
121
+ return '';
122
+ };
123
+
124
+ exports.time = time;
125
+
126
+ var number = function number() {
127
+ return '';
128
+ };
129
+
130
+ exports.number = number;
131
+
132
+ var select = function select() {
133
+ return '';
134
+ };
135
+
136
+ exports.select = select;
137
+
138
+ var plural = function plural() {
139
+ return '';
140
+ };
141
+
142
+ exports.plural = plural;
143
+
144
+ var selectOrdinal = function selectOrdinal() {
145
+ return '';
146
+ };
147
+
148
+ exports.selectOrdinal = selectOrdinal;
package/dist/es/index.js CHANGED
@@ -5,4 +5,22 @@ export { Translation } from './Translation';
5
5
  export { I18nextProvider } from './I18nextProvider';
6
6
  export { withSSR } from './withSSR';
7
7
  export { useSSR } from './useSSR';
8
- export { I18nContext, initReactI18next, setDefaults, getDefaults, setI18n, getI18n, composeInitialProps, getInitialProps } from './context';
8
+ export { I18nContext, initReactI18next, setDefaults, getDefaults, setI18n, getI18n, composeInitialProps, getInitialProps } from './context';
9
+ export var date = function date() {
10
+ return '';
11
+ };
12
+ export var time = function time() {
13
+ return '';
14
+ };
15
+ export var number = function number() {
16
+ return '';
17
+ };
18
+ export var select = function select() {
19
+ return '';
20
+ };
21
+ export var plural = function plural() {
22
+ return '';
23
+ };
24
+ export var selectOrdinal = function selectOrdinal() {
25
+ return '';
26
+ };
@@ -925,17 +925,42 @@
925
925
  };
926
926
  }
927
927
 
928
+ var date = function date() {
929
+ return '';
930
+ };
931
+ var time = function time() {
932
+ return '';
933
+ };
934
+ var number = function number() {
935
+ return '';
936
+ };
937
+ var select = function select() {
938
+ return '';
939
+ };
940
+ var plural = function plural() {
941
+ return '';
942
+ };
943
+ var selectOrdinal = function selectOrdinal() {
944
+ return '';
945
+ };
946
+
928
947
  exports.I18nContext = I18nContext;
929
948
  exports.I18nextProvider = I18nextProvider;
930
949
  exports.Trans = Trans;
931
950
  exports.Translation = Translation;
932
951
  exports.composeInitialProps = composeInitialProps;
952
+ exports.date = date;
933
953
  exports.getDefaults = getDefaults;
934
954
  exports.getI18n = getI18n;
935
955
  exports.getInitialProps = getInitialProps;
936
956
  exports.initReactI18next = initReactI18next;
957
+ exports.number = number;
958
+ exports.plural = plural;
959
+ exports.select = select;
960
+ exports.selectOrdinal = selectOrdinal;
937
961
  exports.setDefaults = setDefaults;
938
962
  exports.setI18n = setI18n;
963
+ exports.time = time;
939
964
  exports.useSSR = useSSR;
940
965
  exports.useTranslation = useTranslation;
941
966
  exports.withSSR = withSSR;
@@ -1 +1 @@
1
- !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e=e||self).ReactI18next={},e.React)}(this,(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 i(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 a(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){a(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,i=function(e,n){if(null==e)return{};var t,r,i={},a=Object.keys(e);for(r=0;r<a.length;r++)t=a[r],n.indexOf(t)>=0||(i[t]=e[t]);return i}(e,n);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)t=a[r],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(i[t]=e[t])}return i}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,i=!1,a=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){i=!0,a=e}finally{try{r||null==c.return||c.return()}finally{if(i)throw a}}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(e);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,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},p=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function d(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(f[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var r=e.indexOf("--\x3e");return{type:"comment",comment:-1!==r?e.slice(4,r):""}}for(var i=new RegExp(p),a=null;null!==(a=i.exec(e));)if(a[0].trim())if(a[1]){var o=a[1].trim(),c=[o,""];o.indexOf("=")>-1&&(c=o.split("=")),n.attrs[c[0]]=c[1],i.lastIndex--}else a[2]&&(n.attrs[a[2]]=a[3].trim().substring(1,a[3].length-1));return n}var m=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,h=/^\s*$/,g=Object.create(null);var y,v=function(e,n){n||(n={}),n.components||(n.components=g);var t,r=[],i=[],a=-1,o=!1;if(0!==e.indexOf("<")){var c=e.indexOf("<");r.push({type:"text",content:-1===c?e:e.substring(0,c)})}return e.replace(m,(function(c,s){if(o){if(c!=="</"+t.name+">")return;o=!1}var u,l="/"!==c.charAt(1),f=c.startsWith("\x3c!--"),p=s+c.length,m=e.charAt(p);if(f){var g=d(c);return a<0?(r.push(g),r):((u=i[a]).children.push(g),r)}if(l&&(a++,"tag"===(t=d(c)).type&&n.components[t.name]&&(t.type="component",o=!0),t.voidElement||o||!m||"<"===m||t.children.push({type:"text",content:e.slice(p,e.indexOf("<",p))}),0===a&&r.push(t),(u=i[a-1])&&u.children.push(t),i[a]=t),(!l||t.voidElement)&&(a>-1&&(t.voidElement||t.name===c.slice(2,-1))&&(a--,t=-1===a?r:i[a]),!o&&"<"!==m&&m)){u=-1===a?r:i[a].children;var y=e.indexOf("<",p),v=e.slice(p,-1===y?void 0:y);h.test(v)&&(v=" "),(y>-1&&a+u.length>=0||" "!==v)&&u.push({type:"text",content:v})}})),r},b={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},O=t.createContext();function w(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b=c(c({},b),e)}function j(){return b}var x=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)}}])&&i(n.prototype,t),r&&i(n,r),e}();function E(e){y=e}function S(){return y}var N={type:"3rdParty",init:function(e){w(e.options.react),E(e)}};function I(e){return function(n){return new Promise((function(t){var r=k();e.getInitialProps?e.getInitialProps(n).then((function(e){t(c(c({},e),r))})):t(r)}))}}function k(){var e=S(),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 P(){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 R={};function C(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&R[n[0]]||("string"==typeof n[0]&&(R[n[0]]=new Date),P.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 T(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!n.languages||!n.languages.length)return C("i18n.languages were undefined or empty",n.languages),!0;var r=n.languages[0],i=!!n.options&&n.options.fallbackLng,a=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)||i&&!o(a,e))))}function z(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}function L(e,n){if(!e)return!1;var t=e.props?e.props.children:e.children;return n?t.length>0:!!t}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 U(e,n,i,a,o){if(""===n)return[];var s=a.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&&(L(n)?e(D(n)):"object"!==r(n)||t.isValidElement(n)||Object.assign(l,n))}))}(e);var f=i.services.interpolator.interpolate(n,c(c({},l),o),i.language),p=v("<0>".concat(f,"</0>"));function d(e,n,r){var i=D(e),a=h(i,n.children,r);return function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((function(e){return t.isValidElement(e)}))}(i)&&0===a.length?i:a}function m(e,n,r,i,a){e.dummy&&(e.children=n),r.push(t.cloneElement(e,c(c({},e.props),{},{key:i}),a?void 0:n))}function h(n,i,o){var l=B(n);return B(i).reduce((function(n,i,f){var p,g,y,v=i.children&&i.children[0]&&i.children[0].content;if("tag"===i.type){var b=l[parseInt(i.name,10)];!b&&1===o.length&&o[0][i.name]&&(b=o[0][i.name]),b||(b={});var O=0!==Object.keys(i.attrs).length?(p={props:i.attrs},(y=c({},g=b)).props=Object.assign(p.props,g.props),y):b,w=t.isValidElement(O),j=w&&L(i,!0)&&!i.voidElement,x=u&&"object"===r(O)&&O.dummy&&!w,E="object"===r(e)&&null!==e&&Object.hasOwnProperty.call(e,i.name);if("string"==typeof O)n.push(O);else if(L(O)||j){m(O,d(O,i,o),n,f)}else if(x){var S=h(l,i.children,o);n.push(t.cloneElement(O,c(c({},O.props),{},{key:f}),S))}else if(Number.isNaN(parseFloat(i.name))){if(E)m(O,d(O,i,o),n,f,i.voidElement);else if(a.transSupportBasicHtmlNodes&&s.indexOf(i.name)>-1)if(i.voidElement)n.push(t.createElement(i.name,{key:"".concat(i.name,"-").concat(f)}));else{var N=h(l,i.children,o);n.push(t.createElement(i.name,{key:"".concat(i.name,"-").concat(f)},N))}else if(i.voidElement)n.push("<".concat(i.name," />"));else{var I=h(l,i.children,o);n.push("<".concat(i.name,">").concat(I,"</").concat(i.name,">"))}}else if("object"!==r(O)||w)1===i.children.length&&v?n.push(t.cloneElement(O,c(c({},O.props),{},{key:f}),v)):n.push(t.cloneElement(O,c(c({},O.props),{},{key:f})));else{var k=i.children[0]?v:null;k&&n.push(k)}}else"text"===i.type&&n.push(i.content);return n}),[])}return D(h([{dummy:!0,children:e}],p,B(e||[]))[0])}function V(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.i18n,i=n.useContext(O)||{},a=i.i18n,o=i.defaultNS,s=r||a||S();if(s&&!s.reportNamespaces&&(s.reportNamespaces=new x),!s){C("You will need to 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}s.options.react&&void 0!==s.options.react.wait&&C("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");var p=c(c(c({},j()),s.options.react),t),d=p.useSuspense,m=e||o||s.options&&s.options.defaultNS;m="string"==typeof m?[m]:m||["translation"],s.reportNamespaces.addUsedNamespaces&&s.reportNamespaces.addUsedNamespaces(m);var h=(s.isInitialized||s.initializedStoreOnce)&&m.every((function(e){return T(e,s,p)}));function g(){return s.getFixedT(null,"fallback"===p.nsMode?m:m[0])}var y=n.useState(g),v=u(y,2),b=v[0],w=v[1],E=n.useRef(!0);n.useEffect((function(){var e=p.bindI18n,n=p.bindI18nStore;function t(){E.current&&w(g)}return E.current=!0,h||d||A(s,m,(function(){E.current&&w(g)})),e&&s&&s.on(e,t),n&&s&&s.store.on(n,t),function(){E.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)}))}}),[s,m.join()]);var N=n.useRef(!0);n.useEffect((function(){E.current&&!N.current&&w(g),N.current=!1}),[s]);var I=[b,s,h];if(I.t=b,I.i18n=s,I.ready=h,h)return I;if(!h&&!d)return I;throw new Promise((function(e){A(s,m,(function(){e()}))}))}function K(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=r.i18n,a=n.useContext(O)||{},o=a.i18n,c=i||o||S();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=O,e.I18nextProvider=function(e){var t=e.i18n,r=e.defaultNS,i=e.children,a=n.useMemo((function(){return{i18n:t,defaultNS:r}}),[t,r]);return n.createElement(O.Provider,{value:a},i)},e.Trans=function(e){var i=e.children,a=e.count,o=e.parent,u=e.i18nKey,l=e.tOptions,f=void 0===l?{}:l,p=e.values,d=e.defaults,m=e.components,h=e.ns,g=e.i18n,y=e.t,v=s(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]),b=n.useContext(O)||{},w=b.i18n,x=b.defaultNS,E=g||w||S();if(!E)return C("You will need to pass in an i18next instance by using i18nextReactModule"),i;var N=y||E.t.bind(E)||function(e){return e},I=c(c({},j()),E.options&&E.options.react),k=h||N.ns||x||E.options&&E.options.defaultNS;k="string"==typeof k?[k]:k||["translation"];var R=d||function e(n,i){if(!n)return"";var a="",o=B(n),c=i.transKeepBasicHtmlNodesFor||[];return o.forEach((function(n,o){if("string"==typeof n)a+="".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)a+="<".concat(n.type,"/>");else if(f||l&&0===u)if(n.props.i18nIsDynamicList)a+="<".concat(o,"></").concat(o,">");else if(l&&1===u&&"string"==typeof f)a+="<".concat(n.type,">").concat(f,"</").concat(n.type,">");else{var p=e(f,i);a+="<".concat(o,">").concat(p,"</").concat(o,">")}else a+="<".concat(o,"></").concat(o,">")}else if(null===n)P("Trans: the passed in value is invalid - seems you passed in a null child.");else if("object"===r(n)){var d=n.format,m=s(n,["format"]),h=Object.keys(m);if(1===h.length){var g=d?"".concat(h[0],", ").concat(d):h[0];a+="{{".concat(g,"}}")}else P("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",n)}else P("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)})),a}(i,I)||I.transEmptyNodeValue||u,A=I.hashTransKey,T=u||(A?A(R):R),z=p?f.interpolation:{interpolation:c(c({},f.interpolation),{},{prefix:"#$?",suffix:"?$#"})},L=c(c(c(c({},f),{},{count:a},p),z),{},{defaultValue:R,ns:k}),D=U(m||i,T?N(T,L):R,E,I,L),V=void 0!==o?o:I.defaultTransParent;return V?t.createElement(V,v,D):D},e.Translation=function(e){var n=e.ns,t=e.children,r=u(V(n,s(e,["ns","children"])),3),i=r[0],a=r[1],o=r[2];return t(i,{i18n:a,lng:a.language},o)},e.composeInitialProps=I,e.getDefaults=j,e.getI18n=S,e.getInitialProps=k,e.initReactI18next=N,e.setDefaults=w,e.setI18n=E,e.useSSR=K,e.useTranslation=V,e.withSSR=function(){return function(e){function n(n){var r=n.initialI18nStore,i=n.initialLanguage,a=s(n,["initialI18nStore","initialLanguage"]);return K(r,i),t.createElement(e,c({},a))}return n.getInitialProps=I(e),n.displayName="withI18nextSSR(".concat(z(e),")"),n.WrappedComponent=e,n}},e.withTranslation=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function i(i){var a=i.forwardedRef,o=s(i,["forwardedRef"]),l=u(V(e,o),3),f=l[0],p=l[1],d=l[2],m=c(c({},o),{},{t:f,i18n:p,tReady:d});return n.withRef&&a?m.ref=a:!n.withRef&&a&&(m.forwardedRef=a),t.createElement(r,m)}i.displayName="withI18nextTranslation(".concat(z(r),")"),i.WrappedComponent=r;return n.withRef?t.forwardRef((function(e,n){return t.createElement(i,Object.assign({},e,{forwardedRef:n}))})):i}},Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e=e||self).ReactI18next={},e.React)}(this,(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 i(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 a(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){a(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,i=function(e,n){if(null==e)return{};var t,r,i={},a=Object.keys(e);for(r=0;r<a.length;r++)t=a[r],n.indexOf(t)>=0||(i[t]=e[t]);return i}(e,n);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)t=a[r],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(i[t]=e[t])}return i}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,i=!1,a=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){i=!0,a=e}finally{try{r||null==c.return||c.return()}finally{if(i)throw a}}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(e);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,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},p=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function d(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(f[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var r=e.indexOf("--\x3e");return{type:"comment",comment:-1!==r?e.slice(4,r):""}}for(var i=new RegExp(p),a=null;null!==(a=i.exec(e));)if(a[0].trim())if(a[1]){var o=a[1].trim(),c=[o,""];o.indexOf("=")>-1&&(c=o.split("=")),n.attrs[c[0]]=c[1],i.lastIndex--}else a[2]&&(n.attrs[a[2]]=a[3].trim().substring(1,a[3].length-1));return n}var m=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,h=/^\s*$/,g=Object.create(null);var y,v=function(e,n){n||(n={}),n.components||(n.components=g);var t,r=[],i=[],a=-1,o=!1;if(0!==e.indexOf("<")){var c=e.indexOf("<");r.push({type:"text",content:-1===c?e:e.substring(0,c)})}return e.replace(m,(function(c,s){if(o){if(c!=="</"+t.name+">")return;o=!1}var u,l="/"!==c.charAt(1),f=c.startsWith("\x3c!--"),p=s+c.length,m=e.charAt(p);if(f){var g=d(c);return a<0?(r.push(g),r):((u=i[a]).children.push(g),r)}if(l&&(a++,"tag"===(t=d(c)).type&&n.components[t.name]&&(t.type="component",o=!0),t.voidElement||o||!m||"<"===m||t.children.push({type:"text",content:e.slice(p,e.indexOf("<",p))}),0===a&&r.push(t),(u=i[a-1])&&u.children.push(t),i[a]=t),(!l||t.voidElement)&&(a>-1&&(t.voidElement||t.name===c.slice(2,-1))&&(a--,t=-1===a?r:i[a]),!o&&"<"!==m&&m)){u=-1===a?r:i[a].children;var y=e.indexOf("<",p),v=e.slice(p,-1===y?void 0:y);h.test(v)&&(v=" "),(y>-1&&a+u.length>=0||" "!==v)&&u.push({type:"text",content:v})}})),r},b={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},O=t.createContext();function w(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b=c(c({},b),e)}function j(){return b}var x=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)}}])&&i(n.prototype,t),r&&i(n,r),e}();function E(e){y=e}function S(){return y}var N={type:"3rdParty",init:function(e){w(e.options.react),E(e)}};function I(e){return function(n){return new Promise((function(t){var r=k();e.getInitialProps?e.getInitialProps(n).then((function(e){t(c(c({},e),r))})):t(r)}))}}function k(){var e=S(),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 P(){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 R={};function C(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&R[n[0]]||("string"==typeof n[0]&&(R[n[0]]=new Date),P.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 T(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!n.languages||!n.languages.length)return C("i18n.languages were undefined or empty",n.languages),!0;var r=n.languages[0],i=!!n.options&&n.options.fallbackLng,a=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)||i&&!o(a,e))))}function z(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}function L(e,n){if(!e)return!1;var t=e.props?e.props.children:e.children;return n?t.length>0:!!t}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 U(e,n,i,a,o){if(""===n)return[];var s=a.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&&(L(n)?e(D(n)):"object"!==r(n)||t.isValidElement(n)||Object.assign(l,n))}))}(e);var f=i.services.interpolator.interpolate(n,c(c({},l),o),i.language),p=v("<0>".concat(f,"</0>"));function d(e,n,r){var i=D(e),a=h(i,n.children,r);return function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((function(e){return t.isValidElement(e)}))}(i)&&0===a.length?i:a}function m(e,n,r,i,a){e.dummy&&(e.children=n),r.push(t.cloneElement(e,c(c({},e.props),{},{key:i}),a?void 0:n))}function h(n,i,o){var l=B(n);return B(i).reduce((function(n,i,f){var p,g,y,v=i.children&&i.children[0]&&i.children[0].content;if("tag"===i.type){var b=l[parseInt(i.name,10)];!b&&1===o.length&&o[0][i.name]&&(b=o[0][i.name]),b||(b={});var O=0!==Object.keys(i.attrs).length?(p={props:i.attrs},(y=c({},g=b)).props=Object.assign(p.props,g.props),y):b,w=t.isValidElement(O),j=w&&L(i,!0)&&!i.voidElement,x=u&&"object"===r(O)&&O.dummy&&!w,E="object"===r(e)&&null!==e&&Object.hasOwnProperty.call(e,i.name);if("string"==typeof O)n.push(O);else if(L(O)||j){m(O,d(O,i,o),n,f)}else if(x){var S=h(l,i.children,o);n.push(t.cloneElement(O,c(c({},O.props),{},{key:f}),S))}else if(Number.isNaN(parseFloat(i.name))){if(E)m(O,d(O,i,o),n,f,i.voidElement);else if(a.transSupportBasicHtmlNodes&&s.indexOf(i.name)>-1)if(i.voidElement)n.push(t.createElement(i.name,{key:"".concat(i.name,"-").concat(f)}));else{var N=h(l,i.children,o);n.push(t.createElement(i.name,{key:"".concat(i.name,"-").concat(f)},N))}else if(i.voidElement)n.push("<".concat(i.name," />"));else{var I=h(l,i.children,o);n.push("<".concat(i.name,">").concat(I,"</").concat(i.name,">"))}}else if("object"!==r(O)||w)1===i.children.length&&v?n.push(t.cloneElement(O,c(c({},O.props),{},{key:f}),v)):n.push(t.cloneElement(O,c(c({},O.props),{},{key:f})));else{var k=i.children[0]?v:null;k&&n.push(k)}}else"text"===i.type&&n.push(i.content);return n}),[])}return D(h([{dummy:!0,children:e}],p,B(e||[]))[0])}function V(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.i18n,i=n.useContext(O)||{},a=i.i18n,o=i.defaultNS,s=r||a||S();if(s&&!s.reportNamespaces&&(s.reportNamespaces=new x),!s){C("You will need to 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}s.options.react&&void 0!==s.options.react.wait&&C("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");var p=c(c(c({},j()),s.options.react),t),d=p.useSuspense,m=e||o||s.options&&s.options.defaultNS;m="string"==typeof m?[m]:m||["translation"],s.reportNamespaces.addUsedNamespaces&&s.reportNamespaces.addUsedNamespaces(m);var h=(s.isInitialized||s.initializedStoreOnce)&&m.every((function(e){return T(e,s,p)}));function g(){return s.getFixedT(null,"fallback"===p.nsMode?m:m[0])}var y=n.useState(g),v=u(y,2),b=v[0],w=v[1],E=n.useRef(!0);n.useEffect((function(){var e=p.bindI18n,n=p.bindI18nStore;function t(){E.current&&w(g)}return E.current=!0,h||d||A(s,m,(function(){E.current&&w(g)})),e&&s&&s.on(e,t),n&&s&&s.store.on(n,t),function(){E.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)}))}}),[s,m.join()]);var N=n.useRef(!0);n.useEffect((function(){E.current&&!N.current&&w(g),N.current=!1}),[s]);var I=[b,s,h];if(I.t=b,I.i18n=s,I.ready=h,h)return I;if(!h&&!d)return I;throw new Promise((function(e){A(s,m,(function(){e()}))}))}function K(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=r.i18n,a=n.useContext(O)||{},o=a.i18n,c=i||o||S();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=O,e.I18nextProvider=function(e){var t=e.i18n,r=e.defaultNS,i=e.children,a=n.useMemo((function(){return{i18n:t,defaultNS:r}}),[t,r]);return n.createElement(O.Provider,{value:a},i)},e.Trans=function(e){var i=e.children,a=e.count,o=e.parent,u=e.i18nKey,l=e.tOptions,f=void 0===l?{}:l,p=e.values,d=e.defaults,m=e.components,h=e.ns,g=e.i18n,y=e.t,v=s(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]),b=n.useContext(O)||{},w=b.i18n,x=b.defaultNS,E=g||w||S();if(!E)return C("You will need to pass in an i18next instance by using i18nextReactModule"),i;var N=y||E.t.bind(E)||function(e){return e},I=c(c({},j()),E.options&&E.options.react),k=h||N.ns||x||E.options&&E.options.defaultNS;k="string"==typeof k?[k]:k||["translation"];var R=d||function e(n,i){if(!n)return"";var a="",o=B(n),c=i.transKeepBasicHtmlNodesFor||[];return o.forEach((function(n,o){if("string"==typeof n)a+="".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)a+="<".concat(n.type,"/>");else if(f||l&&0===u)if(n.props.i18nIsDynamicList)a+="<".concat(o,"></").concat(o,">");else if(l&&1===u&&"string"==typeof f)a+="<".concat(n.type,">").concat(f,"</").concat(n.type,">");else{var p=e(f,i);a+="<".concat(o,">").concat(p,"</").concat(o,">")}else a+="<".concat(o,"></").concat(o,">")}else if(null===n)P("Trans: the passed in value is invalid - seems you passed in a null child.");else if("object"===r(n)){var d=n.format,m=s(n,["format"]),h=Object.keys(m);if(1===h.length){var g=d?"".concat(h[0],", ").concat(d):h[0];a+="{{".concat(g,"}}")}else P("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",n)}else P("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)})),a}(i,I)||I.transEmptyNodeValue||u,A=I.hashTransKey,T=u||(A?A(R):R),z=p?f.interpolation:{interpolation:c(c({},f.interpolation),{},{prefix:"#$?",suffix:"?$#"})},L=c(c(c(c({},f),{},{count:a},p),z),{},{defaultValue:R,ns:k}),D=U(m||i,T?N(T,L):R,E,I,L),V=void 0!==o?o:I.defaultTransParent;return V?t.createElement(V,v,D):D},e.Translation=function(e){var n=e.ns,t=e.children,r=u(V(n,s(e,["ns","children"])),3),i=r[0],a=r[1],o=r[2];return t(i,{i18n:a,lng:a.language},o)},e.composeInitialProps=I,e.date=function(){return""},e.getDefaults=j,e.getI18n=S,e.getInitialProps=k,e.initReactI18next=N,e.number=function(){return""},e.plural=function(){return""},e.select=function(){return""},e.selectOrdinal=function(){return""},e.setDefaults=w,e.setI18n=E,e.time=function(){return""},e.useSSR=K,e.useTranslation=V,e.withSSR=function(){return function(e){function n(n){var r=n.initialI18nStore,i=n.initialLanguage,a=s(n,["initialI18nStore","initialLanguage"]);return K(r,i),t.createElement(e,c({},a))}return n.getInitialProps=I(e),n.displayName="withI18nextSSR(".concat(z(e),")"),n.WrappedComponent=e,n}},e.withTranslation=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function i(i){var a=i.forwardedRef,o=s(i,["forwardedRef"]),l=u(V(e,o),3),f=l[0],p=l[1],d=l[2],m=c(c({},o),{},{t:f,i18n:p,tReady:d});return n.withRef&&a?m.ref=a:!n.withRef&&a&&(m.forwardedRef=a),t.createElement(r,m)}i.displayName="withI18nextTranslation(".concat(z(r),")"),i.WrappedComponent=r;return n.withRef?t.forwardRef((function(e,n){return t.createElement(i,Object.assign({},e,{forwardedRef:n}))})):i}},Object.defineProperty(e,"__esModule",{value:!0})}));
package/icu.macro.js CHANGED
@@ -5,14 +5,24 @@ const { createMacro } = require('babel-plugin-macros');
5
5
  module.exports = createMacro(ICUMacro);
6
6
 
7
7
  function ICUMacro({ references, state, babel }) {
8
- const t = babel.types;
9
- const { Trans = [], Plural = [], Select = [], SelectOrdinal = [] } = references;
8
+ const {
9
+ Trans = [],
10
+ Plural = [],
11
+ Select = [],
12
+ SelectOrdinal = [],
13
+ number = [],
14
+ date = [],
15
+ select = [],
16
+ selectOrdinal = [],
17
+ plural = [],
18
+ time = [],
19
+ } = references;
10
20
 
11
21
  // assert we have the react-i18next Trans component imported
12
- addNeededImports(state, babel);
22
+ addNeededImports(state, babel, references);
13
23
 
14
24
  // transform Plural and SelectOrdinal
15
- [...Plural, ...SelectOrdinal].forEach(referencePath => {
25
+ [...Plural, ...SelectOrdinal].forEach((referencePath) => {
16
26
  if (referencePath.parentPath.type === 'JSXOpeningElement') {
17
27
  pluralAsJSX(
18
28
  referencePath.parentPath,
@@ -28,7 +38,7 @@ function ICUMacro({ references, state, babel }) {
28
38
  });
29
39
 
30
40
  // transform Select
31
- Select.forEach(referencePath => {
41
+ Select.forEach((referencePath) => {
32
42
  if (referencePath.parentPath.type === 'JSXOpeningElement') {
33
43
  selectAsJSX(
34
44
  referencePath.parentPath,
@@ -44,7 +54,7 @@ function ICUMacro({ references, state, babel }) {
44
54
  });
45
55
 
46
56
  // transform Trans
47
- Trans.forEach(referencePath => {
57
+ Trans.forEach((referencePath) => {
48
58
  if (referencePath.parentPath.type === 'JSXOpeningElement') {
49
59
  transAsJSX(
50
60
  referencePath.parentPath,
@@ -59,6 +69,32 @@ function ICUMacro({ references, state, babel }) {
59
69
  // throw a helpful error message or something :)
60
70
  }
61
71
  });
72
+
73
+ // check for number`` and others outside of <Trans>
74
+ Object.entries({
75
+ number,
76
+ date,
77
+ time,
78
+ select,
79
+ plural,
80
+ selectOrdinal,
81
+ }).forEach(([name, node]) => {
82
+ node.forEach((item) => {
83
+ let f = item.parentPath;
84
+ while (f) {
85
+ if (babel.types.isJSXElement(f)) {
86
+ if (f.node.openingElement.name.name === 'Trans') {
87
+ // this is a valid use of number/date/time/etc.
88
+ return;
89
+ }
90
+ }
91
+ f = f.parentPath;
92
+ }
93
+ throw new Error(
94
+ `"${name}\`\`" can only be used inside <Trans> in "${item.node.loc.filename}" on line ${item.node.loc.start.line}`,
95
+ );
96
+ });
97
+ });
62
98
  }
63
99
 
64
100
  function pluralAsJSX(parentPath, { attributes }, babel) {
@@ -198,7 +234,7 @@ function transAsJSX(parentPath, { attributes, children }, babel, { filename }) {
198
234
  let clonedAttributes = cloneExistingAttributes(attributes);
199
235
  if (parseDefaults) {
200
236
  // remove existing defaults so it can be replaced later with the new parsed defaults
201
- clonedAttributes = clonedAttributes.filter(node => node.name.name !== 'defaults');
237
+ clonedAttributes = clonedAttributes.filter((node) => node.name.name !== 'defaults');
202
238
  }
203
239
 
204
240
  // replace the node with the new Trans
@@ -253,7 +289,7 @@ function cloneExistingAttributes(attributes) {
253
289
  }
254
290
 
255
291
  function findAttribute(name, attributes) {
256
- return attributes.find(child => {
292
+ return attributes.find((child) => {
257
293
  const ele = child.node ? child.node : child;
258
294
  return ele.name.name === name;
259
295
  });
@@ -284,41 +320,88 @@ function trimIndent(text) {
284
320
  return newText;
285
321
  }
286
322
 
323
+ /**
324
+ * add comma-delimited expressions like `{ val, number }`
325
+ */
326
+ function mergeCommaExpressions(ele) {
327
+ if (ele.expression && ele.expression.expressions) {
328
+ return `{${ele.expression.expressions
329
+ .reduce((m, i) => {
330
+ m.push(i.name || i.value);
331
+ return m;
332
+ }, [])
333
+ .join(', ')}}`;
334
+ }
335
+ return '';
336
+ }
337
+
338
+ /**
339
+ * this is for supporting complex icu type interpolations
340
+ * date`${variable}` and number`{${varName}, ::percent}`
341
+ * also, plural`{${count}, one { ... } other { ... }}
342
+ */
343
+ function mergeTaggedTemplateExpressions(ele, componentFoundIndex, t, babel) {
344
+ if (t.isTaggedTemplateExpression(ele.expression)) {
345
+ const [, text, index] = getTextAndInterpolatedVariables(
346
+ ele.expression.tag.name,
347
+ ele.expression,
348
+ componentFoundIndex,
349
+ babel,
350
+ );
351
+ return [text, index];
352
+ }
353
+ return ['', componentFoundIndex];
354
+ }
355
+
287
356
  function mergeChildren(children, babel, componentStartIndex = 0) {
288
357
  const t = babel.types;
289
358
  let componentFoundIndex = componentStartIndex;
290
359
 
291
360
  return children.reduce((mem, child) => {
292
361
  const ele = child.node ? child.node : child;
362
+ let result = mem;
293
363
 
294
364
  // add text, but trim indentation whitespace
295
- if (t.isJSXText(ele) && ele.value) mem += trimIndent(ele.value);
365
+ if (t.isJSXText(ele) && ele.value) result += trimIndent(ele.value);
296
366
  // add ?!? forgot
297
- if (ele.expression && ele.expression.value) mem += ele.expression.value;
367
+ if (ele.expression && ele.expression.value) result += ele.expression.value;
298
368
  // add `{ val }`
299
- if (ele.expression && ele.expression.name) mem += `{${ele.expression.name}}`;
369
+ if (ele.expression && ele.expression.name) result += `{${ele.expression.name}}`;
300
370
  // add `{ val, number }`
301
- if (ele.expression && ele.expression.expressions) {
302
- mem += `{${ele.expression.expressions
303
- .reduce((m, i) => {
304
- m.push(i.name || i.value);
305
- return m;
306
- }, [])
307
- .join(', ')}}`;
308
- }
371
+ result += mergeCommaExpressions(ele);
372
+ const [nextText, newIndex] = mergeTaggedTemplateExpressions(ele, componentFoundIndex, t, babel);
373
+ result += nextText;
374
+ componentFoundIndex = newIndex;
309
375
  // add <strong>...</strong> with replace to <0>inner string</0>
310
376
  if (t.isJSXElement(ele)) {
311
- mem += `<${componentFoundIndex}>${mergeChildren(
377
+ result += `<${componentFoundIndex}>${mergeChildren(
312
378
  ele.children,
313
379
  babel,
314
380
  )}</${componentFoundIndex}>`;
315
- componentFoundIndex++;
381
+ componentFoundIndex += 1;
316
382
  }
317
383
 
318
- return mem;
384
+ return result;
319
385
  }, '');
320
386
  }
321
387
 
388
+ const extractTaggedTemplateValues = (ele, babel, toObjectProperty) => {
389
+ // date`${variable}` and so on
390
+ if (ele.expression && ele.expression.type === 'TaggedTemplateExpression') {
391
+ const [variables] = getTextAndInterpolatedVariables(
392
+ ele.expression.tag.name,
393
+ ele.expression,
394
+ 0,
395
+ babel,
396
+ );
397
+ return variables.map((vari) => toObjectProperty(vari));
398
+ }
399
+ return [];
400
+ };
401
+
402
+ /**
403
+ * Extract the names of interpolated value as object properties to pass to Trans
404
+ */
322
405
  function getValues(children, babel) {
323
406
  const t = babel.types;
324
407
  const toObjectProperty = (name, value) =>
@@ -326,66 +409,100 @@ function getValues(children, babel) {
326
409
 
327
410
  return children.reduce((mem, child) => {
328
411
  const ele = child.node ? child.node : child;
412
+ let result = mem;
329
413
 
330
414
  // add `{ var }` to values
331
415
  if (ele.expression && ele.expression.name) mem.push(toObjectProperty(ele.expression.name));
332
416
  // add `{ var, number }` to values
333
417
  if (ele.expression && ele.expression.expressions)
334
- mem.push(
418
+ result.push(
335
419
  toObjectProperty(ele.expression.expressions[0].name || ele.expression.expressions[0].value),
336
420
  );
337
421
  // add `{ var: 'bar' }` to values
338
- if (ele.expression && ele.expression.properties) mem = mem.concat(ele.expression.properties);
422
+ if (ele.expression && ele.expression.properties)
423
+ result = result.concat(ele.expression.properties);
424
+ // date`${variable}` and so on
425
+ result = result.concat(extractTaggedTemplateValues(ele, babel, toObjectProperty));
339
426
  // recursive add inner elements stuff to values
340
427
  if (t.isJSXElement(ele)) {
341
- mem = mem.concat(getValues(ele.children, babel));
428
+ result = result.concat(getValues(ele.children, babel));
342
429
  }
343
430
 
344
- return mem;
431
+ return result;
345
432
  }, []);
346
433
  }
347
434
 
435
+ /**
436
+ * Common logic for adding a child element of Trans to the list of components to hydrate the translation
437
+ * @param {JSXElement} jsxElement
438
+ * @param {JSXElement[]} mem
439
+ */
440
+ const processJSXElement = (jsxElement, mem, t) => {
441
+ const clone = t.clone(jsxElement);
442
+ clone.children = clone.children.reduce((clonedMem, clonedChild) => {
443
+ const clonedEle = clonedChild.node ? clonedChild.node : clonedChild;
444
+
445
+ // clean out invalid definitions by replacing `{ catchDate, date, short }` with `{ catchDate }`
446
+ if (clonedEle.expression && clonedEle.expression.expressions)
447
+ clonedEle.expression.expressions = [clonedEle.expression.expressions[0]];
448
+
449
+ clonedMem.push(clonedChild);
450
+ return clonedMem;
451
+ }, []);
452
+
453
+ mem.push(jsxElement);
454
+ };
455
+
456
+ /**
457
+ * Extract the React components to pass to Trans as components
458
+ */
348
459
  function getComponents(children, babel) {
349
460
  const t = babel.types;
350
461
 
351
462
  return children.reduce((mem, child) => {
352
463
  const ele = child.node ? child.node : child;
353
464
 
465
+ if (t.isJSXExpressionContainer(ele)) {
466
+ // check for date`` and so on
467
+ if (t.isTaggedTemplateExpression(ele.expression)) {
468
+ ele.expression.quasi.expressions.forEach((expr) => {
469
+ // check for sub-expressions. This can happen with plural`` or select`` or selectOrdinal``
470
+ // these can have nested components
471
+ if (t.isTaggedTemplateExpression(expr) && expr.quasi.expressions.length) {
472
+ mem.push(...getComponents(expr.quasi.expressions, babel));
473
+ }
474
+ if (!t.isJSXElement(expr)) {
475
+ // ignore anything that is not a component
476
+ return;
477
+ }
478
+ processJSXElement(expr, mem, t);
479
+ });
480
+ }
481
+ }
354
482
  if (t.isJSXElement(ele)) {
355
- const clone = t.clone(ele);
356
- clone.children = clone.children.reduce((clonedMem, clonedChild) => {
357
- const clonedEle = clonedChild.node ? clonedChild.node : clonedChild;
358
-
359
- // clean out invalid definitions by replacing `{ catchDate, date, short }` with `{ catchDate }`
360
- if (clonedEle.expression && clonedEle.expression.expressions)
361
- clonedEle.expression.expressions = [clonedEle.expression.expressions[0]];
362
-
363
- clonedMem.push(clonedChild);
364
- return clonedMem;
365
- }, []);
366
-
367
- mem.push(ele);
483
+ processJSXElement(ele, mem, t);
368
484
  }
369
485
 
370
486
  return mem;
371
487
  }, []);
372
488
  }
373
489
 
374
- function addNeededImports(state, babel) {
375
- const t = babel.types;
376
- const importsToAdd = ['Trans'];
377
-
378
- // check if there is an existing react-i18next import
379
- const existingImport = state.file.path.node.body.find(
380
- importNode => t.isImportDeclaration(importNode) && importNode.source.value === 'react-i18next',
381
- );
382
-
383
- // append Trans to existing or add a new react-i18next import for the Trans
490
+ const icuInterpolators = ['date', 'time', 'number', 'plural', 'select', 'selectOrdinal'];
491
+ const importsToAdd = ['Trans'];
492
+
493
+ /**
494
+ * helper split out of addNeededImports to make codeclimate happy
495
+ *
496
+ * This does the work of amending an existing import from "react-i18next", or
497
+ * creating a new one if it doesn't exist
498
+ */
499
+ function addImports(state, existingImport, allImportsToAdd, t) {
500
+ // append imports to existing or add a new react-i18next import for the Trans and icu tagged template literals
384
501
  if (existingImport) {
385
- importsToAdd.forEach(name => {
502
+ allImportsToAdd.forEach((name) => {
386
503
  if (
387
504
  existingImport.specifiers.findIndex(
388
- specifier => specifier.imported && specifier.imported.name === name,
505
+ (specifier) => specifier.imported && specifier.imported.name === name,
389
506
  ) === -1
390
507
  ) {
391
508
  existingImport.specifiers.push(t.importSpecifier(t.identifier(name), t.identifier(name)));
@@ -394,9 +511,210 @@ function addNeededImports(state, babel) {
394
511
  } else {
395
512
  state.file.path.node.body.unshift(
396
513
  t.importDeclaration(
397
- importsToAdd.map(name => t.importSpecifier(t.identifier(name), t.identifier(name))),
514
+ allImportsToAdd.map((name) => t.importSpecifier(t.identifier(name), t.identifier(name))),
398
515
  t.stringLiteral('react-i18next'),
399
516
  ),
400
517
  );
401
518
  }
402
519
  }
520
+
521
+ /**
522
+ * Add `import { Trans, number, date, <etc.> } from "react-i18next"` as needed
523
+ */
524
+ function addNeededImports(state, babel, references) {
525
+ const t = babel.types;
526
+
527
+ // check if there is an existing react-i18next import
528
+ const existingImport = state.file.path.node.body.find(
529
+ (importNode) =>
530
+ t.isImportDeclaration(importNode) && importNode.source.value === 'react-i18next',
531
+ );
532
+ // check for any of the tagged template literals that are used in the source, and add them
533
+ const usedRefs = Object.keys(references).filter((importName) => {
534
+ if (!icuInterpolators.includes(importName)) {
535
+ return false;
536
+ }
537
+ return references[importName].length;
538
+ });
539
+
540
+ // combine Trans + any tagged template literals
541
+ const allImportsToAdd = importsToAdd.concat(usedRefs);
542
+
543
+ addImports(state, existingImport, allImportsToAdd, t);
544
+ }
545
+
546
+ /**
547
+ * iterate over a node detected inside a tagged template literal
548
+ *
549
+ * This is a helper function for `extractVariableNamesFromQuasiNodes` defined below
550
+ *
551
+ * this is called using reduce as a way of tricking what would be `.map()`
552
+ * into passing in the parameters needed to both modify `componentFoundIndex`,
553
+ * `stringOutput`, and `interpolatedVariableNames`
554
+ * and to pass in the dependencies babel, and type. Type is the template type.
555
+ * For "date``" the type will be `date`. for "number``" the type is `number`, etc.
556
+ */
557
+ const extractNestedTemplatesAndComponents = (
558
+ { componentFoundIndex: lastIndex, babel, stringOutput, type, interpolatedVariableNames },
559
+ node,
560
+ ) => {
561
+ let componentFoundIndex = lastIndex;
562
+ if (node.type === 'JSXElement') {
563
+ // perform the interpolation of components just as we do in a normal Trans setting
564
+ const subText = `<${componentFoundIndex}>${mergeChildren(
565
+ node.children,
566
+ babel,
567
+ )}</${componentFoundIndex}>`;
568
+ componentFoundIndex += 1;
569
+ stringOutput.push(subText);
570
+ } else if (node.type === 'TaggedTemplateExpression') {
571
+ // a nested date``/number``/plural`` etc., extract whatever is inside of it
572
+ const [variableNames, childText, newIndex] = getTextAndInterpolatedVariables(
573
+ node.tag.name,
574
+ node,
575
+ componentFoundIndex,
576
+ babel,
577
+ );
578
+ interpolatedVariableNames.push(...variableNames);
579
+ componentFoundIndex = newIndex;
580
+ stringOutput.push(childText);
581
+ } else if (node.type === 'Identifier') {
582
+ // turn date`${thing}` into `thing, date`
583
+ stringOutput.push(`${node.name}, ${type}`);
584
+ } else if (node.type === 'TemplateElement') {
585
+ // convert all whitespace into a single space for the text in the tagged template literal
586
+ stringOutput.push(node.value.cooked.replace(/\s+/g, ' '));
587
+ } else {
588
+ // unknown node type, ignore
589
+ }
590
+ return { componentFoundIndex, babel, stringOutput, type, interpolatedVariableNames };
591
+ };
592
+
593
+ /**
594
+ * filter the list of nodes within a tagged template literal to the 4 types we can process,
595
+ * and ignore anything else.
596
+ *
597
+ * this is a helper function for `extractVariableNamesFromQuasiNodes`
598
+ */
599
+ const filterNodes = (node) => {
600
+ if (node.type === 'Identifier') {
601
+ // if the node has a name, keep it
602
+ return node.name;
603
+ }
604
+ if (node.type === 'JSXElement' || node.type === 'TaggedTemplateExpression') {
605
+ // always keep interpolated elements or other tagged template literals like a nested date`` inside a plural``
606
+ return true;
607
+ }
608
+ if (node.type === 'TemplateElement') {
609
+ // return the "cooked" (escaped) text for the text in the template literal (`, ::percent` in number`${varname}, ::percent`)
610
+ return node.value.cooked;
611
+ }
612
+ // unknown node type, ignore
613
+ return false;
614
+ };
615
+
616
+ const errorOnInvalidQuasiNodes = (primaryNode) => {
617
+ const noInterpolationError = !primaryNode.quasi.expressions.length;
618
+ const wrongOrderError = primaryNode.quasi.quasis[0].value.raw.length;
619
+ const message = `${primaryNode.tag.name} argument must be interpolated ${
620
+ noInterpolationError ? 'in' : 'at the beginning of'
621
+ } "${primaryNode.tag.name}\`\`" in "${primaryNode.loc.filename}" on line ${
622
+ primaryNode.loc.start.line
623
+ }`;
624
+ if (noInterpolationError || wrongOrderError) {
625
+ throw new Error(message);
626
+ }
627
+ };
628
+
629
+ const extractNodeVariableNames = (varNode, babel) => {
630
+ const interpolatedVariableNames = [];
631
+ if (varNode.type === 'JSXElement') {
632
+ // extract inner interpolated variables and add to the list
633
+ interpolatedVariableNames.push(
634
+ ...getValues(varNode.children, babel).map((value) => value.value.name),
635
+ );
636
+ } else if (varNode.type === 'Identifier') {
637
+ // the name of the interpolated variable
638
+ interpolatedVariableNames.push(varNode.name);
639
+ }
640
+ return interpolatedVariableNames;
641
+ };
642
+
643
+ const extractVariableNamesFromQuasiNodes = (primaryNode, babel) => {
644
+ errorOnInvalidQuasiNodes(primaryNode);
645
+ // this will contain all the nodes to convert to the ICU messageformat text
646
+ // at first they are unsorted, but will be ordered correctly at the end of the function
647
+ const text = [];
648
+ // the variable names. These are converted to object references as required for the Trans values
649
+ // in getValues() (toObjectProperty helper function)
650
+ const interpolatedVariableNames = [];
651
+ primaryNode.quasi.expressions.forEach((varNode) => {
652
+ if (
653
+ !babel.types.isIdentifier(varNode) &&
654
+ !babel.types.isTaggedTemplateExpression(varNode) &&
655
+ !babel.types.isJSXElement(varNode)
656
+ ) {
657
+ throw new Error(
658
+ `Must pass a variable, not an expression to "${primaryNode.tag.name}\`\`" in "${primaryNode.loc.filename}" on line ${primaryNode.loc.start.line}`,
659
+ );
660
+ }
661
+ text.push(varNode);
662
+ interpolatedVariableNames.push(...extractNodeVariableNames(varNode, babel));
663
+ });
664
+ primaryNode.quasi.quasis.forEach((quasiNode) => {
665
+ // these are the text surrounding the variable interpolation
666
+ // so in date`${varname}, short` it would be `''` and `, short`.
667
+ // (the empty string before `${varname}` and the stuff after it)
668
+ text.push(quasiNode);
669
+ });
670
+ return { text, interpolatedVariableNames };
671
+ };
672
+
673
+ const throwOnInvalidType = (type, primaryNode) => {
674
+ if (!icuInterpolators.includes(type)) {
675
+ throw new Error(
676
+ `Unsupported tagged template literal "${type}", must be one of date, time, number, plural, select, selectOrdinal in "${primaryNode.loc.filename}" on line ${primaryNode.loc.start.line}`,
677
+ );
678
+ }
679
+ };
680
+
681
+ /**
682
+ * Retrieve the new text to use, and any interpolated variables
683
+ *
684
+ * This is used to process tagged template literals like date`${variable}` and number`${num}, ::percent`
685
+ *
686
+ * for the data example, it will return text of `{variable, date}` with a variable of `variable`
687
+ * for the number example, it will return text of `{num, number, ::percent}` with a variable of `num`
688
+ * @param {string} type the name of the tagged template (`date`, `number`, `plural`, etc. - any valid complex ICU type)
689
+ * @param {TaggedTemplateExpression} primaryNode the template expression node
690
+ * @param {int} index starting index number of components to be used for interpolations like <0>
691
+ * @param {*} babel
692
+ */
693
+ function getTextAndInterpolatedVariables(type, primaryNode, index, babel) {
694
+ throwOnInvalidType(type, primaryNode);
695
+ const componentFoundIndex = index;
696
+ const { text, interpolatedVariableNames } = extractVariableNamesFromQuasiNodes(
697
+ primaryNode,
698
+ babel,
699
+ );
700
+ const { stringOutput, componentFoundIndex: newIndex } = text
701
+ .filter(filterNodes)
702
+ // sort by the order they appear in the source code
703
+ .sort((a, b) => {
704
+ if (a.start > b.start) return 1;
705
+ return -1;
706
+ })
707
+ .reduce(extractNestedTemplatesAndComponents, {
708
+ babel,
709
+ componentFoundIndex,
710
+ stringOutput: [],
711
+ type,
712
+ interpolatedVariableNames,
713
+ });
714
+ return [
715
+ interpolatedVariableNames,
716
+ `{${stringOutput.join('')}}`,
717
+ // return the new component interpolation index
718
+ newIndex,
719
+ ];
720
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-i18next",
3
- "version": "11.8.15",
3
+ "version": "11.9.0",
4
4
  "description": "Internationalization for react done right. Using the i18next i18n ecosystem.",
5
5
  "main": "dist/commonjs/index.js",
6
6
  "types": "./index.d.ts",
@@ -48,7 +48,6 @@
48
48
  "@testing-library/jest-dom": "^5.11.6",
49
49
  "@testing-library/react": "^11.2.2",
50
50
  "@testing-library/react-hooks": "^3.4.2",
51
- "@types/react": "^16.8.2",
52
51
  "all-contributors-cli": "^6.1.1",
53
52
  "babel-core": "^7.0.0-bridge.0",
54
53
  "babel-eslint": "10.0.3",
package/react-i18next.js CHANGED
@@ -925,17 +925,42 @@
925
925
  };
926
926
  }
927
927
 
928
+ var date = function date() {
929
+ return '';
930
+ };
931
+ var time = function time() {
932
+ return '';
933
+ };
934
+ var number = function number() {
935
+ return '';
936
+ };
937
+ var select = function select() {
938
+ return '';
939
+ };
940
+ var plural = function plural() {
941
+ return '';
942
+ };
943
+ var selectOrdinal = function selectOrdinal() {
944
+ return '';
945
+ };
946
+
928
947
  exports.I18nContext = I18nContext;
929
948
  exports.I18nextProvider = I18nextProvider;
930
949
  exports.Trans = Trans;
931
950
  exports.Translation = Translation;
932
951
  exports.composeInitialProps = composeInitialProps;
952
+ exports.date = date;
933
953
  exports.getDefaults = getDefaults;
934
954
  exports.getI18n = getI18n;
935
955
  exports.getInitialProps = getInitialProps;
936
956
  exports.initReactI18next = initReactI18next;
957
+ exports.number = number;
958
+ exports.plural = plural;
959
+ exports.select = select;
960
+ exports.selectOrdinal = selectOrdinal;
937
961
  exports.setDefaults = setDefaults;
938
962
  exports.setI18n = setI18n;
963
+ exports.time = time;
939
964
  exports.useSSR = useSSR;
940
965
  exports.useTranslation = useTranslation;
941
966
  exports.withSSR = withSSR;
@@ -1 +1 @@
1
- !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e=e||self).ReactI18next={},e.React)}(this,(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 i(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 a(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){a(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,i=function(e,n){if(null==e)return{};var t,r,i={},a=Object.keys(e);for(r=0;r<a.length;r++)t=a[r],n.indexOf(t)>=0||(i[t]=e[t]);return i}(e,n);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)t=a[r],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(i[t]=e[t])}return i}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,i=!1,a=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){i=!0,a=e}finally{try{r||null==c.return||c.return()}finally{if(i)throw a}}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(e);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,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},p=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function d(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(f[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var r=e.indexOf("--\x3e");return{type:"comment",comment:-1!==r?e.slice(4,r):""}}for(var i=new RegExp(p),a=null;null!==(a=i.exec(e));)if(a[0].trim())if(a[1]){var o=a[1].trim(),c=[o,""];o.indexOf("=")>-1&&(c=o.split("=")),n.attrs[c[0]]=c[1],i.lastIndex--}else a[2]&&(n.attrs[a[2]]=a[3].trim().substring(1,a[3].length-1));return n}var m=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,h=/^\s*$/,g=Object.create(null);var y,v=function(e,n){n||(n={}),n.components||(n.components=g);var t,r=[],i=[],a=-1,o=!1;if(0!==e.indexOf("<")){var c=e.indexOf("<");r.push({type:"text",content:-1===c?e:e.substring(0,c)})}return e.replace(m,(function(c,s){if(o){if(c!=="</"+t.name+">")return;o=!1}var u,l="/"!==c.charAt(1),f=c.startsWith("\x3c!--"),p=s+c.length,m=e.charAt(p);if(f){var g=d(c);return a<0?(r.push(g),r):((u=i[a]).children.push(g),r)}if(l&&(a++,"tag"===(t=d(c)).type&&n.components[t.name]&&(t.type="component",o=!0),t.voidElement||o||!m||"<"===m||t.children.push({type:"text",content:e.slice(p,e.indexOf("<",p))}),0===a&&r.push(t),(u=i[a-1])&&u.children.push(t),i[a]=t),(!l||t.voidElement)&&(a>-1&&(t.voidElement||t.name===c.slice(2,-1))&&(a--,t=-1===a?r:i[a]),!o&&"<"!==m&&m)){u=-1===a?r:i[a].children;var y=e.indexOf("<",p),v=e.slice(p,-1===y?void 0:y);h.test(v)&&(v=" "),(y>-1&&a+u.length>=0||" "!==v)&&u.push({type:"text",content:v})}})),r},b={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},O=t.createContext();function w(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b=c(c({},b),e)}function j(){return b}var x=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)}}])&&i(n.prototype,t),r&&i(n,r),e}();function E(e){y=e}function S(){return y}var N={type:"3rdParty",init:function(e){w(e.options.react),E(e)}};function I(e){return function(n){return new Promise((function(t){var r=k();e.getInitialProps?e.getInitialProps(n).then((function(e){t(c(c({},e),r))})):t(r)}))}}function k(){var e=S(),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 P(){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 R={};function C(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&R[n[0]]||("string"==typeof n[0]&&(R[n[0]]=new Date),P.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 T(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!n.languages||!n.languages.length)return C("i18n.languages were undefined or empty",n.languages),!0;var r=n.languages[0],i=!!n.options&&n.options.fallbackLng,a=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)||i&&!o(a,e))))}function z(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}function L(e,n){if(!e)return!1;var t=e.props?e.props.children:e.children;return n?t.length>0:!!t}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 U(e,n,i,a,o){if(""===n)return[];var s=a.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&&(L(n)?e(D(n)):"object"!==r(n)||t.isValidElement(n)||Object.assign(l,n))}))}(e);var f=i.services.interpolator.interpolate(n,c(c({},l),o),i.language),p=v("<0>".concat(f,"</0>"));function d(e,n,r){var i=D(e),a=h(i,n.children,r);return function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((function(e){return t.isValidElement(e)}))}(i)&&0===a.length?i:a}function m(e,n,r,i,a){e.dummy&&(e.children=n),r.push(t.cloneElement(e,c(c({},e.props),{},{key:i}),a?void 0:n))}function h(n,i,o){var l=B(n);return B(i).reduce((function(n,i,f){var p,g,y,v=i.children&&i.children[0]&&i.children[0].content;if("tag"===i.type){var b=l[parseInt(i.name,10)];!b&&1===o.length&&o[0][i.name]&&(b=o[0][i.name]),b||(b={});var O=0!==Object.keys(i.attrs).length?(p={props:i.attrs},(y=c({},g=b)).props=Object.assign(p.props,g.props),y):b,w=t.isValidElement(O),j=w&&L(i,!0)&&!i.voidElement,x=u&&"object"===r(O)&&O.dummy&&!w,E="object"===r(e)&&null!==e&&Object.hasOwnProperty.call(e,i.name);if("string"==typeof O)n.push(O);else if(L(O)||j){m(O,d(O,i,o),n,f)}else if(x){var S=h(l,i.children,o);n.push(t.cloneElement(O,c(c({},O.props),{},{key:f}),S))}else if(Number.isNaN(parseFloat(i.name))){if(E)m(O,d(O,i,o),n,f,i.voidElement);else if(a.transSupportBasicHtmlNodes&&s.indexOf(i.name)>-1)if(i.voidElement)n.push(t.createElement(i.name,{key:"".concat(i.name,"-").concat(f)}));else{var N=h(l,i.children,o);n.push(t.createElement(i.name,{key:"".concat(i.name,"-").concat(f)},N))}else if(i.voidElement)n.push("<".concat(i.name," />"));else{var I=h(l,i.children,o);n.push("<".concat(i.name,">").concat(I,"</").concat(i.name,">"))}}else if("object"!==r(O)||w)1===i.children.length&&v?n.push(t.cloneElement(O,c(c({},O.props),{},{key:f}),v)):n.push(t.cloneElement(O,c(c({},O.props),{},{key:f})));else{var k=i.children[0]?v:null;k&&n.push(k)}}else"text"===i.type&&n.push(i.content);return n}),[])}return D(h([{dummy:!0,children:e}],p,B(e||[]))[0])}function V(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.i18n,i=n.useContext(O)||{},a=i.i18n,o=i.defaultNS,s=r||a||S();if(s&&!s.reportNamespaces&&(s.reportNamespaces=new x),!s){C("You will need to 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}s.options.react&&void 0!==s.options.react.wait&&C("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");var p=c(c(c({},j()),s.options.react),t),d=p.useSuspense,m=e||o||s.options&&s.options.defaultNS;m="string"==typeof m?[m]:m||["translation"],s.reportNamespaces.addUsedNamespaces&&s.reportNamespaces.addUsedNamespaces(m);var h=(s.isInitialized||s.initializedStoreOnce)&&m.every((function(e){return T(e,s,p)}));function g(){return s.getFixedT(null,"fallback"===p.nsMode?m:m[0])}var y=n.useState(g),v=u(y,2),b=v[0],w=v[1],E=n.useRef(!0);n.useEffect((function(){var e=p.bindI18n,n=p.bindI18nStore;function t(){E.current&&w(g)}return E.current=!0,h||d||A(s,m,(function(){E.current&&w(g)})),e&&s&&s.on(e,t),n&&s&&s.store.on(n,t),function(){E.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)}))}}),[s,m.join()]);var N=n.useRef(!0);n.useEffect((function(){E.current&&!N.current&&w(g),N.current=!1}),[s]);var I=[b,s,h];if(I.t=b,I.i18n=s,I.ready=h,h)return I;if(!h&&!d)return I;throw new Promise((function(e){A(s,m,(function(){e()}))}))}function K(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=r.i18n,a=n.useContext(O)||{},o=a.i18n,c=i||o||S();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=O,e.I18nextProvider=function(e){var t=e.i18n,r=e.defaultNS,i=e.children,a=n.useMemo((function(){return{i18n:t,defaultNS:r}}),[t,r]);return n.createElement(O.Provider,{value:a},i)},e.Trans=function(e){var i=e.children,a=e.count,o=e.parent,u=e.i18nKey,l=e.tOptions,f=void 0===l?{}:l,p=e.values,d=e.defaults,m=e.components,h=e.ns,g=e.i18n,y=e.t,v=s(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]),b=n.useContext(O)||{},w=b.i18n,x=b.defaultNS,E=g||w||S();if(!E)return C("You will need to pass in an i18next instance by using i18nextReactModule"),i;var N=y||E.t.bind(E)||function(e){return e},I=c(c({},j()),E.options&&E.options.react),k=h||N.ns||x||E.options&&E.options.defaultNS;k="string"==typeof k?[k]:k||["translation"];var R=d||function e(n,i){if(!n)return"";var a="",o=B(n),c=i.transKeepBasicHtmlNodesFor||[];return o.forEach((function(n,o){if("string"==typeof n)a+="".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)a+="<".concat(n.type,"/>");else if(f||l&&0===u)if(n.props.i18nIsDynamicList)a+="<".concat(o,"></").concat(o,">");else if(l&&1===u&&"string"==typeof f)a+="<".concat(n.type,">").concat(f,"</").concat(n.type,">");else{var p=e(f,i);a+="<".concat(o,">").concat(p,"</").concat(o,">")}else a+="<".concat(o,"></").concat(o,">")}else if(null===n)P("Trans: the passed in value is invalid - seems you passed in a null child.");else if("object"===r(n)){var d=n.format,m=s(n,["format"]),h=Object.keys(m);if(1===h.length){var g=d?"".concat(h[0],", ").concat(d):h[0];a+="{{".concat(g,"}}")}else P("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",n)}else P("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)})),a}(i,I)||I.transEmptyNodeValue||u,A=I.hashTransKey,T=u||(A?A(R):R),z=p?f.interpolation:{interpolation:c(c({},f.interpolation),{},{prefix:"#$?",suffix:"?$#"})},L=c(c(c(c({},f),{},{count:a},p),z),{},{defaultValue:R,ns:k}),D=U(m||i,T?N(T,L):R,E,I,L),V=void 0!==o?o:I.defaultTransParent;return V?t.createElement(V,v,D):D},e.Translation=function(e){var n=e.ns,t=e.children,r=u(V(n,s(e,["ns","children"])),3),i=r[0],a=r[1],o=r[2];return t(i,{i18n:a,lng:a.language},o)},e.composeInitialProps=I,e.getDefaults=j,e.getI18n=S,e.getInitialProps=k,e.initReactI18next=N,e.setDefaults=w,e.setI18n=E,e.useSSR=K,e.useTranslation=V,e.withSSR=function(){return function(e){function n(n){var r=n.initialI18nStore,i=n.initialLanguage,a=s(n,["initialI18nStore","initialLanguage"]);return K(r,i),t.createElement(e,c({},a))}return n.getInitialProps=I(e),n.displayName="withI18nextSSR(".concat(z(e),")"),n.WrappedComponent=e,n}},e.withTranslation=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function i(i){var a=i.forwardedRef,o=s(i,["forwardedRef"]),l=u(V(e,o),3),f=l[0],p=l[1],d=l[2],m=c(c({},o),{},{t:f,i18n:p,tReady:d});return n.withRef&&a?m.ref=a:!n.withRef&&a&&(m.forwardedRef=a),t.createElement(r,m)}i.displayName="withI18nextTranslation(".concat(z(r),")"),i.WrappedComponent=r;return n.withRef?t.forwardRef((function(e,n){return t.createElement(i,Object.assign({},e,{forwardedRef:n}))})):i}},Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e=e||self).ReactI18next={},e.React)}(this,(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 i(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 a(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){a(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,i=function(e,n){if(null==e)return{};var t,r,i={},a=Object.keys(e);for(r=0;r<a.length;r++)t=a[r],n.indexOf(t)>=0||(i[t]=e[t]);return i}(e,n);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)t=a[r],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(i[t]=e[t])}return i}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,i=!1,a=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){i=!0,a=e}finally{try{r||null==c.return||c.return()}finally{if(i)throw a}}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(e);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,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},p=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function d(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(f[t[1]]||"/"===e.charAt(e.length-2))&&(n.voidElement=!0),n.name.startsWith("!--"))){var r=e.indexOf("--\x3e");return{type:"comment",comment:-1!==r?e.slice(4,r):""}}for(var i=new RegExp(p),a=null;null!==(a=i.exec(e));)if(a[0].trim())if(a[1]){var o=a[1].trim(),c=[o,""];o.indexOf("=")>-1&&(c=o.split("=")),n.attrs[c[0]]=c[1],i.lastIndex--}else a[2]&&(n.attrs[a[2]]=a[3].trim().substring(1,a[3].length-1));return n}var m=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,h=/^\s*$/,g=Object.create(null);var y,v=function(e,n){n||(n={}),n.components||(n.components=g);var t,r=[],i=[],a=-1,o=!1;if(0!==e.indexOf("<")){var c=e.indexOf("<");r.push({type:"text",content:-1===c?e:e.substring(0,c)})}return e.replace(m,(function(c,s){if(o){if(c!=="</"+t.name+">")return;o=!1}var u,l="/"!==c.charAt(1),f=c.startsWith("\x3c!--"),p=s+c.length,m=e.charAt(p);if(f){var g=d(c);return a<0?(r.push(g),r):((u=i[a]).children.push(g),r)}if(l&&(a++,"tag"===(t=d(c)).type&&n.components[t.name]&&(t.type="component",o=!0),t.voidElement||o||!m||"<"===m||t.children.push({type:"text",content:e.slice(p,e.indexOf("<",p))}),0===a&&r.push(t),(u=i[a-1])&&u.children.push(t),i[a]=t),(!l||t.voidElement)&&(a>-1&&(t.voidElement||t.name===c.slice(2,-1))&&(a--,t=-1===a?r:i[a]),!o&&"<"!==m&&m)){u=-1===a?r:i[a].children;var y=e.indexOf("<",p),v=e.slice(p,-1===y?void 0:y);h.test(v)&&(v=" "),(y>-1&&a+u.length>=0||" "!==v)&&u.push({type:"text",content:v})}})),r},b={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},O=t.createContext();function w(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b=c(c({},b),e)}function j(){return b}var x=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)}}])&&i(n.prototype,t),r&&i(n,r),e}();function E(e){y=e}function S(){return y}var N={type:"3rdParty",init:function(e){w(e.options.react),E(e)}};function I(e){return function(n){return new Promise((function(t){var r=k();e.getInitialProps?e.getInitialProps(n).then((function(e){t(c(c({},e),r))})):t(r)}))}}function k(){var e=S(),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 P(){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 R={};function C(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&R[n[0]]||("string"==typeof n[0]&&(R[n[0]]=new Date),P.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 T(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!n.languages||!n.languages.length)return C("i18n.languages were undefined or empty",n.languages),!0;var r=n.languages[0],i=!!n.options&&n.options.fallbackLng,a=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)||i&&!o(a,e))))}function z(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}function L(e,n){if(!e)return!1;var t=e.props?e.props.children:e.children;return n?t.length>0:!!t}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 U(e,n,i,a,o){if(""===n)return[];var s=a.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&&(L(n)?e(D(n)):"object"!==r(n)||t.isValidElement(n)||Object.assign(l,n))}))}(e);var f=i.services.interpolator.interpolate(n,c(c({},l),o),i.language),p=v("<0>".concat(f,"</0>"));function d(e,n,r){var i=D(e),a=h(i,n.children,r);return function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((function(e){return t.isValidElement(e)}))}(i)&&0===a.length?i:a}function m(e,n,r,i,a){e.dummy&&(e.children=n),r.push(t.cloneElement(e,c(c({},e.props),{},{key:i}),a?void 0:n))}function h(n,i,o){var l=B(n);return B(i).reduce((function(n,i,f){var p,g,y,v=i.children&&i.children[0]&&i.children[0].content;if("tag"===i.type){var b=l[parseInt(i.name,10)];!b&&1===o.length&&o[0][i.name]&&(b=o[0][i.name]),b||(b={});var O=0!==Object.keys(i.attrs).length?(p={props:i.attrs},(y=c({},g=b)).props=Object.assign(p.props,g.props),y):b,w=t.isValidElement(O),j=w&&L(i,!0)&&!i.voidElement,x=u&&"object"===r(O)&&O.dummy&&!w,E="object"===r(e)&&null!==e&&Object.hasOwnProperty.call(e,i.name);if("string"==typeof O)n.push(O);else if(L(O)||j){m(O,d(O,i,o),n,f)}else if(x){var S=h(l,i.children,o);n.push(t.cloneElement(O,c(c({},O.props),{},{key:f}),S))}else if(Number.isNaN(parseFloat(i.name))){if(E)m(O,d(O,i,o),n,f,i.voidElement);else if(a.transSupportBasicHtmlNodes&&s.indexOf(i.name)>-1)if(i.voidElement)n.push(t.createElement(i.name,{key:"".concat(i.name,"-").concat(f)}));else{var N=h(l,i.children,o);n.push(t.createElement(i.name,{key:"".concat(i.name,"-").concat(f)},N))}else if(i.voidElement)n.push("<".concat(i.name," />"));else{var I=h(l,i.children,o);n.push("<".concat(i.name,">").concat(I,"</").concat(i.name,">"))}}else if("object"!==r(O)||w)1===i.children.length&&v?n.push(t.cloneElement(O,c(c({},O.props),{},{key:f}),v)):n.push(t.cloneElement(O,c(c({},O.props),{},{key:f})));else{var k=i.children[0]?v:null;k&&n.push(k)}}else"text"===i.type&&n.push(i.content);return n}),[])}return D(h([{dummy:!0,children:e}],p,B(e||[]))[0])}function V(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.i18n,i=n.useContext(O)||{},a=i.i18n,o=i.defaultNS,s=r||a||S();if(s&&!s.reportNamespaces&&(s.reportNamespaces=new x),!s){C("You will need to 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}s.options.react&&void 0!==s.options.react.wait&&C("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");var p=c(c(c({},j()),s.options.react),t),d=p.useSuspense,m=e||o||s.options&&s.options.defaultNS;m="string"==typeof m?[m]:m||["translation"],s.reportNamespaces.addUsedNamespaces&&s.reportNamespaces.addUsedNamespaces(m);var h=(s.isInitialized||s.initializedStoreOnce)&&m.every((function(e){return T(e,s,p)}));function g(){return s.getFixedT(null,"fallback"===p.nsMode?m:m[0])}var y=n.useState(g),v=u(y,2),b=v[0],w=v[1],E=n.useRef(!0);n.useEffect((function(){var e=p.bindI18n,n=p.bindI18nStore;function t(){E.current&&w(g)}return E.current=!0,h||d||A(s,m,(function(){E.current&&w(g)})),e&&s&&s.on(e,t),n&&s&&s.store.on(n,t),function(){E.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)}))}}),[s,m.join()]);var N=n.useRef(!0);n.useEffect((function(){E.current&&!N.current&&w(g),N.current=!1}),[s]);var I=[b,s,h];if(I.t=b,I.i18n=s,I.ready=h,h)return I;if(!h&&!d)return I;throw new Promise((function(e){A(s,m,(function(){e()}))}))}function K(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=r.i18n,a=n.useContext(O)||{},o=a.i18n,c=i||o||S();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=O,e.I18nextProvider=function(e){var t=e.i18n,r=e.defaultNS,i=e.children,a=n.useMemo((function(){return{i18n:t,defaultNS:r}}),[t,r]);return n.createElement(O.Provider,{value:a},i)},e.Trans=function(e){var i=e.children,a=e.count,o=e.parent,u=e.i18nKey,l=e.tOptions,f=void 0===l?{}:l,p=e.values,d=e.defaults,m=e.components,h=e.ns,g=e.i18n,y=e.t,v=s(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]),b=n.useContext(O)||{},w=b.i18n,x=b.defaultNS,E=g||w||S();if(!E)return C("You will need to pass in an i18next instance by using i18nextReactModule"),i;var N=y||E.t.bind(E)||function(e){return e},I=c(c({},j()),E.options&&E.options.react),k=h||N.ns||x||E.options&&E.options.defaultNS;k="string"==typeof k?[k]:k||["translation"];var R=d||function e(n,i){if(!n)return"";var a="",o=B(n),c=i.transKeepBasicHtmlNodesFor||[];return o.forEach((function(n,o){if("string"==typeof n)a+="".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)a+="<".concat(n.type,"/>");else if(f||l&&0===u)if(n.props.i18nIsDynamicList)a+="<".concat(o,"></").concat(o,">");else if(l&&1===u&&"string"==typeof f)a+="<".concat(n.type,">").concat(f,"</").concat(n.type,">");else{var p=e(f,i);a+="<".concat(o,">").concat(p,"</").concat(o,">")}else a+="<".concat(o,"></").concat(o,">")}else if(null===n)P("Trans: the passed in value is invalid - seems you passed in a null child.");else if("object"===r(n)){var d=n.format,m=s(n,["format"]),h=Object.keys(m);if(1===h.length){var g=d?"".concat(h[0],", ").concat(d):h[0];a+="{{".concat(g,"}}")}else P("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",n)}else P("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)})),a}(i,I)||I.transEmptyNodeValue||u,A=I.hashTransKey,T=u||(A?A(R):R),z=p?f.interpolation:{interpolation:c(c({},f.interpolation),{},{prefix:"#$?",suffix:"?$#"})},L=c(c(c(c({},f),{},{count:a},p),z),{},{defaultValue:R,ns:k}),D=U(m||i,T?N(T,L):R,E,I,L),V=void 0!==o?o:I.defaultTransParent;return V?t.createElement(V,v,D):D},e.Translation=function(e){var n=e.ns,t=e.children,r=u(V(n,s(e,["ns","children"])),3),i=r[0],a=r[1],o=r[2];return t(i,{i18n:a,lng:a.language},o)},e.composeInitialProps=I,e.date=function(){return""},e.getDefaults=j,e.getI18n=S,e.getInitialProps=k,e.initReactI18next=N,e.number=function(){return""},e.plural=function(){return""},e.select=function(){return""},e.selectOrdinal=function(){return""},e.setDefaults=w,e.setI18n=E,e.time=function(){return""},e.useSSR=K,e.useTranslation=V,e.withSSR=function(){return function(e){function n(n){var r=n.initialI18nStore,i=n.initialLanguage,a=s(n,["initialI18nStore","initialLanguage"]);return K(r,i),t.createElement(e,c({},a))}return n.getInitialProps=I(e),n.displayName="withI18nextSSR(".concat(z(e),")"),n.WrappedComponent=e,n}},e.withTranslation=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function i(i){var a=i.forwardedRef,o=s(i,["forwardedRef"]),l=u(V(e,o),3),f=l[0],p=l[1],d=l[2],m=c(c({},o),{},{t:f,i18n:p,tReady:d});return n.withRef&&a?m.ref=a:!n.withRef&&a&&(m.forwardedRef=a),t.createElement(r,m)}i.displayName="withI18nextTranslation(".concat(z(r),")"),i.WrappedComponent=r;return n.withRef?t.forwardRef((function(e,n){return t.createElement(i,Object.assign({},e,{forwardedRef:n}))})):i}},Object.defineProperty(e,"__esModule",{value:!0})}));
package/src/index.js CHANGED
@@ -16,3 +16,12 @@ export {
16
16
  composeInitialProps,
17
17
  getInitialProps,
18
18
  } from './context';
19
+
20
+ // dummy functions for icu.macro support
21
+
22
+ export const date = () => '';
23
+ export const time = () => '';
24
+ export const number = () => '';
25
+ export const select = () => '';
26
+ export const plural = () => '';
27
+ export const selectOrdinal = () => '';
@@ -0,0 +1,104 @@
1
+ import React from 'react';
2
+ import { Namespace, DefaultNamespace, TFuncKey, Trans } from '.';
3
+ import { i18n } from 'i18next';
4
+
5
+ export { Trans };
6
+
7
+ declare module 'react-i18next/icu.macro' {
8
+ export interface PluralSubProps<
9
+ K extends TFuncKey<N> extends infer A ? A : never,
10
+ N extends Namespace = DefaultNamespace
11
+ > {
12
+ children?: never;
13
+ i18nKey?: K;
14
+ i18n?: i18n;
15
+ ns?: N;
16
+ count: number;
17
+ zero?: string | React.ReactElement;
18
+ one?: string | React.ReactElement;
19
+ two?: string | React.ReactElement;
20
+ few?: string | React.ReactElement;
21
+ many?: string | React.ReactElement;
22
+ other: string | React.ReactElement;
23
+ }
24
+
25
+ type PluralProps<
26
+ T,
27
+ K extends TFuncKey<N> extends infer A ? A : never,
28
+ N extends Namespace = DefaultNamespace
29
+ > = {
30
+ [P in keyof T]: P extends keyof PluralSubProps<K, N>
31
+ ? // support the standard properties of Plural
32
+ PluralSubProps<K, N>[P]
33
+ : // this supports infinite $0={..} or $123={..}
34
+ // technically it also supports $-1={..} and $2.3={..} but we don't need to
35
+ // worry since that's invalid syntax.
36
+ P extends `$${number}`
37
+ ? string | React.ReactElement
38
+ : never;
39
+ };
40
+
41
+ interface SelectSubProps {
42
+ [key: string]: string | React.ReactElement;
43
+ }
44
+
45
+ interface NoChildren {
46
+ children?: never;
47
+ }
48
+
49
+ interface SelectRequiredProps<
50
+ K extends TFuncKey<N> extends infer A ? A : never,
51
+ N extends Namespace = DefaultNamespace
52
+ > extends NoChildren {
53
+ i18nKey?: K;
54
+ i18n?: i18n;
55
+ ns?: N;
56
+ other: string | React.ReactElement;
57
+ }
58
+
59
+ // defining it this way ensures that `other` is always defined, but allows
60
+ // unlimited other select types.
61
+ type SelectProps<
62
+ K extends TFuncKey<N> extends infer A ? A : never,
63
+ N extends Namespace = DefaultNamespace
64
+ > = SelectSubProps & SelectRequiredProps<K, N>;
65
+
66
+ function Plural<
67
+ T,
68
+ K extends TFuncKey<N> extends infer A ? A : never,
69
+ N extends Namespace = DefaultNamespace
70
+ >(props: PluralProps<T, K, N> & NoChildren): React.ReactElement;
71
+
72
+ function SelectOrdinal<
73
+ T,
74
+ K extends TFuncKey<N> extends infer A ? A : never,
75
+ N extends Namespace = DefaultNamespace
76
+ >(props: PluralProps<T, K, N> & NoChildren): React.ReactElement;
77
+
78
+ function Select<
79
+ K extends TFuncKey<N> extends infer A ? A : never,
80
+ N extends Namespace = DefaultNamespace
81
+ >(props: SelectProps<K, N>): React.ReactElement;
82
+
83
+ function date(strings: TemplateStringsArray, variable: Date): string;
84
+ function time(strings: TemplateStringsArray, variable: Date): string;
85
+ function number(strings: TemplateStringsArray, variable: number): string;
86
+
87
+ type ValidInterpolations = React.ReactElement | string;
88
+
89
+ function plural(
90
+ strings: TemplateStringsArray,
91
+ variable: number,
92
+ ...args: ValidInterpolations[]
93
+ ): string;
94
+ function selectOrdinal(
95
+ strings: TemplateStringsArray,
96
+ variable: number,
97
+ ...args: ValidInterpolations[]
98
+ ): string;
99
+ function select(
100
+ strings: TemplateStringsArray,
101
+ variable: string,
102
+ ...args: ValidInterpolations[]
103
+ ): string;
104
+ }