Skip to content

Internationalization

Vue EP Toolkit components are in English by default, and support multiple languages.

Global Configuration

Vue EP Toolkit provides two ways to configure internationalization.

Full Import

If you use full import, you need to pass the locale configuration when registering the plugin:

ts
import { createApp } from "vue"
import VueEpToolkit, { zhCn } from "vue-ep-toolkit"
import "vue-ep-toolkit/dist/index.css"
import App from "./App.vue"

const app = createApp(App)
app.use(VueEpToolkit, {
  locale: zhCn
})
app.mount("#app")

On-demand Import

If you use on-demand import, you need to use the ElConfigProvider component to configure internationalization:

vue
<template>
  <el-config-provider :locale="locale">
    <app />
  </el-config-provider>
</template>

<script setup>
import { ElConfigProvider } from "element-plus"
import { zhCn } from "vue-ep-toolkit"

const locale = zhCn
</script>

Supported Languages

Vue EP Toolkit has the following built-in language packs:

LanguageFilename
Englishen
Simplified Chinesezh-cn

Using Other Languages

If you need to use other languages, you can refer to the format of existing language packs to customize your own.

Language Pack Format

ts
import zhCn from "element-plus/es/locale/lang/zh-cn"

export default {
  ...zhCn, // Inherit Element Plus language pack
  ep: {
    table: {
      refresh: "Refresh",
      export: "Export",
      search: "Search",
      column: "Column"
    }
  }
}

Using Custom Language Pack

ts
import { createApp } from "vue"
import VueEpToolkit from "vue-ep-toolkit"
import customLocale from "./locale/custom"
import App from "./App.vue"

const app = createApp(App)
app.use(VueEpToolkit, {
  locale: customLocale
})
app.mount("#app")

Dynamic Language Switching

You can use the useLocale composable to dynamically switch languages:

vue
<template>
  <el-button @click="toggleLocale">Toggle Language</el-button>
</template>

<script setup>
import { ref } from "vue"
import { useLocale, en, zhCn } from "vue-ep-toolkit"

const locale = useLocale()
const currentLang = ref("zh-cn")

const toggleLocale = () => {
  if (currentLang.value === "zh-cn") {
    locale.value = en
    currentLang.value = "en"
  } else {
    locale.value = zhCn
    currentLang.value = "zh-cn"
  }
}
</script>

Released under the MIT License.