forked from i18next/react-i18next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
react-i18next.min.js
1 lines (1 loc) · 13.3 KB
/
react-i18next.min.js
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 a(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function o(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function c(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?o(t,!0).forEach((function(n){i(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):o(t).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}function s(e,n){if(null==e)return{};var t,r,a=function(e,n){if(null==e)return{};var t,r,a={},i=Object.keys(e);for(r=0;r<i.length;r++)t=i[r],n.indexOf(t)>=0||(a[t]=e[t]);return a}(e,n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)t=i[r],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(a[t]=e[t])}return a}function u(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var t=[],r=!0,a=!1,i=void 0;try{for(var o,c=e[Symbol.iterator]();!(r=(o=c.next()).done)&&(t.push(o.value),!n||t.length!==n);r=!0);}catch(e){a=!0,i=e}finally{try{r||null==c.return||c.return()}finally{if(a)throw i}}return t}(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var l={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,menuitem:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},f=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,p=/(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,d=Object.create?Object.create(null):{};function g(e,n,t,r,a){var i=n.indexOf("<",r),o=n.slice(r,-1===i?void 0:i);/^\s*$/.test(o)&&(o=" "),(!a&&i>-1&&t+e.length>=0||" "!==o)&&e.push({type:"text",content:o})}function m(e,n){switch(n.type){case"text":return e+n.content;case"tag":return e+="<"+n.name+(n.attrs?function(e){var n=[];for(var t in e)n.push(t+'="'+e[t]+'"');return n.length?" "+n.join(" "):""}(n.attrs):"")+(n.voidElement?"/>":">"),n.voidElement?e:e+n.children.reduce(m,"")+"</"+n.name+">"}}var h,y,v={parse:function(e,n){n||(n={}),n.components||(n.components=d);var t,r=[],a=-1,i=[],o={},c=!1;return e.replace(p,(function(s,u){if(c){if(s!=="</"+t.name+">")return;c=!1}var p,d="/"!==s.charAt(1),m=0===s.indexOf("\x3c!--"),h=u+s.length,y=e.charAt(h);d&&!m&&(a++,"tag"===(t=function(e){var n,t=0,r=!0,a={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return e.replace(f,(function(i){if("="===i)return r=!0,void t++;r?0===t?((l[i]||"/"===e.charAt(e.length-2))&&(a.voidElement=!0),a.name=i):(a.attrs[n]=i.replace(/^['"]|['"]$/g,""),n=void 0):(n&&(a.attrs[n]=n),n=i),t++,r=!1})),a}(s)).type&&n.components[t.name]&&(t.type="component",c=!0),t.voidElement||c||!y||"<"===y||g(t.children,e,a,h,n.ignoreWhitespace),o[t.tagName]=t,0===a&&r.push(t),(p=i[a-1])&&p.children.push(t),i[a]=t),(m||!d||t.voidElement)&&(m||a--,!c&&"<"!==y&&y&&g(p=-1===a?r:i[a].children,e,a,h,n.ignoreWhitespace))})),!r.length&&e.length&&g(r,e,0,0,n.ignoreWhitespace),r},stringify:function(e){return e.reduce((function(e,n){return e+m("",n)}),"")}},b={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0},O=t.createContext();function w(){return y}function j(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};b=c({},b,{},e)}function S(){return b}var E=function(){function e(){!function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this,e),this.usedNamespaces={}}var n,t,r;return n=e,(t=[{key:"addUsedNamespaces",value:function(e){var n=this;e.forEach((function(e){n.usedNamespaces[e]||(n.usedNamespaces[e]=!0)}))}},{key:"getUsedNamespaces",value:function(){return Object.keys(this.usedNamespaces)}}])&&a(n.prototype,t),r&&a(n,r),e}();function x(e){h=e}function N(){return h}var k={type:"3rdParty",init:function(e){j(e.options.react),x(e)}};function I(e){return function(n){return new Promise((function(t){var r=P();e.getInitialProps?e.getInitialProps(n).then((function(e){t(c({},e,{},r))})):t(r)}))}}function P(){var e=N(),n=e.reportNamespaces?e.reportNamespaces.getUsedNamespaces():[],t={},r={};return e.languages.forEach((function(t){r[t]={},n.forEach((function(n){r[t][n]=e.getResourceBundle(t,n)||{}}))})),t.initialI18nStore=r,t.initialLanguage=e.language,t}function R(){if(console&&console.warn){for(var e,n=arguments.length,t=new Array(n),r=0;r<n;r++)t[r]=arguments[r];"string"==typeof t[0]&&(t[0]="react-i18next:: ".concat(t[0])),(e=console).warn.apply(e,t)}}var C={};function T(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];"string"==typeof n[0]&&C[n[0]]||("string"==typeof n[0]&&(C[n[0]]=new Date),R.apply(void 0,n))}function A(e,n,t){e.loadNamespaces(n,(function(){if(e.isInitialized)t();else{e.on("initialized",(function n(){setTimeout((function(){e.off("initialized",n)}),0),t()}))}}))}function L(e){return e.displayName||e.name||("string"==typeof e&&e.length>0?e:"Unknown")}function z(e){return e&&(e.children||e.props&&e.props.children)}function D(e){return e?e&&e.children?e.children:e.props&&e.props.children:[]}function B(e){return Array.isArray(e)?e:[e]}function V(e,n,a,i,o){if(""===n)return[];var s=i.transKeepBasicHtmlNodesFor||[],u=n&&new RegExp(s.join("|")).test(n);if(!e&&!u)return[n];var l={};!function e(n){B(n).forEach((function(n){"string"!=typeof n&&(z(n)?e(D(n)):"object"!==r(n)||t.isValidElement(n)||Object.assign(l,n))}))}(e);var f=a.services.interpolator.interpolate(n,c({},l,{},o),a.language);var p=function e(n,a){var o=B(n);return B(a).reduce((function(n,a,l){var f=a.children&&a.children[0]&&a.children[0].content;if("tag"===a.type){var p=o[parseInt(a.name,10)]||{},d=t.isValidElement(p);if("string"==typeof p)n.push(p);else if(z(p)){var g=D(p),m=e(g,a.children),h=function(e){return"[object Array]"===Object.prototype.toString.call(e)&&e.every((function(e){return t.isValidElement(e)}))}(g)&&0===m.length?g:m;p.dummy&&(p.children=h),n.push(t.cloneElement(p,c({},p.props,{key:l}),h))}else if(u&&"object"===r(p)&&p.dummy&&!d){var y=e(o,a.children);n.push(t.cloneElement(p,c({},p.props,{key:l}),y))}else if(Number.isNaN(parseFloat(a.name)))if(i.transSupportBasicHtmlNodes&&s.indexOf(a.name)>-1)if(a.voidElement)n.push(t.createElement(a.name,{key:"".concat(a.name,"-").concat(l)}));else{var v=e(o,a.children);n.push(t.createElement(a.name,{key:"".concat(a.name,"-").concat(l)},v))}else if(a.voidElement)n.push("<".concat(a.name," />"));else{var b=e(o,a.children);n.push("<".concat(a.name,">").concat(b,"</").concat(a.name,">"))}else if("object"!==r(p)||d)1===a.children.length&&f?n.push(t.cloneElement(p,c({},p.props,{key:l}),f)):n.push(t.cloneElement(p,c({},p.props,{key:l})));else{var O=a.children[0]?f:null;O&&n.push(O)}}else"text"===a.type&&n.push(a.content);return n}),[])}([{dummy:!0,children:e}],v.parse("<0>".concat(f,"</0>")));return D(p[0])}function K(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.i18n,a=n.useContext(O),i=w()&&a||{},o=i.i18n,s=i.defaultNS,l=r||o||N();if(l&&!l.reportNamespaces&&(l.reportNamespaces=new E),!l){T("You will need pass in an i18next instance by using initReactI18next");var f=function(e){return Array.isArray(e)?e[e.length-1]:e},p=[f,{},!1];return p.t=f,p.i18n={},p.ready=!1,p}var d=c({},S(),{},l.options.react,{},t),g=d.useSuspense,m=e||s||l.options&&l.options.defaultNS;m="string"==typeof m?[m]:m||["translation"],l.reportNamespaces.addUsedNamespaces&&l.reportNamespaces.addUsedNamespaces(m);var h=(l.isInitialized||l.initializedStoreOnce)&&m.every((function(e){return function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!n.languages||!n.languages.length)return T("i18n.languages were undefined or empty",n.languages),!0;var r=n.languages[0],a=!!n.options&&n.options.fallbackLng,i=n.languages[n.languages.length-1];if("cimode"===r.toLowerCase())return!0;var o=function(e,t){var r=n.services.backendConnector.state["".concat(e,"|").concat(t)];return-1===r||2===r};return!(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&n.services.backendConnector.backend&&n.isLanguageChangingTo&&!o(n.isLanguageChangingTo,e))&&(!!n.hasResourceBundle(r,e)||(!n.services.backendConnector.backend||!(!o(r,e)||a&&!o(i,e))))}(e,l,d)}));function y(){return{t:l.getFixedT(null,"fallback"===d.nsMode?m:m[0])}}var v=u(n.useState(y()),2),b=v[0],j=v[1],x=n.useRef(!0);n.useEffect((function(){var e=d.bindI18n,n=d.bindI18nStore;function t(){x.current&&j(y())}return x.current=!0,h||g||A(l,m,(function(){x.current&&j(y())})),e&&l&&l.on(e,t),n&&l&&l.store.on(n,t),function(){x.current=!1,e&&l&&e.split(" ").forEach((function(e){return l.off(e,t)})),n&&l&&n.split(" ").forEach((function(e){return l.store.off(e,t)}))}}),[m.join()]);var k=[b.t,l,h];if(k.t=b.t,k.i18n=l,k.ready=h,h)return k;if(!h&&!g)return k;throw new Promise((function(e){A(l,m,(function(){x.current&&j(y()),e()}))}))}function U(e,t){var r=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).i18n,a=n.useContext(O),i=(w()&&a||{}).i18n,o=r||i||N();o.options&&o.options.isClone||(e&&!o.initializedStoreOnce&&(o.services.resourceStore.data=e,o.options.ns=Object.values(e).reduce((function(e,n){return Object.keys(n).forEach((function(n){e.indexOf(n)<0&&e.push(n)})),e}),o.options.ns),o.initializedStoreOnce=!0,o.isInitialized=!0),t&&!o.initializedLanguageOnce&&(o.changeLanguage(t),o.initializedLanguageOnce=!0))}e.I18nContext=O,e.I18nextProvider=function(e){var n=e.i18n,r=e.defaultNS,a=e.children;return y=!0,t.createElement(O.Provider,{value:{i18n:n,defaultNS:r}},a)},e.Trans=function(e){var a=e.children,i=e.count,o=e.parent,u=e.i18nKey,l=e.tOptions,f=e.values,p=e.defaults,d=e.components,g=e.ns,m=e.i18n,h=e.t,y=s(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]),v=n.useContext(O),b=w()&&v||{},j=b.i18n,E=b.defaultNS,x=m||j||N();if(!x)return T("You will need pass in an i18next instance by using i18nextReactModule"),a;var k=h||x.t.bind(x)||function(e){return e},I=c({},S(),{},x.options&&x.options.react),P=void 0!==o?o:I.defaultTransParent,C=g||k.ns||E||x.options&&x.options.defaultNS;C="string"==typeof C?[C]:C||["translation"];var A=p||function e(n,a,i,o){if(!a)return"";var s=n,u=B(a),l=o.transKeepBasicHtmlNodesFor||[];return u.forEach((function(n,a){var i="".concat(a);if("string"==typeof n)s="".concat(s).concat(n);else if(z(n)){var u=l.indexOf(n.type)>-1&&1===Object.keys(n.props).length&&"string"==typeof z(n)?n.type:i;s=n.props&&n.props.i18nIsDynamicList?"".concat(s,"<").concat(u,"></").concat(u,">"):"".concat(s,"<").concat(u,">").concat(e("",D(n),a+1,o),"</").concat(u,">")}else if(t.isValidElement(n))s=l.indexOf(n.type)>-1&&0===Object.keys(n.props).length?"".concat(s,"<").concat(n.type,"/>"):"".concat(s,"<").concat(i,"></").concat(i,">");else if("object"===r(n)){var f=c({},n),p=f.format;delete f.format;var d=Object.keys(f);p&&1===d.length?s="".concat(s,"{{").concat(d[0],", ").concat(p,"}}"):1===d.length?s="".concat(s,"{{").concat(d[0],"}}"):R("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",n)}else R("Trans: the passed in value is invalid - seems you passed in a variable like {number} - please pass in variables for interpolation as full objects like {{number}}.",n)})),s}("",a,0,I)||I.transEmptyNodeValue,L=I.hashTransKey,K=u||(L?L(A):A),U=c({},l,{count:i},f,{},f?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:A,ns:C}),F=K?k(K,U):A;return P?t.createElement(P,y,V(d||a,F,x,I,U)):V(d||a,F,x,I,U)},e.Translation=function(e){var n=e.ns,t=e.children,r=u(K(n,s(e,["ns","children"])),3),a=r[0],i=r[1],o=r[2];return t(a,{i18n:i,lng:i.language},o)},e.composeInitialProps=I,e.getDefaults=S,e.getI18n=N,e.getInitialProps=P,e.initReactI18next=k,e.setDefaults=j,e.setI18n=x,e.useSSR=U,e.useTranslation=K,e.withSSR=function(){return function(e){function n(n){var r=n.initialI18nStore,a=n.initialLanguage,i=s(n,["initialI18nStore","initialLanguage"]);return U(r,a),t.createElement(e,c({},i))}return n.getInitialProps=I(e),n.displayName="withI18nextSSR(".concat(L(e),")"),n.WrappedComponent=e,n}},e.withTranslation=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){function a(a){var i=a.forwardedRef,o=s(a,["forwardedRef"]),l=u(K(e,o),3),f=c({},o,{t:l[0],i18n:l[1],tReady:l[2]});return n.withRef&&i?f.ref=i:!n.withRef&&i&&(f.forwardedRef=i),t.createElement(r,f)}a.displayName="withI18nextTranslation(".concat(L(r),")"),a.WrappedComponent=r;return n.withRef?t.forwardRef((function(e,n){return t.createElement(a,Object.assign({},e,{forwardedRef:n}))})):a}},Object.defineProperty(e,"__esModule",{value:!0})}));