fix: vxe-table i18n

This commit is contained in:
xiaoxian521 2022-03-13 14:01:51 +08:00
parent 51d08e4b82
commit a7576f6971
2 changed files with 9 additions and 23 deletions

View File

@ -3,9 +3,6 @@ import { App, WritableComputedRef } from "vue";
import { storageLocal } from "/@/utils/storage"; import { storageLocal } from "/@/utils/storage";
import { type I18n, createI18n } from "vue-i18n"; import { type I18n, createI18n } from "vue-i18n";
// vxe-table组件国际化
import zhVxeTable from "vxe-table/lib/locale/lang/zh-CN";
import enVxeTable from "vxe-table/lib/locale/lang/en-US";
// element-plus国际化 // element-plus国际化
import enLocale from "element-plus/lib/locale/lang/en"; import enLocale from "element-plus/lib/locale/lang/en";
import zhLocale from "element-plus/lib/locale/lang/zh-cn"; import zhLocale from "element-plus/lib/locale/lang/zh-cn";
@ -24,12 +21,10 @@ function siphonI18n(prefix = "zh-CN") {
export const localesConfigs = { export const localesConfigs = {
zh: { zh: {
...siphonI18n("zh-CN"), ...siphonI18n("zh-CN"),
...zhVxeTable,
...zhLocale ...zhLocale
}, },
en: { en: {
...siphonI18n("en"), ...siphonI18n("en"),
...enVxeTable,
...enLocale ...enLocale
} }
}; };

View File

@ -1,11 +1,14 @@
import "xe-utils"; import "xe-utils";
import { App } from "vue"; import XEUtils from "xe-utils";
import { App, unref } from "vue";
import { i18n } from "/@/plugins/i18n"; import { i18n } from "/@/plugins/i18n";
import "font-awesome/css/font-awesome.min.css"; import "font-awesome/css/font-awesome.min.css";
import zh from "vxe-table/lib/locale/lang/zh-CN";
import en from "vxe-table/lib/locale/lang/en-US";
import { import {
// 核心 // 核心
VXETable, VXETable,
// 表格功能 // 表格功能
Header, Header,
Footer, Footer,
@ -16,7 +19,6 @@ import {
Export, Export,
Keyboard, Keyboard,
Validator, Validator,
// 可选组件 // 可选组件
Column, Column,
Colgroup, Colgroup,
@ -42,7 +44,6 @@ import {
Modal, Modal,
List, List,
Pulldown, Pulldown,
// 表格 // 表格
Table Table
} from "vxe-table"; } from "vxe-table";
@ -61,19 +62,10 @@ VXETable.setup({
input: { input: {
clearable: true clearable: true
}, },
// 对组件内置的提示语进行国际化翻译 i18n: (key, args) => {
// @ts-ignore return unref(i18n.global.locale) === "zh"
i18n: (key, args) => i18n.global.t(key, args), ? XEUtils.toFormatString(XEUtils.get(zh, key), args)
// 可选,对参数中的列头、校验提示..等进行自动翻译(只对支持国际化的有效) : XEUtils.toFormatString(XEUtils.get(en, key), args);
translate(key, args) {
// 例如,只翻译 "buttons." 开头的键值
if (key && key.indexOf("buttons.") > -1) {
return i18n.global.t(key, args);
}
if (key && key.indexOf("el.") > -1) {
return i18n.global.t(key, args);
}
return key;
} }
}); });
@ -88,7 +80,6 @@ export function useTable(app: App) {
.use(Export) .use(Export)
.use(Keyboard) .use(Keyboard)
.use(Validator) .use(Validator)
// 可选组件 // 可选组件
.use(Column) .use(Column)
.use(Colgroup) .use(Colgroup)