i18你,重构代码,细节优化

This commit is contained in:
2025-03-04 23:46:42 +08:00
parent d4b452d234
commit a935369927
10 changed files with 995 additions and 320 deletions

View File

@@ -6,12 +6,41 @@ import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import { createI18n } from 'vue-i18n'
// 引入语言文件
import zh from './locales/zh.json'
import ja from './locales/ja.json'
const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
app.component(key, component)
}
// 获取用户的首选语言
const userLanguage = navigator.language
// 定义支持的语言列表
const supportedLanguages = ['zh', 'ja']
// 根据用户的首选语言选择合适的语言
let locale = 'zh' // 默认语言为中文
if (supportedLanguages.includes(userLanguage.split('-')[0])) {
locale = userLanguage.split('-')[0]
}
const i18n = createI18n({
locale: locale, // 设置默认语言
fallbackLocale: 'zh', // 设置备用语言
messages: {
zh,
ja,
},
})
app.use(i18n)
app.use(ElementPlus)
app.mount('#app')