You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
739 B
36 lines
739 B
import { createI18n } from "vue-i18n";
|
|
const DEFAULT_LANG = "zh";
|
|
|
|
const importFn = (data)=> {
|
|
let lang = {};
|
|
|
|
for (const [key, value] of Object.entries(data)) {
|
|
const moduleName = key.replace(/^\.\.\/(.*)\.\w+$/, "$1");
|
|
const name = moduleName.split("/")[2];
|
|
name && (lang[name] = value);
|
|
}
|
|
return lang;
|
|
};
|
|
|
|
let locales = {
|
|
en: importFn(
|
|
import.meta.glob("../locales/US-EN/*.json", {
|
|
import: "default",
|
|
eager: true,
|
|
})
|
|
),
|
|
zh: importFn(
|
|
import.meta.glob("../locales/ZH-CN/*.json", {
|
|
import: "default",
|
|
eager: true,
|
|
})
|
|
),
|
|
};
|
|
|
|
const $globalLang = createI18n({
|
|
legacy: false, // 使用 Composition API 模式(vue-i18n v11 要求)
|
|
locale: DEFAULT_LANG,
|
|
messages: locales,
|
|
});
|
|
|
|
export { $globalLang };
|
|
|