feat(m179): 外观分组接真语言并拆成五段文件(只接管子,不补文案)
M172 审计:`pages/appearance/**` 中文界面下真正本地化 0/27,两个根因各断一刀。
① 拆文件(纯搬移):`section.rs` 395 行 → `section/` 五个文件,行数守卫只剩 5 行余量,
不拆就加不了任何东西。
- `section/mod.rs`(壳:section() + card() + 五个行控件 + 取词口 t)
- `section/window.rs`(① 整窗 α + ② 圆角,含 notice/说明段)
- `section/panel.rs`(③ 面板 α)、`section/bg_image.rs`(④⑤⑥⑦⑧)、
`section/colour_source.rs`(⑨)
取证:每段与原文件做「去空白/去尾逗号」diff,4/4 相同;只有五处机械改写
(`rows = rows.push(…)`→`rows.push(…)`、`t(Key::X)`→`t(Key::X, lang)`、
`super::notice`→`super::super::notice`、一处 `.into()`、rustfmt 换行)。
② 语言接到渲染层:`settings::Body` 从 `fn(&Ui, States)` 变成 `fn(&Ui, States, Lang)`,
`form` 传 `language.effective`,`settings/appearance.rs` 收 `lang` 转给
`pages::appearance::section(ui, state, lang)`,`section::t(key, lang)` 取词。
选「接进唯一那个槽位」而不是再给 `form` 加一条按下标分发的 `else if`:`settings/mod.rs`
贴着 400 行硬顶(M195 还要在此落地),这条路净增 0 行且不可能与分发表漂开。
验收点:`pages/appearance/**` 里已经搜不到 `Lang::En`。
③ 能变红的守卫:`the_appearance_group_speaks_chinese_when_the_interface_does`
—— 走 `settings::view` 真分发渲染一帧,断言取词记录里含汉字、英文那帧不含汉字且同一 key
中英译文不同。取证口是 `appearance::probe`(`#[cfg(test)]` thread_local):iced 0.14
没有可遍历控件树的公开接口(`Widget::children()` 返回状态 Tree;`operate` 要 Renderer),
所以取证点退到「字进树之前」的唯一取词口。变异证明:把 `t()` 改回 `Lang::En.catalog()`
⇒ 该用例红(失败信息逐条列出四条英文);还原 ⇒ 绿。
只接语言管子,不补文案:本组其余英文仍是字面量(行号见 M179 报告)。真实窗口截图、
macOS/Linux 字体差异未验。
This commit is contained in:
1 parent
e386cfbeee
commit
b457f0acc8
14 files changed
+745
-422
No files matched your search
@@ -0,0 +1,46 @@
|
||||
//! **测试专用**:记录「画一帧时从词表取出的每一条译文」。
|
||||
//!
|
||||
//! ## 为什么需要这一层
|
||||
//!
|
||||
//! 判据是「中文界面下外观分组渲染出来的字里必须含汉字」,但 iced 0.14 **没有**可以遍历控件树的
|
||||
//! 公开接口:
|
||||
//!
|
||||
//! - `Element::as_widget()` 拿到的是 `&dyn Widget`,而 `Widget::children()` 返回的是**状态** `Tree`
|
||||
//! (不是子控件),没有 `as_any` 之类的向下转型口;
|
||||
//! - 想走 `Widget::operate` 得自己造 `Tree` + 跑布局 + 传 `Renderer`,而单测里**没有渲染器**
|
||||
//! (`pages/download/tests/options_screen.rs` 记的正是这条边界)。
|
||||
//!
|
||||
//! 所以取证点退到「字进树之前」那一层:`section::t` 是本分组**唯一**的取词口,它把每条译文
|
||||
//! 顺手记一份,测试再断言这批字里有没有汉字。这不是「看源码字符串」那种假守卫——它要求真的把
|
||||
//! [`crate::pages::appearance::section`] 跑一遍(并且走 `settings::view` 的语言分发),只是不画像素。
|
||||
//!
|
||||
//! ## 为什么是 thread-local
|
||||
//!
|
||||
//! `cargo test` 默认多线程跑,每个测试一个线程;thread-local 让并发测试的取证互不串台,
|
||||
//! 也不需要加锁或串行化。
|
||||
//!
|
||||
//! 整个模块只在 `#[cfg(test)]` 下编译,产品路径零代价。
|
||||
|
||||
use std::cell::RefCell;
|
||||
|
||||
use unlucky_i18n::catalog::Key;
|
||||
|
||||
// 自上次 `take` 以来记录下的 `(key, 译文)`,顺序 = 取词顺序。
|
||||
thread_local! {
|
||||
// clippy 1.99.1(= 本仓 CI 的 stable)对这条 lint **误报**:初始化器已经写成 `const { … }`
|
||||
// 它还是报「can be made const」。最小复现(clippy-driver 原地可验,无本仓任何符号):
|
||||
// `thread_local!{ static X: RefCell<Vec<u32>> = const { RefCell::new(Vec::new()) }; }`
|
||||
// —— 同一个文件加不加 `const` 报同一句。等 clippy 修掉这条误报即可删掉本行 allow。
|
||||
#[allow(clippy::missing_const_for_thread_local)]
|
||||
static TEXTS: RefCell<Vec<(Key, &'static str)>> = const { RefCell::new(Vec::new()) };
|
||||
}
|
||||
|
||||
/// 记一条(由 [`super::section::t`] 调用;不对外)。
|
||||
pub(crate) fn record(key: Key, text: &'static str) {
|
||||
TEXTS.with(|texts| texts.borrow_mut().push((key, text)));
|
||||
}
|
||||
|
||||
/// 取走并清空本线程记录下的取词(测试用)。
|
||||
pub(crate) fn take() -> Vec<(Key, &'static str)> {
|
||||
TEXTS.with(|texts| std::mem::take(&mut *texts.borrow_mut()))
|
||||
}
|
||||
Reference in new issue
Block a user