react-i18next
Advanced tools
Comparing version 6.0.4 to 6.0.5
@@ -0,1 +1,7 @@ | ||
### 6.0.5 | ||
- fixes support passing i18n and t to Trans as props [PR315](https://github.com/i18next/react-i18next/pull/315) | ||
### 6.0.4 | ||
- fixes translate hoc build | ||
### 6.0.3 | ||
@@ -2,0 +8,0 @@ - stop using PureComponent and use Component again...seems we get an issue with react-router v4 if using PureComponents |
@@ -989,10 +989,5 @@ define(['exports', 'react', 'prop-types'], function (exports, React, PropTypes) { 'use strict'; | ||
function Trans(props, context) { | ||
function Trans() { | ||
classCallCheck(this, Trans); | ||
var _this = possibleConstructorReturn(this, (Trans.__proto__ || Object.getPrototypeOf(Trans)).call(this, props, context)); | ||
_this.i18n = props.i18n || context.i18n; | ||
_this.t = props.t || context.t; | ||
return _this; | ||
return possibleConstructorReturn(this, (Trans.__proto__ || Object.getPrototypeOf(Trans)).apply(this, arguments)); | ||
} | ||
@@ -1003,8 +998,10 @@ | ||
value: function render() { | ||
var _props = this.props, | ||
children = _props.children, | ||
count = _props.count, | ||
parent = _props.parent, | ||
i18nKey = _props.i18nKey, | ||
additionalProps = objectWithoutProperties(_props, ['children', 'count', 'parent', 'i18nKey']); | ||
var contextAndProps = _extends({ i18n: this.context.i18n, t: this.context.t }, this.props); | ||
var children = contextAndProps.children, | ||
count = contextAndProps.count, | ||
parent = contextAndProps.parent, | ||
i18nKey = contextAndProps.i18nKey, | ||
i18n = contextAndProps.i18n, | ||
t = contextAndProps.t, | ||
additionalProps = objectWithoutProperties(contextAndProps, ['children', 'count', 'parent', 'i18nKey', 'i18n', 't']); | ||
@@ -1014,14 +1011,14 @@ | ||
var key = i18nKey || defaultValue; | ||
var translation = this.t(key, { interpolation: { prefix: '#$?', suffix: '?$#' }, defaultValue: defaultValue, count: count }); | ||
var translation = t(key, { interpolation: { prefix: '#$?', suffix: '?$#' }, defaultValue: defaultValue, count: count }); | ||
if (this.i18n.options.react && this.i18n.options.react.exposeNamespace) { | ||
var ns = typeof this.t.ns === 'string' ? this.t.ns : this.t.ns[0]; | ||
if (i18nKey && this.i18n.options.nsSeparator && i18nKey.indexOf(this.i18n.options.nsSeparator) > -1) { | ||
var parts = i18nKey.split(this.i18n.options.nsSeparator); | ||
if (i18n.options.react && i18n.options.react.exposeNamespace) { | ||
var ns = typeof t.ns === 'string' ? t.ns : t.ns[0]; | ||
if (i18nKey && i18n.options.nsSeparator && i18nKey.indexOf(i18n.options.nsSeparator) > -1) { | ||
var parts = i18nKey.split(i18n.options.nsSeparator); | ||
ns = parts[0]; | ||
} | ||
if (this.t.ns) additionalProps['data-i18next-options'] = JSON.stringify({ ns: ns }); | ||
if (t.ns) additionalProps['data-i18next-options'] = JSON.stringify({ ns: ns }); | ||
} | ||
return React__default.createElement(parent, additionalProps, renderNodes(children, translation, this.i18n)); | ||
return React__default.createElement(parent, additionalProps, renderNodes(children, translation, i18n)); | ||
} | ||
@@ -1035,3 +1032,5 @@ }]); | ||
parent: PropTypes.string, | ||
i18nKey: PropTypes.string | ||
i18nKey: PropTypes.string, | ||
i18n: PropTypes.object, | ||
t: PropTypes.func | ||
}; | ||
@@ -1099,2 +1098,12 @@ | ||
// shim object entries | ||
if (!Object.entries) Object.entries = function (obj) { | ||
var ownProps = Object.keys(obj), | ||
i = ownProps.length, | ||
resArray = new Array(i); // preallocate the Array | ||
while (i--) { | ||
resArray[i] = [ownProps[i], obj[ownProps[i]]]; | ||
}return resArray; | ||
}; | ||
// Borrowed from https://github.com/Rezonans/redux-async-connect/blob/master/modules/ReduxAsyncConnect.js#L16 | ||
@@ -1101,0 +1110,0 @@ function eachComponents(components, iterator) { |
@@ -1,1 +0,1 @@ | ||
define(["exports","react","prop-types"],function(t,e,n){"use strict";function i(t){W=E({},W,t)}function r(){return W}function o(t){M=t}function a(){return M}function s(t){return t.displayName||t.name||"Component"}function c(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(o){var c=function(e){function n(e,o){T(this,n);var s=L(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e,o));s.i18n=o.i18n||e.i18n||i.i18n||a(),"string"==typeof(t=t||s.i18n.options.defaultNS)&&(t=[t]);var c=s.i18n&&s.i18n.options.react||{};return s.options=E({},r(),c,i),s.getWrappedInstance=s.getWrappedInstance.bind(s),s}return N(n,e),C(n,[{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,n={};return this.options.withRef&&(n.ref=function(t){e.wrappedInstance=t}),g.createElement(K,E({ns:t},this.options,this.props,{i18n:this.i18n}),function(t,i){return g.createElement(o,E({},e.props,n,i))})}}]),n}(e.Component);return c.WrappedComponent=o,c.contextTypes={i18n:n.object},c.displayName="Translate("+s(o)+")",c.namespaces=t,P(c,o)}}function p(t,e,n,i,r){var o=e.indexOf("<",i),a=e.slice(i,-1===o?void 0:o);/^\s*$/.test(a)&&(a=" "),(!r&&o>-1&&n+t.length>=0||" "!==a)&&t.push({type:"text",content:a})}function u(t){var e=[];for(var n in t)e.push(n+'="'+t[n]+'"');return e.length?" "+e.join(" "):""}function l(t,e){switch(e.type){case"text":return t+e.content;case"tag":return t+="<"+e.name+(e.attrs?u(e.attrs):"")+(e.voidElement?"/>":">"),e.voidElement?t:t+e.children.reduce(l,"")+"</"+e.name+">"}}function f(t){return t&&(t.children||t.props&&t.props.children)}function h(t){return t&&t.children?t.children:t.props&&t.props.children}function d(t,e,n){return"[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),e.forEach(function(e,n){var i=""+n;if("string"==typeof e)t=""+t+e;else if(f(e))t=t+"<"+i+">"+d("",h(e),n+1)+"</"+i+">";else if(g.isValidElement(e))t=t+"<"+i+"></"+i+">";else if("object"===(void 0===e?"undefined":k(e))){var r=E({},e),o=r.format;delete r.format;var a=Object.keys(r);o&&1===a.length?t=t+"<"+i+">{{"+a[0]+", "+o+"}}</"+i+">":1===a.length&&(t=t+"<"+i+">{{"+a[0]+"}}</"+i+">")}}),t}function y(t,e,n){function i(t,e){return"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),"[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),e.reduce(function(e,r,o){if("tag"===r.type){var a=t[parseInt(r.name,10)]||{},s=g.isValidElement(a);if("string"==typeof a)e.push(a);else if(f(a)){var c=i(h(a),r.children);a.dummy&&(a.children=c),e.push(g.cloneElement(a,E({},a.props,{key:o}),c))}else if("object"!==(void 0===a?"undefined":k(a))||s)e.push(a);else{var p=n.services.interpolator.interpolate(r.children[0].content,a,n.language);e.push(p)}}else"text"===r.type&&e.push(r.content);return e},[])}return h(i([{dummy:!0,children:t}],U.parse("<0>"+e+"</0>"))[0])}function v(t,e){for(var n=0,i=t.length;n<i;n++)if("object"===k(t[n])){var r=!0,o=!1,a=void 0;try{for(var s,c=Object.entries(t[n])[Symbol.iterator]();!(r=(s=c.next()).done);r=!0){var p=A(s.value,2),u=p[0];e(p[1],n,u)}}catch(t){o=!0,a=t}finally{try{!r&&c.return&&c.return()}finally{if(o)throw a}}}else e(t[n],n)}function m(t){var e=[];return v(t,function(t){t&&t.namespaces&&t.namespaces.forEach(function(t){-1===e.indexOf(t)&&e.push(t)})}),e}var g="default"in e?e.default:e;n=n&&n.hasOwnProperty("default")?n.default:n;var b={childContextTypes:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,mixins:!0,propTypes:!0,type:!0},S={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},O=Object.defineProperty,w=Object.getOwnPropertyNames,x=Object.getOwnPropertySymbols,I=Object.getOwnPropertyDescriptor,j=Object.getPrototypeOf,_=j&&j(Object),P=function t(e,n,i){if("string"!=typeof n){if(_){var r=j(n);r&&r!==_&&t(e,r,i)}var o=w(n);x&&(o=o.concat(x(n)));for(var a=0;a<o.length;++a){var s=o[a];if(!(b[s]||S[s]||i&&i[s])){var c=I(n,s);try{O(e,s,c)}catch(t){}}}return e}return e},k="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},T=(function(){function t(t){this.value=t}function e(e){function n(r,o){try{var a=e[r](o),s=a.value;s instanceof t?Promise.resolve(s.value).then(function(t){n("next",t)},function(t){n("throw",t)}):i(a.done?"return":"normal",a.value)}catch(t){i("throw",t)}}function i(t,e){switch(t){case"return":r.resolve({value:e,done:!0});break;case"throw":r.reject(e);break;default:r.resolve({value:e,done:!1})}(r=r.next)?n(r.key,r.arg):o=null}var r,o;this._invoke=function(t,e){return new Promise(function(i,a){var s={key:t,arg:e,resolve:i,reject:a,next:null};o?o=o.next=s:(r=o=s,n(t,e))})},"function"!=typeof e.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)}}(),function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}),C=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),E=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},N=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},R=function(t,e){var n={};for(var i in t)e.indexOf(i)>=0||Object.prototype.hasOwnProperty.call(t,i)&&(n[i]=t[i]);return n},L=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},A=function(){function t(t,e){var n=[],i=!0,r=!1,o=void 0;try{for(var a,s=t[Symbol.iterator]();!(i=(a=s.next()).done)&&(n.push(a.value),!e||n.length!==e);i=!0);}catch(t){r=!0,o=t}finally{try{!i&&s.return&&s.return()}finally{if(r)throw o}}return n}return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),W={wait:!1,withRef:!1,bindI18n:"languageChanged loaded",bindStore:"added removed",translateFuncName:"t",nsMode:"default"},M=void 0,q={type:"3rdParty",init:function(t){i(t.options.react),o(t)}},D=!1,K=function(t){function e(t,n){T(this,e);var i=L(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n));i.i18n=n.i18n||t.i18n||a(),i.namespaces=i.props.ns||i.i18n.options.defaultNS,"string"==typeof i.namespaces&&(i.namespaces=[i.namespaces]);var o=i.i18n&&i.i18n.options.react||{};return i.options=E({},r(),o,t),t.initialI18nStore&&(i.i18n.services.resourceStore.data=t.initialI18nStore,i.options.wait=!1),t.initialLanguage&&i.i18n.changeLanguage(t.initialLanguage),i.i18n.options.isInitialSSR&&(i.options.wait=!1),i.state={i18nLoadedAt:null,ready:!1},i.onI18nChanged=i.onI18nChanged.bind(i),i.getI18nTranslate=i.getI18nTranslate.bind(i),i}return N(e,t),C(e,[{key:"getChildContext",value:function(){return{t:this.t,i18n:this.i18n}}},{key:"componentWillMount",value:function(){this.t=this.getI18nTranslate()}},{key:"componentDidMount",value:function(){var t=this,e=function(){t.options.bindI18n&&t.i18n&&t.i18n.on(t.options.bindI18n,t.onI18nChanged),t.options.bindStore&&t.i18n.store&&t.i18n.store.on(t.options.bindStore,t.onI18nChanged)};this.mounted=!0,this.i18n.loadNamespaces(this.namespaces,function(){var n=function(){t.mounted&&!t.state.ready&&t.setState({ready:!0}),t.options.wait&&t.mounted&&e()};if(t.i18n.isInitialized)n();else{t.i18n.on("initialized",function e(){setTimeout(function(){t.i18n.off("initialized",e)},1e3),n()})}}),this.options.wait||e()}},{key:"componentWillUnmount",value:function(){var t=this;this.mounted=!1,this.onI18nChanged&&(this.options.bindI18n&&this.options.bindI18n.split(" ").forEach(function(e){return t.i18n.off(e,t.onI18nChanged)}),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.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 t=this,e=this.props.children;return!this.state.ready&&this.options.wait?null:(this.i18n.options.isInitialSSR&&!D&&(D=!0,setTimeout(function(){delete t.i18n.options.isInitialSSR},100)),e(this.t,{i18n:this.i18n,t:this.t}))}}]),e}(e.Component);K.contextTypes={i18n:n.object},K.childContextTypes={t:n.func.isRequired,i18n:n.object},c.setDefaults=i,c.setI18n=o;var $=function(t){function e(t,n){T(this,e);var i=L(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n));return i.i18n=t.i18n||n.i18n,i.t=t.t||n.t,i}return N(e,t),C(e,[{key:"render",value:function(){var t=this,e=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",c=E({},this.props.options,{interpolation:{prefix:"#$?",suffix:"?$#"}}),p=this.t(this.props.i18nKey,c);if(!p||"string"!=typeof p)return g.createElement("noscript",null);var u=[],l=function(e,n){if(e.indexOf(t.i18n.options.interpolation.formatSeparator)<0)return void 0===n[e]&&t.i18n.services.logger.warn("interpolator: missed to pass in variable "+e+" for interpolating "+p),n[e];var i=e.split(t.i18n.options.interpolation.formatSeparator),r=i.shift().trim(),o=i.join(t.i18n.options.interpolation.formatSeparator).trim();return void 0===n[r]&&t.i18n.services.logger.warn("interpolator: missed to pass in variable "+r+" for interpolating "+p),t.i18n.options.interpolation.format(n[r],o,t.i18n.language)};p.split(n).reduce(function(e,n,i){var r=void 0;if(i%2==0){if(0===n.length)return e;r=a?g.createElement(s,{dangerouslySetInnerHTML:{__html:n}}):n}else r=l(n,t.props);return e.push(r),e},u);var f={};if(this.i18n.options.react&&this.i18n.options.react.exposeNamespace){var h="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&&(h=this.props.i18nKey.split(this.i18n.options.nsSeparator)[0]),this.t.ns&&(f["data-i18next-options"]=JSON.stringify({ns:h}))}return r&&(f.className=r),o&&(f.style=o),g.createElement.apply(this,[e,f].concat(u))}}]),e}(e.PureComponent);$.propTypes={className:n.string},$.defaultProps={className:""},$.contextTypes={i18n:n.object.isRequired,t:n.func.isRequired};var z={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},H=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,V=function(t){var e,n=0,i=!0,r={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return t.replace(H,function(o){if("="===o)return i=!0,void n++;i?0===n?((z[o]||"/"===t.charAt(t.length-2))&&(r.voidElement=!0),r.name=o):(r.attrs[e]=o.replace(/^['"]|['"]$/g,""),e=void 0):(e&&(r.attrs[e]=e),e=o),n++,i=!1}),r},F=/(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,J=Object.create?Object.create(null):{},U={parse:function(t,e){e||(e={}),e.components||(e.components=J);var n,i=[],r=-1,o=[],a=!1;return t.replace(F,function(s,c){if(a){if(s!=="</"+n.name+">")return;a=!1}var u,l="/"!==s.charAt(1),f=0===s.indexOf("\x3c!--"),h=c+s.length,d=t.charAt(h);l&&!f&&(r++,"tag"===(n=V(s)).type&&e.components[n.name]&&(n.type="component",a=!0),n.voidElement||a||!d||"<"===d||p(n.children,t,r,h,e.ignoreWhitespace),0===r&&i.push(n),(u=o[r-1])&&u.children.push(n),o[r]=n),(f||!l||n.voidElement)&&(f||r--,!a&&"<"!==d&&d&&p(u=-1===r?i:o[r].children,t,r,h,e.ignoreWhitespace))}),!i.length&&t.length&&p(i,t,0,0,e.ignoreWhitespace),i},stringify:function(t){return t.reduce(function(t,e){return t+l("",e)},"")}},B=function(t){function e(t,n){T(this,e);var i=L(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n));return i.i18n=t.i18n||n.i18n,i.t=t.t||n.t,i}return N(e,t),C(e,[{key:"render",value:function(){var t=this.props,e=t.children,n=t.count,i=t.parent,r=t.i18nKey,o=R(t,["children","count","parent","i18nKey"]),a=d("",e,0),s=r||a,c=this.t(s,{interpolation:{prefix:"#$?",suffix:"?$#"},defaultValue:a,count:n});if(this.i18n.options.react&&this.i18n.options.react.exposeNamespace){var p="string"==typeof this.t.ns?this.t.ns:this.t.ns[0];r&&this.i18n.options.nsSeparator&&r.indexOf(this.i18n.options.nsSeparator)>-1&&(p=r.split(this.i18n.options.nsSeparator)[0]),this.t.ns&&(o["data-i18next-options"]=JSON.stringify({ns:p}))}return g.createElement(i,o,y(e,c,this.i18n))}}]),e}(g.PureComponent);B.propTypes={count:n.number,parent:n.string,i18nKey:n.string},B.defaultProps={parent:"div"},B.contextTypes={i18n:n.object.isRequired,t:n.func.isRequired};var G=function(t){function n(t,e){T(this,n);var i=L(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,t,e));return i.i18n=t.i18n,t.initialI18nStore&&(i.i18n.services.resourceStore.data=t.initialI18nStore,i.i18n.options.isInitialSSR=!0),t.initialLanguage&&i.i18n.changeLanguage(t.initialLanguage),i}return N(n,t),C(n,[{key:"getChildContext",value:function(){return{i18n:this.i18n}}},{key:"componentWillReceiveProps",value:function(t){if(this.props.i18n!==t.i18n)throw new Error("[react-i18next][I18nextProvider]does not support changing the i18n object.")}},{key:"render",value:function(){var t=this.props.children;return e.Children.only(t)}}]),n}(e.Component);G.propTypes={i18n:n.object.isRequired,children:n.element.isRequired},G.childContextTypes={i18n:n.object.isRequired},t.translate=c,t.I18n=K,t.Interpolate=$,t.Trans=B,t.I18nextProvider=G,t.loadNamespaces=function(t){var e=t.components,n=t.i18n,i=m(e);return new Promise(function(t){n.loadNamespaces(i,t)})},t.reactI18nextModule=q,t.setDefaults=i,t.getDefaults=r,t.setI18n=o,t.getI18n=a,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
define(["exports","react","prop-types"],function(t,e,n){"use strict";function i(t){W=E({},W,t)}function r(){return W}function o(t){M=t}function a(){return M}function s(t){return t.displayName||t.name||"Component"}function c(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(o){var c=function(e){function n(e,o){T(this,n);var s=A(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e,o));s.i18n=o.i18n||e.i18n||i.i18n||a(),"string"==typeof(t=t||s.i18n.options.defaultNS)&&(t=[t]);var c=s.i18n&&s.i18n.options.react||{};return s.options=E({},r(),c,i),s.getWrappedInstance=s.getWrappedInstance.bind(s),s}return N(n,e),C(n,[{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,n={};return this.options.withRef&&(n.ref=function(t){e.wrappedInstance=t}),g.createElement(K,E({ns:t},this.options,this.props,{i18n:this.i18n}),function(t,i){return g.createElement(o,E({},e.props,n,i))})}}]),n}(e.Component);return c.WrappedComponent=o,c.contextTypes={i18n:n.object},c.displayName="Translate("+s(o)+")",c.namespaces=t,P(c,o)}}function p(t,e,n,i,r){var o=e.indexOf("<",i),a=e.slice(i,-1===o?void 0:o);/^\s*$/.test(a)&&(a=" "),(!r&&o>-1&&n+t.length>=0||" "!==a)&&t.push({type:"text",content:a})}function u(t){var e=[];for(var n in t)e.push(n+'="'+t[n]+'"');return e.length?" "+e.join(" "):""}function l(t,e){switch(e.type){case"text":return t+e.content;case"tag":return t+="<"+e.name+(e.attrs?u(e.attrs):"")+(e.voidElement?"/>":">"),e.voidElement?t:t+e.children.reduce(l,"")+"</"+e.name+">"}}function f(t){return t&&(t.children||t.props&&t.props.children)}function h(t){return t&&t.children?t.children:t.props&&t.props.children}function d(t,e,n){return"[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),e.forEach(function(e,n){var i=""+n;if("string"==typeof e)t=""+t+e;else if(f(e))t=t+"<"+i+">"+d("",h(e),n+1)+"</"+i+">";else if(g.isValidElement(e))t=t+"<"+i+"></"+i+">";else if("object"===(void 0===e?"undefined":k(e))){var r=E({},e),o=r.format;delete r.format;var a=Object.keys(r);o&&1===a.length?t=t+"<"+i+">{{"+a[0]+", "+o+"}}</"+i+">":1===a.length&&(t=t+"<"+i+">{{"+a[0]+"}}</"+i+">")}}),t}function y(t,e,n){function i(t,e){return"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),"[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),e.reduce(function(e,r,o){if("tag"===r.type){var a=t[parseInt(r.name,10)]||{},s=g.isValidElement(a);if("string"==typeof a)e.push(a);else if(f(a)){var c=i(h(a),r.children);a.dummy&&(a.children=c),e.push(g.cloneElement(a,E({},a.props,{key:o}),c))}else if("object"!==(void 0===a?"undefined":k(a))||s)e.push(a);else{var p=n.services.interpolator.interpolate(r.children[0].content,a,n.language);e.push(p)}}else"text"===r.type&&e.push(r.content);return e},[])}return h(i([{dummy:!0,children:t}],U.parse("<0>"+e+"</0>"))[0])}function v(t,e){for(var n=0,i=t.length;n<i;n++)if("object"===k(t[n])){var r=!0,o=!1,a=void 0;try{for(var s,c=Object.entries(t[n])[Symbol.iterator]();!(r=(s=c.next()).done);r=!0){var p=L(s.value,2),u=p[0];e(p[1],n,u)}}catch(t){o=!0,a=t}finally{try{!r&&c.return&&c.return()}finally{if(o)throw a}}}else e(t[n],n)}function m(t){var e=[];return v(t,function(t){t&&t.namespaces&&t.namespaces.forEach(function(t){-1===e.indexOf(t)&&e.push(t)})}),e}var g="default"in e?e.default:e;n=n&&n.hasOwnProperty("default")?n.default:n;var b={childContextTypes:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,mixins:!0,propTypes:!0,type:!0},S={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},O=Object.defineProperty,j=Object.getOwnPropertyNames,x=Object.getOwnPropertySymbols,w=Object.getOwnPropertyDescriptor,I=Object.getPrototypeOf,_=I&&I(Object),P=function t(e,n,i){if("string"!=typeof n){if(_){var r=I(n);r&&r!==_&&t(e,r,i)}var o=j(n);x&&(o=o.concat(x(n)));for(var a=0;a<o.length;++a){var s=o[a];if(!(b[s]||S[s]||i&&i[s])){var c=w(n,s);try{O(e,s,c)}catch(t){}}}return e}return e},k="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},T=(function(){function t(t){this.value=t}function e(e){function n(r,o){try{var a=e[r](o),s=a.value;s instanceof t?Promise.resolve(s.value).then(function(t){n("next",t)},function(t){n("throw",t)}):i(a.done?"return":"normal",a.value)}catch(t){i("throw",t)}}function i(t,e){switch(t){case"return":r.resolve({value:e,done:!0});break;case"throw":r.reject(e);break;default:r.resolve({value:e,done:!1})}(r=r.next)?n(r.key,r.arg):o=null}var r,o;this._invoke=function(t,e){return new Promise(function(i,a){var s={key:t,arg:e,resolve:i,reject:a,next:null};o?o=o.next=s:(r=o=s,n(t,e))})},"function"!=typeof e.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)}}(),function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}),C=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),E=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},N=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},R=function(t,e){var n={};for(var i in t)e.indexOf(i)>=0||Object.prototype.hasOwnProperty.call(t,i)&&(n[i]=t[i]);return n},A=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},L=function(){function t(t,e){var n=[],i=!0,r=!1,o=void 0;try{for(var a,s=t[Symbol.iterator]();!(i=(a=s.next()).done)&&(n.push(a.value),!e||n.length!==e);i=!0);}catch(t){r=!0,o=t}finally{try{!i&&s.return&&s.return()}finally{if(r)throw o}}return n}return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),W={wait:!1,withRef:!1,bindI18n:"languageChanged loaded",bindStore:"added removed",translateFuncName:"t",nsMode:"default"},M=void 0,q={type:"3rdParty",init:function(t){i(t.options.react),o(t)}},D=!1,K=function(t){function e(t,n){T(this,e);var i=A(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n));i.i18n=n.i18n||t.i18n||a(),i.namespaces=i.props.ns||i.i18n.options.defaultNS,"string"==typeof i.namespaces&&(i.namespaces=[i.namespaces]);var o=i.i18n&&i.i18n.options.react||{};return i.options=E({},r(),o,t),t.initialI18nStore&&(i.i18n.services.resourceStore.data=t.initialI18nStore,i.options.wait=!1),t.initialLanguage&&i.i18n.changeLanguage(t.initialLanguage),i.i18n.options.isInitialSSR&&(i.options.wait=!1),i.state={i18nLoadedAt:null,ready:!1},i.onI18nChanged=i.onI18nChanged.bind(i),i.getI18nTranslate=i.getI18nTranslate.bind(i),i}return N(e,t),C(e,[{key:"getChildContext",value:function(){return{t:this.t,i18n:this.i18n}}},{key:"componentWillMount",value:function(){this.t=this.getI18nTranslate()}},{key:"componentDidMount",value:function(){var t=this,e=function(){t.options.bindI18n&&t.i18n&&t.i18n.on(t.options.bindI18n,t.onI18nChanged),t.options.bindStore&&t.i18n.store&&t.i18n.store.on(t.options.bindStore,t.onI18nChanged)};this.mounted=!0,this.i18n.loadNamespaces(this.namespaces,function(){var n=function(){t.mounted&&!t.state.ready&&t.setState({ready:!0}),t.options.wait&&t.mounted&&e()};if(t.i18n.isInitialized)n();else{t.i18n.on("initialized",function e(){setTimeout(function(){t.i18n.off("initialized",e)},1e3),n()})}}),this.options.wait||e()}},{key:"componentWillUnmount",value:function(){var t=this;this.mounted=!1,this.onI18nChanged&&(this.options.bindI18n&&this.options.bindI18n.split(" ").forEach(function(e){return t.i18n.off(e,t.onI18nChanged)}),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.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 t=this,e=this.props.children;return!this.state.ready&&this.options.wait?null:(this.i18n.options.isInitialSSR&&!D&&(D=!0,setTimeout(function(){delete t.i18n.options.isInitialSSR},100)),e(this.t,{i18n:this.i18n,t:this.t}))}}]),e}(e.Component);K.contextTypes={i18n:n.object},K.childContextTypes={t:n.func.isRequired,i18n:n.object},c.setDefaults=i,c.setI18n=o;var $=function(t){function e(t,n){T(this,e);var i=A(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n));return i.i18n=t.i18n||n.i18n,i.t=t.t||n.t,i}return N(e,t),C(e,[{key:"render",value:function(){var t=this,e=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",c=E({},this.props.options,{interpolation:{prefix:"#$?",suffix:"?$#"}}),p=this.t(this.props.i18nKey,c);if(!p||"string"!=typeof p)return g.createElement("noscript",null);var u=[],l=function(e,n){if(e.indexOf(t.i18n.options.interpolation.formatSeparator)<0)return void 0===n[e]&&t.i18n.services.logger.warn("interpolator: missed to pass in variable "+e+" for interpolating "+p),n[e];var i=e.split(t.i18n.options.interpolation.formatSeparator),r=i.shift().trim(),o=i.join(t.i18n.options.interpolation.formatSeparator).trim();return void 0===n[r]&&t.i18n.services.logger.warn("interpolator: missed to pass in variable "+r+" for interpolating "+p),t.i18n.options.interpolation.format(n[r],o,t.i18n.language)};p.split(n).reduce(function(e,n,i){var r=void 0;if(i%2==0){if(0===n.length)return e;r=a?g.createElement(s,{dangerouslySetInnerHTML:{__html:n}}):n}else r=l(n,t.props);return e.push(r),e},u);var f={};if(this.i18n.options.react&&this.i18n.options.react.exposeNamespace){var h="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&&(h=this.props.i18nKey.split(this.i18n.options.nsSeparator)[0]),this.t.ns&&(f["data-i18next-options"]=JSON.stringify({ns:h}))}return r&&(f.className=r),o&&(f.style=o),g.createElement.apply(this,[e,f].concat(u))}}]),e}(e.PureComponent);$.propTypes={className:n.string},$.defaultProps={className:""},$.contextTypes={i18n:n.object.isRequired,t:n.func.isRequired};var z={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},H=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,V=function(t){var e,n=0,i=!0,r={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return t.replace(H,function(o){if("="===o)return i=!0,void n++;i?0===n?((z[o]||"/"===t.charAt(t.length-2))&&(r.voidElement=!0),r.name=o):(r.attrs[e]=o.replace(/^['"]|['"]$/g,""),e=void 0):(e&&(r.attrs[e]=e),e=o),n++,i=!1}),r},F=/(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,J=Object.create?Object.create(null):{},U={parse:function(t,e){e||(e={}),e.components||(e.components=J);var n,i=[],r=-1,o=[],a=!1;return t.replace(F,function(s,c){if(a){if(s!=="</"+n.name+">")return;a=!1}var u,l="/"!==s.charAt(1),f=0===s.indexOf("\x3c!--"),h=c+s.length,d=t.charAt(h);l&&!f&&(r++,"tag"===(n=V(s)).type&&e.components[n.name]&&(n.type="component",a=!0),n.voidElement||a||!d||"<"===d||p(n.children,t,r,h,e.ignoreWhitespace),0===r&&i.push(n),(u=o[r-1])&&u.children.push(n),o[r]=n),(f||!l||n.voidElement)&&(f||r--,!a&&"<"!==d&&d&&p(u=-1===r?i:o[r].children,t,r,h,e.ignoreWhitespace))}),!i.length&&t.length&&p(i,t,0,0,e.ignoreWhitespace),i},stringify:function(t){return t.reduce(function(t,e){return t+l("",e)},"")}},B=function(t){function e(){return T(this,e),A(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return N(e,t),C(e,[{key:"render",value:function(){var t=E({i18n:this.context.i18n,t:this.context.t},this.props),e=t.children,n=t.count,i=t.parent,r=t.i18nKey,o=t.i18n,a=t.t,s=R(t,["children","count","parent","i18nKey","i18n","t"]),c=d("",e,0),p=a(r||c,{interpolation:{prefix:"#$?",suffix:"?$#"},defaultValue:c,count:n});if(o.options.react&&o.options.react.exposeNamespace){var u="string"==typeof a.ns?a.ns:a.ns[0];r&&o.options.nsSeparator&&r.indexOf(o.options.nsSeparator)>-1&&(u=r.split(o.options.nsSeparator)[0]),a.ns&&(s["data-i18next-options"]=JSON.stringify({ns:u}))}return g.createElement(i,s,y(e,p,o))}}]),e}(g.PureComponent);B.propTypes={count:n.number,parent:n.string,i18nKey:n.string,i18n:n.object,t:n.func},B.defaultProps={parent:"div"},B.contextTypes={i18n:n.object.isRequired,t:n.func.isRequired};var G=function(t){function n(t,e){T(this,n);var i=A(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,t,e));return i.i18n=t.i18n,t.initialI18nStore&&(i.i18n.services.resourceStore.data=t.initialI18nStore,i.i18n.options.isInitialSSR=!0),t.initialLanguage&&i.i18n.changeLanguage(t.initialLanguage),i}return N(n,t),C(n,[{key:"getChildContext",value:function(){return{i18n:this.i18n}}},{key:"componentWillReceiveProps",value:function(t){if(this.props.i18n!==t.i18n)throw new Error("[react-i18next][I18nextProvider]does not support changing the i18n object.")}},{key:"render",value:function(){var t=this.props.children;return e.Children.only(t)}}]),n}(e.Component);G.propTypes={i18n:n.object.isRequired,children:n.element.isRequired},G.childContextTypes={i18n:n.object.isRequired},Object.entries||(Object.entries=function(t){for(var e=Object.keys(t),n=e.length,i=new Array(n);n--;)i[n]=[e[n],t[e[n]]];return i}),t.translate=c,t.I18n=K,t.Interpolate=$,t.Trans=B,t.I18nextProvider=G,t.loadNamespaces=function(t){var e=t.components,n=t.i18n,i=m(e);return new Promise(function(t){n.loadNamespaces(i,t)})},t.reactI18nextModule=q,t.setDefaults=i,t.getDefaults=r,t.setI18n=o,t.getI18n=a,Object.defineProperty(t,"__esModule",{value:!0})}); |
@@ -12,2 +12,12 @@ 'use strict'; | ||
exports.default = loadNamespaces; | ||
// shim object entries | ||
if (!Object.entries) Object.entries = function (obj) { | ||
var ownProps = Object.keys(obj), | ||
i = ownProps.length, | ||
resArray = new Array(i); // preallocate the Array | ||
while (i--) { | ||
resArray[i] = [ownProps[i], obj[ownProps[i]]]; | ||
}return resArray; | ||
}; | ||
// Borrowed from https://github.com/Rezonans/redux-async-connect/blob/master/modules/ReduxAsyncConnect.js#L16 | ||
@@ -14,0 +24,0 @@ function eachComponents(components, iterator) { |
@@ -118,10 +118,6 @@ 'use strict'; | ||
function Trans(props, context) { | ||
function Trans() { | ||
_classCallCheck(this, Trans); | ||
var _this = _possibleConstructorReturn(this, (Trans.__proto__ || Object.getPrototypeOf(Trans)).call(this, props, context)); | ||
_this.i18n = props.i18n || context.i18n; | ||
_this.t = props.t || context.t; | ||
return _this; | ||
return _possibleConstructorReturn(this, (Trans.__proto__ || Object.getPrototypeOf(Trans)).apply(this, arguments)); | ||
} | ||
@@ -132,23 +128,26 @@ | ||
value: function render() { | ||
var _props = this.props, | ||
children = _props.children, | ||
count = _props.count, | ||
parent = _props.parent, | ||
i18nKey = _props.i18nKey, | ||
additionalProps = _objectWithoutProperties(_props, ['children', 'count', 'parent', 'i18nKey']); | ||
var contextAndProps = _extends({ i18n: this.context.i18n, t: this.context.t }, this.props); | ||
var children = contextAndProps.children, | ||
count = contextAndProps.count, | ||
parent = contextAndProps.parent, | ||
i18nKey = contextAndProps.i18nKey, | ||
i18n = contextAndProps.i18n, | ||
t = contextAndProps.t, | ||
additionalProps = _objectWithoutProperties(contextAndProps, ['children', 'count', 'parent', 'i18nKey', 'i18n', 't']); | ||
var defaultValue = nodesToString('', children, 0); | ||
var key = i18nKey || defaultValue; | ||
var translation = this.t(key, { interpolation: { prefix: '#$?', suffix: '?$#' }, defaultValue: defaultValue, count: count }); | ||
var translation = t(key, { interpolation: { prefix: '#$?', suffix: '?$#' }, defaultValue: defaultValue, count: count }); | ||
if (this.i18n.options.react && this.i18n.options.react.exposeNamespace) { | ||
var ns = typeof this.t.ns === 'string' ? this.t.ns : this.t.ns[0]; | ||
if (i18nKey && this.i18n.options.nsSeparator && i18nKey.indexOf(this.i18n.options.nsSeparator) > -1) { | ||
var parts = i18nKey.split(this.i18n.options.nsSeparator); | ||
if (i18n.options.react && i18n.options.react.exposeNamespace) { | ||
var ns = typeof t.ns === 'string' ? t.ns : t.ns[0]; | ||
if (i18nKey && i18n.options.nsSeparator && i18nKey.indexOf(i18n.options.nsSeparator) > -1) { | ||
var parts = i18nKey.split(i18n.options.nsSeparator); | ||
ns = parts[0]; | ||
} | ||
if (this.t.ns) additionalProps['data-i18next-options'] = JSON.stringify({ ns: ns }); | ||
if (t.ns) additionalProps['data-i18next-options'] = JSON.stringify({ ns: ns }); | ||
} | ||
return _react2.default.createElement(parent, additionalProps, renderNodes(children, translation, this.i18n)); | ||
return _react2.default.createElement(parent, additionalProps, renderNodes(children, translation, i18n)); | ||
} | ||
@@ -166,3 +165,5 @@ }]); | ||
parent: _propTypes2.default.string, | ||
i18nKey: _propTypes2.default.string | ||
i18nKey: _propTypes2.default.string, | ||
i18n: _propTypes2.default.object, | ||
t: _propTypes2.default.func | ||
}; | ||
@@ -169,0 +170,0 @@ |
@@ -5,2 +5,12 @@ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
// shim object entries | ||
if (!Object.entries) Object.entries = function (obj) { | ||
var ownProps = Object.keys(obj), | ||
i = ownProps.length, | ||
resArray = new Array(i); // preallocate the Array | ||
while (i--) { | ||
resArray[i] = [ownProps[i], obj[ownProps[i]]]; | ||
}return resArray; | ||
}; | ||
// Borrowed from https://github.com/Rezonans/redux-async-connect/blob/master/modules/ReduxAsyncConnect.js#L16 | ||
@@ -7,0 +17,0 @@ function eachComponents(components, iterator) { |
@@ -102,10 +102,6 @@ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function Trans(props, context) { | ||
function Trans() { | ||
_classCallCheck(this, Trans); | ||
var _this = _possibleConstructorReturn(this, (Trans.__proto__ || Object.getPrototypeOf(Trans)).call(this, props, context)); | ||
_this.i18n = props.i18n || context.i18n; | ||
_this.t = props.t || context.t; | ||
return _this; | ||
return _possibleConstructorReturn(this, (Trans.__proto__ || Object.getPrototypeOf(Trans)).apply(this, arguments)); | ||
} | ||
@@ -116,23 +112,26 @@ | ||
value: function render() { | ||
var _props = this.props, | ||
children = _props.children, | ||
count = _props.count, | ||
parent = _props.parent, | ||
i18nKey = _props.i18nKey, | ||
additionalProps = _objectWithoutProperties(_props, ['children', 'count', 'parent', 'i18nKey']); | ||
var contextAndProps = _extends({ i18n: this.context.i18n, t: this.context.t }, this.props); | ||
var children = contextAndProps.children, | ||
count = contextAndProps.count, | ||
parent = contextAndProps.parent, | ||
i18nKey = contextAndProps.i18nKey, | ||
i18n = contextAndProps.i18n, | ||
t = contextAndProps.t, | ||
additionalProps = _objectWithoutProperties(contextAndProps, ['children', 'count', 'parent', 'i18nKey', 'i18n', 't']); | ||
var defaultValue = nodesToString('', children, 0); | ||
var key = i18nKey || defaultValue; | ||
var translation = this.t(key, { interpolation: { prefix: '#$?', suffix: '?$#' }, defaultValue: defaultValue, count: count }); | ||
var translation = t(key, { interpolation: { prefix: '#$?', suffix: '?$#' }, defaultValue: defaultValue, count: count }); | ||
if (this.i18n.options.react && this.i18n.options.react.exposeNamespace) { | ||
var ns = typeof this.t.ns === 'string' ? this.t.ns : this.t.ns[0]; | ||
if (i18nKey && this.i18n.options.nsSeparator && i18nKey.indexOf(this.i18n.options.nsSeparator) > -1) { | ||
var parts = i18nKey.split(this.i18n.options.nsSeparator); | ||
if (i18n.options.react && i18n.options.react.exposeNamespace) { | ||
var ns = typeof t.ns === 'string' ? t.ns : t.ns[0]; | ||
if (i18nKey && i18n.options.nsSeparator && i18nKey.indexOf(i18n.options.nsSeparator) > -1) { | ||
var parts = i18nKey.split(i18n.options.nsSeparator); | ||
ns = parts[0]; | ||
} | ||
if (this.t.ns) additionalProps['data-i18next-options'] = JSON.stringify({ ns: ns }); | ||
if (t.ns) additionalProps['data-i18next-options'] = JSON.stringify({ ns: ns }); | ||
} | ||
return React.createElement(parent, additionalProps, renderNodes(children, translation, this.i18n)); | ||
return React.createElement(parent, additionalProps, renderNodes(children, translation, i18n)); | ||
} | ||
@@ -150,3 +149,5 @@ }]); | ||
parent: PropTypes.string, | ||
i18nKey: PropTypes.string | ||
i18nKey: PropTypes.string, | ||
i18n: PropTypes.object, | ||
t: PropTypes.func | ||
}; | ||
@@ -153,0 +154,0 @@ |
@@ -993,10 +993,5 @@ (function (global, factory) { | ||
function Trans(props, context) { | ||
function Trans() { | ||
classCallCheck(this, Trans); | ||
var _this = possibleConstructorReturn(this, (Trans.__proto__ || Object.getPrototypeOf(Trans)).call(this, props, context)); | ||
_this.i18n = props.i18n || context.i18n; | ||
_this.t = props.t || context.t; | ||
return _this; | ||
return possibleConstructorReturn(this, (Trans.__proto__ || Object.getPrototypeOf(Trans)).apply(this, arguments)); | ||
} | ||
@@ -1007,8 +1002,10 @@ | ||
value: function render() { | ||
var _props = this.props, | ||
children = _props.children, | ||
count = _props.count, | ||
parent = _props.parent, | ||
i18nKey = _props.i18nKey, | ||
additionalProps = objectWithoutProperties(_props, ['children', 'count', 'parent', 'i18nKey']); | ||
var contextAndProps = _extends({ i18n: this.context.i18n, t: this.context.t }, this.props); | ||
var children = contextAndProps.children, | ||
count = contextAndProps.count, | ||
parent = contextAndProps.parent, | ||
i18nKey = contextAndProps.i18nKey, | ||
i18n = contextAndProps.i18n, | ||
t = contextAndProps.t, | ||
additionalProps = objectWithoutProperties(contextAndProps, ['children', 'count', 'parent', 'i18nKey', 'i18n', 't']); | ||
@@ -1018,14 +1015,14 @@ | ||
var key = i18nKey || defaultValue; | ||
var translation = this.t(key, { interpolation: { prefix: '#$?', suffix: '?$#' }, defaultValue: defaultValue, count: count }); | ||
var translation = t(key, { interpolation: { prefix: '#$?', suffix: '?$#' }, defaultValue: defaultValue, count: count }); | ||
if (this.i18n.options.react && this.i18n.options.react.exposeNamespace) { | ||
var ns = typeof this.t.ns === 'string' ? this.t.ns : this.t.ns[0]; | ||
if (i18nKey && this.i18n.options.nsSeparator && i18nKey.indexOf(this.i18n.options.nsSeparator) > -1) { | ||
var parts = i18nKey.split(this.i18n.options.nsSeparator); | ||
if (i18n.options.react && i18n.options.react.exposeNamespace) { | ||
var ns = typeof t.ns === 'string' ? t.ns : t.ns[0]; | ||
if (i18nKey && i18n.options.nsSeparator && i18nKey.indexOf(i18n.options.nsSeparator) > -1) { | ||
var parts = i18nKey.split(i18n.options.nsSeparator); | ||
ns = parts[0]; | ||
} | ||
if (this.t.ns) additionalProps['data-i18next-options'] = JSON.stringify({ ns: ns }); | ||
if (t.ns) additionalProps['data-i18next-options'] = JSON.stringify({ ns: ns }); | ||
} | ||
return React__default.createElement(parent, additionalProps, renderNodes(children, translation, this.i18n)); | ||
return React__default.createElement(parent, additionalProps, renderNodes(children, translation, i18n)); | ||
} | ||
@@ -1039,3 +1036,5 @@ }]); | ||
parent: PropTypes.string, | ||
i18nKey: PropTypes.string | ||
i18nKey: PropTypes.string, | ||
i18n: PropTypes.object, | ||
t: PropTypes.func | ||
}; | ||
@@ -1103,2 +1102,12 @@ | ||
// shim object entries | ||
if (!Object.entries) Object.entries = function (obj) { | ||
var ownProps = Object.keys(obj), | ||
i = ownProps.length, | ||
resArray = new Array(i); // preallocate the Array | ||
while (i--) { | ||
resArray[i] = [ownProps[i], obj[ownProps[i]]]; | ||
}return resArray; | ||
}; | ||
// Borrowed from https://github.com/Rezonans/redux-async-connect/blob/master/modules/ReduxAsyncConnect.js#L16 | ||
@@ -1105,0 +1114,0 @@ function eachComponents(components, iterator) { |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react","prop-types"],e):e(t.reactI18next={},t.React,t.PropTypes)}(this,function(t,e,n){"use strict";function i(t){A=E({},A,t)}function r(){return A}function o(t){W=t}function a(){return W}function s(t){return t.displayName||t.name||"Component"}function p(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(o){var p=function(e){function n(e,o){k(this,n);var s=L(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e,o));s.i18n=o.i18n||e.i18n||i.i18n||a(),"string"==typeof(t=t||s.i18n.options.defaultNS)&&(t=[t]);var p=s.i18n&&s.i18n.options.react||{};return s.options=E({},r(),p,i),s.getWrappedInstance=s.getWrappedInstance.bind(s),s}return R(n,e),C(n,[{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,n={};return this.options.withRef&&(n.ref=function(t){e.wrappedInstance=t}),g.createElement(K,E({ns:t},this.options,this.props,{i18n:this.i18n}),function(t,i){return g.createElement(o,E({},e.props,n,i))})}}]),n}(e.Component);return p.WrappedComponent=o,p.contextTypes={i18n:n.object},p.displayName="Translate("+s(o)+")",p.namespaces=t,_(p,o)}}function c(t,e,n,i,r){var o=e.indexOf("<",i),a=e.slice(i,-1===o?void 0:o);/^\s*$/.test(a)&&(a=" "),(!r&&o>-1&&n+t.length>=0||" "!==a)&&t.push({type:"text",content:a})}function u(t){var e=[];for(var n in t)e.push(n+'="'+t[n]+'"');return e.length?" "+e.join(" "):""}function l(t,e){switch(e.type){case"text":return t+e.content;case"tag":return t+="<"+e.name+(e.attrs?u(e.attrs):"")+(e.voidElement?"/>":">"),e.voidElement?t:t+e.children.reduce(l,"")+"</"+e.name+">"}}function f(t){return t&&(t.children||t.props&&t.props.children)}function h(t){return t&&t.children?t.children:t.props&&t.props.children}function d(t,e,n){return"[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),e.forEach(function(e,n){var i=""+n;if("string"==typeof e)t=""+t+e;else if(f(e))t=t+"<"+i+">"+d("",h(e),n+1)+"</"+i+">";else if(g.isValidElement(e))t=t+"<"+i+"></"+i+">";else if("object"===(void 0===e?"undefined":T(e))){var r=E({},e),o=r.format;delete r.format;var a=Object.keys(r);o&&1===a.length?t=t+"<"+i+">{{"+a[0]+", "+o+"}}</"+i+">":1===a.length&&(t=t+"<"+i+">{{"+a[0]+"}}</"+i+">")}}),t}function y(t,e,n){function i(t,e){return"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),"[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),e.reduce(function(e,r,o){if("tag"===r.type){var a=t[parseInt(r.name,10)]||{},s=g.isValidElement(a);if("string"==typeof a)e.push(a);else if(f(a)){var p=i(h(a),r.children);a.dummy&&(a.children=p),e.push(g.cloneElement(a,E({},a.props,{key:o}),p))}else if("object"!==(void 0===a?"undefined":T(a))||s)e.push(a);else{var c=n.services.interpolator.interpolate(r.children[0].content,a,n.language);e.push(c)}}else"text"===r.type&&e.push(r.content);return e},[])}return h(i([{dummy:!0,children:t}],U.parse("<0>"+e+"</0>"))[0])}function v(t,e){for(var n=0,i=t.length;n<i;n++)if("object"===T(t[n])){var r=!0,o=!1,a=void 0;try{for(var s,p=Object.entries(t[n])[Symbol.iterator]();!(r=(s=p.next()).done);r=!0){var c=q(s.value,2),u=c[0];e(c[1],n,u)}}catch(t){o=!0,a=t}finally{try{!r&&p.return&&p.return()}finally{if(o)throw a}}}else e(t[n],n)}function m(t){var e=[];return v(t,function(t){t&&t.namespaces&&t.namespaces.forEach(function(t){-1===e.indexOf(t)&&e.push(t)})}),e}var g="default"in e?e.default:e;n=n&&n.hasOwnProperty("default")?n.default:n;var b={childContextTypes:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,mixins:!0,propTypes:!0,type:!0},S={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},x=Object.defineProperty,O=Object.getOwnPropertyNames,I=Object.getOwnPropertySymbols,j=Object.getOwnPropertyDescriptor,w=Object.getPrototypeOf,P=w&&w(Object),_=function t(e,n,i){if("string"!=typeof n){if(P){var r=w(n);r&&r!==P&&t(e,r,i)}var o=O(n);I&&(o=o.concat(I(n)));for(var a=0;a<o.length;++a){var s=o[a];if(!(b[s]||S[s]||i&&i[s])){var p=j(n,s);try{x(e,s,p)}catch(t){}}}return e}return e},T="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},k=(function(){function t(t){this.value=t}function e(e){function n(r,o){try{var a=e[r](o),s=a.value;s instanceof t?Promise.resolve(s.value).then(function(t){n("next",t)},function(t){n("throw",t)}):i(a.done?"return":"normal",a.value)}catch(t){i("throw",t)}}function i(t,e){switch(t){case"return":r.resolve({value:e,done:!0});break;case"throw":r.reject(e);break;default:r.resolve({value:e,done:!1})}(r=r.next)?n(r.key,r.arg):o=null}var r,o;this._invoke=function(t,e){return new Promise(function(i,a){var s={key:t,arg:e,resolve:i,reject:a,next:null};o?o=o.next=s:(r=o=s,n(t,e))})},"function"!=typeof e.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)}}(),function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}),C=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),E=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},R=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},N=function(t,e){var n={};for(var i in t)e.indexOf(i)>=0||Object.prototype.hasOwnProperty.call(t,i)&&(n[i]=t[i]);return n},L=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},q=function(){function t(t,e){var n=[],i=!0,r=!1,o=void 0;try{for(var a,s=t[Symbol.iterator]();!(i=(a=s.next()).done)&&(n.push(a.value),!e||n.length!==e);i=!0);}catch(t){r=!0,o=t}finally{try{!i&&s.return&&s.return()}finally{if(r)throw o}}return n}return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),A={wait:!1,withRef:!1,bindI18n:"languageChanged loaded",bindStore:"added removed",translateFuncName:"t",nsMode:"default"},W=void 0,M={type:"3rdParty",init:function(t){i(t.options.react),o(t)}},D=!1,K=function(t){function e(t,n){k(this,e);var i=L(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n));i.i18n=n.i18n||t.i18n||a(),i.namespaces=i.props.ns||i.i18n.options.defaultNS,"string"==typeof i.namespaces&&(i.namespaces=[i.namespaces]);var o=i.i18n&&i.i18n.options.react||{};return i.options=E({},r(),o,t),t.initialI18nStore&&(i.i18n.services.resourceStore.data=t.initialI18nStore,i.options.wait=!1),t.initialLanguage&&i.i18n.changeLanguage(t.initialLanguage),i.i18n.options.isInitialSSR&&(i.options.wait=!1),i.state={i18nLoadedAt:null,ready:!1},i.onI18nChanged=i.onI18nChanged.bind(i),i.getI18nTranslate=i.getI18nTranslate.bind(i),i}return R(e,t),C(e,[{key:"getChildContext",value:function(){return{t:this.t,i18n:this.i18n}}},{key:"componentWillMount",value:function(){this.t=this.getI18nTranslate()}},{key:"componentDidMount",value:function(){var t=this,e=function(){t.options.bindI18n&&t.i18n&&t.i18n.on(t.options.bindI18n,t.onI18nChanged),t.options.bindStore&&t.i18n.store&&t.i18n.store.on(t.options.bindStore,t.onI18nChanged)};this.mounted=!0,this.i18n.loadNamespaces(this.namespaces,function(){var n=function(){t.mounted&&!t.state.ready&&t.setState({ready:!0}),t.options.wait&&t.mounted&&e()};if(t.i18n.isInitialized)n();else{t.i18n.on("initialized",function e(){setTimeout(function(){t.i18n.off("initialized",e)},1e3),n()})}}),this.options.wait||e()}},{key:"componentWillUnmount",value:function(){var t=this;this.mounted=!1,this.onI18nChanged&&(this.options.bindI18n&&this.options.bindI18n.split(" ").forEach(function(e){return t.i18n.off(e,t.onI18nChanged)}),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.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 t=this,e=this.props.children;return!this.state.ready&&this.options.wait?null:(this.i18n.options.isInitialSSR&&!D&&(D=!0,setTimeout(function(){delete t.i18n.options.isInitialSSR},100)),e(this.t,{i18n:this.i18n,t:this.t}))}}]),e}(e.Component);K.contextTypes={i18n:n.object},K.childContextTypes={t:n.func.isRequired,i18n:n.object},p.setDefaults=i,p.setI18n=o;var $=function(t){function e(t,n){k(this,e);var i=L(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n));return i.i18n=t.i18n||n.i18n,i.t=t.t||n.t,i}return R(e,t),C(e,[{key:"render",value:function(){var t=this,e=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=E({},this.props.options,{interpolation:{prefix:"#$?",suffix:"?$#"}}),c=this.t(this.props.i18nKey,p);if(!c||"string"!=typeof c)return g.createElement("noscript",null);var u=[],l=function(e,n){if(e.indexOf(t.i18n.options.interpolation.formatSeparator)<0)return void 0===n[e]&&t.i18n.services.logger.warn("interpolator: missed to pass in variable "+e+" for interpolating "+c),n[e];var i=e.split(t.i18n.options.interpolation.formatSeparator),r=i.shift().trim(),o=i.join(t.i18n.options.interpolation.formatSeparator).trim();return void 0===n[r]&&t.i18n.services.logger.warn("interpolator: missed to pass in variable "+r+" for interpolating "+c),t.i18n.options.interpolation.format(n[r],o,t.i18n.language)};c.split(n).reduce(function(e,n,i){var r=void 0;if(i%2==0){if(0===n.length)return e;r=a?g.createElement(s,{dangerouslySetInnerHTML:{__html:n}}):n}else r=l(n,t.props);return e.push(r),e},u);var f={};if(this.i18n.options.react&&this.i18n.options.react.exposeNamespace){var h="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&&(h=this.props.i18nKey.split(this.i18n.options.nsSeparator)[0]),this.t.ns&&(f["data-i18next-options"]=JSON.stringify({ns:h}))}return r&&(f.className=r),o&&(f.style=o),g.createElement.apply(this,[e,f].concat(u))}}]),e}(e.PureComponent);$.propTypes={className:n.string},$.defaultProps={className:""},$.contextTypes={i18n:n.object.isRequired,t:n.func.isRequired};var z={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},H=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,V=function(t){var e,n=0,i=!0,r={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return t.replace(H,function(o){if("="===o)return i=!0,void n++;i?0===n?((z[o]||"/"===t.charAt(t.length-2))&&(r.voidElement=!0),r.name=o):(r.attrs[e]=o.replace(/^['"]|['"]$/g,""),e=void 0):(e&&(r.attrs[e]=e),e=o),n++,i=!1}),r},F=/(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,J=Object.create?Object.create(null):{},U={parse:function(t,e){e||(e={}),e.components||(e.components=J);var n,i=[],r=-1,o=[],a=!1;return t.replace(F,function(s,p){if(a){if(s!=="</"+n.name+">")return;a=!1}var u,l="/"!==s.charAt(1),f=0===s.indexOf("\x3c!--"),h=p+s.length,d=t.charAt(h);l&&!f&&(r++,"tag"===(n=V(s)).type&&e.components[n.name]&&(n.type="component",a=!0),n.voidElement||a||!d||"<"===d||c(n.children,t,r,h,e.ignoreWhitespace),0===r&&i.push(n),(u=o[r-1])&&u.children.push(n),o[r]=n),(f||!l||n.voidElement)&&(f||r--,!a&&"<"!==d&&d&&c(u=-1===r?i:o[r].children,t,r,h,e.ignoreWhitespace))}),!i.length&&t.length&&c(i,t,0,0,e.ignoreWhitespace),i},stringify:function(t){return t.reduce(function(t,e){return t+l("",e)},"")}},B=function(t){function e(t,n){k(this,e);var i=L(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n));return i.i18n=t.i18n||n.i18n,i.t=t.t||n.t,i}return R(e,t),C(e,[{key:"render",value:function(){var t=this.props,e=t.children,n=t.count,i=t.parent,r=t.i18nKey,o=N(t,["children","count","parent","i18nKey"]),a=d("",e,0),s=r||a,p=this.t(s,{interpolation:{prefix:"#$?",suffix:"?$#"},defaultValue:a,count:n});if(this.i18n.options.react&&this.i18n.options.react.exposeNamespace){var c="string"==typeof this.t.ns?this.t.ns:this.t.ns[0];r&&this.i18n.options.nsSeparator&&r.indexOf(this.i18n.options.nsSeparator)>-1&&(c=r.split(this.i18n.options.nsSeparator)[0]),this.t.ns&&(o["data-i18next-options"]=JSON.stringify({ns:c}))}return g.createElement(i,o,y(e,p,this.i18n))}}]),e}(g.PureComponent);B.propTypes={count:n.number,parent:n.string,i18nKey:n.string},B.defaultProps={parent:"div"},B.contextTypes={i18n:n.object.isRequired,t:n.func.isRequired};var G=function(t){function n(t,e){k(this,n);var i=L(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,t,e));return i.i18n=t.i18n,t.initialI18nStore&&(i.i18n.services.resourceStore.data=t.initialI18nStore,i.i18n.options.isInitialSSR=!0),t.initialLanguage&&i.i18n.changeLanguage(t.initialLanguage),i}return R(n,t),C(n,[{key:"getChildContext",value:function(){return{i18n:this.i18n}}},{key:"componentWillReceiveProps",value:function(t){if(this.props.i18n!==t.i18n)throw new Error("[react-i18next][I18nextProvider]does not support changing the i18n object.")}},{key:"render",value:function(){var t=this.props.children;return e.Children.only(t)}}]),n}(e.Component);G.propTypes={i18n:n.object.isRequired,children:n.element.isRequired},G.childContextTypes={i18n:n.object.isRequired},t.translate=p,t.I18n=K,t.Interpolate=$,t.Trans=B,t.I18nextProvider=G,t.loadNamespaces=function(t){var e=t.components,n=t.i18n,i=m(e);return new Promise(function(t){n.loadNamespaces(i,t)})},t.reactI18nextModule=M,t.setDefaults=i,t.getDefaults=r,t.setI18n=o,t.getI18n=a,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react","prop-types"],e):e(t.reactI18next={},t.React,t.PropTypes)}(this,function(t,e,n){"use strict";function i(t){q=E({},q,t)}function r(){return q}function o(t){W=t}function a(){return W}function s(t){return t.displayName||t.name||"Component"}function c(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(o){var c=function(e){function n(e,o){T(this,n);var s=A(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e,o));s.i18n=o.i18n||e.i18n||i.i18n||a(),"string"==typeof(t=t||s.i18n.options.defaultNS)&&(t=[t]);var c=s.i18n&&s.i18n.options.react||{};return s.options=E({},r(),c,i),s.getWrappedInstance=s.getWrappedInstance.bind(s),s}return R(n,e),C(n,[{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,n={};return this.options.withRef&&(n.ref=function(t){e.wrappedInstance=t}),g.createElement(K,E({ns:t},this.options,this.props,{i18n:this.i18n}),function(t,i){return g.createElement(o,E({},e.props,n,i))})}}]),n}(e.Component);return c.WrappedComponent=o,c.contextTypes={i18n:n.object},c.displayName="Translate("+s(o)+")",c.namespaces=t,_(c,o)}}function p(t,e,n,i,r){var o=e.indexOf("<",i),a=e.slice(i,-1===o?void 0:o);/^\s*$/.test(a)&&(a=" "),(!r&&o>-1&&n+t.length>=0||" "!==a)&&t.push({type:"text",content:a})}function u(t){var e=[];for(var n in t)e.push(n+'="'+t[n]+'"');return e.length?" "+e.join(" "):""}function l(t,e){switch(e.type){case"text":return t+e.content;case"tag":return t+="<"+e.name+(e.attrs?u(e.attrs):"")+(e.voidElement?"/>":">"),e.voidElement?t:t+e.children.reduce(l,"")+"</"+e.name+">"}}function f(t){return t&&(t.children||t.props&&t.props.children)}function h(t){return t&&t.children?t.children:t.props&&t.props.children}function d(t,e,n){return"[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),e.forEach(function(e,n){var i=""+n;if("string"==typeof e)t=""+t+e;else if(f(e))t=t+"<"+i+">"+d("",h(e),n+1)+"</"+i+">";else if(g.isValidElement(e))t=t+"<"+i+"></"+i+">";else if("object"===(void 0===e?"undefined":k(e))){var r=E({},e),o=r.format;delete r.format;var a=Object.keys(r);o&&1===a.length?t=t+"<"+i+">{{"+a[0]+", "+o+"}}</"+i+">":1===a.length&&(t=t+"<"+i+">{{"+a[0]+"}}</"+i+">")}}),t}function y(t,e,n){function i(t,e){return"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),"[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),e.reduce(function(e,r,o){if("tag"===r.type){var a=t[parseInt(r.name,10)]||{},s=g.isValidElement(a);if("string"==typeof a)e.push(a);else if(f(a)){var c=i(h(a),r.children);a.dummy&&(a.children=c),e.push(g.cloneElement(a,E({},a.props,{key:o}),c))}else if("object"!==(void 0===a?"undefined":k(a))||s)e.push(a);else{var p=n.services.interpolator.interpolate(r.children[0].content,a,n.language);e.push(p)}}else"text"===r.type&&e.push(r.content);return e},[])}return h(i([{dummy:!0,children:t}],U.parse("<0>"+e+"</0>"))[0])}function v(t,e){for(var n=0,i=t.length;n<i;n++)if("object"===k(t[n])){var r=!0,o=!1,a=void 0;try{for(var s,c=Object.entries(t[n])[Symbol.iterator]();!(r=(s=c.next()).done);r=!0){var p=L(s.value,2),u=p[0];e(p[1],n,u)}}catch(t){o=!0,a=t}finally{try{!r&&c.return&&c.return()}finally{if(o)throw a}}}else e(t[n],n)}function m(t){var e=[];return v(t,function(t){t&&t.namespaces&&t.namespaces.forEach(function(t){-1===e.indexOf(t)&&e.push(t)})}),e}var g="default"in e?e.default:e;n=n&&n.hasOwnProperty("default")?n.default:n;var b={childContextTypes:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,mixins:!0,propTypes:!0,type:!0},S={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},O=Object.defineProperty,x=Object.getOwnPropertyNames,j=Object.getOwnPropertySymbols,w=Object.getOwnPropertyDescriptor,I=Object.getPrototypeOf,P=I&&I(Object),_=function t(e,n,i){if("string"!=typeof n){if(P){var r=I(n);r&&r!==P&&t(e,r,i)}var o=x(n);j&&(o=o.concat(j(n)));for(var a=0;a<o.length;++a){var s=o[a];if(!(b[s]||S[s]||i&&i[s])){var c=w(n,s);try{O(e,s,c)}catch(t){}}}return e}return e},k="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},T=(function(){function t(t){this.value=t}function e(e){function n(r,o){try{var a=e[r](o),s=a.value;s instanceof t?Promise.resolve(s.value).then(function(t){n("next",t)},function(t){n("throw",t)}):i(a.done?"return":"normal",a.value)}catch(t){i("throw",t)}}function i(t,e){switch(t){case"return":r.resolve({value:e,done:!0});break;case"throw":r.reject(e);break;default:r.resolve({value:e,done:!1})}(r=r.next)?n(r.key,r.arg):o=null}var r,o;this._invoke=function(t,e){return new Promise(function(i,a){var s={key:t,arg:e,resolve:i,reject:a,next:null};o?o=o.next=s:(r=o=s,n(t,e))})},"function"!=typeof e.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)}}(),function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}),C=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),E=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},R=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},N=function(t,e){var n={};for(var i in t)e.indexOf(i)>=0||Object.prototype.hasOwnProperty.call(t,i)&&(n[i]=t[i]);return n},A=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},L=function(){function t(t,e){var n=[],i=!0,r=!1,o=void 0;try{for(var a,s=t[Symbol.iterator]();!(i=(a=s.next()).done)&&(n.push(a.value),!e||n.length!==e);i=!0);}catch(t){r=!0,o=t}finally{try{!i&&s.return&&s.return()}finally{if(r)throw o}}return n}return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),q={wait:!1,withRef:!1,bindI18n:"languageChanged loaded",bindStore:"added removed",translateFuncName:"t",nsMode:"default"},W=void 0,M={type:"3rdParty",init:function(t){i(t.options.react),o(t)}},D=!1,K=function(t){function e(t,n){T(this,e);var i=A(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n));i.i18n=n.i18n||t.i18n||a(),i.namespaces=i.props.ns||i.i18n.options.defaultNS,"string"==typeof i.namespaces&&(i.namespaces=[i.namespaces]);var o=i.i18n&&i.i18n.options.react||{};return i.options=E({},r(),o,t),t.initialI18nStore&&(i.i18n.services.resourceStore.data=t.initialI18nStore,i.options.wait=!1),t.initialLanguage&&i.i18n.changeLanguage(t.initialLanguage),i.i18n.options.isInitialSSR&&(i.options.wait=!1),i.state={i18nLoadedAt:null,ready:!1},i.onI18nChanged=i.onI18nChanged.bind(i),i.getI18nTranslate=i.getI18nTranslate.bind(i),i}return R(e,t),C(e,[{key:"getChildContext",value:function(){return{t:this.t,i18n:this.i18n}}},{key:"componentWillMount",value:function(){this.t=this.getI18nTranslate()}},{key:"componentDidMount",value:function(){var t=this,e=function(){t.options.bindI18n&&t.i18n&&t.i18n.on(t.options.bindI18n,t.onI18nChanged),t.options.bindStore&&t.i18n.store&&t.i18n.store.on(t.options.bindStore,t.onI18nChanged)};this.mounted=!0,this.i18n.loadNamespaces(this.namespaces,function(){var n=function(){t.mounted&&!t.state.ready&&t.setState({ready:!0}),t.options.wait&&t.mounted&&e()};if(t.i18n.isInitialized)n();else{t.i18n.on("initialized",function e(){setTimeout(function(){t.i18n.off("initialized",e)},1e3),n()})}}),this.options.wait||e()}},{key:"componentWillUnmount",value:function(){var t=this;this.mounted=!1,this.onI18nChanged&&(this.options.bindI18n&&this.options.bindI18n.split(" ").forEach(function(e){return t.i18n.off(e,t.onI18nChanged)}),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.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 t=this,e=this.props.children;return!this.state.ready&&this.options.wait?null:(this.i18n.options.isInitialSSR&&!D&&(D=!0,setTimeout(function(){delete t.i18n.options.isInitialSSR},100)),e(this.t,{i18n:this.i18n,t:this.t}))}}]),e}(e.Component);K.contextTypes={i18n:n.object},K.childContextTypes={t:n.func.isRequired,i18n:n.object},c.setDefaults=i,c.setI18n=o;var $=function(t){function e(t,n){T(this,e);var i=A(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n));return i.i18n=t.i18n||n.i18n,i.t=t.t||n.t,i}return R(e,t),C(e,[{key:"render",value:function(){var t=this,e=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",c=E({},this.props.options,{interpolation:{prefix:"#$?",suffix:"?$#"}}),p=this.t(this.props.i18nKey,c);if(!p||"string"!=typeof p)return g.createElement("noscript",null);var u=[],l=function(e,n){if(e.indexOf(t.i18n.options.interpolation.formatSeparator)<0)return void 0===n[e]&&t.i18n.services.logger.warn("interpolator: missed to pass in variable "+e+" for interpolating "+p),n[e];var i=e.split(t.i18n.options.interpolation.formatSeparator),r=i.shift().trim(),o=i.join(t.i18n.options.interpolation.formatSeparator).trim();return void 0===n[r]&&t.i18n.services.logger.warn("interpolator: missed to pass in variable "+r+" for interpolating "+p),t.i18n.options.interpolation.format(n[r],o,t.i18n.language)};p.split(n).reduce(function(e,n,i){var r=void 0;if(i%2==0){if(0===n.length)return e;r=a?g.createElement(s,{dangerouslySetInnerHTML:{__html:n}}):n}else r=l(n,t.props);return e.push(r),e},u);var f={};if(this.i18n.options.react&&this.i18n.options.react.exposeNamespace){var h="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&&(h=this.props.i18nKey.split(this.i18n.options.nsSeparator)[0]),this.t.ns&&(f["data-i18next-options"]=JSON.stringify({ns:h}))}return r&&(f.className=r),o&&(f.style=o),g.createElement.apply(this,[e,f].concat(u))}}]),e}(e.PureComponent);$.propTypes={className:n.string},$.defaultProps={className:""},$.contextTypes={i18n:n.object.isRequired,t:n.func.isRequired};var z={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},H=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,V=function(t){var e,n=0,i=!0,r={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return t.replace(H,function(o){if("="===o)return i=!0,void n++;i?0===n?((z[o]||"/"===t.charAt(t.length-2))&&(r.voidElement=!0),r.name=o):(r.attrs[e]=o.replace(/^['"]|['"]$/g,""),e=void 0):(e&&(r.attrs[e]=e),e=o),n++,i=!1}),r},F=/(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,J=Object.create?Object.create(null):{},U={parse:function(t,e){e||(e={}),e.components||(e.components=J);var n,i=[],r=-1,o=[],a=!1;return t.replace(F,function(s,c){if(a){if(s!=="</"+n.name+">")return;a=!1}var u,l="/"!==s.charAt(1),f=0===s.indexOf("\x3c!--"),h=c+s.length,d=t.charAt(h);l&&!f&&(r++,"tag"===(n=V(s)).type&&e.components[n.name]&&(n.type="component",a=!0),n.voidElement||a||!d||"<"===d||p(n.children,t,r,h,e.ignoreWhitespace),0===r&&i.push(n),(u=o[r-1])&&u.children.push(n),o[r]=n),(f||!l||n.voidElement)&&(f||r--,!a&&"<"!==d&&d&&p(u=-1===r?i:o[r].children,t,r,h,e.ignoreWhitespace))}),!i.length&&t.length&&p(i,t,0,0,e.ignoreWhitespace),i},stringify:function(t){return t.reduce(function(t,e){return t+l("",e)},"")}},B=function(t){function e(){return T(this,e),A(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return R(e,t),C(e,[{key:"render",value:function(){var t=E({i18n:this.context.i18n,t:this.context.t},this.props),e=t.children,n=t.count,i=t.parent,r=t.i18nKey,o=t.i18n,a=t.t,s=N(t,["children","count","parent","i18nKey","i18n","t"]),c=d("",e,0),p=a(r||c,{interpolation:{prefix:"#$?",suffix:"?$#"},defaultValue:c,count:n});if(o.options.react&&o.options.react.exposeNamespace){var u="string"==typeof a.ns?a.ns:a.ns[0];r&&o.options.nsSeparator&&r.indexOf(o.options.nsSeparator)>-1&&(u=r.split(o.options.nsSeparator)[0]),a.ns&&(s["data-i18next-options"]=JSON.stringify({ns:u}))}return g.createElement(i,s,y(e,p,o))}}]),e}(g.PureComponent);B.propTypes={count:n.number,parent:n.string,i18nKey:n.string,i18n:n.object,t:n.func},B.defaultProps={parent:"div"},B.contextTypes={i18n:n.object.isRequired,t:n.func.isRequired};var G=function(t){function n(t,e){T(this,n);var i=A(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,t,e));return i.i18n=t.i18n,t.initialI18nStore&&(i.i18n.services.resourceStore.data=t.initialI18nStore,i.i18n.options.isInitialSSR=!0),t.initialLanguage&&i.i18n.changeLanguage(t.initialLanguage),i}return R(n,t),C(n,[{key:"getChildContext",value:function(){return{i18n:this.i18n}}},{key:"componentWillReceiveProps",value:function(t){if(this.props.i18n!==t.i18n)throw new Error("[react-i18next][I18nextProvider]does not support changing the i18n object.")}},{key:"render",value:function(){var t=this.props.children;return e.Children.only(t)}}]),n}(e.Component);G.propTypes={i18n:n.object.isRequired,children:n.element.isRequired},G.childContextTypes={i18n:n.object.isRequired},Object.entries||(Object.entries=function(t){for(var e=Object.keys(t),n=e.length,i=new Array(n);n--;)i[n]=[e[n],t[e[n]]];return i}),t.translate=c,t.I18n=K,t.Interpolate=$,t.Trans=B,t.I18nextProvider=G,t.loadNamespaces=function(t){var e=t.components,n=t.i18n,i=m(e);return new Promise(function(t){n.loadNamespaces(i,t)})},t.reactI18nextModule=M,t.setDefaults=i,t.getDefaults=r,t.setI18n=o,t.getI18n=a,Object.defineProperty(t,"__esModule",{value:!0})}); |
{ | ||
"name": "react-i18next", | ||
"version": "6.0.4", | ||
"version": "6.0.5", | ||
"description": "Internationalization for react done right. Using the i18next i18n ecosystem.", | ||
@@ -5,0 +5,0 @@ "main": "dist/commonjs/index.js", |
@@ -993,10 +993,5 @@ (function (global, factory) { | ||
function Trans(props, context) { | ||
function Trans() { | ||
classCallCheck(this, Trans); | ||
var _this = possibleConstructorReturn(this, (Trans.__proto__ || Object.getPrototypeOf(Trans)).call(this, props, context)); | ||
_this.i18n = props.i18n || context.i18n; | ||
_this.t = props.t || context.t; | ||
return _this; | ||
return possibleConstructorReturn(this, (Trans.__proto__ || Object.getPrototypeOf(Trans)).apply(this, arguments)); | ||
} | ||
@@ -1007,8 +1002,10 @@ | ||
value: function render() { | ||
var _props = this.props, | ||
children = _props.children, | ||
count = _props.count, | ||
parent = _props.parent, | ||
i18nKey = _props.i18nKey, | ||
additionalProps = objectWithoutProperties(_props, ['children', 'count', 'parent', 'i18nKey']); | ||
var contextAndProps = _extends({ i18n: this.context.i18n, t: this.context.t }, this.props); | ||
var children = contextAndProps.children, | ||
count = contextAndProps.count, | ||
parent = contextAndProps.parent, | ||
i18nKey = contextAndProps.i18nKey, | ||
i18n = contextAndProps.i18n, | ||
t = contextAndProps.t, | ||
additionalProps = objectWithoutProperties(contextAndProps, ['children', 'count', 'parent', 'i18nKey', 'i18n', 't']); | ||
@@ -1018,14 +1015,14 @@ | ||
var key = i18nKey || defaultValue; | ||
var translation = this.t(key, { interpolation: { prefix: '#$?', suffix: '?$#' }, defaultValue: defaultValue, count: count }); | ||
var translation = t(key, { interpolation: { prefix: '#$?', suffix: '?$#' }, defaultValue: defaultValue, count: count }); | ||
if (this.i18n.options.react && this.i18n.options.react.exposeNamespace) { | ||
var ns = typeof this.t.ns === 'string' ? this.t.ns : this.t.ns[0]; | ||
if (i18nKey && this.i18n.options.nsSeparator && i18nKey.indexOf(this.i18n.options.nsSeparator) > -1) { | ||
var parts = i18nKey.split(this.i18n.options.nsSeparator); | ||
if (i18n.options.react && i18n.options.react.exposeNamespace) { | ||
var ns = typeof t.ns === 'string' ? t.ns : t.ns[0]; | ||
if (i18nKey && i18n.options.nsSeparator && i18nKey.indexOf(i18n.options.nsSeparator) > -1) { | ||
var parts = i18nKey.split(i18n.options.nsSeparator); | ||
ns = parts[0]; | ||
} | ||
if (this.t.ns) additionalProps['data-i18next-options'] = JSON.stringify({ ns: ns }); | ||
if (t.ns) additionalProps['data-i18next-options'] = JSON.stringify({ ns: ns }); | ||
} | ||
return React__default.createElement(parent, additionalProps, renderNodes(children, translation, this.i18n)); | ||
return React__default.createElement(parent, additionalProps, renderNodes(children, translation, i18n)); | ||
} | ||
@@ -1039,3 +1036,5 @@ }]); | ||
parent: PropTypes.string, | ||
i18nKey: PropTypes.string | ||
i18nKey: PropTypes.string, | ||
i18n: PropTypes.object, | ||
t: PropTypes.func | ||
}; | ||
@@ -1103,2 +1102,12 @@ | ||
// shim object entries | ||
if (!Object.entries) Object.entries = function (obj) { | ||
var ownProps = Object.keys(obj), | ||
i = ownProps.length, | ||
resArray = new Array(i); // preallocate the Array | ||
while (i--) { | ||
resArray[i] = [ownProps[i], obj[ownProps[i]]]; | ||
}return resArray; | ||
}; | ||
// Borrowed from https://github.com/Rezonans/redux-async-connect/blob/master/modules/ReduxAsyncConnect.js#L16 | ||
@@ -1105,0 +1114,0 @@ function eachComponents(components, iterator) { |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react","prop-types"],e):e(t.reactI18next={},t.React,t.PropTypes)}(this,function(t,e,n){"use strict";function i(t){A=E({},A,t)}function r(){return A}function o(t){W=t}function a(){return W}function s(t){return t.displayName||t.name||"Component"}function p(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(o){var p=function(e){function n(e,o){k(this,n);var s=L(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e,o));s.i18n=o.i18n||e.i18n||i.i18n||a(),"string"==typeof(t=t||s.i18n.options.defaultNS)&&(t=[t]);var p=s.i18n&&s.i18n.options.react||{};return s.options=E({},r(),p,i),s.getWrappedInstance=s.getWrappedInstance.bind(s),s}return R(n,e),C(n,[{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,n={};return this.options.withRef&&(n.ref=function(t){e.wrappedInstance=t}),g.createElement(K,E({ns:t},this.options,this.props,{i18n:this.i18n}),function(t,i){return g.createElement(o,E({},e.props,n,i))})}}]),n}(e.Component);return p.WrappedComponent=o,p.contextTypes={i18n:n.object},p.displayName="Translate("+s(o)+")",p.namespaces=t,_(p,o)}}function c(t,e,n,i,r){var o=e.indexOf("<",i),a=e.slice(i,-1===o?void 0:o);/^\s*$/.test(a)&&(a=" "),(!r&&o>-1&&n+t.length>=0||" "!==a)&&t.push({type:"text",content:a})}function u(t){var e=[];for(var n in t)e.push(n+'="'+t[n]+'"');return e.length?" "+e.join(" "):""}function l(t,e){switch(e.type){case"text":return t+e.content;case"tag":return t+="<"+e.name+(e.attrs?u(e.attrs):"")+(e.voidElement?"/>":">"),e.voidElement?t:t+e.children.reduce(l,"")+"</"+e.name+">"}}function f(t){return t&&(t.children||t.props&&t.props.children)}function h(t){return t&&t.children?t.children:t.props&&t.props.children}function d(t,e,n){return"[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),e.forEach(function(e,n){var i=""+n;if("string"==typeof e)t=""+t+e;else if(f(e))t=t+"<"+i+">"+d("",h(e),n+1)+"</"+i+">";else if(g.isValidElement(e))t=t+"<"+i+"></"+i+">";else if("object"===(void 0===e?"undefined":T(e))){var r=E({},e),o=r.format;delete r.format;var a=Object.keys(r);o&&1===a.length?t=t+"<"+i+">{{"+a[0]+", "+o+"}}</"+i+">":1===a.length&&(t=t+"<"+i+">{{"+a[0]+"}}</"+i+">")}}),t}function y(t,e,n){function i(t,e){return"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),"[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),e.reduce(function(e,r,o){if("tag"===r.type){var a=t[parseInt(r.name,10)]||{},s=g.isValidElement(a);if("string"==typeof a)e.push(a);else if(f(a)){var p=i(h(a),r.children);a.dummy&&(a.children=p),e.push(g.cloneElement(a,E({},a.props,{key:o}),p))}else if("object"!==(void 0===a?"undefined":T(a))||s)e.push(a);else{var c=n.services.interpolator.interpolate(r.children[0].content,a,n.language);e.push(c)}}else"text"===r.type&&e.push(r.content);return e},[])}return h(i([{dummy:!0,children:t}],U.parse("<0>"+e+"</0>"))[0])}function v(t,e){for(var n=0,i=t.length;n<i;n++)if("object"===T(t[n])){var r=!0,o=!1,a=void 0;try{for(var s,p=Object.entries(t[n])[Symbol.iterator]();!(r=(s=p.next()).done);r=!0){var c=q(s.value,2),u=c[0];e(c[1],n,u)}}catch(t){o=!0,a=t}finally{try{!r&&p.return&&p.return()}finally{if(o)throw a}}}else e(t[n],n)}function m(t){var e=[];return v(t,function(t){t&&t.namespaces&&t.namespaces.forEach(function(t){-1===e.indexOf(t)&&e.push(t)})}),e}var g="default"in e?e.default:e;n=n&&n.hasOwnProperty("default")?n.default:n;var b={childContextTypes:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,mixins:!0,propTypes:!0,type:!0},S={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},x=Object.defineProperty,O=Object.getOwnPropertyNames,I=Object.getOwnPropertySymbols,j=Object.getOwnPropertyDescriptor,w=Object.getPrototypeOf,P=w&&w(Object),_=function t(e,n,i){if("string"!=typeof n){if(P){var r=w(n);r&&r!==P&&t(e,r,i)}var o=O(n);I&&(o=o.concat(I(n)));for(var a=0;a<o.length;++a){var s=o[a];if(!(b[s]||S[s]||i&&i[s])){var p=j(n,s);try{x(e,s,p)}catch(t){}}}return e}return e},T="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},k=(function(){function t(t){this.value=t}function e(e){function n(r,o){try{var a=e[r](o),s=a.value;s instanceof t?Promise.resolve(s.value).then(function(t){n("next",t)},function(t){n("throw",t)}):i(a.done?"return":"normal",a.value)}catch(t){i("throw",t)}}function i(t,e){switch(t){case"return":r.resolve({value:e,done:!0});break;case"throw":r.reject(e);break;default:r.resolve({value:e,done:!1})}(r=r.next)?n(r.key,r.arg):o=null}var r,o;this._invoke=function(t,e){return new Promise(function(i,a){var s={key:t,arg:e,resolve:i,reject:a,next:null};o?o=o.next=s:(r=o=s,n(t,e))})},"function"!=typeof e.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)}}(),function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}),C=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),E=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},R=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},N=function(t,e){var n={};for(var i in t)e.indexOf(i)>=0||Object.prototype.hasOwnProperty.call(t,i)&&(n[i]=t[i]);return n},L=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},q=function(){function t(t,e){var n=[],i=!0,r=!1,o=void 0;try{for(var a,s=t[Symbol.iterator]();!(i=(a=s.next()).done)&&(n.push(a.value),!e||n.length!==e);i=!0);}catch(t){r=!0,o=t}finally{try{!i&&s.return&&s.return()}finally{if(r)throw o}}return n}return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),A={wait:!1,withRef:!1,bindI18n:"languageChanged loaded",bindStore:"added removed",translateFuncName:"t",nsMode:"default"},W=void 0,M={type:"3rdParty",init:function(t){i(t.options.react),o(t)}},D=!1,K=function(t){function e(t,n){k(this,e);var i=L(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n));i.i18n=n.i18n||t.i18n||a(),i.namespaces=i.props.ns||i.i18n.options.defaultNS,"string"==typeof i.namespaces&&(i.namespaces=[i.namespaces]);var o=i.i18n&&i.i18n.options.react||{};return i.options=E({},r(),o,t),t.initialI18nStore&&(i.i18n.services.resourceStore.data=t.initialI18nStore,i.options.wait=!1),t.initialLanguage&&i.i18n.changeLanguage(t.initialLanguage),i.i18n.options.isInitialSSR&&(i.options.wait=!1),i.state={i18nLoadedAt:null,ready:!1},i.onI18nChanged=i.onI18nChanged.bind(i),i.getI18nTranslate=i.getI18nTranslate.bind(i),i}return R(e,t),C(e,[{key:"getChildContext",value:function(){return{t:this.t,i18n:this.i18n}}},{key:"componentWillMount",value:function(){this.t=this.getI18nTranslate()}},{key:"componentDidMount",value:function(){var t=this,e=function(){t.options.bindI18n&&t.i18n&&t.i18n.on(t.options.bindI18n,t.onI18nChanged),t.options.bindStore&&t.i18n.store&&t.i18n.store.on(t.options.bindStore,t.onI18nChanged)};this.mounted=!0,this.i18n.loadNamespaces(this.namespaces,function(){var n=function(){t.mounted&&!t.state.ready&&t.setState({ready:!0}),t.options.wait&&t.mounted&&e()};if(t.i18n.isInitialized)n();else{t.i18n.on("initialized",function e(){setTimeout(function(){t.i18n.off("initialized",e)},1e3),n()})}}),this.options.wait||e()}},{key:"componentWillUnmount",value:function(){var t=this;this.mounted=!1,this.onI18nChanged&&(this.options.bindI18n&&this.options.bindI18n.split(" ").forEach(function(e){return t.i18n.off(e,t.onI18nChanged)}),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.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 t=this,e=this.props.children;return!this.state.ready&&this.options.wait?null:(this.i18n.options.isInitialSSR&&!D&&(D=!0,setTimeout(function(){delete t.i18n.options.isInitialSSR},100)),e(this.t,{i18n:this.i18n,t:this.t}))}}]),e}(e.Component);K.contextTypes={i18n:n.object},K.childContextTypes={t:n.func.isRequired,i18n:n.object},p.setDefaults=i,p.setI18n=o;var $=function(t){function e(t,n){k(this,e);var i=L(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n));return i.i18n=t.i18n||n.i18n,i.t=t.t||n.t,i}return R(e,t),C(e,[{key:"render",value:function(){var t=this,e=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=E({},this.props.options,{interpolation:{prefix:"#$?",suffix:"?$#"}}),c=this.t(this.props.i18nKey,p);if(!c||"string"!=typeof c)return g.createElement("noscript",null);var u=[],l=function(e,n){if(e.indexOf(t.i18n.options.interpolation.formatSeparator)<0)return void 0===n[e]&&t.i18n.services.logger.warn("interpolator: missed to pass in variable "+e+" for interpolating "+c),n[e];var i=e.split(t.i18n.options.interpolation.formatSeparator),r=i.shift().trim(),o=i.join(t.i18n.options.interpolation.formatSeparator).trim();return void 0===n[r]&&t.i18n.services.logger.warn("interpolator: missed to pass in variable "+r+" for interpolating "+c),t.i18n.options.interpolation.format(n[r],o,t.i18n.language)};c.split(n).reduce(function(e,n,i){var r=void 0;if(i%2==0){if(0===n.length)return e;r=a?g.createElement(s,{dangerouslySetInnerHTML:{__html:n}}):n}else r=l(n,t.props);return e.push(r),e},u);var f={};if(this.i18n.options.react&&this.i18n.options.react.exposeNamespace){var h="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&&(h=this.props.i18nKey.split(this.i18n.options.nsSeparator)[0]),this.t.ns&&(f["data-i18next-options"]=JSON.stringify({ns:h}))}return r&&(f.className=r),o&&(f.style=o),g.createElement.apply(this,[e,f].concat(u))}}]),e}(e.PureComponent);$.propTypes={className:n.string},$.defaultProps={className:""},$.contextTypes={i18n:n.object.isRequired,t:n.func.isRequired};var z={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},H=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,V=function(t){var e,n=0,i=!0,r={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return t.replace(H,function(o){if("="===o)return i=!0,void n++;i?0===n?((z[o]||"/"===t.charAt(t.length-2))&&(r.voidElement=!0),r.name=o):(r.attrs[e]=o.replace(/^['"]|['"]$/g,""),e=void 0):(e&&(r.attrs[e]=e),e=o),n++,i=!1}),r},F=/(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,J=Object.create?Object.create(null):{},U={parse:function(t,e){e||(e={}),e.components||(e.components=J);var n,i=[],r=-1,o=[],a=!1;return t.replace(F,function(s,p){if(a){if(s!=="</"+n.name+">")return;a=!1}var u,l="/"!==s.charAt(1),f=0===s.indexOf("\x3c!--"),h=p+s.length,d=t.charAt(h);l&&!f&&(r++,"tag"===(n=V(s)).type&&e.components[n.name]&&(n.type="component",a=!0),n.voidElement||a||!d||"<"===d||c(n.children,t,r,h,e.ignoreWhitespace),0===r&&i.push(n),(u=o[r-1])&&u.children.push(n),o[r]=n),(f||!l||n.voidElement)&&(f||r--,!a&&"<"!==d&&d&&c(u=-1===r?i:o[r].children,t,r,h,e.ignoreWhitespace))}),!i.length&&t.length&&c(i,t,0,0,e.ignoreWhitespace),i},stringify:function(t){return t.reduce(function(t,e){return t+l("",e)},"")}},B=function(t){function e(t,n){k(this,e);var i=L(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n));return i.i18n=t.i18n||n.i18n,i.t=t.t||n.t,i}return R(e,t),C(e,[{key:"render",value:function(){var t=this.props,e=t.children,n=t.count,i=t.parent,r=t.i18nKey,o=N(t,["children","count","parent","i18nKey"]),a=d("",e,0),s=r||a,p=this.t(s,{interpolation:{prefix:"#$?",suffix:"?$#"},defaultValue:a,count:n});if(this.i18n.options.react&&this.i18n.options.react.exposeNamespace){var c="string"==typeof this.t.ns?this.t.ns:this.t.ns[0];r&&this.i18n.options.nsSeparator&&r.indexOf(this.i18n.options.nsSeparator)>-1&&(c=r.split(this.i18n.options.nsSeparator)[0]),this.t.ns&&(o["data-i18next-options"]=JSON.stringify({ns:c}))}return g.createElement(i,o,y(e,p,this.i18n))}}]),e}(g.PureComponent);B.propTypes={count:n.number,parent:n.string,i18nKey:n.string},B.defaultProps={parent:"div"},B.contextTypes={i18n:n.object.isRequired,t:n.func.isRequired};var G=function(t){function n(t,e){k(this,n);var i=L(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,t,e));return i.i18n=t.i18n,t.initialI18nStore&&(i.i18n.services.resourceStore.data=t.initialI18nStore,i.i18n.options.isInitialSSR=!0),t.initialLanguage&&i.i18n.changeLanguage(t.initialLanguage),i}return R(n,t),C(n,[{key:"getChildContext",value:function(){return{i18n:this.i18n}}},{key:"componentWillReceiveProps",value:function(t){if(this.props.i18n!==t.i18n)throw new Error("[react-i18next][I18nextProvider]does not support changing the i18n object.")}},{key:"render",value:function(){var t=this.props.children;return e.Children.only(t)}}]),n}(e.Component);G.propTypes={i18n:n.object.isRequired,children:n.element.isRequired},G.childContextTypes={i18n:n.object.isRequired},t.translate=p,t.I18n=K,t.Interpolate=$,t.Trans=B,t.I18nextProvider=G,t.loadNamespaces=function(t){var e=t.components,n=t.i18n,i=m(e);return new Promise(function(t){n.loadNamespaces(i,t)})},t.reactI18nextModule=M,t.setDefaults=i,t.getDefaults=r,t.setI18n=o,t.getI18n=a,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react","prop-types"],e):e(t.reactI18next={},t.React,t.PropTypes)}(this,function(t,e,n){"use strict";function i(t){q=E({},q,t)}function r(){return q}function o(t){W=t}function a(){return W}function s(t){return t.displayName||t.name||"Component"}function c(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(o){var c=function(e){function n(e,o){T(this,n);var s=A(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e,o));s.i18n=o.i18n||e.i18n||i.i18n||a(),"string"==typeof(t=t||s.i18n.options.defaultNS)&&(t=[t]);var c=s.i18n&&s.i18n.options.react||{};return s.options=E({},r(),c,i),s.getWrappedInstance=s.getWrappedInstance.bind(s),s}return R(n,e),C(n,[{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,n={};return this.options.withRef&&(n.ref=function(t){e.wrappedInstance=t}),g.createElement(K,E({ns:t},this.options,this.props,{i18n:this.i18n}),function(t,i){return g.createElement(o,E({},e.props,n,i))})}}]),n}(e.Component);return c.WrappedComponent=o,c.contextTypes={i18n:n.object},c.displayName="Translate("+s(o)+")",c.namespaces=t,_(c,o)}}function p(t,e,n,i,r){var o=e.indexOf("<",i),a=e.slice(i,-1===o?void 0:o);/^\s*$/.test(a)&&(a=" "),(!r&&o>-1&&n+t.length>=0||" "!==a)&&t.push({type:"text",content:a})}function u(t){var e=[];for(var n in t)e.push(n+'="'+t[n]+'"');return e.length?" "+e.join(" "):""}function l(t,e){switch(e.type){case"text":return t+e.content;case"tag":return t+="<"+e.name+(e.attrs?u(e.attrs):"")+(e.voidElement?"/>":">"),e.voidElement?t:t+e.children.reduce(l,"")+"</"+e.name+">"}}function f(t){return t&&(t.children||t.props&&t.props.children)}function h(t){return t&&t.children?t.children:t.props&&t.props.children}function d(t,e,n){return"[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),e.forEach(function(e,n){var i=""+n;if("string"==typeof e)t=""+t+e;else if(f(e))t=t+"<"+i+">"+d("",h(e),n+1)+"</"+i+">";else if(g.isValidElement(e))t=t+"<"+i+"></"+i+">";else if("object"===(void 0===e?"undefined":k(e))){var r=E({},e),o=r.format;delete r.format;var a=Object.keys(r);o&&1===a.length?t=t+"<"+i+">{{"+a[0]+", "+o+"}}</"+i+">":1===a.length&&(t=t+"<"+i+">{{"+a[0]+"}}</"+i+">")}}),t}function y(t,e,n){function i(t,e){return"[object Array]"!==Object.prototype.toString.call(t)&&(t=[t]),"[object Array]"!==Object.prototype.toString.call(e)&&(e=[e]),e.reduce(function(e,r,o){if("tag"===r.type){var a=t[parseInt(r.name,10)]||{},s=g.isValidElement(a);if("string"==typeof a)e.push(a);else if(f(a)){var c=i(h(a),r.children);a.dummy&&(a.children=c),e.push(g.cloneElement(a,E({},a.props,{key:o}),c))}else if("object"!==(void 0===a?"undefined":k(a))||s)e.push(a);else{var p=n.services.interpolator.interpolate(r.children[0].content,a,n.language);e.push(p)}}else"text"===r.type&&e.push(r.content);return e},[])}return h(i([{dummy:!0,children:t}],U.parse("<0>"+e+"</0>"))[0])}function v(t,e){for(var n=0,i=t.length;n<i;n++)if("object"===k(t[n])){var r=!0,o=!1,a=void 0;try{for(var s,c=Object.entries(t[n])[Symbol.iterator]();!(r=(s=c.next()).done);r=!0){var p=L(s.value,2),u=p[0];e(p[1],n,u)}}catch(t){o=!0,a=t}finally{try{!r&&c.return&&c.return()}finally{if(o)throw a}}}else e(t[n],n)}function m(t){var e=[];return v(t,function(t){t&&t.namespaces&&t.namespaces.forEach(function(t){-1===e.indexOf(t)&&e.push(t)})}),e}var g="default"in e?e.default:e;n=n&&n.hasOwnProperty("default")?n.default:n;var b={childContextTypes:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,mixins:!0,propTypes:!0,type:!0},S={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},O=Object.defineProperty,x=Object.getOwnPropertyNames,j=Object.getOwnPropertySymbols,w=Object.getOwnPropertyDescriptor,I=Object.getPrototypeOf,P=I&&I(Object),_=function t(e,n,i){if("string"!=typeof n){if(P){var r=I(n);r&&r!==P&&t(e,r,i)}var o=x(n);j&&(o=o.concat(j(n)));for(var a=0;a<o.length;++a){var s=o[a];if(!(b[s]||S[s]||i&&i[s])){var c=w(n,s);try{O(e,s,c)}catch(t){}}}return e}return e},k="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},T=(function(){function t(t){this.value=t}function e(e){function n(r,o){try{var a=e[r](o),s=a.value;s instanceof t?Promise.resolve(s.value).then(function(t){n("next",t)},function(t){n("throw",t)}):i(a.done?"return":"normal",a.value)}catch(t){i("throw",t)}}function i(t,e){switch(t){case"return":r.resolve({value:e,done:!0});break;case"throw":r.reject(e);break;default:r.resolve({value:e,done:!1})}(r=r.next)?n(r.key,r.arg):o=null}var r,o;this._invoke=function(t,e){return new Promise(function(i,a){var s={key:t,arg:e,resolve:i,reject:a,next:null};o?o=o.next=s:(r=o=s,n(t,e))})},"function"!=typeof e.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)}}(),function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}),C=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),E=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},R=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},N=function(t,e){var n={};for(var i in t)e.indexOf(i)>=0||Object.prototype.hasOwnProperty.call(t,i)&&(n[i]=t[i]);return n},A=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},L=function(){function t(t,e){var n=[],i=!0,r=!1,o=void 0;try{for(var a,s=t[Symbol.iterator]();!(i=(a=s.next()).done)&&(n.push(a.value),!e||n.length!==e);i=!0);}catch(t){r=!0,o=t}finally{try{!i&&s.return&&s.return()}finally{if(r)throw o}}return n}return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),q={wait:!1,withRef:!1,bindI18n:"languageChanged loaded",bindStore:"added removed",translateFuncName:"t",nsMode:"default"},W=void 0,M={type:"3rdParty",init:function(t){i(t.options.react),o(t)}},D=!1,K=function(t){function e(t,n){T(this,e);var i=A(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n));i.i18n=n.i18n||t.i18n||a(),i.namespaces=i.props.ns||i.i18n.options.defaultNS,"string"==typeof i.namespaces&&(i.namespaces=[i.namespaces]);var o=i.i18n&&i.i18n.options.react||{};return i.options=E({},r(),o,t),t.initialI18nStore&&(i.i18n.services.resourceStore.data=t.initialI18nStore,i.options.wait=!1),t.initialLanguage&&i.i18n.changeLanguage(t.initialLanguage),i.i18n.options.isInitialSSR&&(i.options.wait=!1),i.state={i18nLoadedAt:null,ready:!1},i.onI18nChanged=i.onI18nChanged.bind(i),i.getI18nTranslate=i.getI18nTranslate.bind(i),i}return R(e,t),C(e,[{key:"getChildContext",value:function(){return{t:this.t,i18n:this.i18n}}},{key:"componentWillMount",value:function(){this.t=this.getI18nTranslate()}},{key:"componentDidMount",value:function(){var t=this,e=function(){t.options.bindI18n&&t.i18n&&t.i18n.on(t.options.bindI18n,t.onI18nChanged),t.options.bindStore&&t.i18n.store&&t.i18n.store.on(t.options.bindStore,t.onI18nChanged)};this.mounted=!0,this.i18n.loadNamespaces(this.namespaces,function(){var n=function(){t.mounted&&!t.state.ready&&t.setState({ready:!0}),t.options.wait&&t.mounted&&e()};if(t.i18n.isInitialized)n();else{t.i18n.on("initialized",function e(){setTimeout(function(){t.i18n.off("initialized",e)},1e3),n()})}}),this.options.wait||e()}},{key:"componentWillUnmount",value:function(){var t=this;this.mounted=!1,this.onI18nChanged&&(this.options.bindI18n&&this.options.bindI18n.split(" ").forEach(function(e){return t.i18n.off(e,t.onI18nChanged)}),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.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 t=this,e=this.props.children;return!this.state.ready&&this.options.wait?null:(this.i18n.options.isInitialSSR&&!D&&(D=!0,setTimeout(function(){delete t.i18n.options.isInitialSSR},100)),e(this.t,{i18n:this.i18n,t:this.t}))}}]),e}(e.Component);K.contextTypes={i18n:n.object},K.childContextTypes={t:n.func.isRequired,i18n:n.object},c.setDefaults=i,c.setI18n=o;var $=function(t){function e(t,n){T(this,e);var i=A(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n));return i.i18n=t.i18n||n.i18n,i.t=t.t||n.t,i}return R(e,t),C(e,[{key:"render",value:function(){var t=this,e=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",c=E({},this.props.options,{interpolation:{prefix:"#$?",suffix:"?$#"}}),p=this.t(this.props.i18nKey,c);if(!p||"string"!=typeof p)return g.createElement("noscript",null);var u=[],l=function(e,n){if(e.indexOf(t.i18n.options.interpolation.formatSeparator)<0)return void 0===n[e]&&t.i18n.services.logger.warn("interpolator: missed to pass in variable "+e+" for interpolating "+p),n[e];var i=e.split(t.i18n.options.interpolation.formatSeparator),r=i.shift().trim(),o=i.join(t.i18n.options.interpolation.formatSeparator).trim();return void 0===n[r]&&t.i18n.services.logger.warn("interpolator: missed to pass in variable "+r+" for interpolating "+p),t.i18n.options.interpolation.format(n[r],o,t.i18n.language)};p.split(n).reduce(function(e,n,i){var r=void 0;if(i%2==0){if(0===n.length)return e;r=a?g.createElement(s,{dangerouslySetInnerHTML:{__html:n}}):n}else r=l(n,t.props);return e.push(r),e},u);var f={};if(this.i18n.options.react&&this.i18n.options.react.exposeNamespace){var h="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&&(h=this.props.i18nKey.split(this.i18n.options.nsSeparator)[0]),this.t.ns&&(f["data-i18next-options"]=JSON.stringify({ns:h}))}return r&&(f.className=r),o&&(f.style=o),g.createElement.apply(this,[e,f].concat(u))}}]),e}(e.PureComponent);$.propTypes={className:n.string},$.defaultProps={className:""},$.contextTypes={i18n:n.object.isRequired,t:n.func.isRequired};var z={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},H=/([\w-]+)|=|(['"])([.\s\S]*?)\2/g,V=function(t){var e,n=0,i=!0,r={type:"tag",name:"",voidElement:!1,attrs:{},children:[]};return t.replace(H,function(o){if("="===o)return i=!0,void n++;i?0===n?((z[o]||"/"===t.charAt(t.length-2))&&(r.voidElement=!0),r.name=o):(r.attrs[e]=o.replace(/^['"]|['"]$/g,""),e=void 0):(e&&(r.attrs[e]=e),e=o),n++,i=!1}),r},F=/(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g,J=Object.create?Object.create(null):{},U={parse:function(t,e){e||(e={}),e.components||(e.components=J);var n,i=[],r=-1,o=[],a=!1;return t.replace(F,function(s,c){if(a){if(s!=="</"+n.name+">")return;a=!1}var u,l="/"!==s.charAt(1),f=0===s.indexOf("\x3c!--"),h=c+s.length,d=t.charAt(h);l&&!f&&(r++,"tag"===(n=V(s)).type&&e.components[n.name]&&(n.type="component",a=!0),n.voidElement||a||!d||"<"===d||p(n.children,t,r,h,e.ignoreWhitespace),0===r&&i.push(n),(u=o[r-1])&&u.children.push(n),o[r]=n),(f||!l||n.voidElement)&&(f||r--,!a&&"<"!==d&&d&&p(u=-1===r?i:o[r].children,t,r,h,e.ignoreWhitespace))}),!i.length&&t.length&&p(i,t,0,0,e.ignoreWhitespace),i},stringify:function(t){return t.reduce(function(t,e){return t+l("",e)},"")}},B=function(t){function e(){return T(this,e),A(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return R(e,t),C(e,[{key:"render",value:function(){var t=E({i18n:this.context.i18n,t:this.context.t},this.props),e=t.children,n=t.count,i=t.parent,r=t.i18nKey,o=t.i18n,a=t.t,s=N(t,["children","count","parent","i18nKey","i18n","t"]),c=d("",e,0),p=a(r||c,{interpolation:{prefix:"#$?",suffix:"?$#"},defaultValue:c,count:n});if(o.options.react&&o.options.react.exposeNamespace){var u="string"==typeof a.ns?a.ns:a.ns[0];r&&o.options.nsSeparator&&r.indexOf(o.options.nsSeparator)>-1&&(u=r.split(o.options.nsSeparator)[0]),a.ns&&(s["data-i18next-options"]=JSON.stringify({ns:u}))}return g.createElement(i,s,y(e,p,o))}}]),e}(g.PureComponent);B.propTypes={count:n.number,parent:n.string,i18nKey:n.string,i18n:n.object,t:n.func},B.defaultProps={parent:"div"},B.contextTypes={i18n:n.object.isRequired,t:n.func.isRequired};var G=function(t){function n(t,e){T(this,n);var i=A(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,t,e));return i.i18n=t.i18n,t.initialI18nStore&&(i.i18n.services.resourceStore.data=t.initialI18nStore,i.i18n.options.isInitialSSR=!0),t.initialLanguage&&i.i18n.changeLanguage(t.initialLanguage),i}return R(n,t),C(n,[{key:"getChildContext",value:function(){return{i18n:this.i18n}}},{key:"componentWillReceiveProps",value:function(t){if(this.props.i18n!==t.i18n)throw new Error("[react-i18next][I18nextProvider]does not support changing the i18n object.")}},{key:"render",value:function(){var t=this.props.children;return e.Children.only(t)}}]),n}(e.Component);G.propTypes={i18n:n.object.isRequired,children:n.element.isRequired},G.childContextTypes={i18n:n.object.isRequired},Object.entries||(Object.entries=function(t){for(var e=Object.keys(t),n=e.length,i=new Array(n);n--;)i[n]=[e[n],t[e[n]]];return i}),t.translate=c,t.I18n=K,t.Interpolate=$,t.Trans=B,t.I18nextProvider=G,t.loadNamespaces=function(t){var e=t.components,n=t.i18n,i=m(e);return new Promise(function(t){n.loadNamespaces(i,t)})},t.reactI18nextModule=M,t.setDefaults=i,t.getDefaults=r,t.setI18n=o,t.getI18n=a,Object.defineProperty(t,"__esModule",{value:!0})}); |
@@ -0,1 +1,13 @@ | ||
// shim object entries | ||
if (!Object.entries) | ||
Object.entries = function( obj ){ | ||
var ownProps = Object.keys( obj ), | ||
i = ownProps.length, | ||
resArray = new Array(i); // preallocate the Array | ||
while (i--) | ||
resArray[i] = [ownProps[i], obj[ownProps[i]]]; | ||
return resArray; | ||
}; | ||
// Borrowed from https://github.com/Rezonans/redux-async-connect/blob/master/modules/ReduxAsyncConnect.js#L16 | ||
@@ -2,0 +14,0 @@ function eachComponents(components, iterator) { |
@@ -92,22 +92,17 @@ import React from 'react'; | ||
constructor(props, context) { | ||
super(props, context); | ||
this.i18n = props.i18n || context.i18n; | ||
this.t = props.t || context.t; | ||
} | ||
render() { | ||
const { children, count, parent, i18nKey, ...additionalProps } = this.props; | ||
const contextAndProps = { i18n: this.context.i18n, t: this.context.t, ...this.props }; | ||
const { children, count, parent, i18nKey, i18n, t, ...additionalProps } = contextAndProps; | ||
const defaultValue = nodesToString('', children, 0); | ||
const key = i18nKey || defaultValue; | ||
const translation = this.t(key, { interpolation: { prefix: '#$?', suffix: '?$#' }, defaultValue, count }); | ||
const translation = t(key, { interpolation: { prefix: '#$?', suffix: '?$#' }, defaultValue, count }); | ||
if (this.i18n.options.react && this.i18n.options.react.exposeNamespace) { | ||
let ns = typeof this.t.ns === 'string' ? this.t.ns : this.t.ns[0]; | ||
if (i18nKey && this.i18n.options.nsSeparator && i18nKey.indexOf(this.i18n.options.nsSeparator) > -1) { | ||
const parts = i18nKey.split(this.i18n.options.nsSeparator); | ||
if (i18n.options.react && i18n.options.react.exposeNamespace) { | ||
let ns = typeof t.ns === 'string' ? t.ns : t.ns[0]; | ||
if (i18nKey && i18n.options.nsSeparator && i18nKey.indexOf(i18n.options.nsSeparator) > -1) { | ||
const parts = i18nKey.split(i18n.options.nsSeparator); | ||
ns = parts[0]; | ||
} | ||
if (this.t.ns) additionalProps['data-i18next-options'] = JSON.stringify({ ns }); | ||
if (t.ns) additionalProps['data-i18next-options'] = JSON.stringify({ ns }); | ||
} | ||
@@ -118,3 +113,3 @@ | ||
additionalProps, | ||
renderNodes(children, translation, this.i18n) | ||
renderNodes(children, translation, i18n) | ||
); | ||
@@ -127,3 +122,5 @@ } | ||
parent: PropTypes.string, | ||
i18nKey: PropTypes.string | ||
i18nKey: PropTypes.string, | ||
i18n: PropTypes.object, | ||
t: PropTypes.func | ||
}; | ||
@@ -130,0 +127,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
249830
38
4809