优化翻译
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user