feat(i18n): 添加中文和英文语言文件,集成国际化支持
Some checks failed
/ build-and-deploy-to-vercel (push) Failing after 1m10s
/ playwright (push) Successful in 2m34s
/ depcheck (push) Successful in 1m39s

This commit is contained in:
严浩
2024-11-06 18:28:53 +08:00
parent 40752e555f
commit ec1d932250
8 changed files with 269 additions and 23 deletions

View File

@ -9,6 +9,12 @@ import { createI18n } from 'vue-i18n';
import { DataLoaderPlugin } from 'unplugin-vue-router/data-loaders';
import App from './App.vue';
import { router } from './router';
// 自动导入语言文件
const messages = Object.fromEntries(
Object.entries(import.meta.glob('./locales/*.json', { eager: true })).map(([key, value]) => {
return [key.slice('./locales/'.length, -5), value.default];
}),
);
async function init() {
if (import.meta.env.MODE === 'development' || 1 === 1) {
@ -33,20 +39,10 @@ async function init() {
.use(router)
.use(
createI18n({
locale: 'zh_CN', // 默认显示语言
fallbackLocale: 'zh_CN',
messages: {
en_US: {
message: {
hello: 'hello',
},
},
zh_CN: {
message: {
hello: '你好',
},
},
},
legacy: false, // 使用 Composition API 模式
locale: 'zh', // 默认语言
fallbackLocale: 'en', // 回退语言
messages,
}),
);
app.config.globalProperties.$__DEV__ = $__DEV__;