UNPKG

hc-components-test

Version:

基于react的通用组件库

23 lines (20 loc) 711 B
import propTypes from 'prop-types'; export default function locale(name, defaultLocale) { return BaseComponent => { BaseComponent.contextTypes = Object.assign(BaseComponent.contextTypes || {}, {antLocale: propTypes.object}); BaseComponent.prototype.getLocale = function (key) { let locale; if (this.context.locale) { locale = this.context.locale; } else { locale = this.context.locale = Object.assign({}, defaultLocale, this.context && this.context.antLocale && this.context.antLocale[name], this.props && this.props.locale); } if (key) { return locale[key]; } else { return locale; } }; return BaseComponent; }; }