mirror of https://github.com/ElemeFE/element
49 lines
1.2 KiB
Markdown
49 lines
1.2 KiB
Markdown
## 国际化
|
||
|
||
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 的 IgnorePlugin 忽略掉它以减少打包后的文件体积。
|
||
|
||
**webpack.config.js**
|
||
```javascript
|
||
{
|
||
plugins: [
|
||
new webpack.IgnorePlugin(/element-ui\/lib\/locale\/lang\/zh-CN/)
|
||
]
|
||
}
|
||
```
|
||
|
||
目前 Element 内置了以下语言:
|
||
- 汉语
|
||
- 英语
|
||
- 德语
|
||
- 葡萄牙语
|
||
|
||
如果你需要使用其他的语言,欢迎贡献 PR:只需在 [这里](https://github.com/ElemeFE/element/tree/master/src/locale/lang) 添加一个语言配置文件即可。
|