react-i18next
Advanced tools
Comparing version 0.0.4 to 0.1.0
@@ -1,1 +0,1 @@ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.reactI18next=e()}}(function(){return function e(t,n,o){function r(u,a){if(!n[u]){if(!t[u]){var l="function"==typeof require&&require;if(!a&&l)return l(u,!0);if(i)return i(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var c=n[u]={exports:{}};t[u][0].call(c.exports,function(e){var n=t[u][1][e];return r(n?n:e)},c,c.exports,e,t,n,o)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;u<o.length;u++)r(o[u]);return r}({1:[function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{"default":e}}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(n,"__esModule",{value:!0});var u=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),a=function(e,t,n){for(var o=!0;o;){var r=e,i=t,u=n;o=!1,null===r&&(r=Function.prototype);var a=Object.getOwnPropertyDescriptor(r,i);if(void 0!==a){if("value"in a)return a.value;var l=a.get;return void 0===l?void 0:l.call(u)}var f=Object.getPrototypeOf(r);if(null===f)return void 0;e=f,t=i,n=u,o=!0,a=f=void 0}},l=e("react"),f=(o(l),function(e){function t(e,n){r(this,t),a(Object.getPrototypeOf(t.prototype),"constructor",this).call(this,e,n),this.i18n=e.i18n}return i(t,e),u(t,[{key:"getChildContext",value:function(){return{i18n:this.i18n}}},{key:"componentWillReceiveProps",value:function(e){this.props.i18n!==e.i18n&&console.error("[react-i18next][I18nextProvider]does not support changing the i18n object.")}},{key:"render",value:function(){var e=this.props.children;return l.Children.only(e)}}]),t}(l.Component));f.propTypes={i18n:l.PropTypes.object.isRequired,children:l.PropTypes.element.isRequired},f.childContextTypes={i18n:l.PropTypes.object.isRequired},n["default"]=f,t.exports=n["default"]},{react:"react"}],2:[function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(n,"__esModule",{value:!0});var r=e("./translate"),i=o(r),u=e("./I18nextProvider"),a=o(u);n["default"]={translate:i["default"],I18nextProvider:a["default"]},t.exports=n["default"]},{"./I18nextProvider":1,"./translate":3}],3:[function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{"default":e}}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function u(e){return e.displayName||e.name||"Component"}function a(e){return function(t){var n=void 0,o=void 0,a=function(u){function a(e,t){r(this,a),c(Object.getPrototypeOf(a.prototype),"constructor",this).call(this,e,t),o=t.i18n,this.state={i18nLoadedAt:null}}return i(a,u),f(a,[{key:"componentWillMount",value:function(){this.mounted=!0,o.loadNamespaces(e),n=o.getFixedT(null,e)}},{key:"componentDidMount",value:function(){var e=this;this.onI18nChanged=function(){e.mounted&&e.setState({i18nLoadedAt:new Date})},o.on("languageChanged loaded",this.onI18nChanged)}},{key:"componentWillUnmount",value:function(){this.mounted=!1,this.onI18nChanged&&(o.off("languageChanged",this.onI18nChanged),o.off("loaded",this.onI18nChanged))}},{key:"onI18nChange",value:function(){this.mounted&&this.setState({i18nLoadedAt:new Date})}},{key:"render",value:function(){var e=this.state.i18nLoadedAt;return p["default"].createElement(t,l({},this.props,{t:n,i18nLoadedAt:e}))}}]),a}(s.Component);return a.contextTypes={i18n:s.PropTypes.object.isRequired},a.displayName="Translate["+u(t)+"]",a}}Object.defineProperty(n,"__esModule",{value:!0});var l=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},f=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),c=function(e,t,n){for(var o=!0;o;){var r=e,i=t,u=n;o=!1,null===r&&(r=Function.prototype);var a=Object.getOwnPropertyDescriptor(r,i);if(void 0!==a){if("value"in a)return a.value;var l=a.get;return void 0===l?void 0:l.call(u)}var f=Object.getPrototypeOf(r);if(null===f)return void 0;e=f,t=i,n=u,o=!0,a=f=void 0}},s=e("react"),p=o(s);n["default"]=a,t.exports=n["default"]},{react:"react"}]},{},[2])(2)}); | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.reactI18next=e()}}(function(){return function e(t,n,r){function o(u,a){if(!n[u]){if(!t[u]){var c="function"==typeof require&&require;if(!a&&c)return c(u,!0);if(i)return i(u,!0);var l=new Error("Cannot find module '"+u+"'");throw l.code="MODULE_NOT_FOUND",l}var f=n[u]={exports:{}};t[u][0].call(f.exports,function(e){var n=t[u][1][e];return o(n?n:e)},f,f.exports,e,t,n,r)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(n,"__esModule",{value:!0});var u=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),a=function(e,t,n){for(var r=!0;r;){var o=e,i=t,u=n;r=!1,null===o&&(o=Function.prototype);var a=Object.getOwnPropertyDescriptor(o,i);if(void 0!==a){if("value"in a)return a.value;var c=a.get;return void 0===c?void 0:c.call(u)}var l=Object.getPrototypeOf(o);if(null===l)return void 0;e=l,t=i,n=u,r=!0,a=l=void 0}},c=e("react"),l=(r(c),function(e){function t(e,n){o(this,t),a(Object.getPrototypeOf(t.prototype),"constructor",this).call(this,e,n),this.i18n=e.i18n}return i(t,e),u(t,[{key:"getChildContext",value:function(){return{i18n:this.i18n}}},{key:"componentWillReceiveProps",value:function(e){this.props.i18n!==e.i18n&&console.error("[react-i18next][I18nextProvider]does not support changing the i18n object.")}},{key:"render",value:function(){var e=this.props.children;return c.Children.only(e)}}]),t}(c.Component));l.propTypes={i18n:c.PropTypes.object.isRequired,children:c.PropTypes.element.isRequired},l.childContextTypes={i18n:c.PropTypes.object.isRequired},n["default"]=l,t.exports=n["default"]},{react:"react"}],2:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(n,"__esModule",{value:!0});var o=e("./translate"),i=r(o),u=e("./interpolate"),a=r(u),c=e("./I18nextProvider"),l=r(c);n["default"]={translate:i["default"],Interpolate:a["default"],I18nextProvider:l["default"]},t.exports=n["default"]},{"./I18nextProvider":1,"./interpolate":3,"./translate":4}],3:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(n,"__esModule",{value:!0});var u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},a=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),c=function(e,t,n){for(var r=!0;r;){var o=e,i=t,u=n;r=!1,null===o&&(o=Function.prototype);var a=Object.getOwnPropertyDescriptor(o,i);if(void 0!==a){if("value"in a)return a.value;var c=a.get;return void 0===c?void 0:c.call(u)}var l=Object.getPrototypeOf(o);if(null===l)return void 0;e=l,t=i,n=u,r=!0,a=l=void 0}},l=e("react"),f=r(l),p=function(e){function t(e,n){o(this,t),c(Object.getPrototypeOf(t.prototype),"constructor",this).call(this,e,n),this.i18n=n.i18n,this.t=n.t}return i(t,e),a(t,[{key:"render",value:function(){var e=this,t=this.props.parent||"span",n=this.props.regexp||this.i18n.services.interpolator.regexp,r=u({},this.props.options,{interpolation:{prefix:"#$?",suffix:"?$#"}}),o=this.t(this.props.i18nKey,r);if(!o||"string"!=typeof o)return f["default"].createElement("noscript",null);var i=[];return o.split(n).reduce(function(t,n,r){var o;if(r%2===0){if(0===n.length)return t;o=n}else o=e.props[n];return t.push(o),t},i),f["default"].createElement.apply(this,[t,this.props].concat(i))}}]),t}(l.Component);p.contextTypes={i18n:l.PropTypes.object.isRequired,t:l.PropTypes.func.isRequired},n["default"]=p,t.exports=n["default"]},{react:"react"}],4:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function u(e){return e.displayName||e.name||"Component"}function a(e){return function(t){var n=void 0,r=void 0,a=function(u){function a(e,t){o(this,a),f(Object.getPrototypeOf(a.prototype),"constructor",this).call(this,e,t),r=t.i18n,this.state={i18nLoadedAt:null}}return i(a,u),l(a,[{key:"getChildContext",value:function(){return{t:n}}},{key:"componentWillMount",value:function(){this.mounted=!0,r.loadNamespaces(e),n=r.getFixedT(null,e)}},{key:"componentDidMount",value:function(){var e=this;this.onI18nChanged=function(){e.mounted&&e.setState({i18nLoadedAt:new Date})},r.on("languageChanged loaded",this.onI18nChanged)}},{key:"componentWillUnmount",value:function(){this.mounted=!1,this.onI18nChanged&&(r.off("languageChanged",this.onI18nChanged),r.off("loaded",this.onI18nChanged))}},{key:"onI18nChange",value:function(){this.mounted&&this.setState({i18nLoadedAt:new Date})}},{key:"render",value:function(){var e=this.state.i18nLoadedAt;return s["default"].createElement(t,c({},this.props,{t:n,i18nLoadedAt:e}))}}]),a}(p.Component);return a.contextTypes={i18n:p.PropTypes.object.isRequired},a.childContextTypes={t:p.PropTypes.func.isRequired},a.displayName="Translate["+u(t)+"]",a}}Object.defineProperty(n,"__esModule",{value:!0});var c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},l=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),f=function(e,t,n){for(var r=!0;r;){var o=e,i=t,u=n;r=!1,null===o&&(o=Function.prototype);var a=Object.getOwnPropertyDescriptor(o,i);if(void 0!==a){if("value"in a)return a.value;var c=a.get;return void 0===c?void 0:c.call(u)}var l=Object.getPrototypeOf(o);if(null===l)return void 0;e=l,t=i,n=u,r=!0,a=l=void 0}},p=e("react"),s=r(p);n["default"]=a,t.exports=n["default"]},{react:"react"}]},{},[2])(2)}); |
@@ -13,2 +13,6 @@ 'use strict'; | ||
var _interpolate = require('./interpolate'); | ||
var _interpolate2 = _interopRequireDefault(_interpolate); | ||
var _I18nextProvider = require('./I18nextProvider'); | ||
@@ -20,4 +24,5 @@ | ||
translate: _translate2['default'], | ||
Interpolate: _interpolate2['default'], | ||
I18nextProvider: _I18nextProvider2['default'] | ||
}; | ||
module.exports = exports['default']; |
@@ -47,2 +47,7 @@ 'use strict'; | ||
_createClass(Translate, [{ | ||
key: 'getChildContext', | ||
value: function getChildContext() { | ||
return { t: t }; | ||
} | ||
}, { | ||
key: 'componentWillMount', | ||
@@ -99,2 +104,6 @@ value: function componentWillMount() { | ||
Translate.childContextTypes = { | ||
t: _react.PropTypes.func.isRequired | ||
}; | ||
Translate.displayName = 'Translate[' + getDisplayName(WrappedComponent) + ']'; | ||
@@ -101,0 +110,0 @@ |
{ | ||
"name": "react-i18next", | ||
"version": "0.0.4", | ||
"description": "i18next plugin for jquery usage", | ||
"version": "0.1.0", | ||
"description": "React integration for i18next", | ||
"main": "./bin/index.js", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -52,2 +52,3 @@ # react-i18next | ||
- props.t will default to first namespace in array of given namespaces (providing a string as namespace will convert automatically to array) | ||
- used nested inside I18nextProvider (context.i18n) | ||
@@ -73,1 +74,35 @@ | ||
``` | ||
### Interpolate Component | ||
__Interpolate__: component that allows to interpolate React Components or other props into translations. | ||
- used nested inside I18nextProvider and translation hoc (context.i18n, context.t) | ||
__props__: | ||
- i18nKey: the key to lookup | ||
- options: [options](http://i18next.com/docs/options/#t-options) to use for translation (exclude interpolation variables!) | ||
- parent: optional component to wrap translation into (default 'span') | ||
- ...props: values to interpolate into found translation (eg. `my value with {{replaceMe}} interpolation`) | ||
```javascript | ||
import React from 'react'; | ||
import { translate, Interpolate } from 'react-i18next'; | ||
function TranslatableView(props) { | ||
const { t } = props; | ||
let interpolateComponent = <strong>a interpolated component</strong>; | ||
return ( | ||
<div> | ||
<Interpolate i18nKey='ns:key' value='some string' component={interpolateComponent} /> | ||
</div> | ||
) | ||
} | ||
export default translate(['defaultNamespace', 'anotherNamespace'])(TranslatableView); | ||
``` |
import translate from './translate'; | ||
import Interpolate from './interpolate'; | ||
import I18nextProvider from './I18nextProvider'; | ||
@@ -6,3 +7,4 @@ | ||
translate, | ||
Interpolate, | ||
I18nextProvider | ||
}; |
@@ -21,2 +21,6 @@ import React, { Component, PropTypes } from 'react'; | ||
getChildContext() { | ||
return { t: t }; | ||
} | ||
componentWillMount() { | ||
@@ -65,2 +69,6 @@ this.mounted = true; | ||
Translate.childContextTypes = { | ||
t: PropTypes.func.isRequired | ||
}; | ||
Translate.displayName = 'Translate[' + getDisplayName(WrappedComponent) + ']'; | ||
@@ -67,0 +75,0 @@ |
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
38535
15
368
107