feat:国际化多语言适配

This commit is contained in:
2025-10-29 15:48:40 +08:00
parent 985d739324
commit 3d67dc928d
41 changed files with 2636 additions and 2801 deletions
+33
View File
@@ -0,0 +1,33 @@
// i18n工具函数 - 用于在 Vue 3 setup 中安全获取 $t
import { getCurrentInstance } from 'vue'
/**
* 在 setup 中使用 i18n
* @returns {{ t: Function, locale: string, i18n: object }}
*/
export function useI18n() {
const instance = getCurrentInstance()
if (!instance || !instance.proxy) {
return {
t: (key) => key,
locale: 'zh-CN',
i18n: null
}
}
const proxy = instance.proxy
// 返回一个函数,每次调用时动态获取 $t(确保 $t 已经注入)
return {
t: (key, ...args) => {
if (proxy.$t && typeof proxy.$t === 'function') {
return proxy.$t(key, ...args)
}
return key
},
locale: proxy.$i18n?.locale || 'zh-CN',
i18n: proxy.$i18n
}
}