chowa
Version:
UI component library based on React
34 lines (33 loc) • 1.29 kB
JavaScript
/**
* @license chowa v1.1.3
*
* Copyright (c) Chowa Techonlogies Co.,Ltd.(http://www.chowa.cn).
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
;
Object.defineProperty(exports, "__esModule", { value: true });
const React = require("react");
const PropTypes = require("prop-types");
const utils_1 = require("../utils");
const context_1 = require("./context");
const lang_1 = require("./lang");
class I18nReceiver extends React.PureComponent {
render() {
const { children, module } = this.props;
const i18n = utils_1.isExist(this.context.egeI18n) && utils_1.hasProperty(this.context.egeI18n, module)
? this.context.egeI18n[module] : {};
const element = children(Object.assign(Object.assign({}, (utils_1.hasProperty(lang_1.default, module) ? lang_1.default[module] : {})), i18n));
if (!utils_1.isReactElement(element)) {
return element;
}
return React.cloneElement(element, utils_1.omitProps(this.props, ['children', 'module']));
}
}
I18nReceiver.propTypes = {
module: PropTypes.string.isRequired,
children: PropTypes.func
};
I18nReceiver.contextType = context_1.default;
exports.default = I18nReceiver;