feat(i18n): 更新语言文件导入逻辑,增强类型支持
All checks were successful
/ playwright (push) Successful in 2m47s
/ depcheck (push) Successful in 1m36s
/ build-and-deploy-to-vercel (push) Successful in 1m17s

This commit is contained in:
严浩
2024-11-06 18:45:37 +08:00
parent ec1d932250
commit b717b6252c

View File

@ -10,10 +10,16 @@ import { DataLoaderPlugin } from 'unplugin-vue-router/data-loaders';
import App from './App.vue';
import { router } from './router';
// 自动导入语言文件
interface LocaleMessages {
[key: string]: string;
}
const messages = Object.fromEntries(
Object.entries(import.meta.glob('./locales/*.json', { eager: true })).map(([key, value]) => {
return [key.slice('./locales/'.length, -5), value.default];
}),
Object.entries(import.meta.glob<Record<string, LocaleMessages>>('./locales/*.json', { eager: true })).map(
([key, value]) => {
return [key.slice('./locales/'.length, -5), value.default];
},
),
);
async function init() {