Skip to content

fix(i18n): 切换语言后刷新启动按钮与版本文本,避免中英混排 #3306

Merged
Pigeon0v0 merged 10 commits into
PCL-Community:devfrom
NoClassFoundError:fix/3246-lang-refresh
Jul 5, 2026
Merged

fix(i18n): 切换语言后刷新启动按钮与版本文本,避免中英混排 #3306
Pigeon0v0 merged 10 commits into
PCL-Community:devfrom
NoClassFoundError:fix/3246-lang-refresh

Conversation

@NoClassFoundError

@NoClassFoundError NoClassFoundError commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

启动页 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:

  • Fix launch page button and version labels not refreshing after language change, preventing mixed-language UI on returning to the page.

启动页 PageLaunchLeft 为常驻缓存实例,其 Loaded 用 isLoad 守卫、初始化仅
执行一次;BtnLaunch/LabVersion 等文本由 RefreshButtonsUI 以 Lang.Text 直接
赋值(非 DynamicResource 绑定),故语言热切换后不会刷新。又因 RefreshButtonsUI
在“启动状态未变化”时会跳过文本重设,即便切回页面时 BtnLaunch.Loaded 重新触发
它也不生效,导致切回启动页后按钮/版本文本停留在旧语言、与已刷新的绑定文本混排。

订阅 LocalizationService.LanguageChanged(常驻实例,无需退订),事件触发时把
btnLaunchState 置为无效值使文本缓存失效,从而切回页面时 RefreshButtonsUI 以
新语言重新赋值。
@pcl-ce-automation pcl-ce-automation Bot added 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查 size: S PR 大小评估:小型 labels Jul 1, 2026
@sourcery-ai

sourcery-ai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor
审阅者指南(在小型 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
Loading

文件级更改

变更 详情 文件
让启动页面订阅语言变更事件,并在语言更改时强制刷新缓存的按钮/版本文本。
  • 在 PageLaunchLeft 构造函数中,将 OnLanguageChanged 处理程序注册到 LocalizationService.LanguageChanged,利用页面自身的缓存生命周期,因此不需要取消订阅。
  • 实现 OnLanguageChanged,以使 btnLaunchState 失效,并在 UI 线程上调用 RefreshButtonsUI,从而即使逻辑上的启动状态没有变化,BtnLaunch 和 LabVersion 文本也会被重新赋值为新语言。
Plain Craft Launcher 2/Pages/PageLaunch/PageLaunchLeft.xaml.cs

与关联 Issue 的对照评估

Issue 目标 是否解决 说明
#3246 确保在更改应用语言后,当返回到启动页面时,启动页面控件(例如启动按钮文本和版本标签)会刷新为新语言,避免出现中英文混杂显示。

可能相关的 Issue


提示与命令

与 Sourcery 交互

  • 触发新审阅: 在 pull request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 从审阅评论生成 GitHub Issue: 在某条审阅评论下回复,请求 Sourcery 从该评论创建一个 Issue。你也可以在审阅评论下回复 @sourcery-ai issue 来从该评论创建 Issue。
  • 生成 pull request 标题: 在 pull request 标题的任意位置写上 @sourcery-ai,即可随时生成标题。你也可以在 pull request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request 正文的任意位置写上 @sourcery-ai summary,即可在你想要的位置生成 PR 摘要。你也可以在 pull request 中评论 @sourcery-ai summary 来(重新)生成摘要。
  • 生成审阅者指南: 在 pull request 中评论 @sourcery-ai guide,即可在任意时间(重新)生成审阅者指南。
  • 一次性解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve,即可将所有 Sourcery 评论标记为已解决。如果你已经处理完所有评论且不想再看到它们,这会很有用。
  • 一次性忽略所有 Sourcery 审阅: 在 pull request 中评论 @sourcery-ai dismiss,即可忽略所有现有的 Sourcery 审阅。如果你想从头开始一次新的审阅,这尤其有用 —— 记得再评论 @sourcery-ai review 来触发新审阅!

自定义你的使用体验

访问你的 控制面板 以:

  • 启用或禁用审阅功能,例如 Sourcery 生成的 pull request 摘要、审阅者指南等。
  • 更改审阅语言。
  • 添加、移除或编辑自定义审阅说明。
  • 调整其他审阅设置。

获取帮助

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This 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 texts

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
Loading

File-Level Changes

Change Details Files
Subscribe launch page to language change events and force-refresh cached button/version texts when language changes.
  • Register OnLanguageChanged handler to LocalizationService.LanguageChanged in the PageLaunchLeft constructor, leveraging the page’s cached lifetime so no unsubscription is required.
  • Implement OnLanguageChanged to invalidate btnLaunchState and invoke RefreshButtonsUI on the UI thread so that BtnLaunch and LabVersion texts are reassigned in the new language even if the logical launch state didn’t change.
Plain Craft Launcher 2/Pages/PageLaunch/PageLaunchLeft.xaml.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#3246 Ensure that after changing the application language, the launch page controls (e.g., Launch button text and version label) refresh to the new language when returning to the launch page, avoiding mixed-language (Chinese/English) display.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've left some high level feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
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 之类魔法值表示强制刷新。
@pcl-ce-automation pcl-ce-automation Bot added size: L PR 大小评估:大型 and removed size: S PR 大小评估:小型 labels Jul 1, 2026
@Chiloven945

Copy link
Copy Markdown
Member

计划在 #2927 中修掉,不过这样也行。。

@Chiloven945 Chiloven945 added this to the I18n milestone Jul 1, 2026
@Chiloven945 Chiloven945 changed the title fix(launch): 切换语言后刷新启动按钮与版本文本,避免中英混排 (#3246) fix(i18n): 切换语言后刷新启动按钮与版本文本,避免中英混排 (#3246) Jul 1, 2026
Comment thread PCL.Core/App/Localization/WeakLanguageChanged.cs
Comment thread PCL.Core/App/Localization/WeakLanguageChanged.cs
@Chiloven945

Chiloven945 commented Jul 1, 2026

Copy link
Copy Markdown
Member

只是提一嘴,没有别的意思。如果使用了 AI 工具,考虑在 PR 信息或 Commit 里提及使用的模型。参考 技术规范-AI 工具使用规范

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

@Chiloven945 Chiloven945 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

同 Codex

@NoClassFoundError NoClassFoundError changed the title fix(i18n): 切换语言后刷新启动按钮与版本文本,避免中英混排 (#3246) fix(i18n): 切换语言后刷新启动按钮与版本文本,避免中英混排 Jul 3, 2026

@Chiloven945 Chiloven945 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

请移除没有必要的注释。

还有:

d6c60b41461d6a325725e02a439d1c54

@pcl-ce-automation pcl-ce-automation Bot added 🕑 等待合并 已处理完毕,正在等待代码合并入主分支 and removed 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查 labels Jul 5, 2026
@Pigeon0v0 Pigeon0v0 merged commit 8cfec15 into PCL-Community:dev Jul 5, 2026
3 checks passed
@pcl-ce-automation pcl-ce-automation Bot added 👌 完成 相关问题已修复或功能已实现,计划在下次版本更新时正式上线 and removed 🕑 等待合并 已处理完毕,正在等待代码合并入主分支 labels Jul 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: L PR 大小评估:大型 👌 完成 相关问题已修复或功能已实现,计划在下次版本更新时正式上线

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C#]: 更改语言后部分控件文本不会同步刷新

3 participants