ant-design/components/locale-provider/index.en-US.md

51 lines
1.9 KiB
Markdown
Raw Normal View History

---
category: Components
2016-12-02 21:06:21 +08:00
type: Other
cols: 1
title: LocaleProvider
---
2016-12-02 21:06:21 +08:00
`LocaleProvider` provides a uniform localization support for built-in text of components.
## Usage
`LocaleProvider` takes use of [context](https://facebook.github.io/react/docs/context.html), a feature of React, to accomplish global effectiveness by wrapping the app only once.
```jsx
import { LocaleProvider } from 'antd';
import fr_FR from 'antd/lib/locale-provider/fr_FR';
2018-12-07 18:16:23 +08:00
import moment from 'moment';
import 'moment/locale/fr';
2018-12-07 18:16:23 +08:00
moment.locale('fr');
...
return <LocaleProvider locale={fr_FR}><App /></LocaleProvider>;
```
2017-03-12 12:44:27 +08:00
We provide some locale like English, Chinese, Russian, German, French and etc, all locale packages can be found in [here](https://github.com/ant-design/ant-design/blob/master/components/locale-provider/).
2017-01-27 17:54:57 +08:00
Note: if you need to use antd's UMD dist file, please use `antd/dist/antd-with-locales.js` and corresponding moment locale:
```jsx
const { LocaleProvider, locales } = window.antd;
...
return <LocaleProvider locale={locales.fr_FR}><App /></LocaleProvider>;
```
2017-01-31 15:08:35 +08:00
### Add a new language
2017-01-27 17:54:57 +08:00
If you can't find your language, you are welcome to create a locale package based on [en_US](https://github.com/ant-design/ant-design/blob/master/components/locale-provider/en_US.tsx) and send us a pull request.
### Other localization needs
This component aims for localization of the built-in text, if you want to support other documents, we recommend using [react-intl](https://github.com/yahoo/react-intl), refer to [Intl demo 1](http://github.com/ant-design/intl-example) and [Intl demo 2](http://yiminghe.me/learning-react/examples/react-intl.html?locale=en-US).
## API
2017-10-25 10:25:44 +08:00
| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
2018-08-20 11:46:56 +08:00
| locale | language package setting, you can find the packages in [antd/lib/locale-provider](http://unpkg.com/antd/lib/locale-provider/) | object | - |