@m6web/react-i18n
Advanced tools
Comparing version 1.4.0 to 1.5.0
@@ -5,3 +5,3 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
import PropTypes from 'prop-types'; | ||
import { Consumer } from './i18n.context'; | ||
import { Context } from '../context/i18n.context'; | ||
@@ -11,3 +11,3 @@ export var translate = function translate(RenderComponent) { | ||
return React.createElement( | ||
Consumer, | ||
Context.Consumer, | ||
null, | ||
@@ -14,0 +14,0 @@ function (t) { |
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { translate } from '../utils/i18n.utils'; | ||
import { Provider } from './i18n.context'; | ||
import { Context } from '../context/i18n.context'; | ||
@@ -11,3 +11,3 @@ export var I18nProvider = function I18nProvider(_ref) { | ||
return React.createElement( | ||
Provider, | ||
Context.Provider, | ||
{ value: translate(lang, i18nNames) }, | ||
@@ -14,0 +14,0 @@ children |
@@ -7,3 +7,3 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
import PropTypes from 'prop-types'; | ||
import { Consumer } from './i18n.context'; | ||
import { Context } from '../context/i18n.context'; | ||
@@ -19,3 +19,3 @@ var HtmlTrans = function HtmlTrans(_ref) { | ||
return React.createElement( | ||
Consumer, | ||
Context.Consumer, | ||
null, | ||
@@ -36,3 +36,3 @@ function (t) { | ||
HtmlTrans.propTypes = { | ||
element: PropTypes.oneOfType([PropTypes.string, PropTypes.element]), | ||
element: PropTypes.oneOfType([PropTypes.string, PropTypes.element, PropTypes.func]), | ||
i18nKey: PropTypes.string.isRequired, | ||
@@ -39,0 +39,0 @@ data: PropTypes.object, |
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Consumer } from './i18n.context'; | ||
import { Context } from './../context/i18n.context'; | ||
@@ -11,3 +11,3 @@ export var Trans = function Trans(_ref) { | ||
return React.createElement( | ||
Consumer, | ||
Context.Consumer, | ||
null, | ||
@@ -14,0 +14,0 @@ function (t) { |
@@ -18,3 +18,3 @@ 'use strict'; | ||
var _i18n = require('./i18n.context'); | ||
var _i18n = require('../context/i18n.context'); | ||
@@ -26,3 +26,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
return _react2.default.createElement( | ||
_i18n.Consumer, | ||
_i18n.Context.Consumer, | ||
null, | ||
@@ -29,0 +29,0 @@ function (t) { |
@@ -18,3 +18,3 @@ 'use strict'; | ||
var _i18n2 = require('./i18n.context'); | ||
var _i18n2 = require('../context/i18n.context'); | ||
@@ -28,3 +28,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
return _react2.default.createElement( | ||
_i18n2.Provider, | ||
_i18n2.Context.Provider, | ||
{ value: (0, _i18n.translate)(lang, i18nNames) }, | ||
@@ -31,0 +31,0 @@ children |
@@ -18,3 +18,3 @@ 'use strict'; | ||
var _i18n = require('./i18n.context'); | ||
var _i18n = require('../context/i18n.context'); | ||
@@ -34,3 +34,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
return _react2.default.createElement( | ||
_i18n.Consumer, | ||
_i18n.Context.Consumer, | ||
null, | ||
@@ -51,3 +51,3 @@ function (t) { | ||
HtmlTrans.propTypes = { | ||
element: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.element]), | ||
element: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.element, _propTypes2.default.func]), | ||
i18nKey: _propTypes2.default.string.isRequired, | ||
@@ -54,0 +54,0 @@ data: _propTypes2.default.object, |
@@ -16,3 +16,3 @@ 'use strict'; | ||
var _i18n = require('./i18n.context'); | ||
var _i18n = require('./../context/i18n.context'); | ||
@@ -27,3 +27,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
return _react2.default.createElement( | ||
_i18n.Consumer, | ||
_i18n.Context.Consumer, | ||
null, | ||
@@ -30,0 +30,0 @@ function (t) { |
{ | ||
"name": "@m6web/react-i18n", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "Provider and utils for translation in a react app", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -23,3 +23,3 @@ # React i18n for 6play apps | ||
// Import the provider | ||
import { I18nProvider } from '@m6we/react-i18n'; | ||
import { I18nProvider } from '@m6web/react-i18n'; | ||
@@ -55,3 +55,3 @@ // Dictionnary for your app, you should have a different dictionary for each language | ||
import React from 'react'; | ||
import { Trans } from '@m6we/react-i18n'; | ||
import { Trans } from '@m6web/react-i18n'; | ||
@@ -84,3 +84,3 @@ // Interpolation values | ||
import React from 'react'; | ||
import { HtmlTrans } from '@m6we/react-i18n'; | ||
import { HtmlTrans } from '@m6web/react-i18n'; | ||
@@ -104,3 +104,3 @@ // Interpolation values | ||
* **general**: use general plural form if truthy | ||
* **element**: HTML element, or React element used for rendering. (default value: `span`) | ||
* **element**: HTML element, or React element used for rendering. (default value: `span`) | ||
@@ -115,3 +115,3 @@ Note that **number** and **data** can be used together. | ||
import React from 'react'; | ||
import { translate } from '@m6we/react-i18n'; | ||
import { translate } from '@m6web/react-i18n'; | ||
@@ -145,2 +145,29 @@ // Interpolation values | ||
### useTranslate hook | ||
This hook provides the `t` function in a functional component. | ||
```jsx harmony | ||
import React from 'react'; | ||
import { useTranslate } from '@m6web/react-i18n'; | ||
// Interpolation values | ||
const data = { element: 'foo' }; | ||
export const MyComponent = ({ nbExample }) => { | ||
const t = useTranslate(); | ||
return ( | ||
<div class="foo"> | ||
<h1> | ||
{t('foo.bar')} | ||
</h1> | ||
<p> | ||
{t('foo.exemple', data, nbExample, true)} | ||
</p> | ||
</div> | ||
); | ||
}; | ||
``` | ||
### BuildList | ||
@@ -151,3 +178,3 @@ | ||
```jsx harmony | ||
import { buildListFunction } from '@m6we/react-i18n'; | ||
import { buildListFunction } from '@m6web/react-i18n'; | ||
@@ -154,0 +181,0 @@ // Define separators with translations |
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
48331
30
920
208