afc163
9 years ago
committed by
Benjy Cui
8 changed files with 93 additions and 3 deletions
@ -0,0 +1,29 @@ |
|||
# 国际化 |
|||
|
|||
- order: 1 |
|||
|
|||
用 `LocaleProvider` 包裹你的应用,并引用对应的语言包。 |
|||
|
|||
--- |
|||
|
|||
````jsx |
|||
import { Pagination, DatePicker, LocaleProvider } from 'antd'; |
|||
import enUS from 'antd/lib/locale-provider/en_US'; |
|||
|
|||
const App = React.createClass({ |
|||
render() { |
|||
return ( |
|||
<div> |
|||
<DatePicker /> |
|||
<Pagination defaultCurrent={1} total={50} showSizeChanger /> |
|||
</div> |
|||
); |
|||
} |
|||
}); |
|||
|
|||
ReactDOM.render( |
|||
<LocaleProvider locale={enUS}> |
|||
<App /> |
|||
</LocaleProvider> |
|||
, mountNode); |
|||
```` |
@ -0,0 +1,3 @@ |
|||
module.exports = { |
|||
Pagination: require('rc-pagination/lib/locale/en_US'), |
|||
}; |
@ -0,0 +1,20 @@ |
|||
import React from 'react'; |
|||
|
|||
export default class LocaleProvider extends React.Component { |
|||
getChildContext() { |
|||
return { |
|||
locale: this.props.locale, |
|||
}; |
|||
} |
|||
render() { |
|||
return React.cloneElement(this.props.children); |
|||
} |
|||
} |
|||
|
|||
LocaleProvider.childContextTypes = { |
|||
locale: React.PropTypes.object, |
|||
}; |
|||
|
|||
LocaleProvider.propTypes = { |
|||
locale: React.PropTypes.object, |
|||
}; |
@ -0,0 +1,21 @@ |
|||
# LocaleProvider |
|||
|
|||
- category: Components |
|||
- chinese: 国际化 |
|||
- cols: 1 |
|||
|
|||
--- |
|||
|
|||
为组件文案提供统一的国际化配置功能。 |
|||
|
|||
## API |
|||
|
|||
Wrap your App with `LocaleProvider` once. |
|||
|
|||
```jsx |
|||
<LocaleProvider locale={enUS}> |
|||
<App /> |
|||
</LocaleProvider> |
|||
``` |
|||
|
|||
### Add a language |
Loading…
Reference in new issue