diff --git a/react-i18next.js b/react-i18next.js index 97e7bd958..ffa0cf461 100644 --- a/react-i18next.js +++ b/react-i18next.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) : typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) : - (global = global || self, factory(global.ReactI18next = {}, global.react)); + (global = global || self, factory(global.ReactI18next = {}, global.React)); }(this, function (exports, react) { 'use strict'; function ownKeys(object, enumerableOnly) { diff --git a/react-i18next.min.js b/react-i18next.min.js index 27dc93f23..4985717c8 100644 --- a/react-i18next.min.js +++ b/react-i18next.min.js @@ -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";function t(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 r(e){for(var n=1;n=0||(a[t]=e[t]);return a}(e,n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(a[t]=e[t])}return a}function s(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){var t=e&&("undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"]);if(null==t)return;var r,a,i=[],o=!0,c=!1;try{for(t=t.call(e);!(o=(r=t.next()).done)&&(i.push(r.value),!n||i.length!==n);o=!0);}catch(e){c=!0,a=e}finally{try{o||null==t.return||t.return()}finally{if(c)throw a}}return i}(e,n)||function(e,n){if(!e)return;if("string"==typeof e)return u(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 u(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 u(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function p(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(l[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 a=new RegExp(f),i=null;null!==(i=a.exec(e));)if(i[0].trim())if(i[1]){var o=i[1].trim(),c=[o,""];o.indexOf("=")>-1&&(c=o.split("=")),n.attrs[c[0]]=c[1],a.lastIndex--}else i[2]&&(n.attrs[i[2]]=i[3].trim().substring(1,i[3].length-1));return n}var d=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,g=/^\s*$/,m=Object.create(null);var h=function(e,n){n||(n={}),n.components||(n.components=m);var t,r=[],a=[],i=-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(d,(function(c,s){if(o){if(c!=="")return;o=!1}var u,l="/"!==c.charAt(1),f=c.startsWith("\x3c!--"),d=s+c.length,m=e.charAt(d);if(f){var h=p(c);return i<0?(r.push(h),r):((u=a[i]).children.push(h),r)}if(l&&(i++,"tag"===(t=p(c)).type&&n.components[t.name]&&(t.type="component",o=!0),t.voidElement||o||!m||"<"===m||t.children.push({type:"text",content:e.slice(d,e.indexOf("<",d))}),0===i&&r.push(t),(u=a[i-1])&&u.children.push(t),a[i]=t),(!l||t.voidElement)&&(i>-1&&(t.voidElement||t.name===c.slice(2,-1))&&(i--,t=-1===i?r:a[i]),!o&&"<"!==m&&m)){u=-1===i?r:a[i].children;var v=e.indexOf("<",d),y=e.slice(d,-1===v?void 0:v);g.test(y)&&(y=" "),(v>-1&&i+u.length>=0||" "!==y)&&u.push({type:"text",content:y})}})),r},v="".replace,y=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g,b={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'};function O(e){return b[e]}var x,w={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},j=n.createContext();function E(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};w=r(r({},w),e)}function S(){return w}var N=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 k(e){x=e}function I(){return x}var P={type:"3rdParty",init:function(e){E(e.options.react),k(e)}};function R(e){return function(n){return new Promise((function(t){var a=C();e.getInitialProps?e.getInitialProps(n).then((function(e){t(r(r({},e),a))})):t(a)}))}}function C(){var e=I(),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 T(){if(console&&console.warn){for(var e,n=arguments.length,t=new Array(n),r=0;r2&&void 0!==arguments[2]?arguments[2]:{},r=n.languages[0],a=!!n.options&&n.options.fallbackLng,i=n.languages[n.languages.length-1];if("cimode"===r.toLowerCase())return!0;var o=function(e,t){var r=n.services.backendConnector.state["".concat(e,"|").concat(t)];return-1===r||2===r};return!(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!o(n.isLanguageChangingTo,e))&&(!!n.hasResourceBundle(r,e)||(!(n.services.backendConnector.backend&&(!n.options.resources||n.options.partialBundledLanguages))||!(!o(r,e)||a&&!o(i,e))))}function U(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!n.languages||!n.languages.length)return L("i18n.languages were undefined or empty",n.languages),!0;var r=void 0!==n.options.ignoreJSONStructure;return r?n.hasLoadedNamespace(e,{precheck:function(n,r){if(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!r(n.isLanguageChangingTo,e))return!1}}):B(e,n,t)}function D(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}var H=["format"],K=["children","count","parent","i18nKey","context","tOptions","values","defaults","components","ns","i18n","t","shouldUnescape"];function V(e,n){if(!e)return!1;var t=e.props?e.props.children:e.children;return n?t.length>0:!!t}function F(e){return e?e&&e.children?e.children:e.props&&e.props.children:[]}function W(e){return Array.isArray(e)?e:[e]}function M(e,t,i,o,c,s){if(""===t)return[];var u=o.transKeepBasicHtmlNodesFor||[],l=t&&new RegExp(u.join("|")).test(t);if(!e&&!l)return[t];var f={};!function e(t){W(t).forEach((function(t){"string"!=typeof t&&(V(t)?e(F(t)):"object"!==a(t)||n.isValidElement(t)||Object.assign(f,t))}))}(e);var p=h("<0>".concat(t,"")),d=r(r({},f),c);function g(e,t,r){var a=F(e),i=b(a,t.children,r);return function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((function(e){return n.isValidElement(e)}))}(a)&&0===i.length?a:i}function m(e,t,a,i,o){e.dummy&&(e.children=t),a.push(n.cloneElement(e,r(r({},e.props),{},{key:i}),o?void 0:t))}function b(t,c,f){var p=W(t);return W(c).reduce((function(t,c,h){var x,w,j,E,S=c.children&&c.children[0]&&c.children[0].content&&i.services.interpolator.interpolate(c.children[0].content,d,i.language);if("tag"===c.type){var N=p[parseInt(c.name,10)];!N&&1===f.length&&f[0][c.name]&&(N=f[0][c.name]),N||(N={});var k=0!==Object.keys(c.attrs).length?(w={props:c.attrs},(E=r({},j=N)).props=Object.assign(w.props,j.props),E):N,I=n.isValidElement(k),P=I&&V(c,!0)&&!c.voidElement,R=l&&"object"===a(k)&&k.dummy&&!I,C="object"===a(e)&&null!==e&&Object.hasOwnProperty.call(e,c.name);if("string"==typeof k){var T=i.services.interpolator.interpolate(k,d,i.language);t.push(T)}else if(V(k)||P){m(k,g(k,c,f),t,h)}else if(R){var A=b(p,c.children,f);t.push(n.cloneElement(k,r(r({},k.props),{},{key:h}),A))}else if(Number.isNaN(parseFloat(c.name))){if(C)m(k,g(k,c,f),t,h,c.voidElement);else if(o.transSupportBasicHtmlNodes&&u.indexOf(c.name)>-1)if(c.voidElement)t.push(n.createElement(c.name,{key:"".concat(c.name,"-").concat(h)}));else{var L=b(p,c.children,f);t.push(n.createElement(c.name,{key:"".concat(c.name,"-").concat(h)},L))}else if(c.voidElement)t.push("<".concat(c.name," />"));else{var z=b(p,c.children,f);t.push("<".concat(c.name,">").concat(z,""))}}else if("object"!==a(k)||I)1===c.children.length&&S?t.push(n.cloneElement(k,r(r({},k.props),{},{key:h}),S)):t.push(n.cloneElement(k,r(r({},k.props),{},{key:h})));else{var B=c.children[0]?S:null;B&&t.push(B)}}else if("text"===c.type){var U=o.transWrapTextNodes,D=s?(x=i.services.interpolator.interpolate(c.content,d,i.language),v.call(x,y,O)):i.services.interpolator.interpolate(c.content,d,i.language);U?t.push(n.createElement(U,{key:"".concat(c.name,"-").concat(h)},D)):t.push(D)}return t}),[])}return F(b([{dummy:!0,children:e||[]}],p,W(e||[]))[0])}var $=function(e,t){var r=n.useRef();return n.useEffect((function(){r.current=t?r.current:e}),[e,t]),r.current};function q(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=t.i18n,i=n.useContext(j)||{},o=i.i18n,c=i.defaultNS,u=a||o||I();if(u&&!u.reportNamespaces&&(u.reportNamespaces=new N),!u){L("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}u.options.react&&void 0!==u.options.react.wait&&L("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");var p=r(r(r({},S()),u.options.react),t),d=p.useSuspense,g=p.keyPrefix,m=e||c||u.options&&u.options.defaultNS;m="string"==typeof m?[m]:m||["translation"],u.reportNamespaces.addUsedNamespaces&&u.reportNamespaces.addUsedNamespaces(m);var h=(u.isInitialized||u.initializedStoreOnce)&&m.every((function(e){return U(e,u,p)}));function v(){return u.getFixedT(null,"fallback"===p.nsMode?m:m[0],g)}var y=n.useState(v),b=s(y,2),O=b[0],x=b[1],w=m.join(),E=$(w),k=n.useRef(!0);n.useEffect((function(){var e=p.bindI18n,n=p.bindI18nStore;function t(){k.current&&x(v)}return k.current=!0,h||d||z(u,m,(function(){k.current&&x(v)})),h&&E&&E!==w&&k.current&&x(v),e&&u&&u.on(e,t),n&&u&&u.store.on(n,t),function(){k.current=!1,e&&u&&e.split(" ").forEach((function(e){return u.off(e,t)})),n&&u&&n.split(" ").forEach((function(e){return u.store.off(e,t)}))}}),[u,w]);var P=n.useRef(!0);n.useEffect((function(){k.current&&!P.current&&x(v),P.current=!1}),[u]);var R=[O,u,h];if(R.t=O,R.i18n=u,R.ready=h,h)return R;if(!h&&!d)return R;throw new Promise((function(e){z(u,m,(function(){e()}))}))}var Y=["forwardedRef"];var _=["ns","children"];function J(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=r.i18n,i=n.useContext(j)||{},o=i.i18n,c=a||o||I();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))}var Z=["initialI18nStore","initialLanguage"];e.I18nContext=j,e.I18nextProvider=function(e){var t=e.i18n,r=e.defaultNS,a=e.children,i=n.useMemo((function(){return{i18n:t,defaultNS:r}}),[t,r]);return n.createElement(j.Provider,{value:i},a)},e.Trans=function(e){var t=e.children,i=e.count,o=e.parent,s=e.i18nKey,u=e.context,l=e.tOptions,f=void 0===l?{}:l,p=e.values,d=e.defaults,g=e.components,m=e.ns,h=e.i18n,v=e.t,y=e.shouldUnescape,b=c(e,K),O=n.useContext(j)||{},x=O.i18n,w=O.defaultNS,E=h||x||I();if(!E)return L("You will need to pass in an i18next instance by using i18nextReactModule"),t;var N=v||E.t.bind(E)||function(e){return e};u&&(f.context=u);var k=r(r({},S()),E.options&&E.options.react),P=m||N.ns||w||E.options&&E.options.defaultNS;P="string"==typeof P?[P]:P||["translation"];var R=d||function e(t,r){if(!t)return"";var i="",o=W(t),s=r.transSupportBasicHtmlNodes&&r.transKeepBasicHtmlNodesFor?r.transKeepBasicHtmlNodesFor:[];return o.forEach((function(t,o){if("string"==typeof t)i+="".concat(t);else if(n.isValidElement(t)){var u=Object.keys(t.props).length,l=s.indexOf(t.type)>-1,f=t.props.children;if(!f&&l&&0===u)i+="<".concat(t.type,"/>");else if(f||l&&0===u)if(t.props.i18nIsDynamicList)i+="<".concat(o,">");else if(l&&1===u&&"string"==typeof f)i+="<".concat(t.type,">").concat(f,"");else{var p=e(f,r);i+="<".concat(o,">").concat(p,"")}else i+="<".concat(o,">")}else if(null===t)T("Trans: the passed in value is invalid - seems you passed in a null child.");else if("object"===a(t)){var d=t.format,g=c(t,H),m=Object.keys(g);if(1===m.length){var h=d?"".concat(m[0],", ").concat(d):m[0];i+="{{".concat(h,"}}")}else T("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",t)}else T("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}}.",t)})),i}(t,k)||k.transEmptyNodeValue||s,C=k.hashTransKey,A=s||(C?C(R):R),z=p?f.interpolation:{interpolation:r(r({},f.interpolation),{},{prefix:"#$?",suffix:"?$#"})},B=r(r(r(r({},f),{},{count:i},p),z),{},{defaultValue:R,ns:P}),U=M(g||t,A?N(A,B):R,E,k,B,y),D=void 0!==o?o:k.defaultTransParent;return D?n.createElement(D,b,U):U},e.Translation=function(e){var n=e.ns,t=e.children,r=s(q(n,c(e,_)),3),a=r[0],i=r[1],o=r[2];return t(a,{i18n:i,lng:i.language},o)},e.composeInitialProps=R,e.date=function(){return""},e.getDefaults=S,e.getI18n=I,e.getInitialProps=C,e.initReactI18next=P,e.number=function(){return""},e.plural=function(){return""},e.select=function(){return""},e.selectOrdinal=function(){return""},e.setDefaults=E,e.setI18n=k,e.time=function(){return""},e.useSSR=J,e.useTranslation=q,e.withSSR=function(){return function(e){function t(t){var a=t.initialI18nStore,i=t.initialLanguage,o=c(t,Z);return J(a,i),n.createElement(e,r({},o))}return t.getInitialProps=R(e),t.displayName="withI18nextSSR(".concat(D(e),")"),t.WrappedComponent=e,t}},e.withTranslation=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(a){function i(i){var o=i.forwardedRef,u=c(i,Y),l=s(q(e,r(r({},u),{},{keyPrefix:t.keyPrefix})),3),f=l[0],p=l[1],d=l[2],g=r(r({},u),{},{t:f,i18n:p,tReady:d});return t.withRef&&o?g.ref=o:!t.withRef&&o&&(g.forwardedRef=o),n.createElement(a,g)}i.displayName="withI18nextTranslation(".concat(D(a),")"),i.WrappedComponent=a;return t.withRef?n.forwardRef((function(e,t){return n.createElement(i,Object.assign({},e,{forwardedRef:t}))})):i}},Object.defineProperty(e,"__esModule",{value:!0})})); +!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";function t(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 r(e){for(var n=1;n=0||(a[t]=e[t]);return a}(e,n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(a[t]=e[t])}return a}function s(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){var t=e&&("undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"]);if(null==t)return;var r,a,i=[],o=!0,c=!1;try{for(t=t.call(e);!(o=(r=t.next()).done)&&(i.push(r.value),!n||i.length!==n);o=!0);}catch(e){c=!0,a=e}finally{try{o||null==t.return||t.return()}finally{if(c)throw a}}return i}(e,n)||function(e,n){if(!e)return;if("string"==typeof e)return u(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 u(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 u(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function p(e){var n={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},t=e.match(/<\/?([^\s]+?)[/\s>]/);if(t&&(n.name=t[1],(l[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 a=new RegExp(f),i=null;null!==(i=a.exec(e));)if(i[0].trim())if(i[1]){var o=i[1].trim(),c=[o,""];o.indexOf("=")>-1&&(c=o.split("=")),n.attrs[c[0]]=c[1],a.lastIndex--}else i[2]&&(n.attrs[i[2]]=i[3].trim().substring(1,i[3].length-1));return n}var d=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,g=/^\s*$/,m=Object.create(null);var h=function(e,n){n||(n={}),n.components||(n.components=m);var t,r=[],a=[],i=-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(d,(function(c,s){if(o){if(c!=="")return;o=!1}var u,l="/"!==c.charAt(1),f=c.startsWith("\x3c!--"),d=s+c.length,m=e.charAt(d);if(f){var h=p(c);return i<0?(r.push(h),r):((u=a[i]).children.push(h),r)}if(l&&(i++,"tag"===(t=p(c)).type&&n.components[t.name]&&(t.type="component",o=!0),t.voidElement||o||!m||"<"===m||t.children.push({type:"text",content:e.slice(d,e.indexOf("<",d))}),0===i&&r.push(t),(u=a[i-1])&&u.children.push(t),a[i]=t),(!l||t.voidElement)&&(i>-1&&(t.voidElement||t.name===c.slice(2,-1))&&(i--,t=-1===i?r:a[i]),!o&&"<"!==m&&m)){u=-1===i?r:a[i].children;var v=e.indexOf("<",d),y=e.slice(d,-1===v?void 0:v);g.test(y)&&(y=" "),(v>-1&&i+u.length>=0||" "!==y)&&u.push({type:"text",content:y})}})),r},v="".replace,y=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g,b={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'};function O(e){return b[e]}var x,w={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},j=n.createContext();function E(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};w=r(r({},w),e)}function S(){return w}var N=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 k(e){x=e}function I(){return x}var P={type:"3rdParty",init:function(e){E(e.options.react),k(e)}};function R(e){return function(n){return new Promise((function(t){var a=C();e.getInitialProps?e.getInitialProps(n).then((function(e){t(r(r({},e),a))})):t(a)}))}}function C(){var e=I(),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 T(){if(console&&console.warn){for(var e,n=arguments.length,t=new Array(n),r=0;r2&&void 0!==arguments[2]?arguments[2]:{},r=n.languages[0],a=!!n.options&&n.options.fallbackLng,i=n.languages[n.languages.length-1];if("cimode"===r.toLowerCase())return!0;var o=function(e,t){var r=n.services.backendConnector.state["".concat(e,"|").concat(t)];return-1===r||2===r};return!(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!o(n.isLanguageChangingTo,e))&&(!!n.hasResourceBundle(r,e)||(!(n.services.backendConnector.backend&&(!n.options.resources||n.options.partialBundledLanguages))||!(!o(r,e)||a&&!o(i,e))))}function U(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!n.languages||!n.languages.length)return L("i18n.languages were undefined or empty",n.languages),!0;var r=void 0!==n.options.ignoreJSONStructure;return r?n.hasLoadedNamespace(e,{precheck:function(n,r){if(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!r(n.isLanguageChangingTo,e))return!1}}):B(e,n,t)}function D(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}var H=["format"],K=["children","count","parent","i18nKey","context","tOptions","values","defaults","components","ns","i18n","t","shouldUnescape"];function V(e,n){if(!e)return!1;var t=e.props?e.props.children:e.children;return n?t.length>0:!!t}function F(e){return e?e&&e.children?e.children:e.props&&e.props.children:[]}function W(e){return Array.isArray(e)?e:[e]}function M(e,t,i,o,c,s){if(""===t)return[];var u=o.transKeepBasicHtmlNodesFor||[],l=t&&new RegExp(u.join("|")).test(t);if(!e&&!l)return[t];var f={};!function e(t){W(t).forEach((function(t){"string"!=typeof t&&(V(t)?e(F(t)):"object"!==a(t)||n.isValidElement(t)||Object.assign(f,t))}))}(e);var p=h("<0>".concat(t,"")),d=r(r({},f),c);function g(e,t,r){var a=F(e),i=b(a,t.children,r);return function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((function(e){return n.isValidElement(e)}))}(a)&&0===i.length?a:i}function m(e,t,a,i,o){e.dummy&&(e.children=t),a.push(n.cloneElement(e,r(r({},e.props),{},{key:i}),o?void 0:t))}function b(t,c,f){var p=W(t);return W(c).reduce((function(t,c,h){var x,w,j,E,S=c.children&&c.children[0]&&c.children[0].content&&i.services.interpolator.interpolate(c.children[0].content,d,i.language);if("tag"===c.type){var N=p[parseInt(c.name,10)];!N&&1===f.length&&f[0][c.name]&&(N=f[0][c.name]),N||(N={});var k=0!==Object.keys(c.attrs).length?(w={props:c.attrs},(E=r({},j=N)).props=Object.assign(w.props,j.props),E):N,I=n.isValidElement(k),P=I&&V(c,!0)&&!c.voidElement,R=l&&"object"===a(k)&&k.dummy&&!I,C="object"===a(e)&&null!==e&&Object.hasOwnProperty.call(e,c.name);if("string"==typeof k){var T=i.services.interpolator.interpolate(k,d,i.language);t.push(T)}else if(V(k)||P){m(k,g(k,c,f),t,h)}else if(R){var A=b(p,c.children,f);t.push(n.cloneElement(k,r(r({},k.props),{},{key:h}),A))}else if(Number.isNaN(parseFloat(c.name))){if(C)m(k,g(k,c,f),t,h,c.voidElement);else if(o.transSupportBasicHtmlNodes&&u.indexOf(c.name)>-1)if(c.voidElement)t.push(n.createElement(c.name,{key:"".concat(c.name,"-").concat(h)}));else{var L=b(p,c.children,f);t.push(n.createElement(c.name,{key:"".concat(c.name,"-").concat(h)},L))}else if(c.voidElement)t.push("<".concat(c.name," />"));else{var z=b(p,c.children,f);t.push("<".concat(c.name,">").concat(z,""))}}else if("object"!==a(k)||I)1===c.children.length&&S?t.push(n.cloneElement(k,r(r({},k.props),{},{key:h}),S)):t.push(n.cloneElement(k,r(r({},k.props),{},{key:h})));else{var B=c.children[0]?S:null;B&&t.push(B)}}else if("text"===c.type){var U=o.transWrapTextNodes,D=s?(x=i.services.interpolator.interpolate(c.content,d,i.language),v.call(x,y,O)):i.services.interpolator.interpolate(c.content,d,i.language);U?t.push(n.createElement(U,{key:"".concat(c.name,"-").concat(h)},D)):t.push(D)}return t}),[])}return F(b([{dummy:!0,children:e||[]}],p,W(e||[]))[0])}var $=function(e,t){var r=n.useRef();return n.useEffect((function(){r.current=t?r.current:e}),[e,t]),r.current};function q(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=t.i18n,i=n.useContext(j)||{},o=i.i18n,c=i.defaultNS,u=a||o||I();if(u&&!u.reportNamespaces&&(u.reportNamespaces=new N),!u){L("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}u.options.react&&void 0!==u.options.react.wait&&L("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");var p=r(r(r({},S()),u.options.react),t),d=p.useSuspense,g=p.keyPrefix,m=e||c||u.options&&u.options.defaultNS;m="string"==typeof m?[m]:m||["translation"],u.reportNamespaces.addUsedNamespaces&&u.reportNamespaces.addUsedNamespaces(m);var h=(u.isInitialized||u.initializedStoreOnce)&&m.every((function(e){return U(e,u,p)}));function v(){return u.getFixedT(null,"fallback"===p.nsMode?m:m[0],g)}var y=n.useState(v),b=s(y,2),O=b[0],x=b[1],w=m.join(),E=$(w),k=n.useRef(!0);n.useEffect((function(){var e=p.bindI18n,n=p.bindI18nStore;function t(){k.current&&x(v)}return k.current=!0,h||d||z(u,m,(function(){k.current&&x(v)})),h&&E&&E!==w&&k.current&&x(v),e&&u&&u.on(e,t),n&&u&&u.store.on(n,t),function(){k.current=!1,e&&u&&e.split(" ").forEach((function(e){return u.off(e,t)})),n&&u&&n.split(" ").forEach((function(e){return u.store.off(e,t)}))}}),[u,w]);var P=n.useRef(!0);n.useEffect((function(){k.current&&!P.current&&x(v),P.current=!1}),[u]);var R=[O,u,h];if(R.t=O,R.i18n=u,R.ready=h,h)return R;if(!h&&!d)return R;throw new Promise((function(e){z(u,m,(function(){e()}))}))}var Y=["forwardedRef"];var _=["ns","children"];function J(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=r.i18n,i=n.useContext(j)||{},o=i.i18n,c=a||o||I();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))}var Z=["initialI18nStore","initialLanguage"];e.I18nContext=j,e.I18nextProvider=function(e){var t=e.i18n,r=e.defaultNS,a=e.children,i=n.useMemo((function(){return{i18n:t,defaultNS:r}}),[t,r]);return n.createElement(j.Provider,{value:i},a)},e.Trans=function(e){var t=e.children,i=e.count,o=e.parent,s=e.i18nKey,u=e.context,l=e.tOptions,f=void 0===l?{}:l,p=e.values,d=e.defaults,g=e.components,m=e.ns,h=e.i18n,v=e.t,y=e.shouldUnescape,b=c(e,K),O=n.useContext(j)||{},x=O.i18n,w=O.defaultNS,E=h||x||I();if(!E)return L("You will need to pass in an i18next instance by using i18nextReactModule"),t;var N=v||E.t.bind(E)||function(e){return e};u&&(f.context=u);var k=r(r({},S()),E.options&&E.options.react),P=m||N.ns||w||E.options&&E.options.defaultNS;P="string"==typeof P?[P]:P||["translation"];var R=d||function e(t,r){if(!t)return"";var i="",o=W(t),s=r.transSupportBasicHtmlNodes&&r.transKeepBasicHtmlNodesFor?r.transKeepBasicHtmlNodesFor:[];return o.forEach((function(t,o){if("string"==typeof t)i+="".concat(t);else if(n.isValidElement(t)){var u=Object.keys(t.props).length,l=s.indexOf(t.type)>-1,f=t.props.children;if(!f&&l&&0===u)i+="<".concat(t.type,"/>");else if(f||l&&0===u)if(t.props.i18nIsDynamicList)i+="<".concat(o,">");else if(l&&1===u&&"string"==typeof f)i+="<".concat(t.type,">").concat(f,"");else{var p=e(f,r);i+="<".concat(o,">").concat(p,"")}else i+="<".concat(o,">")}else if(null===t)T("Trans: the passed in value is invalid - seems you passed in a null child.");else if("object"===a(t)){var d=t.format,g=c(t,H),m=Object.keys(g);if(1===m.length){var h=d?"".concat(m[0],", ").concat(d):m[0];i+="{{".concat(h,"}}")}else T("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",t)}else T("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}}.",t)})),i}(t,k)||k.transEmptyNodeValue||s,C=k.hashTransKey,A=s||(C?C(R):R),z=p?f.interpolation:{interpolation:r(r({},f.interpolation),{},{prefix:"#$?",suffix:"?$#"})},B=r(r(r(r({},f),{},{count:i},p),z),{},{defaultValue:R,ns:P}),U=M(g||t,A?N(A,B):R,E,k,B,y),D=void 0!==o?o:k.defaultTransParent;return D?n.createElement(D,b,U):U},e.Translation=function(e){var n=e.ns,t=e.children,r=s(q(n,c(e,_)),3),a=r[0],i=r[1],o=r[2];return t(a,{i18n:i,lng:i.language},o)},e.composeInitialProps=R,e.date=function(){return""},e.getDefaults=S,e.getI18n=I,e.getInitialProps=C,e.initReactI18next=P,e.number=function(){return""},e.plural=function(){return""},e.select=function(){return""},e.selectOrdinal=function(){return""},e.setDefaults=E,e.setI18n=k,e.time=function(){return""},e.useSSR=J,e.useTranslation=q,e.withSSR=function(){return function(e){function t(t){var a=t.initialI18nStore,i=t.initialLanguage,o=c(t,Z);return J(a,i),n.createElement(e,r({},o))}return t.getInitialProps=R(e),t.displayName="withI18nextSSR(".concat(D(e),")"),t.WrappedComponent=e,t}},e.withTranslation=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(a){function i(i){var o=i.forwardedRef,u=c(i,Y),l=s(q(e,r(r({},u),{},{keyPrefix:t.keyPrefix})),3),f=l[0],p=l[1],d=l[2],g=r(r({},u),{},{t:f,i18n:p,tReady:d});return t.withRef&&o?g.ref=o:!t.withRef&&o&&(g.forwardedRef=o),n.createElement(a,g)}i.displayName="withI18nextTranslation(".concat(D(a),")"),i.WrappedComponent=a;return t.withRef?n.forwardRef((function(e,t){return n.createElement(i,Object.assign({},e,{forwardedRef:t}))})):i}},Object.defineProperty(e,"__esModule",{value:!0})})); diff --git a/rollup.config.js b/rollup.config.js index 21a6670c0..091b9b013 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -47,5 +47,9 @@ export default { name: 'ReactI18next', format, file, + globals: { + react: 'React', + 'react-dom': 'ReactDOM', + }, }, };