2020-08-13 15:18:26 +08:00
## Internationalisation
2020-11-09 14:53:43 +08:00
La langue par défaut d'Element Plus est le Anglais. Si vous souhaitez utiliser une autre langue, il vous faudra la configurer. Par exemple, dans votre fichier d'entrée, si vous importez Element Plus entièrement:
2020-08-13 15:18:26 +08:00
2021-01-19 23:49:07 +08:00
```typescript
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/fr'
2020-12-23 16:38:06 +08:00
import 'dayjs/locale/fr'
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
```
2021-01-25 16:23:15 +08:00
Ou si vous importez Element Plus à la demande via **es modules** :
2020-08-13 15:18:26 +08:00
2021-01-19 23:49:07 +08:00
```typescript
2021-01-25 16:23:15 +08:00
import { createApp } from 'vue'
import { ElButton, locale } from 'element-plus'
import lang from 'element-plus/lib/locale/lang/fr'
import 'dayjs/locale/fr'
locale(lang)
createApp(App).component(ElButton.name, ElButton)
```
Ou si vous importez Element Plus à la demande via [babel-plugin-component ](#/fe-FR/component/quickstart#on-demand ):
```typescript
import { createApp } from 'vue'
2020-11-23 16:28:06 +08:00
import { ElButton, ElSelect } from 'element-plus'
2020-11-09 14:53:43 +08:00
import lang from 'element-plus/lib/locale/lang/fr'
2020-12-23 16:38:06 +08:00
import 'dayjs/locale/fr'
2020-10-16 11:14:34 +08:00
import locale from 'element-plus/lib/locale'
2020-08-13 15:18:26 +08:00
2021-01-25 16:23:15 +08:00
// configure language
2020-08-13 15:18:26 +08:00
locale.use(lang)
2021-01-25 16:23:15 +08:00
// import components
createApp(App).component(ElButton.name, ElButton)
createApp(App).component(ElSelect.name, ElSelect)
2020-08-13 15:18:26 +08:00
```
2020-12-23 16:38:06 +08:00
### Set Day.js locale
Element Plus use date time locale (month name, first day of the week ...) from [Day.js ](https://day.js.org/ ) directlly. And will set the global Day.js locale automaticatlly after the locale file is loaded.
2021-01-19 23:49:07 +08:00
```typescript
2020-12-23 16:38:06 +08:00
import locale from 'element-plus/lib/locale/lang/fr'
import 'dayjs/locale/fr'
// will auto set Day.js locale to 'fr'
app.use(ElementPlus, { locale })
```
However, you can use another Day.js locale if needed.
2021-01-19 23:49:07 +08:00
```typescript
2020-12-23 16:38:06 +08:00
import 'dayjs/locale/es'
dayjs.locale('es')
```
2020-11-09 14:53:43 +08:00
La pack de la langue Anglais est importé par défaut, même si vous configurez une autre langue. En utilisant le `NormalModuleReplacementPlugin` fournit par webpack vous pouvez remplacer la locale par défaut:
2020-08-13 15:18:26 +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/,
'element-plus/lib/locale/lang/fr',
),
2020-08-13 15:18:26 +08:00
]
}
```
2021-01-19 23:49:07 +08:00
### Compatible avec `vue-i18n@9.x`
2020-08-13 15:18:26 +08:00
2021-01-19 23:49:07 +08:00
Element Plus est compatible avec [vue-i18n@9.x ](https://vue-i18n-next.intlify.dev/guide/#html ), ce qui rend le changement de langue encore plus simple.
2020-08-13 15:18:26 +08:00
2021-01-19 23:49:07 +08:00
```typescript
import { createApp } from 'vue'
import { createI18n } 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'
2021-01-19 23:49:07 +08:00
import App from './App.vue'
const messages = {
[enLocale.name]: {
// el property is critical, set this in order for ElementPlus translate strings correctly.
el: enLocale.el,
// Define your own dictionary with your own namespace, but DO NOT use the namespace `el` ,
// Because that makes the ElementPlus internal translation invalid.
message: {
hello: 'hello world',
},
},
[zhLocale.name]: {
el: zhLocale.el,
// Define your own dictionary with your own namespace, but DO NOT use the namespace `el` ,
// Because that makes the ElementPlus internal translation invalid.
message: {
hello: '你好,世界',
},
},
testLocale: {
el: {},
// No message translations, it will fallback to en lang, the definition of fallbackLocale is below 👇
},
}
const i18n = createI18n({
locale: zhLocale.name,
fallbackLocale: enLocale.name,
messages,
})
2020-08-13 15:18:26 +08:00
2020-10-16 11:22:08 +08:00
const app = createApp(App)
2020-08-13 15:18:26 +08:00
2021-01-19 23:49:07 +08:00
app.use(ElementPlus, {
i18n: i18n.global.t,
})
// Remember to use this plugin.
app.use(i18n)
2020-08-13 15:18:26 +08:00
```
2021-01-19 23:49:07 +08:00
### Compatible avec d'autres plugins i18n
2020-08-13 15:18:26 +08:00
2020-10-16 11:14:34 +08:00
Element Plus n'est pas forcément compatible avec d'autres plugins i18n que vue-i18n, mais vous pouvez configurer le fonctionnement i18n.
2020-08-13 15:18:26 +08:00
2021-01-19 23:49:07 +08:00
:::tip
Once you set this method, the internal translation function will be invalid, only the customized translation method will be used, be sure that your custom translation method can translate format like `el.scope.subName` , other wise the internal translation string will be raw string.
:::
```typescript
2020-08-13 15:18:26 +08:00
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
2021-01-19 23:49:07 +08:00
// The is the signature of i18n method.
type i18n = (...args: any[]) => string
2020-08-13 15:18:26 +08:00
Vue.use(Element, {
2021-01-19 23:49:07 +08:00
i18n: function(path, options) {
2020-08-13 15:18:26 +08:00
// ...
},
2021-01-19 23:49:07 +08:00
// others.
2020-08-13 15:18:26 +08:00
})
```
2021-01-19 23:49:07 +08:00
### i18n personnalisée dans les composants à la demande
2020-08-13 15:18:26 +08:00
2021-01-19 23:49:07 +08:00
Need translation
If you need to know how to lazy loading translation strings, please check this out[Lazy loading](https://vue-i18n-next.intlify.dev/guide/advanced/lazy.html)
2020-08-13 15:18:26 +08:00
2021-01-19 23:49:07 +08:00
```typescript
import { createApp } from 'vue'
import { createI18n } from 'vue-i18n'
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:14:34 +08:00
import ElementLocale from 'element-plus/lib/locale'
2021-01-19 23:49:07 +08:00
import App from './App.vue'
2020-08-13 15:18:26 +08:00
const messages = {
2021-01-19 23:49:07 +08:00
[enLocale.name]: {
// el property is critical, set this in order for ElementPlus translate strings correctly.
el: enLocale.el,
// Define your own dictionary with your own namespace, but DO NOT use the namespace `el` ,
// Because that makes the ElementPlus internal translation invalid.
message: {
hello: 'hello world',
},
},
[zhLocale.name]: {
el: zhLocale.el,
// Define your own dictionary with your own namespace, but DO NOT use the namespace `el` ,
// Because that makes the ElementPlus internal translation invalid.
message: {
hello: '你好,世界',
},
},
testLocale: {
el: {},
// No message translations, it will fallback to en lang, the definition of fallbackLocale is below 👇
2020-08-13 15:18:26 +08:00
},
}
2021-01-19 23:49:07 +08:00
const i18n = createI18n({
locale: zhLocale.name,
fallbackLocale: enLocale.name,
messages,
2020-08-13 15:18:26 +08:00
})
2021-01-19 23:49:07 +08:00
ElementLocale.i18n(i18n.global.t)
const app = createApp(App)
app.use(i18n)
2020-08-13 15:18:26 +08:00
```
2021-01-19 23:49:07 +08:00
### Import via un CDN
2020-08-13 15:18:26 +08:00
```html
2021-01-25 16:23:15 +08:00
< script src = "//unpkg.com/vue@next" > < / script >
< script src = "//unpkg.com/element-plus/lib/index.full.js" > < / script >
2020-12-23 16:38:06 +08:00
< script src = "//unpkg.com/element-plus/lib/umd/locale/fr.js" > < / script >
< script src = "//unpkg.com/dayjs/locale/fr.js" > < / script >
2020-08-13 15:18:26 +08:00
2021-01-25 16:23:15 +08:00
< script >
ElementPlus.locale(ElementPlus.lang.fr)
< / script >
```
Compatible avec `vue-i18n`
```html
< script src = "//unpkg.com/vue" > < / script >
< script src = "//unpkg.com/vue-i18n/dist/vue-i18n.js" > < / script >
< script src = "//unpkg.com/element-plus" > < / script >
< script src = "//unpkg.com/element-plus/lib/umd/locale/zh-cn.js" > < / script >
< script src = "//unpkg.com/element-plus/lib/umd/locale/en.js" > < / script >
2020-08-13 15:18:26 +08:00
< script >
2021-01-19 23:49:07 +08:00
// Need translation
const i18n = Vue18n.createI18n({
2021-01-25 16:23:15 +08:00
locale: ElementPlus.lang.zhCN.name,
fallbackLocale: ElementPlus.lang.en.name,
2021-01-19 23:49:07 +08:00
messages: {
2021-01-25 16:23:15 +08:00
[ElementPlus.lang.en.name]: {
2021-01-19 23:49:07 +08:00
// el property is critical, set this in order for ElementPlus translate strings correctly.
2021-01-25 16:23:15 +08:00
el: ElementPlus.lang.en.el,
2021-01-19 23:49:07 +08:00
// Define your own dictionary with your own namespace, but DO NOT use the namespace `el` ,
// Because that makes the ElementPlus internal translation invalid.
message: {
hello: 'hello world',
},
},
2021-01-25 16:23:15 +08:00
[ElementPlus.lang.zhCN.name]: {
el: ElementPlus.lang.zhCN.el,
2021-01-19 23:49:07 +08:00
// Define your own dictionary with your own namespace, but DO NOT use the namespace `el` ,
// Because that makes the ElementPlus internal translation invalid.
message: {
hello: '你好,世界',
},
},
testLocale: {
el: {},
// No message translations, it will fallback to en lang.
},
},
})
const app = Vue.createApp()
app.use(i18n)
2020-08-13 15:18:26 +08:00
< / script >
```
2020-10-16 11:14:34 +08:00
Actuellement, Element Plus supporte les langues suivantes:
2021-01-19 23:49:07 +08:00
2020-08-13 15:18:26 +08:00
< ul class = "language-list" >
2020-11-09 14:53:43 +08:00
< li > Chinois simplifié (zh-cn)< / li >
2020-08-13 15:18:26 +08:00
< li > Anglais (en)< / li >
< li > Allemand (de)< / li >
< li > Portugais (pt)< / li >
< li > Espagnol (es)< / li >
< li > Danois (da)< / li >
< li > Français (fr)< / li >
2020-11-09 14:53:43 +08:00
< li > Norvégien (nb-no)< / li >
< li > Chinois traditionnel (zh-tw)< / li >
2020-08-13 15:18:26 +08:00
< li > Italien (it)< / li >
< li > Coréen (ko)< / li >
< li > Japonais (ja)< / li >
< li > Néerlandais (nl)< / li >
< li > Vietnamien (vi)< / li >
2020-11-19 15:58:25 +08:00
< li > Russe (ru)< / li >
< li > Turque (tr)< / li >
2020-08-13 15:18:26 +08:00
< li > Portugais brésilien (pt-br)< / li >
< li > Farsi (fa)< / li >
< li > Thaï (th)< / li >
< li > Indonésien (id)< / li >
< li > Bulgare (bg)< / li >
< li > Polonais (pl)< / li >
< li > Finnois (fi)< / li >
2020-11-19 15:58:25 +08:00
< li > Suédois (sv)< / li >
2020-08-13 15:18:26 +08:00
< li > Grec (el)< / li >
< li > Slovaque (sk)< / li >
< li > Catalan (ca)< / li >
2020-11-19 15:58:25 +08:00
< li > Tchèque (cs)< / li >
< li > Ukrainien (uk)< / li >
2020-08-13 15:18:26 +08:00
< li > Turkmène (tk)< / li >
< li > Tamoul (ta)< / li >
< li > Letton (lv)< / li >
2020-11-19 15:58:25 +08:00
< li > Afrikaans (af)< / li >
< li > Estonien (et)< / li >
2020-08-13 15:18:26 +08:00
< li > Slovène (sl)< / li >
< li > Arabe (ar)< / li >
< li > Hébreu (he)< / li >
< li > Lituanien (lt)< / li >
< li > Mongol (mn)< / li >
2020-11-19 15:58:25 +08:00
< li > Kazakh (kk)< / li >
2020-08-13 15:18:26 +08:00
< li > Hongrois (hu)< / li >
< li > Roumain (ro)< / li >
< li > Kurde (ku)< / li >
2020-11-09 14:53:43 +08:00
< li > Ouïghour (ug-cn)< / li >
2020-08-13 15:18:26 +08:00
< li > Khmer (km)< / li >
< li > Serbe (sr)< / li >
< li > Basque (eu)< / li >
2020-11-19 15:58:25 +08:00
< li > Kirghize (ky)< / li >
< li > Arménien (hy-am)< / li >
2020-08-13 15:18:26 +08:00
< li > Croate (hr)< / li >
< li > Espéranto (eo)< / li >
< / ul >
2020-11-09 14:53:43 +08:00
Si votre langue n'apparaît pas dans la liste, n'hésitez pas a contribuer: ajoutez simplement un fichier de configuration [ici ](https://github.com/element-plus/element-plus/tree/dev/packages/locale/lang ) et créez une pull request.