Change context locale name

This commit is contained in:
afc163 2016-03-05 16:39:27 +08:00 committed by Benjy Cui
parent 193eb14423
commit 2482140d2f
8 changed files with 26 additions and 25 deletions

View File

@ -6,13 +6,13 @@ import GregorianCalendar from 'gregorian-calendar';
export default {
contextTypes: {
locale: React.PropTypes.object,
antLocale: React.PropTypes.object,
},
getLocale() {
let locale = defaultLocale;
if (this.context.locale && this.context.locale.DatePicker) {
locale = this.context.locale.DatePicker;
if (this.context.antLocale && this.context.antLocale.DatePicker) {
locale = this.context.antLocale.DatePicker;
}
// Locale
const result = objectAssign({}, locale, this.props.locale);

View File

@ -7,7 +7,8 @@
---
````jsx
import { LocaleProvider, Pagination, DatePicker, TimePicker, Popconfirm, Table, Modal, Button, Select } from 'antd';
import { LocaleProvider, Pagination, DatePicker, TimePicker,
Popconfirm, Table, Modal, Button, Select } from 'antd';
import enUS from 'antd/lib/locale-provider/en_US';
const Option = Select.Option;
@ -68,7 +69,7 @@ const App = React.createClass({
<div>
<LocaleProvider locale={this.state.locale}><Page /></LocaleProvider>
<div>
<Select defaultValue={enUS} onChange={this.changeLocale}>
<Select defaultValue={enUS} onChange={this.changeLocale} dropdownMatchSelectWidth={false}>
<Option value={enUS}>English</Option>
<Option value={null}>中文</Option>
</Select>

View File

@ -3,16 +3,16 @@ import React from 'react';
export default class LocaleProvider extends React.Component {
getChildContext() {
return {
locale: this.props.locale,
antLocale: this.props.locale,
};
}
render() {
return React.cloneElement(this.props.children);
return React.Children.only(this.props.children);
}
}
LocaleProvider.childContextTypes = {
locale: React.PropTypes.object,
antLocale: React.PropTypes.object,
};
LocaleProvider.propTypes = {

View File

@ -23,7 +23,7 @@ let AntModal = React.createClass({
},
contextTypes: {
locale: React.PropTypes.object,
antLocale: React.PropTypes.object,
},
handleCancel(e) {
@ -56,9 +56,9 @@ let AntModal = React.createClass({
let props = this.props;
let { okText, cancelText } = props;
if (this.context.locale && this.context.locale.Modal) {
okText = okText || this.context.locale.Modal.okText;
cancelText = cancelText || this.context.locale.Modal.cancelText;
if (this.context.antLocale && this.context.antLocale.Modal) {
okText = okText || this.context.antLocale.Modal.okText;
cancelText = cancelText || this.context.antLocale.Modal.cancelText;
}
let defaultFooter = [

View File

@ -17,8 +17,8 @@ class AntPagination extends React.Component {
let selectComponentClass = Select;
let locale;
if (this.context.locale && this.context.locale.Pagination) {
locale = this.context.locale.Pagination;
if (this.context.antLocale && this.context.antLocale.Pagination) {
locale = this.context.antLocale.Pagination;
} else {
locale = this.props.locale;
}
@ -45,7 +45,7 @@ AntPagination.defaultProps = {
};
AntPagination.contextTypes = {
locale: React.PropTypes.object,
antLocale: React.PropTypes.object,
};
export default AntPagination;

View File

@ -38,7 +38,7 @@ export default React.createClass({
};
},
contextTypes: {
locale: React.PropTypes.object,
antLocale: React.PropTypes.object,
},
componentWillReceiveProps(nextProps) {
if ('visible' in nextProps) {
@ -65,9 +65,9 @@ export default React.createClass({
render() {
const { title, placement, overlayStyle, trigger, ...restProps } = this.props;
let { okText, cancelText } = this.props;
if (this.context.locale && this.context.locale.Popconfirm) {
okText = okText || this.context.locale.Popconfirm.okText;
cancelText = cancelText || this.context.locale.Popconfirm.cancelText;
if (this.context.antLocale && this.context.antLocale.Popconfirm) {
okText = okText || this.context.antLocale.Popconfirm.okText;
cancelText = cancelText || this.context.antLocale.Popconfirm.cancelText;
}
const overlay = (
<div>

View File

@ -75,7 +75,7 @@ let AntTable = React.createClass({
},
contextTypes: {
locale: React.PropTypes.object,
antLocale: React.PropTypes.object,
},
getDefaultSelection() {
@ -89,8 +89,8 @@ let AntTable = React.createClass({
getLocale() {
let locale = {};
if (this.context.locale && this.context.locale.Table) {
locale = this.context.locale.Table;
if (this.context.antLocale && this.context.antLocale.Table) {
locale = this.context.antLocale.Table;
}
return objectAssign({}, defaultLocale, locale, this.props.locale);
},

View File

@ -28,7 +28,7 @@ const AntTimePicker = React.createClass({
},
contextTypes: {
locale: React.PropTypes.object,
antLocale: React.PropTypes.object,
},
getFormatter() {
@ -73,8 +73,8 @@ const AntTimePicker = React.createClass({
getLocale() {
let locale = defaultLocale;
if (this.context.locale && this.context.locale.TimePicker) {
locale = this.context.locale.TimePicker;
if (this.context.antLocale && this.context.antLocale.TimePicker) {
locale = this.context.antLocale.TimePicker;
}
// Locale
return objectAssign({}, locale, this.props.locale);