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