Translation support
This commit is contained in:
parent
04ed8e9fb3
commit
e317c3c060
|
@ -102,14 +102,27 @@ var FormItemError = function (_Component) {
|
|||
createClass(FormItemError, [{
|
||||
key: "render",
|
||||
value: function render() {
|
||||
var _this2 = this;
|
||||
|
||||
var data = this.props.data;
|
||||
|
||||
if (!data || !data.errors || !data.errors[this.props.name]) return null;
|
||||
|
||||
return React.createElement(
|
||||
FormTranslationConsumer,
|
||||
null,
|
||||
function (translator) {
|
||||
return _this2.renderError(data, translator);
|
||||
}
|
||||
);
|
||||
}
|
||||
}, {
|
||||
key: "renderError",
|
||||
value: function renderError(data, translator) {
|
||||
return React.createElement(
|
||||
"p",
|
||||
{ className: "text-danger" },
|
||||
data.errors[this.props.name].error
|
||||
translator.handleText(data.errors[this.props.name].error)
|
||||
);
|
||||
}
|
||||
}]);
|
||||
|
@ -3273,5 +3286,36 @@ TextArea.defaultProps = {
|
|||
onChangeValue: function onChangeValue(text) {}
|
||||
};
|
||||
|
||||
export { CheckBox, Form, Input, Option, OptionGroup, RadioGroup, Radio, Submit, TextArea };
|
||||
var FormTranslationContext = React.createContext({
|
||||
renderText: function renderText(text) {
|
||||
return text;
|
||||
}
|
||||
});
|
||||
|
||||
var FormTranslationConsumer$1 = function (_Component) {
|
||||
inherits(FormTranslationConsumer, _Component);
|
||||
|
||||
function FormTranslationConsumer() {
|
||||
classCallCheck(this, FormTranslationConsumer);
|
||||
return possibleConstructorReturn(this, (FormTranslationConsumer.__proto__ || Object.getPrototypeOf(FormTranslationConsumer)).apply(this, arguments));
|
||||
}
|
||||
|
||||
createClass(FormTranslationConsumer, [{
|
||||
key: 'render',
|
||||
value: function render() {
|
||||
var _this2 = this;
|
||||
|
||||
return React.createElement(
|
||||
FormTranslationContext.Consumer,
|
||||
null,
|
||||
function (props) {
|
||||
return _this2.props.children(props);
|
||||
}
|
||||
);
|
||||
}
|
||||
}]);
|
||||
return FormTranslationConsumer;
|
||||
}(Component);
|
||||
|
||||
export { CheckBox, Form, Input, Option, OptionGroup, RadioGroup, Radio, Submit, TextArea, FormTranslationContext };
|
||||
//# sourceMappingURL=index.es.js.map
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -109,14 +109,27 @@ var FormItemError = function (_Component) {
|
|||
createClass(FormItemError, [{
|
||||
key: "render",
|
||||
value: function render() {
|
||||
var _this2 = this;
|
||||
|
||||
var data = this.props.data;
|
||||
|
||||
if (!data || !data.errors || !data.errors[this.props.name]) return null;
|
||||
|
||||
return React__default.createElement(
|
||||
FormTranslationConsumer,
|
||||
null,
|
||||
function (translator) {
|
||||
return _this2.renderError(data, translator);
|
||||
}
|
||||
);
|
||||
}
|
||||
}, {
|
||||
key: "renderError",
|
||||
value: function renderError(data, translator) {
|
||||
return React__default.createElement(
|
||||
"p",
|
||||
{ className: "text-danger" },
|
||||
data.errors[this.props.name].error
|
||||
translator.handleText(data.errors[this.props.name].error)
|
||||
);
|
||||
}
|
||||
}]);
|
||||
|
@ -3280,6 +3293,37 @@ TextArea.defaultProps = {
|
|||
onChangeValue: function onChangeValue(text) {}
|
||||
};
|
||||
|
||||
var FormTranslationContext = React__default.createContext({
|
||||
renderText: function renderText(text) {
|
||||
return text;
|
||||
}
|
||||
});
|
||||
|
||||
var FormTranslationConsumer$1 = function (_Component) {
|
||||
inherits(FormTranslationConsumer, _Component);
|
||||
|
||||
function FormTranslationConsumer() {
|
||||
classCallCheck(this, FormTranslationConsumer);
|
||||
return possibleConstructorReturn(this, (FormTranslationConsumer.__proto__ || Object.getPrototypeOf(FormTranslationConsumer)).apply(this, arguments));
|
||||
}
|
||||
|
||||
createClass(FormTranslationConsumer, [{
|
||||
key: 'render',
|
||||
value: function render() {
|
||||
var _this2 = this;
|
||||
|
||||
return React__default.createElement(
|
||||
FormTranslationContext.Consumer,
|
||||
null,
|
||||
function (props) {
|
||||
return _this2.props.children(props);
|
||||
}
|
||||
);
|
||||
}
|
||||
}]);
|
||||
return FormTranslationConsumer;
|
||||
}(React.Component);
|
||||
|
||||
exports.CheckBox = CheckBox;
|
||||
exports.Form = Form;
|
||||
exports.Input = Input;
|
||||
|
@ -3289,4 +3333,5 @@ exports.RadioGroup = RadioGroup;
|
|||
exports.Radio = Radio;
|
||||
exports.Submit = Submit;
|
||||
exports.TextArea = TextArea;
|
||||
exports.FormTranslationContext = FormTranslationContext;
|
||||
//# sourceMappingURL=index.js.map
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -8,7 +8,14 @@ export default class FormItemError extends Component
|
|||
if (!data || !data.errors || !data.errors[this.props.name]) return null
|
||||
|
||||
return (
|
||||
<p className="text-danger">{data.errors[this.props.name].error}</p>
|
||||
<FormTranslationConsumer>
|
||||
{(translator) => this.renderError(data, translator)}
|
||||
</FormTranslationConsumer>
|
||||
)
|
||||
}
|
||||
|
||||
renderError(data, translator)
|
||||
{
|
||||
return <p className="text-danger">{translator.handleText(data.errors[this.props.name].error)}</p>
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
import React, { Component } from 'react'
|
||||
|
||||
const FormTranslationContext = React.createContext({
|
||||
renderText: (text) => (text)
|
||||
});
|
||||
|
||||
export default FormTranslationContext
|
||||
|
||||
export class FormTranslationConsumer extends Component
|
||||
{
|
||||
render()
|
||||
{
|
||||
return (
|
||||
<FormTranslationContext.Consumer>
|
||||
{(props) => this.props.children(props)}
|
||||
</FormTranslationContext.Consumer>
|
||||
)
|
||||
}
|
||||
}
|
|
@ -7,7 +7,8 @@ import Radio from './Radio'
|
|||
import RadioGroup from './RadioGroup'
|
||||
import Submit from './Submit'
|
||||
import TextArea from './TextArea'
|
||||
import FormTranslationContext from './FormTranslationContext'
|
||||
|
||||
export {
|
||||
CheckBox, Form, Input, Option, OptionGroup, RadioGroup, Radio, Submit, TextArea
|
||||
CheckBox, Form, Input, Option, OptionGroup, RadioGroup, Radio, Submit, TextArea, FormTranslationContext
|
||||
}
|
Loading…
Reference in New Issue