element/examples/docs/zh-CN/i18n.md

76 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<style>
ul.language-list {
color: #5e6d82;
font-size: 14px;
padding-left: 20px;
li {
line-height: 1.8
}
}
</style>
## 国际化
Element 组件内部默认使用中文,若希望使用其他语言,则需要进行多语言设置。以英文为例,在 main.js 中:
```javascript
// 完整引入 Element
import Vue from 'vue'
import ElementUI from 'element-ui'
import locale from 'element-ui/lib/locale/lang/en'
Vue.use(ElementUI, { locale })
```
```javascript
// 按需引入 Element
import Vue from 'vue'
import { Button, Select } from 'element-ui'
import lang from 'element-ui/lib/locale/lang/en'
import locale from 'element-ui/lib/locale'
// 设置语言
locale.use(lang)
// 引入组件
Vue.component(Button.name, Button)
Vue.component(Select.name, Select)
```
如果使用其它语言,默认情况下中文语言包依旧是被引入的,可以使用 webpack 的 NormalModuleReplacementPlugin 替换默认语言包。
**webpack.config.js**
```javascript
{
plugins: [
new webpack.NormalModuleReplacementPlugin(/element-ui[\/\\]lib[\/\\]locale[\/\\]lang[\/\\]zh-CN/, 'element-ui/lib/locale/lang/en')
]
}
```
目前 Element 内置了以下语言:
<ul class="language-list">
<li>简体中文zh-CN</li>
<li>英语en</li>
<li>德语de</li>
<li>葡萄牙语pt</li>
<li>西班牙语es</li>
<li>丹麦语da</li>
<li>法语fr</li>
<li>挪威语nb-NO</li>
<li>繁体中文zh-TW</li>
<li>意大利语it</li>
<li>韩语ko</li>
<li>日语ja</li>
<li>荷兰语nl</li>
<li>越南语vi</li>
<li>俄语ru-RU</li>
<li>土耳其语tr-TR</li>
<li>巴西葡萄牙语pt-br</li>
<li>波斯语fa</li>
<li>泰语th</li>
</ul>
如果你需要使用其他的语言,欢迎贡献 PR只需在 [这里](https://github.com/ElemeFE/element/tree/master/src/locale/lang) 添加一个语言配置文件即可。