import Vue from "vue" import VueI18n from "vue-i18n" // 导入本地国际化文件 import enLocal from "./en-US" import zhLocal from "./zh-CN" const messages = { "en-US": { ...enLocal }, "zh-CN": { ...zhLocal } } Vue.use(VueI18n) const i18n = new VueI18n({ locale: "zh-CN", messages }) function t(key, ...args) { if (args.length === 0) { return i18n.t(key) } else if (args.length === 1 && (typeof args[0]).toLowerCase() === "string") { return i18n.t(key, { field: i18n.t(args[0]) }) } else if (args.length === 1 && (typeof args[0]).toLowerCase() === "object") { let obj = {} return i18n.t(key, obj) } else { throw new Error("出错了,请联系管理员") } } export { i18n as default, t }