fix(i18n): 切换语言后刷新启动按钮与版本文本,避免中英混排 #3306
Conversation
启动页 PageLaunchLeft 为常驻缓存实例,其 Loaded 用 isLoad 守卫、初始化仅 执行一次;BtnLaunch/LabVersion 等文本由 RefreshButtonsUI 以 Lang.Text 直接 赋值(非 DynamicResource 绑定),故语言热切换后不会刷新。又因 RefreshButtonsUI 在“启动状态未变化”时会跳过文本重设,即便切回页面时 BtnLaunch.Loaded 重新触发 它也不生效,导致切回启动页后按钮/版本文本停留在旧语言、与已刷新的绑定文本混排。 订阅 LocalizationService.LanguageChanged(常驻实例,无需退订),事件触发时把 btnLaunchState 置为无效值使文本缓存失效,从而切回页面时 RefreshButtonsUI 以 新语言重新赋值。
审阅者指南(在小型 PR 上折叠)审阅者指南此 PR 将 PageLaunchLeft 连接到 LocalizationService.LanguageChanged,使缓存的启动按钮和版本标签文本在语言更改时失效并刷新,防止在返回启动页面时出现语言混合(旧语言残留)的情况。 语言变更时刷新启动按钮文本的时序图sequenceDiagram
actor User
participant SettingsPage
participant LocalizationService
participant PageLaunchLeft
participant ModBase
User->>SettingsPage: changeLanguage
SettingsPage->>LocalizationService: setLanguage
LocalizationService-->>PageLaunchLeft: LanguageChanged
PageLaunchLeft->>PageLaunchLeft: OnLanguageChanged
PageLaunchLeft->>PageLaunchLeft: btnLaunchState = -1
PageLaunchLeft->>ModBase: RunInUi(RefreshButtonsUI)
ModBase-->>PageLaunchLeft: RefreshButtonsUI()
PageLaunchLeft->>PageLaunchLeft: reassign BtnLaunch/LabVersion texts
文件级更改
与关联 Issue 的对照评估
可能相关的 Issue
提示与命令与 Sourcery 交互
自定义你的使用体验访问你的 控制面板 以:
获取帮助Original review guide in EnglishReviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR wires PageLaunchLeft into LocalizationService.LanguageChanged so that the cached launch button and version label texts are invalidated and refreshed on language change, preventing stale-language mixing when navigating back to the launch page. Sequence diagram for language change refreshing launch button textssequenceDiagram
actor User
participant SettingsPage
participant LocalizationService
participant PageLaunchLeft
participant ModBase
User->>SettingsPage: changeLanguage
SettingsPage->>LocalizationService: setLanguage
LocalizationService-->>PageLaunchLeft: LanguageChanged
PageLaunchLeft->>PageLaunchLeft: OnLanguageChanged
PageLaunchLeft->>PageLaunchLeft: btnLaunchState = -1
PageLaunchLeft->>ModBase: RunInUi(RefreshButtonsUI)
ModBase-->>PageLaunchLeft: RefreshButtonsUI()
PageLaunchLeft->>PageLaunchLeft: reassign BtnLaunch/LabVersion texts
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - 我在这里给出了一些整体性的反馈:
- 使用
-1作为btnLaunchState的魔法值会让意图变得不太清晰;建议引入一个具名常量或枚举成员来表示无效/强制刷新状态。 - 在构造函数中订阅
LocalizationService.LanguageChanged事件而不取消订阅,假定了此页面是真正长生命周期的单例;如果这一假设将来不再成立,建议使用弱事件模式或显式取消订阅以避免内存泄漏。
给 AI Agent 的提示
Please address the comments from this code review:
## Overall Comments
- Using `-1` as a magic value for `btnLaunchState` makes the intent less clear; consider introducing a named constant or enum member to represent the invalid/force-refresh state.
- Subscribing to `LocalizationService.LanguageChanged` in the constructor without unsubscribing assumes this page is truly a long-lived singleton; if that assumption ever changes, consider a weak-event pattern or explicit unsubscription to avoid leaks.帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English
Hey - I've left some high level feedback:
- Using
-1as a magic value forbtnLaunchStatemakes the intent less clear; consider introducing a named constant or enum member to represent the invalid/force-refresh state. - Subscribing to
LocalizationService.LanguageChangedin the constructor without unsubscribing assumes this page is truly a long-lived singleton; if that assumption ever changes, consider a weak-event pattern or explicit unsubscription to avoid leaks.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Using `-1` as a magic value for `btnLaunchState` makes the intent less clear; consider introducing a named constant or enum member to represent the invalid/force-refresh state.
- Subscribing to `LocalizationService.LanguageChanged` in the constructor without unsubscribing assumes this page is truly a long-lived singleton; if that assumption ever changes, consider a weak-event pattern or explicit unsubscription to avoid leaks.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
启动页、下载页等为常驻缓存单例,其 code-behind 用 Lang.Text 一次性赋值的 文本在语言热切换后不会刷新,切回页面时与 DynamicResource 绑定文本混排。 新增 WeakLanguageChanged:以弱引用订阅 LocalizationService.LanguageChanged, 订阅者被 GC 后自动移除。据此让缓存页在语言变更时即时重刷: - PageLaunchLeft:RefreshButtonsUI 以语言令牌为重设条件,重刷启动按钮与版本; - PageDownloadInstall:重建版本分类卡片(标题含动态计数,无法用 DynamicResource); - PageDownloadCompFavorites:按 CompType 重设各分类标题并重排。 回应 review:采用弱事件模式而非构造函数强订阅,规避单例假设失效导致的内存 泄漏;不再使用 -1 之类魔法值表示强制刷新。
|
计划在 #2927 中修掉,不过这样也行。。 |
|
只是提一嘴,没有别的意思。如果使用了 AI 工具,考虑在 PR 信息或 Commit 里提及使用的模型。参考 技术规范-AI 工具使用规范。 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 046c0c4602
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b11d7037ec
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

启动页 PageLaunchLeft 为常驻缓存实例,其 Loaded 用 isLoad 守卫、初始化仅 执行一次;BtnLaunch/LabVersion 等文本由 RefreshButtonsUI 以 Lang.Text 直接 赋值(非 DynamicResource 绑定),故语言热切换后不会刷新。又因 RefreshButtonsUI 在“启动状态未变化”时会跳过文本重设,即便切回页面时 BtnLaunch.Loaded 重新触发
它也不生效,导致切回启动页后按钮/版本文本停留在旧语言、与已刷新的绑定文本混排。
订阅 LocalizationService.LanguageChanged(常驻实例,无需退订),事件触发时把 btnLaunchState 置为无效值使文本缓存失效,从而切回页面时 RefreshButtonsUI 以 新语言重新赋值。
resolves #3246
本PR的信息生成由Claude Code Opus 4.8辅助完成,由Opus 4.8对代码进行了审查和少量修改并添加了注释。
Summary by Sourcery
Bug Fixes:
Original summary in English
Summary by Sourcery
Bug Fixes: