lingui-react
Advanced tools
Comparing version 1.0.4 to 1.1.0-0
@@ -1,2 +0,2 @@ | ||
import linguiI18n_dev from 'lingui-i18n/dev'; | ||
import dev from 'lingui-i18n/dev'; | ||
@@ -6,2 +6,2 @@ // Most React projects will import everything from lingui-react module. | ||
export default linguiI18n_dev; | ||
export default dev; |
@@ -5,3 +5,3 @@ 'use strict'; | ||
var linguiI18n_dev = _interopDefault(require('lingui-i18n/dev')); | ||
var dev = _interopDefault(require('lingui-i18n/dev')); | ||
@@ -11,2 +11,2 @@ // Most React projects will import everything from lingui-react module. | ||
module.exports = linguiI18n_dev; | ||
module.exports = dev; |
import { date, number } from 'lingui-formats'; | ||
import React, { cloneElement } from 'react'; | ||
import _extends from 'babel-runtime/helpers/extends'; | ||
import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of'; | ||
@@ -10,2 +9,3 @@ import _classCallCheck from 'babel-runtime/helpers/classCallCheck'; | ||
import PropTypes from 'prop-types'; | ||
import _extends from 'babel-runtime/helpers/extends'; | ||
import { setupI18n } from 'lingui-i18n'; | ||
@@ -17,25 +17,38 @@ import _getIterator from 'babel-runtime/core-js/get-iterator'; | ||
var Render = function Render(_ref) { | ||
var render = _ref.render, | ||
className = _ref.className, | ||
children = _ref.children; | ||
var Render = function (_React$Component) { | ||
_inherits(Render, _React$Component); | ||
if (render) { | ||
// Built-in element: h1, p | ||
if (typeof render === 'string') { | ||
return React.createElement(render, {}, children); | ||
} | ||
function Render() { | ||
_classCallCheck(this, Render); | ||
return React.isValidElement(render) | ||
// Custom element: <p className="lear' /> | ||
? React.cloneElement(render, {}, children) | ||
// Custom component: ({ translation }) => <a title={translation}>x</a> | ||
: React.createElement(render, { translation: children }); | ||
return _possibleConstructorReturn(this, (Render.__proto__ || _Object$getPrototypeOf(Render)).apply(this, arguments)); | ||
} | ||
return React.createElement( | ||
'span', | ||
{ className: className }, | ||
children | ||
); | ||
_createClass(Render, [{ | ||
key: 'render', | ||
value: function render() { | ||
var _props = this.props, | ||
className = _props.className, | ||
value = _props.value; | ||
var render = this.props.render || this.context.linguiDefaultRender || 'span'; | ||
// Built-in element: h1, p | ||
if (typeof render === 'string') { | ||
return React.createElement(render, { className: className }, value); | ||
} | ||
return React.isValidElement(render) | ||
// Custom element: <p className="lear' /> | ||
? React.cloneElement(render, {}, value) | ||
// Custom component: ({ translation }) => <a title={translation}>x</a> | ||
: React.createElement(render, { translation: value }); | ||
} | ||
}]); | ||
return Render; | ||
}(React.Component); | ||
Render.contextTypes = { | ||
linguiDefaultRender: PropTypes.any | ||
}; | ||
@@ -52,11 +65,11 @@ | ||
var formatter = formatFunction(i18n.language, format); | ||
return React.createElement( | ||
Render, | ||
{ className: className, render: render }, | ||
formatter(value) | ||
); | ||
return React.createElement(Render, { | ||
className: className, | ||
render: render, | ||
value: formatter(value) | ||
}); | ||
}; | ||
} | ||
var WithI18n = (function () { | ||
var withI18n = function withI18n() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -66,3 +79,3 @@ return function (WrappedComponent) { | ||
if (typeof options === 'function' || React.isValidElement(options)) { | ||
console.warn('WithI18n([options]) takes options as a first argument, ' + 'but received React component itself. Without options, the Component ' + 'should be wrapped as WithI18n()(Component), not WithI18n(Component).'); | ||
console.warn('withI18n([options]) takes options as a first argument, ' + 'but received React component itself. Without options, the Component ' + 'should be wrapped as withI18n()(Component), not withI18n(Component).'); | ||
} | ||
@@ -76,6 +89,6 @@ } | ||
var WithI18n = function (_React$Component) { | ||
_inherits(WithI18n, _React$Component); | ||
var withI18n = function (_React$Component) { | ||
_inherits(withI18n, _React$Component); | ||
function WithI18n() { | ||
function withI18n() { | ||
var _ref; | ||
@@ -85,3 +98,3 @@ | ||
_classCallCheck(this, WithI18n); | ||
_classCallCheck(this, withI18n); | ||
@@ -92,3 +105,3 @@ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = WithI18n.__proto__ || _Object$getPrototypeOf(WithI18n)).call.apply(_ref, [this].concat(args))), _this), _this.wrappedInstance = null, _this.setWrappedInstance = function (ref) { | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = withI18n.__proto__ || _Object$getPrototypeOf(withI18n)).call.apply(_ref, [this].concat(args))), _this), _this.wrappedInstance = null, _this.setWrappedInstance = function (ref) { | ||
if (withRef) _this.wrappedInstance = ref; | ||
@@ -106,3 +119,3 @@ }, _this.getWrappedInstance = function () { | ||
_createClass(WithI18n, [{ | ||
_createClass(withI18n, [{ | ||
key: 'componentDidMount', | ||
@@ -141,3 +154,3 @@ value: function componentDidMount() { | ||
return WithI18n; | ||
return withI18n; | ||
}(React.Component); | ||
@@ -149,9 +162,19 @@ | ||
WithI18n.contextTypes = { | ||
withI18n.contextTypes = { | ||
linguiPublisher: PropTypes.object | ||
}; | ||
return WithI18n; | ||
return withI18n; | ||
}; | ||
}); | ||
}; | ||
var WithI18n = function WithI18n() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
if (process.env.NODE_ENV !== 'production') { | ||
console.warn('WithI18n is deprecated and will be removed in lingui-react@2.x, ' + 'use withI18n instead (lower-cased first letter).'); | ||
} | ||
return withI18n(options); | ||
}; | ||
/* | ||
@@ -232,3 +255,4 @@ * I18nPublisher - Connects to lingui-i18n/I18n class | ||
return { | ||
linguiPublisher: this.linguiPublisher | ||
linguiPublisher: this.linguiPublisher, | ||
linguiDefaultRender: this.props.defaultRender | ||
}; | ||
@@ -241,3 +265,3 @@ } | ||
return children && children.length > 1 ? React.createElement( | ||
return children && React.Children.count(children) > 1 ? React.createElement( | ||
'div', | ||
@@ -253,4 +277,8 @@ null, | ||
I18nProvider.defaultProps = { | ||
defaultRender: 'span' | ||
}; | ||
I18nProvider.childContextTypes = { | ||
linguiPublisher: PropTypes.object.isRequired | ||
linguiPublisher: PropTypes.object.isRequired, | ||
linguiDefaultRender: PropTypes.any.isRequired | ||
}; | ||
@@ -387,7 +415,7 @@ | ||
var translation = formatElements(this.getTranslation(), this.props.components); | ||
return React.createElement( | ||
Render, | ||
{ className: this.props.className, render: this.props.render }, | ||
translation | ||
); | ||
return React.createElement(Render, { | ||
render: this.props.render, | ||
className: this.props.className, | ||
value: translation | ||
}); | ||
} | ||
@@ -399,5 +427,5 @@ }]); | ||
var Trans$1 = WithI18n()(Trans); | ||
var Trans$1 = withI18n()(Trans); | ||
var Select = WithI18n()(function (_React$Component) { | ||
var Select = withI18n()(function (_React$Component) { | ||
_inherits(Select, _React$Component); | ||
@@ -420,7 +448,7 @@ | ||
return React.createElement( | ||
Render, | ||
{ className: className, render: render }, | ||
i18n.select(selectProps) | ||
); | ||
return React.createElement(Render, { | ||
className: className, | ||
render: render, | ||
value: i18n.select(selectProps) | ||
}); | ||
} | ||
@@ -481,7 +509,7 @@ }]); | ||
return React.createElement( | ||
Render, | ||
{ className: className, render: render }, | ||
i18n[pluralType](pluralProps) | ||
); | ||
return React.createElement(Render, { | ||
className: className, | ||
render: render, | ||
value: i18n[pluralType](pluralProps) | ||
}); | ||
} | ||
@@ -496,8 +524,8 @@ }]); | ||
var Plural = WithI18n()(PluralFactory(false)); | ||
var SelectOrdinal = WithI18n()(PluralFactory(true)); | ||
var Plural = withI18n()(PluralFactory(false)); | ||
var SelectOrdinal = withI18n()(PluralFactory(true)); | ||
var DateFormat = WithI18n()(createFormat(date)); | ||
var NumberFormat = WithI18n()(createFormat(number)); | ||
var DateFormat = withI18n()(createFormat(date)); | ||
var NumberFormat = withI18n()(createFormat(number)); | ||
export { WithI18n, DateFormat, NumberFormat, I18nProvider, Trans$1 as Trans, Plural, Select, SelectOrdinal }; | ||
export { withI18n, WithI18n, DateFormat, NumberFormat, I18nProvider, Trans$1 as Trans, Plural, Select, SelectOrdinal }; |
@@ -10,3 +10,2 @@ 'use strict'; | ||
var React__default = _interopDefault(React); | ||
var _extends = _interopDefault(require('babel-runtime/helpers/extends')); | ||
var _Object$getPrototypeOf = _interopDefault(require('babel-runtime/core-js/object/get-prototype-of')); | ||
@@ -18,2 +17,3 @@ var _classCallCheck = _interopDefault(require('babel-runtime/helpers/classCallCheck')); | ||
var PropTypes = _interopDefault(require('prop-types')); | ||
var _extends = _interopDefault(require('babel-runtime/helpers/extends')); | ||
var linguiI18n = require('lingui-i18n'); | ||
@@ -25,25 +25,38 @@ var _getIterator = _interopDefault(require('babel-runtime/core-js/get-iterator')); | ||
var Render = function Render(_ref) { | ||
var render = _ref.render, | ||
className = _ref.className, | ||
children = _ref.children; | ||
var Render = function (_React$Component) { | ||
_inherits(Render, _React$Component); | ||
if (render) { | ||
// Built-in element: h1, p | ||
if (typeof render === 'string') { | ||
return React__default.createElement(render, {}, children); | ||
} | ||
function Render() { | ||
_classCallCheck(this, Render); | ||
return React__default.isValidElement(render) | ||
// Custom element: <p className="lear' /> | ||
? React__default.cloneElement(render, {}, children) | ||
// Custom component: ({ translation }) => <a title={translation}>x</a> | ||
: React__default.createElement(render, { translation: children }); | ||
return _possibleConstructorReturn(this, (Render.__proto__ || _Object$getPrototypeOf(Render)).apply(this, arguments)); | ||
} | ||
return React__default.createElement( | ||
'span', | ||
{ className: className }, | ||
children | ||
); | ||
_createClass(Render, [{ | ||
key: 'render', | ||
value: function render() { | ||
var _props = this.props, | ||
className = _props.className, | ||
value = _props.value; | ||
var render = this.props.render || this.context.linguiDefaultRender || 'span'; | ||
// Built-in element: h1, p | ||
if (typeof render === 'string') { | ||
return React__default.createElement(render, { className: className }, value); | ||
} | ||
return React__default.isValidElement(render) | ||
// Custom element: <p className="lear' /> | ||
? React__default.cloneElement(render, {}, value) | ||
// Custom component: ({ translation }) => <a title={translation}>x</a> | ||
: React__default.createElement(render, { translation: value }); | ||
} | ||
}]); | ||
return Render; | ||
}(React__default.Component); | ||
Render.contextTypes = { | ||
linguiDefaultRender: PropTypes.any | ||
}; | ||
@@ -60,11 +73,11 @@ | ||
var formatter = formatFunction(i18n.language, format); | ||
return React__default.createElement( | ||
Render, | ||
{ className: className, render: render }, | ||
formatter(value) | ||
); | ||
return React__default.createElement(Render, { | ||
className: className, | ||
render: render, | ||
value: formatter(value) | ||
}); | ||
}; | ||
} | ||
var WithI18n = (function () { | ||
var withI18n = function withI18n() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -74,3 +87,3 @@ return function (WrappedComponent) { | ||
if (typeof options === 'function' || React__default.isValidElement(options)) { | ||
console.warn('WithI18n([options]) takes options as a first argument, ' + 'but received React component itself. Without options, the Component ' + 'should be wrapped as WithI18n()(Component), not WithI18n(Component).'); | ||
console.warn('withI18n([options]) takes options as a first argument, ' + 'but received React component itself. Without options, the Component ' + 'should be wrapped as withI18n()(Component), not withI18n(Component).'); | ||
} | ||
@@ -84,6 +97,6 @@ } | ||
var WithI18n = function (_React$Component) { | ||
_inherits(WithI18n, _React$Component); | ||
var withI18n = function (_React$Component) { | ||
_inherits(withI18n, _React$Component); | ||
function WithI18n() { | ||
function withI18n() { | ||
var _ref; | ||
@@ -93,3 +106,3 @@ | ||
_classCallCheck(this, WithI18n); | ||
_classCallCheck(this, withI18n); | ||
@@ -100,3 +113,3 @@ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = WithI18n.__proto__ || _Object$getPrototypeOf(WithI18n)).call.apply(_ref, [this].concat(args))), _this), _this.wrappedInstance = null, _this.setWrappedInstance = function (ref) { | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = withI18n.__proto__ || _Object$getPrototypeOf(withI18n)).call.apply(_ref, [this].concat(args))), _this), _this.wrappedInstance = null, _this.setWrappedInstance = function (ref) { | ||
if (withRef) _this.wrappedInstance = ref; | ||
@@ -114,3 +127,3 @@ }, _this.getWrappedInstance = function () { | ||
_createClass(WithI18n, [{ | ||
_createClass(withI18n, [{ | ||
key: 'componentDidMount', | ||
@@ -149,3 +162,3 @@ value: function componentDidMount() { | ||
return WithI18n; | ||
return withI18n; | ||
}(React__default.Component); | ||
@@ -157,9 +170,19 @@ | ||
WithI18n.contextTypes = { | ||
withI18n.contextTypes = { | ||
linguiPublisher: PropTypes.object | ||
}; | ||
return WithI18n; | ||
return withI18n; | ||
}; | ||
}); | ||
}; | ||
var WithI18n = function WithI18n() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
if (process.env.NODE_ENV !== 'production') { | ||
console.warn('WithI18n is deprecated and will be removed in lingui-react@2.x, ' + 'use withI18n instead (lower-cased first letter).'); | ||
} | ||
return withI18n(options); | ||
}; | ||
/* | ||
@@ -240,3 +263,4 @@ * I18nPublisher - Connects to lingui-i18n/I18n class | ||
return { | ||
linguiPublisher: this.linguiPublisher | ||
linguiPublisher: this.linguiPublisher, | ||
linguiDefaultRender: this.props.defaultRender | ||
}; | ||
@@ -249,3 +273,3 @@ } | ||
return children && children.length > 1 ? React__default.createElement( | ||
return children && React__default.Children.count(children) > 1 ? React__default.createElement( | ||
'div', | ||
@@ -261,4 +285,8 @@ null, | ||
I18nProvider.defaultProps = { | ||
defaultRender: 'span' | ||
}; | ||
I18nProvider.childContextTypes = { | ||
linguiPublisher: PropTypes.object.isRequired | ||
linguiPublisher: PropTypes.object.isRequired, | ||
linguiDefaultRender: PropTypes.any.isRequired | ||
}; | ||
@@ -395,7 +423,7 @@ | ||
var translation = formatElements(this.getTranslation(), this.props.components); | ||
return React__default.createElement( | ||
Render, | ||
{ className: this.props.className, render: this.props.render }, | ||
translation | ||
); | ||
return React__default.createElement(Render, { | ||
render: this.props.render, | ||
className: this.props.className, | ||
value: translation | ||
}); | ||
} | ||
@@ -407,5 +435,5 @@ }]); | ||
var Trans$1 = WithI18n()(Trans); | ||
var Trans$1 = withI18n()(Trans); | ||
var Select = WithI18n()(function (_React$Component) { | ||
var Select = withI18n()(function (_React$Component) { | ||
_inherits(Select, _React$Component); | ||
@@ -428,7 +456,7 @@ | ||
return React__default.createElement( | ||
Render, | ||
{ className: className, render: render }, | ||
i18n.select(selectProps) | ||
); | ||
return React__default.createElement(Render, { | ||
className: className, | ||
render: render, | ||
value: i18n.select(selectProps) | ||
}); | ||
} | ||
@@ -489,7 +517,7 @@ }]); | ||
return React__default.createElement( | ||
Render, | ||
{ className: className, render: render }, | ||
i18n[pluralType](pluralProps) | ||
); | ||
return React__default.createElement(Render, { | ||
className: className, | ||
render: render, | ||
value: i18n[pluralType](pluralProps) | ||
}); | ||
} | ||
@@ -504,8 +532,9 @@ }]); | ||
var Plural = WithI18n()(PluralFactory(false)); | ||
var SelectOrdinal = WithI18n()(PluralFactory(true)); | ||
var Plural = withI18n()(PluralFactory(false)); | ||
var SelectOrdinal = withI18n()(PluralFactory(true)); | ||
var DateFormat = WithI18n()(createFormat(linguiFormats.date)); | ||
var NumberFormat = WithI18n()(createFormat(linguiFormats.number)); | ||
var DateFormat = withI18n()(createFormat(linguiFormats.date)); | ||
var NumberFormat = withI18n()(createFormat(linguiFormats.number)); | ||
exports.withI18n = withI18n; | ||
exports.WithI18n = WithI18n; | ||
@@ -512,0 +541,0 @@ exports.DateFormat = DateFormat; |
{ | ||
"name": "lingui-react", | ||
"version": "1.0.4", | ||
"version": "1.1.0-0", | ||
"description": "React components for translations", | ||
@@ -36,5 +36,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"babel-runtime": "^6.23.0", | ||
"babel-runtime": "^6.26.0", | ||
"lingui-formats": "^1.0.1", | ||
"lingui-i18n": "^1.2.1", | ||
"lingui-i18n": "^1.2.2-0", | ||
"prop-types": "^15.5.10" | ||
@@ -41,0 +41,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
49865
859
0
2
6
Updatedbabel-runtime@^6.26.0
Updatedlingui-i18n@^1.2.2-0