Merge pull request #650 from wucm667/feat/sync-page-title-on-locale-change

feat(i18n): 切换语言时同步更新页面标题
This commit is contained in:
Wesley Liddick
2026-02-27 19:48:36 +08:00
committed by GitHub
3 changed files with 26 additions and 5 deletions

View File

@@ -68,6 +68,14 @@ export async function setLocale(locale: string): Promise<void> {
i18n.global.locale.value = locale
localStorage.setItem(LOCALE_KEY, locale)
document.documentElement.setAttribute('lang', locale)
// 同步更新浏览器页签标题,使其跟随语言切换
const { resolveDocumentTitle } = await import('@/router/title')
const { default: router } = await import('@/router')
const { useAppStore } = await import('@/stores/app')
const route = router.currentRoute.value
const appStore = useAppStore()
document.title = resolveDocumentTitle(route.meta.title, appStore.siteName, route.meta.titleKey as string)
}
export function getLocale(): LocaleCode {