From a987e34f6f847629765a508d1a68ac9fcfebd16b Mon Sep 17 00:00:00 2001 From: Benjy Cui Date: Sat, 8 Oct 2016 10:42:13 +0800 Subject: [PATCH] fix: Transfer[title] should follow LocaleProvider, ref: #3264 (#3318) --- components/locale-provider/demo/all.md | 1 - components/locale-provider/en_US.tsx | 1 + .../locale-provider/{es_ES.js => es_ES.tsx} | 12 +++++--- components/transfer/index.tsx | 29 +++++++++++++++++-- components/transfer/list.tsx | 6 ++-- 5 files changed, 39 insertions(+), 10 deletions(-) rename components/locale-provider/{es_ES.js => es_ES.tsx} (65%) diff --git a/components/locale-provider/demo/all.md b/components/locale-provider/demo/all.md index 48eb44ca33..5210db2561 100644 --- a/components/locale-provider/demo/all.md +++ b/components/locale-provider/demo/all.md @@ -93,7 +93,6 @@ const Page = React.createClass({ item.title} /> diff --git a/components/locale-provider/en_US.tsx b/components/locale-provider/en_US.tsx index 7381ebe7ae..03166bc0be 100644 --- a/components/locale-provider/en_US.tsx +++ b/components/locale-provider/en_US.tsx @@ -27,6 +27,7 @@ export default { cancelText: 'Cancel', }, Transfer: { + titles: ['Source', 'Target'], notFoundContent: 'Not Found', searchPlaceholder: 'Search here', itemUnit: 'item', diff --git a/components/locale-provider/es_ES.js b/components/locale-provider/es_ES.tsx similarity index 65% rename from components/locale-provider/es_ES.js rename to components/locale-provider/es_ES.tsx index f0cfdd7788..87ff987d7f 100644 --- a/components/locale-provider/es_ES.js +++ b/components/locale-provider/es_ES.tsx @@ -1,7 +1,11 @@ -module.exports = { - Pagination: require('rc-pagination/lib/locale/en_US'), - DatePicker: require('../date-picker/locale/en_US'), - TimePicker: require('../time-picker/locale/en_US'), +import Pagination from 'rc-pagination/lib/locale/en_US'; +import DatePicker from '../date-picker/locale/en_US'; +import TimePicker from '../time-picker/locale/en_US'; + +export default { + Pagination, + DatePicker, + TimePicker, Table: { filterTitle: 'Filtrar Menu', filterConfirm: 'OK', diff --git a/components/transfer/index.tsx b/components/transfer/index.tsx index 0627170751..40e029cb25 100644 --- a/components/transfer/index.tsx +++ b/components/transfer/index.tsx @@ -37,6 +37,13 @@ export interface TransferProps { rowKey?: (record: any) => string; } +export interface TransferContext { + antLocale?: { + Transfer?: any, + }; +} + +const defaultTitles = ['源列表', '目的列表']; export default class Transfer extends React.Component { static List = List; static Operation = Operation; @@ -48,7 +55,6 @@ export default class Transfer extends React.Component { render: noop, onChange: noop, onSelectChange: noop, - titles: ['源列表', '目的列表'], operations: [], showSearch: false, body: noop, @@ -75,6 +81,11 @@ export default class Transfer extends React.Component { rowKey: PropTypes.func, }; + static contextTypes = { + antLocale: PropTypes.object, + }; + + context: TransferContext; splitedDataSource: any; constructor(props) { @@ -227,9 +238,22 @@ export default class Transfer extends React.Component { handleLeftSelect = (selectedItem, checked) => this.handleSelect('left', selectedItem, checked); handleRightSelect = (selectedItem, checked) => this.handleSelect('right', selectedItem, checked); + getTitles(): string[] { + if (this.props.titles) { + return this.props.titles; + } + if (this.context && + this.context.antLocale && + this.context.antLocale.Transfer + ) { + return this.context.antLocale.Transfer.titles || []; + } + return defaultTitles; + } + render() { const { - prefixCls, titles, operations, showSearch, notFoundContent, + prefixCls, operations, showSearch, notFoundContent, searchPlaceholder, body, footer, listStyle, className, filterOption, render, } = this.props; @@ -244,6 +268,7 @@ export default class Transfer extends React.Component { [prefixCls]: true, }); + const titles = this.getTitles(); return (
boolean; } -export interface TransferContext { +export interface TransferListContext { antLocale?: { Transfer?: any, }; @@ -80,8 +80,8 @@ export default class TransferList extends React.Component