2020-08-13 15:18:26 +08:00
## Internationalization
2020-11-09 14:53:43 +08:00
The default language of Element Plus is English. If you want to use another language, you'll need to do some i18n configuration. In your entry file, if you are importing Element Plus entirely:
2020-08-13 15:18:26 +08:00
```javascript
2020-10-26 17:16:22 +08:00
import { createApp } from 'vue'
import ElementPlus from 'element-plus'
2020-11-09 14:53:43 +08:00
import locale from 'element-plus/lib/locale/lang/zh-cn'
2020-08-13 15:18:26 +08:00
2020-10-26 17:16:22 +08:00
createApp(App).use(ElementPlus, { locale })
2020-08-13 15:18:26 +08:00
```
2020-10-16 11:14:34 +08:00
Or if you are importing Element Plus on demand:
2020-08-13 15:18:26 +08:00
```javascript
import Vue from 'vue'
2020-10-16 11:14:34 +08:00
import { Button, Select } from 'element-plus'
2020-11-09 14:53:43 +08:00
import lang from 'element-plus/lib/locale/lang/zh-cn'
2020-10-16 11:14:34 +08:00
import locale from 'element-plus/lib/locale'
2020-08-13 15:18:26 +08:00
// configure language
locale.use(lang)
// import components
Vue.component(Button.name, Button)
Vue.component(Select.name, Select)
```
2020-11-09 14:53:43 +08:00
The English language is imported by default, even if you're using another language. But with `NormalModuleReplacementPlugin` provided by webpack you can replace default locale:
2020-08-13 15:18:26 +08:00
webpack.config.js
```javascript
{
plugins: [
2020-11-09 14:53:43 +08:00
new webpack.NormalModuleReplacementPlugin(/element-plus[\/\\]lib[\/\\]locale[\/\\]lang[\/\\]en/, 'element-plus/lib/locale/lang/zh-cn')
2020-08-13 15:18:26 +08:00
]
}
```
## Compatible with `vue-i18n@5.x`
2020-10-16 11:14:34 +08:00
Element Plus is compatible with [vue-i18n@5.x ](https://github.com/kazupon/vue-i18n ), which makes multilingual switching even easier.
2020-08-13 15:18:26 +08:00
```javascript
import Vue from 'vue'
import VueI18n from 'vue-i18n'
2020-10-16 11:19:36 +08:00
import ElementPlus from 'element-plus'
2020-10-16 11:14:34 +08:00
import enLocale from 'element-plus/lib/locale/lang/en'
2020-11-14 01:39:03 +08:00
import zhLocale from 'element-plus/lib/locale/lang/zh-cn'
2020-10-16 11:22:08 +08:00
import App from './App.vue';
2020-08-13 15:18:26 +08:00
2020-10-16 11:22:08 +08:00
const app = createApp(App)
app.use(ElementPlus)
2020-08-13 15:18:26 +08:00
Vue.use(VueI18n)
Vue.config.lang = 'zh-cn'
Vue.locale('zh-cn', zhLocale)
Vue.locale('en', enLocale)
```
## Compatible with other i18n plugins
2020-10-16 11:14:34 +08:00
Element Plus may not be compatible with i18n plugins other than vue-i18n, but you can customize how Element Plus processes i18n.
2020-08-13 15:18:26 +08:00
```javascript
import Vue from 'vue'
2020-10-16 11:19:36 +08:00
import ElementPlus from 'element-plus'
2020-10-16 11:14:34 +08:00
import enLocale from 'element-plus/lib/locale/lang/en'
2020-11-14 01:39:03 +08:00
import zhLocale from 'element-plus/lib/locale/lang/zh-cn'
2020-08-13 15:18:26 +08:00
Vue.use(Element, {
i18n: function (path, options) {
// ...
}
})
```
## Compatible with `vue-i18n@6.x`
You need to manually handle it for compatibility with `6.x` .
```javascript
import Vue from 'vue'
2020-10-16 11:19:36 +08:00
import ElementPlus from 'element-plus'
2020-08-13 15:18:26 +08:00
import VueI18n from 'vue-i18n'
2020-10-16 11:14:34 +08:00
import enLocale from 'element-plus/lib/locale/lang/en'
2020-11-14 01:39:03 +08:00
import zhLocale from 'element-plus/lib/locale/lang/zh-cn'
2020-08-13 15:18:26 +08:00
Vue.use(VueI18n)
const messages = {
en: {
message: 'hello',
...enLocale // Or use `Object.assign({ message: 'hello' }, enLocale)`
},
zh: {
message: '你好',
...zhLocale // Or use `Object.assign({ message: '你好' }, zhLocale)`
}
}
// Create VueI18n instance with options
const i18n = new VueI18n({
locale: 'en', // set locale
messages, // set locale messages
})
Vue.use(Element, {
i18n: (key, value) => i18n.t(key, value)
})
new Vue({ i18n }).$mount('#app')
```
## Custom i18n in on-demand components
```js
import Vue from 'vue'
import DatePicker from 'element/lib/date-picker'
import VueI18n from 'vue-i18n'
2020-10-16 11:14:34 +08:00
import enLocale from 'element-plus/lib/locale/lang/en'
2020-11-14 01:39:03 +08:00
import zhLocale from 'element-plus/lib/locale/lang/zh-cn'
2020-10-16 11:14:34 +08:00
import ElementLocale from 'element-plus/lib/locale'
2020-08-13 15:18:26 +08:00
Vue.use(VueI18n)
Vue.use(DatePicker)
const messages = {
en: {
message: 'hello',
...enLocale
},
zh: {
message: '你好',
...zhLocale
}
}
// Create VueI18n instance with options
const i18n = new VueI18n({
locale: 'en', // set locale
messages, // set locale messages
})
ElementLocale.i18n((key, value) => i18n.t(key, value))
```
## Import via CDN
```html
< script src = "//unpkg.com/vue" > < / script >
2020-10-16 11:14:34 +08:00
< script src = "//unpkg.com/element-plus" > < / script >
< script src = "//unpkg.com/element-plus/lib/umd/locale/en.js" > < / script >
2020-08-13 15:18:26 +08:00
< script >
ELEMENT.locale(ELEMENT.lang.en)
< / script >
```
Compatible with `vue-i18n`
```html
< script src = "//unpkg.com/vue" > < / script >
< script src = "//unpkg.com/vue-i18n/dist/vue-i18n.js" > < / script >
2020-10-16 11:14:34 +08:00
< script src = "//unpkg.com/element-plus" > < / script >
2020-11-14 01:39:03 +08:00
< script src = "//unpkg.com/element-plus/lib/umd/locale/zh-cn.js" > < / script >
2020-10-16 11:14:34 +08:00
< script src = "//unpkg.com/element-plus/lib/umd/locale/en.js" > < / script >
2020-08-13 15:18:26 +08:00
< script >
Vue.locale('en', ELEMENT.lang.en)
Vue.locale('zh-cn', ELEMENT.lang.zhCN)
< / script >
```
2020-10-16 11:14:34 +08:00
Currently Element Plus ships with the following languages:
2020-08-13 15:18:26 +08:00
< ul class = "language-list" >
2020-11-09 14:53:43 +08:00
< li > Simplified Chinese (zh-cn)< / li >
2020-08-13 15:18:26 +08:00
< li > English (en)< / li >
< li > German (de)< / li >
< li > Portuguese (pt)< / li >
< li > Spanish (es)< / li >
< li > Danish (da)< / li >
< li > French (fr)< / li >
< li > Norwegian (nb-NO)< / li >
2020-11-09 14:53:43 +08:00
< li > Traditional Chinese (zh-tw)< / li >
2020-08-13 15:18:26 +08:00
< li > Italian (it)< / li >
< li > Korean (ko)< / li >
< li > Japanese (ja)< / li >
< li > Dutch (nl)< / li >
< li > Vietnamese (vi)< / li >
2020-11-09 14:53:43 +08:00
< li > Russian (ru-ru)< / li >
< li > Turkish (tr-tr)< / li >
2020-08-13 15:18:26 +08:00
< li > Brazilian Portuguese (pt-br)< / li >
< li > Farsi (fa)< / li >
< li > Thai (th)< / li >
< li > Indonesian (id)< / li >
< li > Bulgarian (bg)< / li >
< li > Polish (pl)< / li >
< li > Finnish (fi)< / li >
2020-11-09 14:53:43 +08:00
< li > Swedish (sv-se)< / li >
2020-08-13 15:18:26 +08:00
< li > Greek (el)< / li >
< li > Slovak (sk)< / li >
< li > Catalunya (ca)< / li >
2020-11-09 14:53:43 +08:00
< li > Czech (cs-cz)< / li >
2020-08-13 15:18:26 +08:00
< li > Ukrainian (ua)< / li >
< li > Turkmen (tk)< / li >
< li > Tamil (ta)< / li >
< li > Latvian (lv)< / li >
2020-11-09 14:53:43 +08:00
< li > Afrikaans (af-za)< / li >
2020-08-13 15:18:26 +08:00
< li > Estonian (ee)< / li >
< li > Slovenian (sl)< / li >
< li > Arabic (ar)< / li >
< li > Hebrew (he)< / li >
< li > Lithuanian (lt)< / li >
< li > Mongolian (mn)< / li >
< li > Kazakh (kz)< / li >
< li > Hungarian (hu)< / li >
< li > Romanian (ro)< / li >
< li > Kurdish (ku)< / li >
2020-11-09 14:53:43 +08:00
< li > Uighur (ug-cn)< / li >
2020-08-13 15:18:26 +08:00
< li > Khmer (km)< / li >
< li > Serbian (sr)< / li >
< li > Basque (eu)< / li >
< li > Kyrgyz (kg)< / li >
< li > Armenian (hy)< / li >
< li > Croatian (hr)< / li >
< li > Esperanto (eo)< / li >
< / ul >
2020-11-09 14:53:43 +08:00
If your target language is not included, you are more than welcome to contribute: just add another language config [here ](https://github.com/element-plus/element-plus/tree/dev/packages/locale/lang ) and create a pull request.