react-i18next 7.9.0 → 7.11.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.
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react","prop-types"],t):t(e.reactI18next={},e.React,e.PropTypes)}(this,function(e,t,n){"use strict";function i(e,t){return e===t?0!==e||0!==t||1/e==1/t:e!=e&&t!=t}function r(e,t){if(i(e,t))return!0;if("object"!==(void 0===e?"undefined":C(e))||null===e||"object"!==(void 0===t?"undefined":C(t))||null===t)return!1;var n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(var o=0;o<n.length;o++)if(!D.call(t,n[o])||!i(e[n[o]],t[n[o]]))return!1;return!0}function o(e){K=R({},K,e)}function a(){return K}function s(e){M=e}function p(){return M}function u(e){return e.displayName||e.name||"Component"}function c(e){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(o){var s=function(t){function n(t,r){N(this,n);var o=W(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,t,r));o.i18n=t.i18n||i.i18n||r.i18n||p(),o.namespaces="function"==typeof e?e(t):e||r.defaultNS||o.i18n.options&&o.i18n.options.defaultNS,"string"==typeof o.namespaces&&(o.namespaces=[o.namespaces]);var s=o.i18n&&o.i18n.options&&o.i18n.options.react||{};return o.options=R({},a(),s,i),o.getWrappedInstance=o.getWrappedInstance.bind(o),o}return A(n,t),E(n,[{key:"shouldComponentUpdate",value:function(e){return!this.options.usePureComponent||!r(this.props,e)}},{key:"getWrappedInstance",value:function(){return this.options.withRef||console.error("To access the wrapped instance, you need to specify { withRef: true } as the second argument of the translate() call."),this.wrappedInstance}},{key:"render",value:function(){var e=this,t={};return this.options.withRef&&(t.ref=function(t){e.wrappedInstance=t}),S.createElement(B,R({ns:this.namespaces},this.options,this.props,{i18n:this.i18n}),function(n,i){var r=i.ready,a=L(i,["ready"]);return S.createElement(o,R({tReady:r},e.props,t,a))})}}]),n}(t.Component);return s.WrappedComponent=o,s.contextTypes={i18n:n.object,defaultNS:n.string},s.displayName="Translate("+u(o)+")",s.namespaces=e,_(s,o)}}function l(e,t,n,i,r){var o=t.indexOf("<",i),a=t.slice(i,-1===o?void 0:o);/^\s*$/.test(a)&&(a=" "),(!r&&o>-1&&n+e.length>=0||" "!==a)&&e.push({type:"text",content:a})}function f(e){var t=[];for(var n in e)t.push(n+'="'+e[n]+'"');return t.length?" "+t.join(" "):""}function d(e,t){switch(t.type){case"text":return e+t.content;case"tag":return e+="<"+t.name+(t.attrs?f(t.attrs):"")+(t.voidElement?"/>":">"),t.voidElement?e:e+t.children.reduce(d,"")+"</"+t.name+">"}}function h(e){return e&&(e.children||e.props&&e.props.children)}function y(e){return e&&e.children?e.children:e.props&&e.props.children}function v(e,t,n){return t?("[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),t.forEach(function(t,n){var i=""+n;if("string"==typeof t)e=""+e+t;else if(h(t))e=e+"<"+i+">"+v("",y(t),n+1)+"</"+i+">";else if(S.isValidElement(t))e=e+"<"+i+"></"+i+">";else if("object"===(void 0===t?"undefined":C(t))){var r=R({},t),o=r.format;delete r.format;var a=Object.keys(r);o&&1===a.length?e=e+"<"+i+">{{"+a[0]+", "+o+"}}</"+i+">":1===a.length?e=e+"<"+i+">{{"+a[0]+"}}</"+i+">":console&&console.warn&&console.warn("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",t)}else console&&console.warn&&console.warn("react-i18next: 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)}),e):""}function m(e,t,n){function i(e,t){return"[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),t.reduce(function(t,r,o){if("tag"===r.type){var a=e[parseInt(r.name,10)]||{},s=S.isValidElement(a);if("string"==typeof a)t.push(a);else if(h(a)){var p=i(y(a),r.children);a.dummy&&(a.children=p),t.push(S.cloneElement(a,R({},a.props,{key:o}),p))}else if("object"!==(void 0===a?"undefined":C(a))||s)t.push(a);else{var u=n.services.interpolator.interpolate(r.children[0].content,a,n.language);t.push(u)}}else"text"===r.type&&t.push(r.content);return t},[])}return""===t?[]:e?y(i([{dummy:!0,children:e}],Q.parse("<0>"+t+"</0>"))[0]):[t]}function g(e,t){for(var n=0,i=e.length;n<i;n++)if("object"===C(e[n])){var r=!0,o=!1,a=void 0;try{for(var s,p=Z(e[n])[Symbol.iterator]();!(r=(s=p.next()).done);r=!0){var u=q(s.value,2),c=u[0];t(u[1],n,c)}}catch(e){o=!0,a=e}finally{try{!r&&p.return&&p.return()}finally{if(o)throw a}}}else t(e[n],n)}function b(e){var t=[];return g(e,function(e){e&&e.namespaces&&e.namespaces.forEach(function(e){-1===t.indexOf(e)&&t.push(e)})}),t}var S="default"in t?t.default:t;n=n&&n.hasOwnProperty("default")?n.default:n;var O={childContextTypes:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,mixins:!0,propTypes:!0,type:!0},j={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},w=Object.defineProperty,x=Object.getOwnPropertyNames,I=Object.getOwnPropertySymbols,k=Object.getOwnPropertyDescriptor,P=Object.getPrototypeOf,T=P&&P(Object),_=function e(t,n,i){if("string"!=typeof n){if(T){var r=P(n);r&&r!==T&&e(t,r,i)}var o=x(n);I&&(o=o.concat(I(n)));for(var a=0;a<o.length;++a){var s=o[a];if(!(O[s]||j[s]||i&&i[s])){var p=k(n,s);try{w(t,s,p)}catch(e){}}}return t}return t},C="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},N=(function(){function e(e){this.value=e}function t(t){function n(r,o){try{var a=t[r](o),s=a.value;s instanceof e?Promise.resolve(s.value).then(function(e){n("next",e)},function(e){n("throw",e)}):i(a.done?"return":"normal",a.value)}catch(e){i("throw",e)}}function i(e,t){switch(e){case"return":r.resolve({value:t,done:!0});break;case"throw":r.reject(t);break;default:r.resolve({value:t,done:!1})}(r=r.next)?n(r.key,r.arg):o=null}var r,o;this._invoke=function(e,t){return new Promise(function(i,a){var s={key:e,arg:t,resolve:i,reject:a,next:null};o?o=o.next=s:(r=o=s,n(e,t))})},"function"!=typeof t.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(t.prototype[Symbol.asyncIterator]=function(){return this}),t.prototype.next=function(e){return this._invoke("next",e)},t.prototype.throw=function(e){return this._invoke("throw",e)},t.prototype.return=function(e){return this._invoke("return",e)}}(),function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}),E=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),R=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},A=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},L=function(e,t){var n={};for(var i in e)t.indexOf(i)>=0||Object.prototype.hasOwnProperty.call(e,i)&&(n[i]=e[i]);return n},W=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},q=function(){function e(e,t){var n=[],i=!0,r=!1,o=void 0;try{for(var a,s=e[Symbol.iterator]();!(i=(a=s.next()).done)&&(n.push(a.value),!t||n.length!==t);i=!0);}catch(e){r=!0,o=e}finally{try{!i&&s.return&&s.return()}finally{if(r)throw o}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),D=Object.prototype.hasOwnProperty,K={wait:!1,withRef:!1,bindI18n:"languageChanged loaded",bindStore:"added removed",translateFuncName:"t",nsMode:"default",usePureComponent:!1,omitBoundRerender:!0},M=void 0,$={type:"3rdParty",init:function(e){o(e.options.react),s(e)}},z=!1,B=function(e){function t(e,n){N(this,t);var i=W(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n));i.i18n=e.i18n||n.i18n||p(),i.namespaces=e.ns||i.i18n.options&&i.i18n.options.defaultNS,"string"==typeof i.namespaces&&(i.namespaces=[i.namespaces]);var r=i.i18n&&i.i18n.options&&i.i18n.options.react||{};i.options=R({},a(),r,e),e.initialI18nStore&&(i.i18n.services.resourceStore.data=e.initialI18nStore,i.options.wait=!1),e.initialLanguage&&i.i18n.changeLanguage(e.initialLanguage),i.i18n.options&&i.i18n.options.isInitialSSR&&(i.options.wait=!1);var o=i.i18n.languages&&i.i18n.languages[0],s=!!o&&i.namespaces.every(function(e){return i.i18n.hasResourceBundle(o,e)});return i.state={i18nLoadedAt:null,ready:s},i.t=i.getI18nTranslate(),i.onI18nChanged=i.onI18nChanged.bind(i),i.getI18nTranslate=i.getI18nTranslate.bind(i),i}return A(t,e),E(t,[{key:"getChildContext",value:function(){return{t:this.t,i18n:this.i18n}}},{key:"componentDidMount",value:function(){var e=this,t=function(){e.options.bindI18n&&e.i18n&&e.i18n.on(e.options.bindI18n,e.onI18nChanged),e.options.bindStore&&e.i18n.store&&e.i18n.store.on(e.options.bindStore,e.onI18nChanged)};this.mounted=!0,this.i18n.loadNamespaces(this.namespaces,function(){var n=function(){e.mounted&&!e.state.ready&&e.setState({ready:!0}),e.options.wait&&e.mounted&&t()};if(e.i18n.isInitialized)n();else{e.i18n.on("initialized",function t(){setTimeout(function(){e.i18n.off("initialized",t)},1e3),n()})}}),this.options.wait||t()}},{key:"componentWillUnmount",value:function(){var e=this;this.mounted=!1,this.onI18nChanged&&(this.options.bindI18n&&this.options.bindI18n.split(" ").forEach(function(t){return e.i18n.off(t,e.onI18nChanged)}),this.options.bindStore&&this.options.bindStore.split(" ").forEach(function(t){return e.i18n.store&&e.i18n.store.off(t,e.onI18nChanged)}))}},{key:"onI18nChanged",value:function(){this.mounted&&(!this.state.ready&&this.options.omitBoundRerender||(this.t=this.getI18nTranslate(),this.setState({i18nLoadedAt:new Date})))}},{key:"getI18nTranslate",value:function(){return this.i18n.getFixedT(null,"fallback"===this.options.nsMode?this.namespaces:this.namespaces[0])}},{key:"render",value:function(){var e=this,t=this.props.children,n=this.state.ready;return!n&&this.options.wait?null:(this.i18n.options&&this.i18n.options.isInitialSSR&&!z&&(z=!0,setTimeout(function(){delete e.i18n.options.isInitialSSR},100)),t(this.t,{i18n:this.i18n,t:this.t,ready:n}))}}]),t}(t.Component);B.contextTypes={i18n:n.object},B.childContextTypes={t:n.func.isRequired,i18n:n.object},c.setDefaults=o,c.setI18n=s;var H=function(e){function t(e,n){N(this,t);var i=W(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n));return i.i18n=e.i18n||n.i18n,i.t=e.t||n.t,i}return A(t,e),E(t,[{key:"render",value:function(){var e=this,t=this.props.parent||"span",n=this.props.regexp||this.i18n.services.interpolator.regexp,i=this.props,r=i.className,o=i.style,a=this.props.useDangerouslySetInnerHTML||!1,s=this.props.dangerouslySetInnerHTMLPartElement||"span",p=R({},this.props.options,{interpolation:{prefix:"#$?",suffix:"?$#"}}),u=this.t(this.props.i18nKey,p);if(!u||"string"!=typeof u)return S.createElement("noscript",null);var c=[],l=function(t,n){if(t.indexOf(e.i18n.options.interpolation.formatSeparator)<0)return void 0===n[t]&&e.i18n.services.logger.warn("interpolator: missed to pass in variable "+t+" for interpolating "+u),n[t];var i=t.split(e.i18n.options.interpolation.formatSeparator),r=i.shift().trim(),o=i.join(e.i18n.options.interpolation.formatSeparator).trim();return void 0===n[r]&&e.i18n.services.logger.warn("interpolator: missed to pass in variable "+r+" for interpolating "+u),e.i18n.options.interpolation.format(n[r],o,e.i18n.language)};u.split(n).reduce(function(t,n,i){var r=void 0;if(i%2==0){if(0===n.length)return t;r=a?S.createElement(s,{dangerouslySetInnerHTML:{__html:n}}):n}else r=l(n,e.props);return t.push(r),t},c);var f={};if(this.i18n.options.react&&this.i18n.options.react.exposeNamespace){var d="string"==typeof this.t.ns?this.t.ns:this.t.ns[0];this.props.i18nKey&&this.i18n.options.nsSeparator&&this.props.i18nKey.indexOf(this.i18n.options.nsSeparator)>-1&&(d=this.props.i18nKey.split(this.i18n.options.nsSeparator)[0]),this.t.ns&&(f["data-i18next-options"]=JSON.stringify({ns:d}))}return r&&(f.className=r),o&&(f.style=o),S.createElement.apply(this,[t,f].concat(c))}}]),t}(t.Component);H.propTypes={className:n.string},H.defaultProps={className:""},H.contextTypes={i18n:n.object.isRequired,t:n.func.isRequired};var V={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,J=function(e){var t,n=0,i=!0,r={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return e.replace(F,function(o){if("="===o)return i=!0,void n++;i?0===n?((V[o]||"/"===e.charAt(e.length-2))&&(r.voidElement=!0),r.name=o):(r.attrs[t]=o.replace(/^['"]|['"]$/g,""),t=void 0):(t&&(r.attrs[t]=t),t=o),n++,i=!1}),r},U=/(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,G=Object.create?Object.create(null):{},Q={parse:function(e,t){t||(t={}),t.components||(t.components=G);var n,i=[],r=-1,o=[],a=!1;return e.replace(U,function(s,p){if(a){if(s!=="</"+n.name+">")return;a=!1}var u,c="/"!==s.charAt(1),f=0===s.indexOf("\x3c!--"),d=p+s.length,h=e.charAt(d);c&&!f&&(r++,"tag"===(n=J(s)).type&&t.components[n.name]&&(n.type="component",a=!0),n.voidElement||a||!h||"<"===h||l(n.children,e,r,d,t.ignoreWhitespace),0===r&&i.push(n),(u=o[r-1])&&u.children.push(n),o[r]=n),(f||!c||n.voidElement)&&(f||r--,!a&&"<"!==h&&h&&l(u=-1===r?i:o[r].children,e,r,d,t.ignoreWhitespace))}),!i.length&&e.length&&l(i,e,0,0,t.ignoreWhitespace),i},stringify:function(e){return e.reduce(function(e,t){return e+d("",t)},"")}},X=function(e){function t(){return N(this,t),W(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return A(t,e),E(t,[{key:"render",value:function(){var e=R({i18n:this.context.i18n,t:this.context.t},this.props),t=e.children,n=e.count,i=e.parent,r=e.i18nKey,o=e.tOptions,a=e.values,s=e.defaults,p=e.components,u=e.ns,c=e.i18n,l=e.t,f=L(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]),d=l||c.t.bind(c),h=c.options&&c.options.react||{},y=void 0!==i?i:h.defaultTransParent,g=s||v("",t,0),b=h.hashTransKey,O=r||(b?b(g):g),j=O?d(O,R({},o,a,a?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:g,count:n,ns:u})):g;if(h.exposeNamespace){var w="string"==typeof d.ns?d.ns:d.ns[0];r&&c.options&&c.options.nsSeparator&&r.indexOf(c.options.nsSeparator)>-1&&(w=r.split(c.options.nsSeparator)[0]),d.ns&&(f["data-i18next-options"]=JSON.stringify({ns:w}))}return y?S.createElement(y,f,m(p||t,j,c)):m(p||t,j,c)}}]),t}(S.Component);X.propTypes={count:n.number,parent:n.oneOfType([n.node,n.func]),i18nKey:n.string,i18n:n.object,t:n.func},X.contextTypes={i18n:n.object,t:n.func};var Y=function(e){function n(e,t){N(this,n);var i=W(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e,t));return i.i18n=e.i18n,i.defaultNS=e.defaultNS,e.initialI18nStore&&(i.i18n.services.resourceStore.data=e.initialI18nStore,i.i18n.options.isInitialSSR=!0),e.initialLanguage&&i.i18n.changeLanguage(e.initialLanguage),i}return A(n,e),E(n,[{key:"getChildContext",value:function(){return{i18n:this.i18n,defaultNS:this.defaultNS}}},{key:"componentWillReceiveProps",value:function(e){if(this.props.i18n!==e.i18n)throw new Error("[react-i18next][I18nextProvider]does not support changing the i18n object.")}},{key:"render",value:function(){var e=this.props.children;return t.Children.only(e)}}]),n}(t.Component);Y.propTypes={i18n:n.object.isRequired,children:n.element.isRequired,defaultNS:n.string},Y.childContextTypes={i18n:n.object.isRequired,defaultNS:n.string},Y.defaultProps={defaultNS:void 0};var Z=Object.entries||function(e){for(var t=Object.keys(e),n=t.length,i=new Array(n);n--;)i[n]=[t[n],e[t[n]]];return i};e.translate=c,e.I18n=B,e.Interpolate=H,e.Trans=X,e.I18nextProvider=Y,e.loadNamespaces=function(e){var t=e.components,n=e.i18n,i=b(t);return new Promise(function(e){n.loadNamespaces(i,e)})},e.reactI18nextModule=$,e.setDefaults=o,e.getDefaults=a,e.setI18n=s,e.getI18n=p,Object.defineProperty(e,"__esModule",{value:!0})});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react","prop-types"],t):t(e.reactI18next={},e.React,e.PropTypes)}(this,function(e,n,r){"use strict";var O="default"in n?n.default:n;r=r&&r.hasOwnProperty("default")?r.default:r;var c={childContextTypes:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},u={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},l=Object.defineProperty,f=Object.getOwnPropertyNames,d=Object.getOwnPropertySymbols,h=Object.getOwnPropertyDescriptor,y=Object.getPrototypeOf,v=y&&y(Object);var i=function e(t,n,r){if("string"!=typeof n){if(v){var i=y(n);i&&i!==v&&e(t,i,r)}var o=f(n);d&&(o=o.concat(d(n)));for(var a=0;a<o.length;++a){var s=o[a];if(!(c[s]||u[s]||r&&r[s])){var p=h(n,s);try{l(t,s,p)}catch(e){}}}return t}return t},j="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},p=(function(){function c(e){this.value=e}function e(i){var o,a;function s(e,t){try{var n=i[e](t),r=n.value;r instanceof c?Promise.resolve(r.value).then(function(e){s("next",e)},function(e){s("throw",e)}):p(n.done?"return":"normal",n.value)}catch(e){p("throw",e)}}function p(e,t){switch(e){case"return":o.resolve({value:t,done:!0});break;case"throw":o.reject(t);break;default:o.resolve({value:t,done:!1})}(o=o.next)?s(o.key,o.arg):a=null}this._invoke=function(r,i){return new Promise(function(e,t){var n={key:r,arg:i,resolve:e,reject:t,next:null};a?a=a.next=n:(o=a=n,s(r,i))})},"function"!=typeof i.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(e){return this._invoke("next",e)},e.prototype.throw=function(e){return this._invoke("throw",e)},e.prototype.return=function(e){return this._invoke("return",e)}}(),function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}),m=function(){function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}}(),w=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},g=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},x=function(e,t){var n={};for(var r in e)0<=t.indexOf(r)||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},b=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},S=function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var n=[],r=!0,i=!1,o=void 0;try{for(var a,s=e[Symbol.iterator]();!(r=(a=s.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){i=!0,o=e}finally{try{!r&&s.return&&s.return()}finally{if(i)throw o}}return n}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")},I=Object.prototype.hasOwnProperty;function N(e,t){return e===t?0!==e||0!==t||1/e==1/t:e!=e&&t!=t}var t={wait:!1,withRef:!1,bindI18n:"languageChanged loaded",bindStore:"added removed",translateFuncName:"t",nsMode:"default",usePureComponent:!1,omitBoundRerender:!0},o=void 0;function a(e){t=w({},t,e)}function k(){return t}function s(e){o=e}function P(){return o}var T={type:"3rdParty",init:function(e){a(e.options.react),s(e)}},_=!1,C=function(e){function a(e,t){p(this,a);var n=b(this,(a.__proto__||Object.getPrototypeOf(a)).call(this,e,t));n.i18n=e.i18n||t.i18n||P(),n.namespaces=e.ns||n.i18n.options&&n.i18n.options.defaultNS,"string"==typeof n.namespaces&&(n.namespaces=[n.namespaces]);var r=n.i18n&&n.i18n.options&&n.i18n.options.react||{};n.options=w({},k(),r,e),e.initialI18nStore&&(n.i18n.services.resourceStore.data=e.initialI18nStore,n.options.wait=!1),e.initialLanguage&&n.i18n.changeLanguage(e.initialLanguage),n.i18n.options&&n.i18n.options.isInitialSSR&&(n.options.wait=!1);var i=n.i18n.languages&&n.i18n.languages[0],o=!!i&&n.namespaces.every(function(e){return n.i18n.hasResourceBundle(i,e)});return n.state={i18nLoadedAt:null,ready:o},n.t=n.getI18nTranslate(),n.onI18nChanged=n.onI18nChanged.bind(n),n.getI18nTranslate=n.getI18nTranslate.bind(n),n}return g(a,e),m(a,[{key:"getChildContext",value:function(){return{t:this.t,i18n:this.i18n}}},{key:"componentDidMount",value:function(){var n=this,e=function(){n.options.bindI18n&&n.i18n&&n.i18n.on(n.options.bindI18n,n.onI18nChanged),n.options.bindStore&&n.i18n.store&&n.i18n.store.on(n.options.bindStore,n.onI18nChanged)};this.mounted=!0,this.i18n.loadNamespaces(this.namespaces,function(){var t=function(){n.mounted&&!n.state.ready&&n.setState({ready:!0}),n.options.wait&&n.mounted&&e()};if(n.i18n.isInitialized)t();else{n.i18n.on("initialized",function e(){setTimeout(function(){n.i18n.off("initialized",e)},1e3),t()})}}),this.options.wait||e()}},{key:"componentWillUnmount",value:function(){var t=this;if(this.mounted=!1,this.onI18nChanged){if(this.options.bindI18n)this.options.bindI18n.split(" ").forEach(function(e){return t.i18n.off(e,t.onI18nChanged)});if(this.options.bindStore)this.options.bindStore.split(" ").forEach(function(e){return t.i18n.store&&t.i18n.store.off(e,t.onI18nChanged)})}}},{key:"onI18nChanged",value:function(){this.mounted&&(!this.state.ready&&this.options.omitBoundRerender||(this.t=this.getI18nTranslate(),this.setState({i18nLoadedAt:new Date})))}},{key:"getI18nTranslate",value:function(){return this.i18n.getFixedT(null,"fallback"===this.options.nsMode?this.namespaces:this.namespaces[0])}},{key:"render",value:function(){var e=this,t=this.props.children,n=this.state.ready;return!n&&this.options.wait?null:(this.i18n.options&&this.i18n.options.isInitialSSR&&!_&&(_=!0,setTimeout(function(){delete e.i18n.options.isInitialSSR},100)),t(this.t,{i18n:this.i18n,t:this.t,ready:n}))}}]),a}(n.Component);function E(o){var s=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return function(a){var e,t=function(e){function i(e,t){p(this,i);var n=b(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e,t));n.i18n=e.i18n||s.i18n||t.i18n||P(),n.namespaces="function"==typeof o?o(e):o||t.defaultNS||n.i18n.options&&n.i18n.options.defaultNS,"string"==typeof n.namespaces&&(n.namespaces=[n.namespaces]);var r=n.i18n&&n.i18n.options&&n.i18n.options.react||{};(n.options=w({},k(),r,s),t.reportNS)&&(Array.isArray(o)?o:[o]).forEach(t.reportNS);return n.getWrappedInstance=n.getWrappedInstance.bind(n),n}return g(i,e),m(i,[{key:"shouldComponentUpdate",value:function(e){return!this.options.usePureComponent||!function(e,t){if(N(e,t))return!0;if("object"!==(void 0===e?"undefined":j(e))||null===e||"object"!==(void 0===t?"undefined":j(t))||null===t)return!1;var n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(var i=0;i<n.length;i++)if(!I.call(t,n[i])||!N(e[n[i]],t[n[i]]))return!1;return!0}(this.props,e)}},{key:"getWrappedInstance",value:function(){return this.options.withRef||console.error("To access the wrapped instance, you need to specify { withRef: true } as the second argument of the translate() call."),this.wrappedInstance}},{key:"render",value:function(){var i=this,o={};return this.options.withRef&&(o.ref=function(e){i.wrappedInstance=e}),O.createElement(C,w({ns:this.namespaces},this.options,this.props,{i18n:this.i18n}),function(e,t){var n=t.ready,r=x(t,["ready"]);return O.createElement(a,w({tReady:n},i.props,o,r))})}}]),i}(n.Component);return t.WrappedComponent=a,t.contextTypes={i18n:r.object,defaultNS:r.string,reportNS:r.func},t.displayName="Translate("+((e=a).displayName||e.name||"Component")+")",t.namespaces=o,i(t,a)}}C.contextTypes={i18n:r.object},C.childContextTypes={t:r.func.isRequired,i18n:r.object},E.setDefaults=a,E.setI18n=s;var R=function(e){function r(e,t){p(this,r);var n=b(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,e,t));return n.i18n=e.i18n||t.i18n,n.t=e.t||t.t,n}return g(r,e),m(r,[{key:"render",value:function(){var o=this,e=this.props.parent||"span",t=this.props.regexp||this.i18n.services.interpolator.regexp,n=this.props,r=n.className,i=n.style,a=this.props.useDangerouslySetInnerHTML||!1,s=this.props.dangerouslySetInnerHTMLPartElement||"span",p=w({},this.props.options,{interpolation:{prefix:"#$?",suffix:"?$#"}}),c=this.t(this.props.i18nKey,p);if(!c||"string"!=typeof c)return O.createElement("noscript",null);var u=[];c.split(t).reduce(function(e,t,n){var r=void 0;if(n%2==0){if(0===t.length)return e;r=a?O.createElement(s,{dangerouslySetInnerHTML:{__html:t}}):t}else r=function(e,t){if(e.indexOf(o.i18n.options.interpolation.formatSeparator)<0)return void 0===t[e]&&o.i18n.services.logger.warn("interpolator: missed to pass in variable "+e+" for interpolating "+c),t[e];var n=e.split(o.i18n.options.interpolation.formatSeparator),r=n.shift().trim(),i=n.join(o.i18n.options.interpolation.formatSeparator).trim();return void 0===t[r]&&o.i18n.services.logger.warn("interpolator: missed to pass in variable "+r+" for interpolating "+c),o.i18n.options.interpolation.format(t[r],i,o.i18n.language)}(t,o.props);return e.push(r),e},u);var l={};if(this.i18n.options.react&&this.i18n.options.react.exposeNamespace){var f="string"==typeof this.t.ns?this.t.ns:this.t.ns[0];if(this.props.i18nKey&&this.i18n.options.nsSeparator&&-1<this.props.i18nKey.indexOf(this.i18n.options.nsSeparator))f=this.props.i18nKey.split(this.i18n.options.nsSeparator)[0];this.t.ns&&(l["data-i18next-options"]=JSON.stringify({ns:f}))}return r&&(l.className=r),i&&(l.style=i),O.createElement.apply(this,[e,l].concat(u))}}]),r}(n.Component);R.propTypes={className:r.string},R.defaultProps={className:""},R.contextTypes={i18n:r.object.isRequired,t:r.func.isRequired};var A={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},L=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,D=/(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,W=Object.create?Object.create(null):{};function q(e,t,n,r,i){var o=t.indexOf("<",r),a=t.slice(r,-1===o?void 0:o);/^\s*$/.test(a)&&(a=" "),(!i&&-1<o&&0<=n+e.length||" "!==a)&&e.push({type:"text",content:a})}var K=function(f,d){d||(d={}),d.components||(d.components=W);var h,y=[],v=-1,m=[],g=!1;return f.replace(D,function(e,t){if(g){if(e!=="</"+h.name+">")return;g=!1}var n,r,i,o,a,s,p="/"!==e.charAt(1),c=0===e.indexOf("\x3c!--"),u=t+e.length,l=f.charAt(u);p&&!c&&(v++,s={type:"tag",name:"",voidElement:!(a=!(o=0)),attrs:{},children:[]},(r=e).replace(L,function(e){if("="===e)return a=!0,void o++;a?0===o?((A[e]||"/"===r.charAt(r.length-2))&&(s.voidElement=!0),s.name=e):(s.attrs[i]=e.replace(/^['"]|['"]$/g,""),i=void 0):(i&&(s.attrs[i]=i),i=e),o++,a=!1}),"tag"===(h=s).type&&d.components[h.name]&&(h.type="component",g=!0),h.voidElement||g||!l||"<"===l||q(h.children,f,v,u,d.ignoreWhitespace),0===v&&y.push(h),(n=m[v-1])&&n.children.push(h),m[v]=h),(c||!p||h.voidElement)&&(c||v--,!g&&"<"!==l&&l&&q(n=-1===v?y:m[v].children,f,v,u,d.ignoreWhitespace))}),!y.length&&f.length&&q(y,f,0,0,d.ignoreWhitespace),y};function M(e){return e&&(e.children||e.props&&e.props.children)}function $(e){return e&&e.children?e.children:e.props&&e.props.children}function z(e,t,c){if(""===t)return[];if(!e)return[t];return $(function s(p,e){return"[object Array]"!==Object.prototype.toString.call(p)&&(p=[p]),"[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),e.reduce(function(e,t,n){if("tag"===t.type){var r=p[parseInt(t.name,10)]||{},i=O.isValidElement(r);if("string"==typeof r)e.push(r);else if(M(r)){var o=s($(r),t.children);r.dummy&&(r.children=o),e.push(O.cloneElement(r,w({},r.props,{key:n}),o))}else if("object"!==(void 0===r?"undefined":j(r))||i)e.push(r);else if(t.children[0]&&t.children[0].content){var a=c.services.interpolator.interpolate(t.children[0].content,r,c.language);e.push(a)}}else"text"===t.type&&e.push(t.content);return e},[])}([{dummy:!0,children:e}],K("<0>"+t+"</0>"))[0])}var B=function(e){function t(){return p(this,t),b(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return g(t,e),m(t,[{key:"render",value:function(){var e=w({i18n:this.context.i18n,t:this.context.t},this.props),t=e.children,n=e.count,r=e.parent,i=e.i18nKey,o=e.tOptions,a=e.values,s=e.defaults,p=e.components,c=e.ns,u=e.i18n,l=e.t,f=x(e,["children","count","parent","i18nKey","tOptions","values","defaults","components","ns","i18n","t"]),d=l||u.t.bind(u),h=u.options&&u.options.react||{},y=void 0!==r?r:h.defaultTransParent,v=s||function a(s,e,t){return e?("[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),e.forEach(function(e,t){var n=""+t;if("string"==typeof e)s=""+s+e;else if(M(e))s=s+"<"+n+">"+a("",$(e),t+1)+"</"+n+">";else if(O.isValidElement(e))s=s+"<"+n+"></"+n+">";else if("object"===(void 0===e?"undefined":j(e))){var r=w({},e),i=r.format;delete r.format;var o=Object.keys(r);i&&1===o.length?s=s+"<"+n+">{{"+o[0]+", "+i+"}}</"+n+">":1===o.length?s=s+"<"+n+">{{"+o[0]+"}}</"+n+">":console&&console.warn&&console.warn("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.",e)}else console&&console.warn&&console.warn("react-i18next: 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}}.",e)}),s):""}("",t),m=h.hashTransKey,g=i||(m?m(v):v),b=g?d(g,w({},o,a,a?{}:{interpolation:{prefix:"#$?",suffix:"?$#"}},{defaultValue:v,count:n,ns:c})):v;if(h.exposeNamespace){var S="string"==typeof d.ns?d.ns:d.ns[0];if(i&&u.options&&u.options.nsSeparator&&-1<i.indexOf(u.options.nsSeparator))S=i.split(u.options.nsSeparator)[0];d.ns&&(f["data-i18next-options"]=JSON.stringify({ns:S}))}return y?O.createElement(y,f,z(p||t,b,u)):z(p||t,b,u)}}]),t}(O.Component);B.propTypes={count:r.number,parent:r.oneOfType([r.node,r.func]),i18nKey:r.string,i18n:r.object,t:r.func},B.contextTypes={i18n:r.object,t:r.func};var F=function(e){function r(e,t){p(this,r);var n=b(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,e,t));return n.i18n=e.i18n,n.defaultNS=e.defaultNS,e.initialI18nStore&&(n.i18n.services.resourceStore.data=e.initialI18nStore,n.i18n.options.isInitialSSR=!0),e.initialLanguage&&n.i18n.changeLanguage(e.initialLanguage),n.reportNS=e.reportNS,n}return g(r,e),m(r,[{key:"getChildContext",value:function(){return{i18n:this.i18n,defaultNS:this.defaultNS,reportNS:this.reportNS}}},{key:"componentWillReceiveProps",value:function(e){if(this.props.i18n!==e.i18n)throw new Error("[react-i18next][I18nextProvider]does not support changing the i18n object.")}},{key:"render",value:function(){var e=this.props.children;return n.Children.only(e)}}]),r}(n.Component);F.propTypes={i18n:r.object.isRequired,children:r.element.isRequired,defaultNS:r.string,reportNS:r.func},F.childContextTypes={i18n:r.object.isRequired,defaultNS:r.string,reportNS:r.func},F.defaultProps={defaultNS:void 0,reportNS:void 0};var H=Object.entries||function(e){for(var t=Object.keys(e),n=t.length,r=new Array(n);n--;)r[n]=[t[n],e[t[n]]];return r};function V(e){var t=[];return function(e,t){for(var n=0,r=e.length;n<r;n++)if("object"===j(e[n])){var i=!0,o=!1,a=void 0;try{for(var s,p=H(e[n])[Symbol.iterator]();!(i=(s=p.next()).done);i=!0){var c=S(s.value,2),u=c[0];t(c[1],n,u)}}catch(e){o=!0,a=e}finally{try{!i&&p.return&&p.return()}finally{if(o)throw a}}}else t(e[n],n)}(e,function(e){e&&e.namespaces&&e.namespaces.forEach(function(e){-1===t.indexOf(e)&&t.push(e)})}),t}e.translate=E,e.I18n=C,e.Interpolate=R,e.Trans=B,e.I18nextProvider=F,e.loadNamespaces=function(e){var t=e.components,n=e.i18n,r=V(t);return new Promise(function(e){n.loadNamespaces(r,e)})},e.reactI18nextModule=T,e.setDefaults=a,e.getDefaults=k,e.setI18n=s,e.getI18n=P,Object.defineProperty(e,"__esModule",{value:!0})});
package/icu.macro.js ADDED
@@ -0,0 +1,331 @@
1
+ const { createMacro } = require('babel-plugin-macros');
2
+
3
+ // copy to:
4
+ // https://astexplorer.net/#/gist/642aebbb9e449e959f4ad8907b4adf3a/4a65742e2a3e926eb55eaa3d657d1472b9ac7970
5
+ module.exports = createMacro(ICUMacro);
6
+
7
+ function ICUMacro({ references, state, babel }) {
8
+ const t = babel.types;
9
+ const { Trans = [], Plural = [], Select = [] } = references;
10
+
11
+ // assert we have the react-i18next Trans component imported
12
+ addNeededImports(state, babel);
13
+
14
+ // transform Plural
15
+ Plural.forEach(referencePath => {
16
+ if (referencePath.parentPath.type === 'JSXOpeningElement') {
17
+ pluralAsJSX(
18
+ referencePath.parentPath,
19
+ {
20
+ attributes: referencePath.parentPath.get('attributes'),
21
+ children: referencePath.parentPath.parentPath.get('children'),
22
+ },
23
+ babel
24
+ );
25
+ } else {
26
+ // throw a helpful error message or something :)
27
+ }
28
+ });
29
+
30
+ // transform Select
31
+ Select.forEach(referencePath => {
32
+ if (referencePath.parentPath.type === 'JSXOpeningElement') {
33
+ selectAsJSX(
34
+ referencePath.parentPath,
35
+ {
36
+ attributes: referencePath.parentPath.get('attributes'),
37
+ children: referencePath.parentPath.parentPath.get('children'),
38
+ },
39
+ babel
40
+ );
41
+ } else {
42
+ // throw a helpful error message or something :)
43
+ }
44
+ });
45
+
46
+ // transform Trans
47
+ Trans.forEach(referencePath => {
48
+ if (referencePath.parentPath.type === 'JSXOpeningElement') {
49
+ transAsJSX(
50
+ referencePath.parentPath,
51
+ {
52
+ attributes: referencePath.parentPath.get('attributes'),
53
+ children: referencePath.parentPath.parentPath.get('children'),
54
+ },
55
+ babel
56
+ );
57
+ } else {
58
+ // throw a helpful error message or something :)
59
+ }
60
+ });
61
+ }
62
+
63
+ function pluralAsJSX(parentPath, { attributes }, babel) {
64
+ const t = babel.types;
65
+ const toObjectProperty = (name, value) =>
66
+ t.objectProperty(t.identifier(name), t.identifier(name), false, !value);
67
+
68
+ let componentStartIndex = 0;
69
+
70
+ const extracted = attributes.reduce(
71
+ (mem, attr) => {
72
+ if (attr.node.name.name === 'i18nKey') {
73
+ // copy the i18nKey
74
+ mem.attributesToCopy.push(attr.node);
75
+ } else if (attr.node.name.name === 'count') {
76
+ // take the count for plural element
77
+ mem.values.push(toObjectProperty(attr.node.value.expression.name));
78
+ mem.defaults = `{${attr.node.value.expression.name}, plural, ${mem.defaults}`;
79
+ } else if (attr.node.value.type === 'StringLiteral') {
80
+ // take any string node as plural option
81
+ let pluralForm = attr.node.name.name;
82
+ if (pluralForm.indexOf('$') === 0) pluralForm = pluralForm.replace('$', '=');
83
+ mem.defaults = `${mem.defaults} ${pluralForm} {${attr.node.value.value}}`;
84
+ } else if (attr.node.value.type === 'JSXExpressionContainer') {
85
+ // convert any Trans component to plural option extracting any values and components
86
+ const children = attr.node.value.expression.children;
87
+ const thisTrans = processTrans(children, babel, componentStartIndex);
88
+
89
+ let pluralForm = attr.node.name.name;
90
+ if (pluralForm.indexOf('$') === 0) pluralForm = pluralForm.replace('$', '=');
91
+
92
+ mem.defaults = `${mem.defaults} ${pluralForm} {${thisTrans.defaults}}`;
93
+ mem.components = mem.components.concat(thisTrans.components);
94
+ mem.values = mem.values.concat(thisTrans.values);
95
+
96
+ componentStartIndex += thisTrans.components.length;
97
+ }
98
+ return mem;
99
+ },
100
+ { attributesToCopy: [], values: [], components: [], defaults: '' }
101
+ );
102
+
103
+ // replace the node with the new Trans
104
+ parentPath.replaceWith(buildTransElement(extracted, extracted.attributesToCopy, t, true));
105
+ }
106
+
107
+ function selectAsJSX(parentPath, { attributes }, babel) {
108
+ const t = babel.types;
109
+ const toObjectProperty = (name, value) =>
110
+ t.objectProperty(t.identifier(name), t.identifier(name), false, !value);
111
+
112
+ let componentStartIndex = 0;
113
+
114
+ const extracted = attributes.reduce(
115
+ (mem, attr) => {
116
+ if (attr.node.name.name === 'i18nKey') {
117
+ // copy the i18nKey
118
+ mem.attributesToCopy.push(attr.node);
119
+ } else if (attr.node.name.name === 'switch') {
120
+ // take the switch for plural element
121
+ mem.values.push(toObjectProperty(attr.node.value.expression.name));
122
+ mem.defaults = `{${attr.node.value.expression.name}, select, ${mem.defaults}`;
123
+ } else if (attr.node.value.type === 'StringLiteral') {
124
+ // take any string node as select option
125
+ mem.defaults = `${mem.defaults} ${attr.node.name.name} {${attr.node.value.value}}`;
126
+ } else if (attr.node.value.type === 'JSXExpressionContainer') {
127
+ // convert any Trans component to select option extracting any values and components
128
+ const children = attr.node.value.expression.children;
129
+ const thisTrans = processTrans(children, babel, componentStartIndex);
130
+
131
+ mem.defaults = `${mem.defaults} ${attr.node.name.name} {${thisTrans.defaults}}`;
132
+ mem.components = mem.components.concat(thisTrans.components);
133
+ mem.values = mem.values.concat(thisTrans.values);
134
+
135
+ componentStartIndex += thisTrans.components.length;
136
+ }
137
+ return mem;
138
+ },
139
+ { attributesToCopy: [], values: [], components: [], defaults: '' }
140
+ );
141
+
142
+ // replace the node with the new Trans
143
+ parentPath.replaceWith(buildTransElement(extracted, extracted.attributesToCopy, t, true));
144
+ }
145
+
146
+ function transAsJSX(parentPath, { attributes, children }, babel) {
147
+ const extracted = processTrans(children, babel);
148
+
149
+ // replace the node with the new Trans
150
+ children[0].parentPath.replaceWith(
151
+ buildTransElement(extracted, cloneExistingAttributes(attributes), babel.types, false, true)
152
+ );
153
+ }
154
+
155
+ function buildTransElement(
156
+ extracted,
157
+ finalAttributes,
158
+ t,
159
+ closeDefaults = false,
160
+ wasElementWithChildren = false
161
+ ) {
162
+ const nodeName = t.jSXIdentifier('Trans');
163
+
164
+ // plural, select open { but do not close it while reduce
165
+ if (closeDefaults) extracted.defaults += '}';
166
+
167
+ // convert arrays into needed expressions
168
+ extracted.components = t.arrayExpression(extracted.components);
169
+ extracted.values = t.objectExpression(extracted.values);
170
+
171
+ // add generated Trans attributes
172
+ if (!attributeExistsAlready('defaults', finalAttributes))
173
+ finalAttributes.push(
174
+ t.jSXAttribute(t.jSXIdentifier('defaults'), t.StringLiteral(extracted.defaults))
175
+ );
176
+ if (!attributeExistsAlready('components', finalAttributes))
177
+ finalAttributes.push(
178
+ t.jSXAttribute(t.jSXIdentifier('components'), t.jSXExpressionContainer(extracted.components))
179
+ );
180
+ if (!attributeExistsAlready('values', finalAttributes))
181
+ finalAttributes.push(
182
+ t.jSXAttribute(t.jSXIdentifier('values'), t.jSXExpressionContainer(extracted.values))
183
+ );
184
+
185
+ // create selfclosing Trans component
186
+ const openElement = t.jSXOpeningElement(nodeName, finalAttributes, true);
187
+ if (!wasElementWithChildren) return openElement;
188
+
189
+ return t.jSXElement(openElement, null, [], true);
190
+ }
191
+
192
+ function cloneExistingAttributes(attributes) {
193
+ return attributes.reduce((mem, attr) => {
194
+ mem.push(attr.node);
195
+ return mem;
196
+ }, []);
197
+ }
198
+
199
+ function attributeExistsAlready(name, attributes) {
200
+ const found = attributes.find(child => {
201
+ const ele = child.node ? child.node : child;
202
+ return ele.name.name === name;
203
+ });
204
+ return !!found;
205
+ }
206
+
207
+ function processTrans(children, babel, componentStartIndex = 0) {
208
+ const res = {};
209
+
210
+ res.defaults = mergeChildren(children, babel, componentStartIndex);
211
+ res.components = getComponents(children, babel);
212
+ res.values = getValues(children, babel);
213
+
214
+ return res;
215
+ }
216
+
217
+ function mergeChildren(children, babel, componentStartIndex = 0) {
218
+ const t = babel.types;
219
+ let componentFoundIndex = componentStartIndex;
220
+
221
+ return children.reduce((mem, child) => {
222
+ const ele = child.node ? child.node : child;
223
+
224
+ // add text
225
+ if (t.isJSXText(ele) && ele.value) mem += ele.value;
226
+ // add ?!? forgot
227
+ if (ele.expression && ele.expression.value) mem += ele.expression.value;
228
+ // add `{ val }`
229
+ if (ele.expression && ele.expression.name) mem += `{${ele.expression.name}}`;
230
+ // add `{ val, number }`
231
+ if (ele.expression && ele.expression.expressions) {
232
+ mem += `{${ele.expression.expressions
233
+ .reduce((m, i) => {
234
+ m.push(i.name || i.value);
235
+ return m;
236
+ }, [])
237
+ .join(', ')}}`;
238
+ }
239
+ // add <strong>...</strong> with replace to <0>inner string</0>
240
+ if (t.isJSXElement(ele)) {
241
+ mem += `<${componentFoundIndex}>${mergeChildren(
242
+ ele.children,
243
+ babel
244
+ )}</${componentFoundIndex}>`;
245
+ componentFoundIndex++;
246
+ }
247
+
248
+ return mem;
249
+ }, '');
250
+ }
251
+
252
+ function getValues(children, babel) {
253
+ const t = babel.types;
254
+ const toObjectProperty = (name, value) =>
255
+ t.objectProperty(t.identifier(name), t.identifier(name), false, !value);
256
+
257
+ return children.reduce((mem, child) => {
258
+ const ele = child.node ? child.node : child;
259
+
260
+ // add `{ var }` to values
261
+ if (ele.expression && ele.expression.name) mem.push(toObjectProperty(ele.expression.name));
262
+ // add `{ var, number }` to values
263
+ if (ele.expression && ele.expression.expressions)
264
+ mem.push(
265
+ toObjectProperty(ele.expression.expressions[0].name || ele.expression.expressions[0].value)
266
+ );
267
+ // add `{ var: 'bar' }` to values
268
+ if (ele.expression && ele.expression.properties) mem = mem.concat(ele.expression.properties);
269
+ // recursive add inner elements stuff to values
270
+ if (t.isJSXElement(ele)) {
271
+ mem = mem.concat(getValues(ele.children, babel));
272
+ }
273
+
274
+ return mem;
275
+ }, []);
276
+ }
277
+
278
+ function getComponents(children, babel) {
279
+ const t = babel.types;
280
+
281
+ return children.reduce((mem, child) => {
282
+ const ele = child.node ? child.node : child;
283
+
284
+ if (t.isJSXElement(ele)) {
285
+ const clone = t.clone(ele);
286
+ clone.children = clone.children.reduce((mem, child) => {
287
+ const ele = child.node ? child.node : child;
288
+
289
+ // clean out invalid definitions by replacing `{ catchDate, date, short }` with `{ catchDate }`
290
+ if (ele.expression && ele.expression.expressions)
291
+ ele.expression.expressions = [ele.expression.expressions[0]];
292
+
293
+ mem.push(child);
294
+ }, []);
295
+
296
+ mem.push(ele);
297
+ }
298
+
299
+ return mem;
300
+ }, []);
301
+ }
302
+
303
+ function addNeededImports(state, babel) {
304
+ const t = babel.types;
305
+ const importsToAdd = ['Trans'];
306
+
307
+ // check if there is an existing react-i18next import
308
+ const existingImport = state.file.path.node.body.find(
309
+ importNode => t.isImportDeclaration(importNode) && importNode.source.value === 'react-i18next'
310
+ );
311
+
312
+ // append Trans to existing or add a new react-i18next import for the Trans
313
+ if (existingImport) {
314
+ importsToAdd.forEach(name => {
315
+ if (
316
+ existingImport.specifiers.findIndex(
317
+ specifier => specifier.imported && specifier.imported.name === name
318
+ ) === -1
319
+ ) {
320
+ existingImport.specifiers.push(t.importSpecifier(t.identifier(name), t.identifier(name)));
321
+ }
322
+ });
323
+ } else {
324
+ state.file.path.node.body.unshift(
325
+ t.importDeclaration(
326
+ importsToAdd.map(name => t.importSpecifier(t.identifier(name), t.identifier(name))),
327
+ t.stringLiteral('react/i18next')
328
+ )
329
+ );
330
+ }
331
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-i18next",
3
- "version": "7.9.0",
3
+ "version": "7.11.0",
4
4
  "description": "Internationalization for react done right. Using the i18next i18n ecosystem.",
5
5
  "main": "dist/commonjs/index.js",
6
6
  "jsnext:main": "dist/es/index.js",
@@ -30,8 +30,10 @@
30
30
  "devDependencies": {
31
31
  "babel-cli": "6.26.0",
32
32
  "babel-core": "6.26.0",
33
- "babel-eslint": "8.0.1",
33
+ "babel-eslint": "8.2.6",
34
34
  "babel-jest": "21.2.0",
35
+ "babel-plugin-macros": "^2.3.0",
36
+ "babel-plugin-tester": "^5.4.0",
35
37
  "babel-preset-es2015": "6.24.1",
36
38
  "babel-preset-es2015-rollup": "3.0.0",
37
39
  "babel-preset-react": "6.24.1",
@@ -41,15 +43,19 @@
41
43
  "enzyme": "^3.3.0",
42
44
  "enzyme-adapter-react-16": "^1.1.1",
43
45
  "enzyme-adapter-react-helper": "^1.2.3",
44
- "eslint": "4.10.0",
45
- "eslint-config-airbnb": "16.1.0",
46
- "eslint-plugin-import": "2.8.0",
47
- "eslint-plugin-jsx-a11y": "6.0.2",
48
- "eslint-plugin-react": "7.4.0",
46
+ "eslint": "4.19.1",
47
+ "eslint-config-airbnb": "17.0.0",
48
+ "eslint-config-prettier": "2.9.0",
49
+ "eslint-plugin-import": "2.13.0",
50
+ "eslint-plugin-jsx-a11y": "6.1.1",
51
+ "eslint-plugin-prettier": "2.6.2",
52
+ "eslint-plugin-react": "7.10.0",
49
53
  "i18next": "10.0.7",
50
54
  "jest": "21.2.1",
51
55
  "jest-cli": "21.2.1",
52
56
  "mkdirp": "0.5.1",
57
+ "prettier": "1.13.7",
58
+ "prettier-eslint": "8.8.2",
53
59
  "raf": "^3.4.0",
54
60
  "react": "^16.0.0",
55
61
  "react-dom": "^16.0.0",
@@ -77,10 +83,10 @@
77
83
  "build": "npm run clean && npm run build:cjs && npm run build:es && npm run build:umd && npm run build:amd && npm run copy",
78
84
  "preversion": "npm run build && git push",
79
85
  "postversion": "git push && git push --tags",
80
- "pretest": "enzyme-adapter-react-install 16",
86
+ "pretest": "",
81
87
  "test": "BABEL_ENV=development jest --no-cache",
82
88
  "test:watch": "BABEL_ENV=development jest --no-cache --watch",
83
- "test:coverage": "BABEL_ENV=development jest --no-cache --coverage",
89
+ "test:coverage": "enzyme-adapter-react-install 16 && BABEL_ENV=development jest --no-cache --coverage",
84
90
  "test:lint": "./node_modules/.bin/eslint ./src"
85
91
  },
86
92
  "author": "Jan Mühlemann <jan.muehlemann@gmail.com> (https://github.com/jamuhl)",
package/react-i18next.js CHANGED
@@ -7,31 +7,32 @@
7
7
  var React__default = 'default' in React ? React['default'] : React;
8
8
  PropTypes = PropTypes && PropTypes.hasOwnProperty('default') ? PropTypes['default'] : PropTypes;
9
9
 
10
+ 'use strict';
11
+
10
12
  /**
11
13
  * Copyright 2015, Yahoo! Inc.
12
14
  * Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
13
15
  */
14
- 'use strict';
15
-
16
16
  var REACT_STATICS = {
17
17
  childContextTypes: true,
18
18
  contextTypes: true,
19
19
  defaultProps: true,
20
20
  displayName: true,
21
21
  getDefaultProps: true,
22
+ getDerivedStateFromProps: true,
22
23
  mixins: true,
23
24
  propTypes: true,
24
25
  type: true
25
26
  };
26
27
 
27
28
  var KNOWN_STATICS = {
28
- name: true,
29
- length: true,
30
- prototype: true,
31
- caller: true,
32
- callee: true,
33
- arguments: true,
34
- arity: true
29
+ name: true,
30
+ length: true,
31
+ prototype: true,
32
+ caller: true,
33
+ callee: true,
34
+ arguments: true,
35
+ arity: true
35
36
  };
36
37
 
37
38
  var defineProperty = Object.defineProperty;
@@ -41,7 +42,7 @@ var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
41
42
  var getPrototypeOf = Object.getPrototypeOf;
42
43
  var objectPrototype = getPrototypeOf && getPrototypeOf(Object);
43
44
 
44
- var hoistNonReactStatics = function hoistNonReactStatics(targetComponent, sourceComponent, blacklist) {
45
+ function hoistNonReactStatics(targetComponent, sourceComponent, blacklist) {
45
46
  if (typeof sourceComponent !== 'string') { // don't hoist over string (html) components
46
47
 
47
48
  if (objectPrototype) {
@@ -71,7 +72,9 @@ var hoistNonReactStatics = function hoistNonReactStatics(targetComponent, source
71
72
  }
72
73
 
73
74
  return targetComponent;
74
- };
75
+ }
76
+
77
+ var hoistNonReactStatics_cjs = hoistNonReactStatics;
75
78
 
76
79
  var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
77
80
  return typeof obj;
@@ -619,6 +622,11 @@ function translate(namespaceArg) {
619
622
  var i18nOptions = _this.i18n && _this.i18n.options && _this.i18n.options.react || {};
620
623
  _this.options = _extends({}, getDefaults(), i18nOptions, options);
621
624
 
625
+ if (context.reportNS) {
626
+ var namespaces = Array.isArray(namespaceArg) ? namespaceArg : [namespaceArg];
627
+ namespaces.forEach(context.reportNS);
628
+ }
629
+
622
630
  _this.getWrappedInstance = _this.getWrappedInstance.bind(_this);
623
631
  return _this;
624
632
  }
@@ -672,14 +680,15 @@ function translate(namespaceArg) {
672
680
 
673
681
  Translate.contextTypes = {
674
682
  i18n: PropTypes.object,
675
- defaultNS: PropTypes.string
683
+ defaultNS: PropTypes.string,
684
+ reportNS: PropTypes.func
676
685
  };
677
686
 
678
687
  Translate.displayName = 'Translate(' + getDisplayName(WrappedComponent) + ')';
679
688
 
680
689
  Translate.namespaces = namespaceArg;
681
690
 
682
- return hoistNonReactStatics(Translate, WrappedComponent);
691
+ return hoistNonReactStatics_cjs(Translate, WrappedComponent);
683
692
  };
684
693
  }
685
694
 
@@ -1061,8 +1070,11 @@ function renderNodes(children, targetString, i18n) {
1061
1070
  if (child.dummy) child.children = inner; // needed on preact!
1062
1071
  mem.push(React__default.cloneElement(child, _extends({}, child.props, { key: i }), inner));
1063
1072
  } else if ((typeof child === 'undefined' ? 'undefined' : _typeof(child)) === 'object' && !isElement) {
1064
- var interpolated = i18n.services.interpolator.interpolate(node.children[0].content, child, i18n.language);
1065
- mem.push(interpolated);
1073
+ var content = node.children[0] ? node.children[0].content : null;
1074
+ if (content) {
1075
+ var interpolated = i18n.services.interpolator.interpolate(node.children[0].content, child, i18n.language);
1076
+ mem.push(interpolated);
1077
+ }
1066
1078
  } else {
1067
1079
  mem.push(child);
1068
1080
  }
@@ -1167,6 +1179,7 @@ var I18nextProvider = function (_Component) {
1167
1179
  if (props.initialLanguage) {
1168
1180
  _this.i18n.changeLanguage(props.initialLanguage);
1169
1181
  }
1182
+ _this.reportNS = props.reportNS;
1170
1183
  return _this;
1171
1184
  }
1172
1185
 
@@ -1175,7 +1188,8 @@ var I18nextProvider = function (_Component) {
1175
1188
  value: function getChildContext() {
1176
1189
  return {
1177
1190
  i18n: this.i18n,
1178
- defaultNS: this.defaultNS
1191
+ defaultNS: this.defaultNS,
1192
+ reportNS: this.reportNS
1179
1193
  };
1180
1194
  }
1181
1195
  }, {
@@ -1199,16 +1213,19 @@ var I18nextProvider = function (_Component) {
1199
1213
  I18nextProvider.propTypes = {
1200
1214
  i18n: PropTypes.object.isRequired,
1201
1215
  children: PropTypes.element.isRequired,
1202
- defaultNS: PropTypes.string
1216
+ defaultNS: PropTypes.string,
1217
+ reportNS: PropTypes.func
1203
1218
  };
1204
1219
 
1205
1220
  I18nextProvider.childContextTypes = {
1206
1221
  i18n: PropTypes.object.isRequired,
1207
- defaultNS: PropTypes.string
1222
+ defaultNS: PropTypes.string,
1223
+ reportNS: PropTypes.func
1208
1224
  };
1209
1225
 
1210
1226
  I18nextProvider.defaultProps = {
1211
- defaultNS: undefined
1227
+ defaultNS: undefined,
1228
+ reportNS: undefined
1212
1229
  };
1213
1230
 
1214
1231
  var objectEntries = Object.entries || function (obj) {