feat(i18n): 外观页 40 条文案进词表(M180 I18NAPPEAR)
- 卡片内 22 处硬编码英文(整窗/面板透明度、背景图开关+路径、填充、暗化、配色来源)全部改走 Key
- 运行时诊断改成 key + 参数:`background::Note`(读盘/解码/过大/小图平铺)、`state::backend_note`、
`palette::note` 全部返回 Key;`state.rs` 只留 key、不放文案表(390 → 391 行)
- 上限/下限常量走占位符 `{floor}` / `{max}` / `{limit}` / `{requested}`;`{:.2}` 在 Rust 侧格式化好
再套模板(`Catalog::render` 只认 `{name}`)
- 新增 40 条 key(中英各一条),按装配链锚点插在 `SettingsAppearanceCornerSuspended` 之后,
金表 `golden/tail.rs` 同位置插入 40 行(`rows() == len() == Key::ALL.len()`)
- 守卫三条:中文渲染全非 ASCII、卡片 key 全覆盖(改回写死英文即红)、外观 key 逐条真翻过
- probe 加第二条取证路(`record_rendered`),`take()` 签名不动(M179 的守卫在 scope 外)
This commit is contained in:
1 parent
65e7ccc3bf
commit
c4c3c15285
14 files changed
+858
-184
No files matched your search
@@ -4,6 +4,8 @@
|
||||
|
||||
use super::{dim_alpha, load, small_tile_note, tiles, LoadError, BG_DIM_MAX, MAX_TILES};
|
||||
use std::path::{Path, PathBuf};
|
||||
use unlucky_i18n::catalog::Key;
|
||||
use unlucky_i18n::Lang;
|
||||
use unlucky_presenter::prefs::BgFill;
|
||||
|
||||
fn temp_file(label: &str, name: &str) -> PathBuf {
|
||||
@@ -66,19 +68,28 @@ fn a_real_jpeg_decodes_too() {
|
||||
#[test]
|
||||
fn a_missing_or_broken_file_reports_a_readable_reason() {
|
||||
// 抓得住:①路径不存在 → Io;②文件存在但不是图片 → Undecodable;③空路径 → Io。
|
||||
// 都必须是 Err(不许静默回默认色),且 describe() 是人话。
|
||||
// 都必须是 Err(不许静默回默认色),且 note() 给出**哪条 key + 哪些参数**(句子在词表里)。
|
||||
// 抓不住:webp/tiff 这类没开编码器的格式具体报什么字符串(只钉分类,不钉解码库原文)。
|
||||
let missing = temp_file("missing", "bg.png");
|
||||
let error = load(missing.to_str().unwrap()).expect_err("不存在的路径必须报错");
|
||||
assert!(matches!(error, LoadError::Io(_)), "实际 {error:?}");
|
||||
assert!(error
|
||||
.describe()
|
||||
.starts_with("Background image could not be read"));
|
||||
let note = error.note();
|
||||
assert_eq!(note.key(), Key::SettingsAppearanceBgReadFailed);
|
||||
assert!(
|
||||
note.contains("could not be read"),
|
||||
"英文基线要说出「读不出来」:{}",
|
||||
note.render(Lang::En)
|
||||
);
|
||||
|
||||
let broken = temp_file("broken", "bg.png");
|
||||
std::fs::write(&broken, b"this is not an image").expect("写坏文件");
|
||||
let error = load(broken.to_str().unwrap()).expect_err("非图片必须报错");
|
||||
assert!(matches!(error, LoadError::Undecodable(_)), "实际 {error:?}");
|
||||
assert_eq!(
|
||||
error.note().key(),
|
||||
Key::SettingsAppearanceBgDecodeFailed,
|
||||
"解不开与读不出来必须是两条 key(措辞与修法都不同)"
|
||||
);
|
||||
cleanup(&broken);
|
||||
|
||||
let empty = load(" ").expect_err("空路径必须报错");
|
||||
@@ -168,10 +179,21 @@ fn an_over_sized_image_reports_too_large_instead_of_trying_to_decode() {
|
||||
),
|
||||
"实际 {error:?}"
|
||||
);
|
||||
let note = error.note();
|
||||
assert_eq!(note.key(), Key::SettingsAppearanceBgTooLarge);
|
||||
assert!(
|
||||
error.describe().contains("too large"),
|
||||
"提示要人话:{}",
|
||||
error.describe()
|
||||
note.contains("too large"),
|
||||
"英文基线要说出「太大」:{}",
|
||||
note.render(Lang::En)
|
||||
);
|
||||
let args = note.args();
|
||||
assert!(
|
||||
args.contains(&("width", "9000")) && args.contains(&("height", "4")),
|
||||
"宽高要作为参数传进去(不是写进译文):{args:?}"
|
||||
);
|
||||
assert!(
|
||||
args.contains(&("limit", "8192")),
|
||||
"上限走占位符而不是写进译文:{args:?}"
|
||||
);
|
||||
// 上限不许再放宽(r1 的 16384 等于允许 1 GB 的中间缓冲):常量级约束放在测试里钉。
|
||||
const _: () = assert!(super::MAX_SOURCE_EDGE <= 8_192);
|
||||
@@ -187,8 +209,21 @@ fn an_over_sized_image_reports_too_large_instead_of_trying_to_decode() {
|
||||
fn small_images_get_a_tile_diagnostic_instead_of_silently_degrading() {
|
||||
let small = super::Image::from_rgba((32, 32), 4, 4, vec![0; 64]);
|
||||
let note = small_tile_note(&small, BgFill::Tile).expect("小图 tile 必须有提示");
|
||||
assert!(note.contains("32×32"), "{note}");
|
||||
assert!(note.contains("scaled up"), "{note}");
|
||||
assert_eq!(note.key(), Key::SettingsAppearanceBgSmallTile);
|
||||
let args = note.args();
|
||||
assert!(
|
||||
args.contains(&("width", "32")) && args.contains(&("height", "32")),
|
||||
"尺寸作为参数:{args:?}"
|
||||
);
|
||||
assert!(
|
||||
args.contains(&("max", "64")),
|
||||
"块数上限走占位符(`MAX_TILES` 改了不该动译文):{args:?}"
|
||||
);
|
||||
assert!(
|
||||
note.render(Lang::En).contains("scaled up"),
|
||||
"英文基线要说出「会被放大」:{}",
|
||||
note.render(Lang::En)
|
||||
);
|
||||
|
||||
// 非 tile 档不提示(cover/contain 会等比铺满,不存在「小图被放大铺」这件事)。
|
||||
assert!(small_tile_note(&small, BgFill::Cover).is_none());
|
||||
|
||||
Reference in new issue
Block a user