Translation support

This commit is contained in:
Maxime Renou 2019-03-01 14:43:37 +01:00
parent 04ed8e9fb3
commit e317c3c060
7 changed files with 123 additions and 7 deletions

48
dist/index.es.js vendored
View File

@ -102,14 +102,27 @@ var FormItemError = function (_Component) {
createClass(FormItemError, [{ createClass(FormItemError, [{
key: "render", key: "render",
value: function render() { value: function render() {
var _this2 = this;
var data = this.props.data; var data = this.props.data;
if (!data || !data.errors || !data.errors[this.props.name]) return null; if (!data || !data.errors || !data.errors[this.props.name]) return null;
return React.createElement( return React.createElement(
FormTranslationConsumer,
null,
function (translator) {
return _this2.renderError(data, translator);
}
);
}
}, {
key: "renderError",
value: function renderError(data, translator) {
return React.createElement(
"p", "p",
{ className: "text-danger" }, { 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) {} 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 //# sourceMappingURL=index.es.js.map

File diff suppressed because one or more lines are too long

47
dist/index.js vendored
View File

@ -109,14 +109,27 @@ var FormItemError = function (_Component) {
createClass(FormItemError, [{ createClass(FormItemError, [{
key: "render", key: "render",
value: function render() { value: function render() {
var _this2 = this;
var data = this.props.data; var data = this.props.data;
if (!data || !data.errors || !data.errors[this.props.name]) return null; if (!data || !data.errors || !data.errors[this.props.name]) return null;
return React__default.createElement( 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", "p",
{ className: "text-danger" }, { 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) {} 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.CheckBox = CheckBox;
exports.Form = Form; exports.Form = Form;
exports.Input = Input; exports.Input = Input;
@ -3289,4 +3333,5 @@ exports.RadioGroup = RadioGroup;
exports.Radio = Radio; exports.Radio = Radio;
exports.Submit = Submit; exports.Submit = Submit;
exports.TextArea = TextArea; exports.TextArea = TextArea;
exports.FormTranslationContext = FormTranslationContext;
//# sourceMappingURL=index.js.map //# sourceMappingURL=index.js.map

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -8,7 +8,14 @@ export default class FormItemError extends Component
if (!data || !data.errors || !data.errors[this.props.name]) return null if (!data || !data.errors || !data.errors[this.props.name]) return null
return ( 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>
}
} }

View File

@ -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>
)
}
}

View File

@ -7,7 +7,8 @@ import Radio from './Radio'
import RadioGroup from './RadioGroup' import RadioGroup from './RadioGroup'
import Submit from './Submit' import Submit from './Submit'
import TextArea from './TextArea' import TextArea from './TextArea'
import FormTranslationContext from './FormTranslationContext'
export { export {
CheckBox, Form, Input, Option, OptionGroup, RadioGroup, Radio, Submit, TextArea CheckBox, Form, Input, Option, OptionGroup, RadioGroup, Radio, Submit, TextArea, FormTranslationContext
} }