Skip to content

feat(i18n): 切换语言时同步更新页面标题#650

Merged
Wei-Shaw merged 1 commit intoWei-Shaw:mainfrom
wucm667:feat/sync-page-title-on-locale-change
Feb 27, 2026
Merged

feat(i18n): 切换语言时同步更新页面标题#650
Wei-Shaw merged 1 commit intoWei-Shaw:mainfrom
wucm667:feat/sync-page-title-on-locale-change

Conversation

@wucm667
Copy link
Copy Markdown
Contributor

@wucm667 wucm667 commented Feb 26, 2026

问题

切换语言后,浏览器页签标题不会跟随更新,仍显示旧语言的标题文本。

解决方案

1. router/title.ts — 新增 titleKey 参数

resolveDocumentTitle() 新增可选参数 titleKey,优先通过 i18n 翻译生成标题,翻译失败时回退到静态 routeTitle

2. router/index.ts — 传入路由 meta.titleKey

beforeEach 守卫调用 resolveDocumentTitle 时,将路由 meta.titleKey 一并传入,使导航时的标题即可国际化。

3. i18n/index.ts — setLocale 后同步刷新标题

setLocale() 完成语言切换后,读取当前路由的 meta.titleKey 并重新调用 resolveDocumentTitle,更新 document.title,确保页签标题与 UI 语言保持一致。

测试

  1. 登录后进入任意页面(如「API Keys」)
  2. 切换语言(英文 ↔ 中文)
  3. 观察浏览器页签标题是否同步变更

- resolveDocumentTitle() 新增 titleKey 参数,优先通过 i18n 翻译
- router beforeEach 中将路由 meta.titleKey 传入标题解析函数
- setLocale() 切换语言后同步刷新 document.title
Copilot AI review requested due to automatic review settings February 26, 2026 06:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements automatic page title synchronization when users switch languages in the application. The implementation extends the existing i18n title infrastructure (titleKey) to support three authentication-related routes: Login, Register, and Forgot Password.

Changes:

  • Enhanced resolveDocumentTitle() to prioritize i18n translations via titleKey parameter
  • Added titleKey metadata to Login, Register, and Forgot Password routes
  • Implemented automatic title refresh in setLocale() to update browser tab title after language change

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
frontend/src/router/title.ts Added i18n integration with optional titleKey parameter and fallback logic to existing title resolver
frontend/src/router/index.ts Added titleKey metadata to Login, Register, and Forgot Password routes for i18n support
frontend/src/i18n/index.ts Added dynamic title refresh logic after locale change to synchronize browser tab title

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread frontend/src/router/index.ts
Comment thread frontend/src/router/title.ts
Comment thread frontend/src/router/index.ts
@Wei-Shaw Wei-Shaw merged commit 3bae525 into Wei-Shaw:main Feb 27, 2026
7 of 8 checks passed
@wucm667 wucm667 deleted the feat/sync-page-title-on-locale-change branch February 27, 2026 11:51
xuebkgithub pushed a commit to xuebkgithub/sub2api that referenced this pull request Mar 3, 2026
…locale-change

feat(i18n): 切换语言时同步更新页面标题
liafonx pushed a commit to liafonx/sub2api that referenced this pull request Mar 20, 2026
…locale-change

feat(i18n): 切换语言时同步更新页面标题
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants