2021-08-24 13:36:48 +08:00
|
|
|
# Internationalization
|
2020-08-13 15:18:26 +08:00
|
|
|
|
2021-08-24 13:36:48 +08:00
|
|
|
ElementPlus components are using English **by default**, if you wish you use other
|
|
|
|
languages, you can get you answer by keep reading.
|
2020-08-13 15:18:26 +08:00
|
|
|
|
2021-08-24 13:36:48 +08:00
|
|
|
## Global configuration
|
2020-08-13 15:18:26 +08:00
|
|
|
|
2021-08-24 13:36:48 +08:00
|
|
|
ElementPlus provides global configurations
|
2020-08-13 15:18:26 +08:00
|
|
|
|
2021-08-24 13:36:48 +08:00
|
|
|
```typescript
|
|
|
|
import ElementPlus from 'element-plus'
|
|
|
|
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
2020-08-13 15:18:26 +08:00
|
|
|
|
2021-08-24 13:36:48 +08:00
|
|
|
app.use(ElementPlus, {
|
|
|
|
locale: zhCn,
|
|
|
|
})
|
|
|
|
```
|
2021-01-25 16:23:15 +08:00
|
|
|
|
2021-08-24 13:36:48 +08:00
|
|
|
## ConfigProvider
|
2021-01-25 16:23:15 +08:00
|
|
|
|
2021-08-24 13:36:48 +08:00
|
|
|
ElementPlus also provides a Vue component [ConfigProvider](/#/zh-CN/component/config-provider)
|
|
|
|
for globally configuring locale and other settings.
|
2021-01-25 16:23:15 +08:00
|
|
|
|
2021-07-26 00:40:37 +08:00
|
|
|
```html
|
|
|
|
<template>
|
|
|
|
<el-config-provider :locale="locale">
|
2021-08-24 13:36:48 +08:00
|
|
|
<app />
|
2021-07-26 00:40:37 +08:00
|
|
|
</el-config-provider>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-09-04 19:29:28 +08:00
|
|
|
import { defineComponent } from 'vue'
|
|
|
|
import { ElConfigProvider } from 'element-plus'
|
|
|
|
|
|
|
|
import zhCn from 'element-plus/lib/locale/lang/zh-cn'
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
components: {
|
|
|
|
ElConfigProvider,
|
|
|
|
},
|
|
|
|
setup() {
|
|
|
|
return {
|
|
|
|
locale: zhCn,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
2021-07-26 00:40:37 +08:00
|
|
|
</script>
|
2021-07-26 00:24:30 +08:00
|
|
|
```
|
2020-08-13 15:18:26 +08:00
|
|
|
|
2021-08-25 16:52:23 +08:00
|
|
|
## CDN Usage
|
|
|
|
|
|
|
|
If you are using ElementPlus via CDN, then you need to do this, let's again take
|
|
|
|
unpkg as an example
|
|
|
|
|
|
|
|
```html
|
|
|
|
<script src="//unpkg.com/element-plus/dist/locale/zh-cn">
|
2021-09-04 19:29:28 +08:00
|
|
|
<script>
|
|
|
|
app.use(ElementPlus, {
|
|
|
|
locale: ElementPlus.lang.zhCn
|
|
|
|
})
|
2021-08-25 16:52:23 +08:00
|
|
|
</script>
|
|
|
|
```
|
|
|
|
|
2021-08-24 13:36:48 +08:00
|
|
|
Full documentation refer to: [ConfigProvider](/#/zh-CN/component/config-provider)
|
2021-07-26 00:24:30 +08:00
|
|
|
|
2021-08-24 13:36:48 +08:00
|
|
|
[Supported Language List](https://github.com/element-plus/element-plus/tree/dev/packages/locale/lang)
|
2021-07-26 00:24:30 +08:00
|
|
|
|
2021-08-24 13:36:48 +08:00
|
|
|
<ul class="language-list">
|
|
|
|
<li>Simplified Chinese (zh-cn)</li>
|
|
|
|
<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>
|
|
|
|
<li>Traditional Chinese (zh-tw)</li>
|
|
|
|
<li>Italian (it)</li>
|
|
|
|
<li>Korean (ko)</li>
|
|
|
|
<li>Japanese (ja)</li>
|
|
|
|
<li>Dutch (nl)</li>
|
|
|
|
<li>Vietnamese (vi)</li>
|
|
|
|
<li>Russian (ru)</li>
|
|
|
|
<li>Turkish (tr)</li>
|
|
|
|
<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>
|
|
|
|
<li>Swedish (sv)</li>
|
|
|
|
<li>Greek (el)</li>
|
|
|
|
<li>Slovak (sk)</li>
|
|
|
|
<li>Catalunya (ca)</li>
|
|
|
|
<li>Czech (cs)</li>
|
|
|
|
<li>Ukrainian (uk)</li>
|
|
|
|
<li>Turkmen (tk)</li>
|
|
|
|
<li>Tamil (ta)</li>
|
|
|
|
<li>Latvian (lv)</li>
|
|
|
|
<li>Afrikaans (af)</li>
|
|
|
|
<li>Estonian (et)</li>
|
|
|
|
<li>Slovenian (sl)</li>
|
|
|
|
<li>Arabic (ar)</li>
|
|
|
|
<li>Hebrew (he)</li>
|
|
|
|
<li>Lithuanian (lt)</li>
|
|
|
|
<li>Mongolian (mn)</li>
|
|
|
|
<li>Kazakh (kk)</li>
|
|
|
|
<li>Hungarian (hu)</li>
|
|
|
|
<li>Romanian (ro)</li>
|
|
|
|
<li>Kurdish (ku)</li>
|
|
|
|
<li>Uighur (ug-cn)</li>
|
|
|
|
<li>Khmer (km)</li>
|
|
|
|
<li>Serbian (sr)</li>
|
|
|
|
<li>Basque (eu)</li>
|
|
|
|
<li>Kyrgyz (ky)</li>
|
|
|
|
<li>Armenian (hy-am)</li>
|
|
|
|
<li>Croatian (hr)</li>
|
|
|
|
<li>Esperanto (eo)</li>
|
|
|
|
</ul>
|
2020-12-23 16:38:06 +08:00
|
|
|
|
2021-08-24 13:36:48 +08:00
|
|
|
If you need any other languages, [PR](https://github.com/element-plus/element-plus/pulls)
|
|
|
|
is always welcomed, you only need to add a language file at
|
|
|
|
[here](https://github.com/element-plus/element-plus/tree/dev/packages/locale/lang).
|
2020-12-23 16:38:06 +08:00
|
|
|
|
2021-08-24 13:36:48 +08:00
|
|
|
## FAQs
|
2021-01-19 23:49:07 +08:00
|
|
|
|
2021-08-24 13:36:48 +08:00
|
|
|
### If I want to replace the default language pack to reduce the size, how do I do?
|
2020-12-23 16:38:06 +08:00
|
|
|
|
2021-08-24 13:36:48 +08:00
|
|
|
When the default language of your app is not **English**, you will be going to need
|
|
|
|
to import another language file, which will increase the bundle size since you have
|
|
|
|
both **English** and **Your desired language** bundled,
|
|
|
|
you can use the plugin [NormalModuleReplacementPlugin](https://webpack.js.org/plugins/normal-module-replacement-plugin/#root)
|
|
|
|
provided by [webpack](https://webpack.js.org) to replace the default language file,
|
|
|
|
so that you will only get **1** language file bundled.
|
|
|
|
Add the code below into your `webpack.config.js` to get it work.
|
2020-08-13 15:18:26 +08:00
|
|
|
|
2021-08-24 13:36:48 +08:00
|
|
|
> webpack.config.js
|
2021-01-19 23:49:07 +08:00
|
|
|
|
|
|
|
```typescript
|
2020-08-13 15:18:26 +08:00
|
|
|
{
|
|
|
|
plugins: [
|
2021-01-19 23:49:07 +08:00
|
|
|
new webpack.NormalModuleReplacementPlugin(
|
|
|
|
/element-plus[\/\\]lib[\/\\]locale[\/\\]lang[\/\\]en/,
|
2021-09-04 19:29:28 +08:00
|
|
|
'element-plus/lib/locale/lang/zh-cn'
|
2021-01-19 23:49:07 +08:00
|
|
|
),
|
2020-08-13 15:18:26 +08:00
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|