feat(i18n): 添加中文和英文语言文件,集成国际化支持
This commit is contained in:
24
src/main.ts
24
src/main.ts
@ -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__;
|
||||
|
Reference in New Issue
Block a user