优化翻译

This commit is contained in:
2026-03-19 14:43:08 +08:00
parent f63616e735
commit db0e420a8f
6 changed files with 113 additions and 33 deletions

View File

@@ -43,14 +43,33 @@ export async function loadPageLocale(routePath: string): Promise<void> {
return
}
const locale = getCurrentLocale()
const key = getModuleKey(locale, path)
const modules = locale === LanguageEnum.EN ? enModules : zhModules
const loader = modules[key]
const tryPaths: string[] = [path]
// 兼容别名路由:例如 /user 实际页面为 /system/user
if (!path.includes('/')) {
tryPaths.push(`system/${path}`)
}
if (path === 'user') {
tryPaths.push('system/user')
}
let matchedPath: string | null = null
let loader: (() => Promise<PageLocaleModule>) | undefined
for (const p of tryPaths) {
const key = getModuleKey(locale, p)
const l = modules[key]
if (l) {
matchedPath = p
loader = l
break
}
}
if (!loader) {
clearPageLocale()
return
}
if (lastLoadedPath === path && lastLoadedLocale === locale) {
if (lastLoadedPath === matchedPath && lastLoadedLocale === locale) {
return
}
try {
@@ -58,7 +77,7 @@ export async function loadPageLocale(routePath: string): Promise<void> {
const message = mod?.default
if (message && typeof message === 'object') {
i18n.global.mergeLocaleMessage(locale, { page: message })
lastLoadedPath = path
lastLoadedPath = matchedPath
lastLoadedLocale = locale
}
} catch {