feat(download): M94 下载页换成真组件 + 真快照 + 真指令(PAGEDL)
页面(crates/app-iced/src/pages/download*):
- Tabs(分类)/ ListItem(版本行)/ filled 安装按钮 / progress / EmptyState / divider
全部取自 components/ 的真组件;页头动作换成 buttons::text
- 数据只吃 pages::download::Download(app/view.rs 由 AppState 快照转,installed_only 与
download_query 照用);页面自己不留业务状态,交互只发意图
- 状态:加载(不确定进度 + 文案)/ 空(EmptyState + 刷新 CTA)/ 有数据 / 安装中 / 安装失败
(失败给可读文案 + 「打开日志」出口)
接线(追加式):
- pages::Message 加 SelectVersion / InstallVersion / CancelInstall / SetCategory
- app/update.rs 翻成 AppCommand::{InstallVersion, CancelInstall, ListVersions}
(SelectVersion 只改视图模型;「刷新」= 当前分类重新拉,全部走 RefreshAll)
- pages::Model 加 download 字段
文案:28 个 Download* key 进中英两套 catalog(一行一个 key 的全语言);页面零中文字面量,
core 的中文阶段串(InstallStage::label / message)一律不进界面
i18n 结构:catalog.rs 的既有测试模块原样外置到 catalog/tests.rs(392 行 → 282 行,
逐字未改),新 key 才装得下 400 行硬上限
测试:app-iced 276 + i18n 23 全绿;clippy -D warnings 与 fmt --check 干净
This commit is contained in:
1 parent
b3f99652bb
commit
57e8380b24
14 files changed
+1633
-247
No files matched your search
+50
-160
@@ -115,6 +115,55 @@ catalog! {
|
||||
|
||||
// ── core / presenter 只给了中文串、UI 又不许画原文时的兜底(见 `bridge`)
|
||||
CoreTextUntranslated => ("[system text not translated]", "[未翻译的系统文案]"),
|
||||
|
||||
// --- download page (M94) ---
|
||||
// 下载页(`crates/app-iced/src/pages/download`)。一句话一个 key:带变量的句子用 `{name}`,
|
||||
// 页面只做 `Catalog::render`,不拼片段(`bridge` 的规矩 1)。
|
||||
DownloadTitle => ("Downloads", "下载"),
|
||||
DownloadSubtitle => ("Version list from the official manifest", "来自官方版本清单的版本列表"),
|
||||
DownloadRefresh => ("Refresh", "刷新"),
|
||||
DownloadInstall => ("Install", "安装"),
|
||||
DownloadCancel => ("Cancel install", "取消安装"),
|
||||
DownloadInstalled => ("Installed", "已安装"),
|
||||
DownloadCount => ("{count} versions", "{count} 个版本"),
|
||||
DownloadRowSupporting => ("{kind} · released {date}", "{kind} · 发布于 {date}"),
|
||||
DownloadSelectHint => ("Pick a version, then install", "选一个版本再安装"),
|
||||
DownloadSelected => ("Selected {version}", "已选 {version}"),
|
||||
DownloadLoading => ("Loading the version list…", "正在加载版本列表…"),
|
||||
DownloadLoadingHint => (
|
||||
"The list appears after the first successful fetch; this page never goes blank.",
|
||||
"首次拉取成功后这里会出现版本列表;这一页不会是一片白。"
|
||||
),
|
||||
DownloadEmptyTitle => ("No matching versions", "没有匹配的版本"),
|
||||
DownloadEmptyBody => (
|
||||
"Switch the category or clear the filter to see more.",
|
||||
"换一个分类或清掉筛选后再看。"
|
||||
),
|
||||
DownloadCategoryAll => ("All", "全部"),
|
||||
DownloadCategoryRelease => ("Release", "正式版"),
|
||||
DownloadCategorySnapshot => ("Snapshot", "预览版"),
|
||||
DownloadCategoryAncient => ("Ancient", "远古版"),
|
||||
DownloadStagePlanning => ("Planning", "解析版本"),
|
||||
DownloadStageDownloading => ("Downloading files", "下载文件"),
|
||||
DownloadStageInstalling => ("Building the version", "生成版本"),
|
||||
DownloadStageRegistering => ("Registering the instance", "登记实例"),
|
||||
DownloadStageDone => ("Done", "已完成"),
|
||||
DownloadStageFailed => ("Install failed", "安装失败"),
|
||||
DownloadStageCancelled => ("Install cancelled", "安装已取消"),
|
||||
DownloadProgress => (
|
||||
"{done}/{total} files",
|
||||
"{done}/{total} 文件"
|
||||
),
|
||||
DownloadProgressUnknown => ("Waiting for the first file…", "等第一个文件…"),
|
||||
// 速率与剩余时间是两个独立短语,各占一个 key(`DownloadRate` 只负责把它们排成一行)
|
||||
DownloadRate => ("{speed} · {eta}", "{speed},{eta}"),
|
||||
DownloadEtaSecs => ("{secs}s left", "剩 {secs}s"),
|
||||
DownloadEtaMins => ("{mins}m{secs}s left", "剩 {mins}m{secs}s"),
|
||||
DownloadFailedHint => (
|
||||
"The Logs page has the full reason.",
|
||||
"完整原因在日志页。"
|
||||
),
|
||||
DownloadOpenLogs => ("Open logs", "打开日志"),
|
||||
}
|
||||
|
||||
/// 一套语言的目录(不可变;`Copy`,随手传值)。
|
||||
@@ -229,164 +278,5 @@ pub fn placeholders(text: &str) -> Vec<&str> {
|
||||
}
|
||||
found
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// 手写一套**故意缺条**的目录(不经过 `catalog!`,模拟后续 mission 的注入表)。
|
||||
const PARTIAL_ZH: &[(Key, &str)] = &[
|
||||
(Key::NavInstances, "实例"),
|
||||
(Key::NavLogs, "日志"),
|
||||
(Key::NavSettings, "设置"),
|
||||
(Key::NavDownload, "下载"),
|
||||
(Key::InstancesNew, "新建实例"),
|
||||
(Key::InstancesImport, "导入"),
|
||||
(Key::InstancesBack, "返回实例列表"),
|
||||
(Key::InstancesPlay, "启动"),
|
||||
(Key::InstancesLastPlayed, "上次游玩 {when}"),
|
||||
(Key::InstancesEmptyTitle, "未选择实例"),
|
||||
(Key::InstancesEmptyBody, "选择一个实例查看详情。"),
|
||||
(Key::LoaderVanilla, "原版"),
|
||||
(Key::LaunchOutcomeNormal, "正常结束"),
|
||||
(Key::LaunchOutcomeCrash, "游戏崩溃"),
|
||||
// 缺:LaunchOutcomeSilent / LaunchFailedWithCode / FontCjk* / Settings* / CoreTextUntranslated
|
||||
];
|
||||
|
||||
#[test]
|
||||
fn built_in_catalogs_have_every_key() {
|
||||
// 抓得住:`catalog!` 的成对生成被绕开(有人改回「两套各写一遍」并漏了一条 / 抄重了一条)。
|
||||
// 判据是**集合相等**:`Key` 枚举拦住了「表里有、枚举没有」,这里拦反方向。
|
||||
// 抓不住:译文对不对(这只能是人工 / 后续的语言审查)。
|
||||
for lang in Lang::ALL {
|
||||
let catalog = Catalog::of(*lang);
|
||||
assert_eq!(catalog.missing(), Vec::new(), "{}", catalog.lang().tag());
|
||||
assert_eq!(catalog.diagnose(), None);
|
||||
|
||||
let mut keys = catalog
|
||||
.entries()
|
||||
.iter()
|
||||
.map(|(key, _)| *key)
|
||||
.collect::<Vec<_>>();
|
||||
let total = keys.len();
|
||||
keys.sort_unstable();
|
||||
keys.dedup();
|
||||
assert_eq!(keys.len(), total, "{} 目录里有重复条目", lang.tag());
|
||||
assert_eq!(
|
||||
keys.len(),
|
||||
Key::ALL.len(),
|
||||
"{} 条目数与 key 数不等",
|
||||
lang.tag()
|
||||
);
|
||||
|
||||
for key in Key::ALL {
|
||||
assert!(
|
||||
catalog.get(*key).is_some(),
|
||||
"{} 缺 {}",
|
||||
lang.tag(),
|
||||
key.name()
|
||||
);
|
||||
}
|
||||
}
|
||||
assert!(!Key::ALL.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn key_names_are_unique_and_stable() {
|
||||
// 抓得住:同一个 key 被写成两个变体(名字重复会让日志/诊断指认失准)。
|
||||
// 抓不住:重命名变体对下游源码的影响(那是编译错误,本来就跑不过)。
|
||||
let mut names = Key::ALL.iter().map(|key| key.name()).collect::<Vec<_>>();
|
||||
let total = names.len();
|
||||
names.sort_unstable();
|
||||
names.dedup();
|
||||
assert_eq!(names.len(), total);
|
||||
assert_eq!(Key::NavInstances.name(), "NavInstances");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn chinese_catalog_is_actually_chinese() {
|
||||
// 抓得住:整句漏译(英文被抄进中文表);一条都没有说明这张表是真翻过的。
|
||||
// 抓不住:语义翻错、语气不合(机器能查的只有「与英文不同」这一层)。
|
||||
let en = Catalog::of(Lang::En);
|
||||
let zh = Catalog::of(Lang::ZhCn);
|
||||
for key in Key::ALL {
|
||||
let english = en.text(*key);
|
||||
assert_ne!(english, zh.text(*key), "{} 未翻译", key.name());
|
||||
assert!(!english.is_empty() && !zh.text(*key).is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn placeholder_sets_match_across_languages() {
|
||||
// 抓得住:一处文案的 `{code}` / `{when}` 在另一套译文里丢了或写错名——
|
||||
// 那会让 render() 输出半截句子,或让参数静默失效。
|
||||
// 抓不住:占位符本身是不是正确的变量(那是调用方的职责,由页面侧测试守)。
|
||||
let en = Catalog::of(Lang::En);
|
||||
let zh = Catalog::of(Lang::ZhCn);
|
||||
for key in Key::ALL {
|
||||
let mut left = placeholders(en.text(*key));
|
||||
let mut right = placeholders(zh.text(*key));
|
||||
left.sort_unstable();
|
||||
right.sort_unstable();
|
||||
assert_eq!(left, right, "{}", key.name());
|
||||
}
|
||||
assert_eq!(placeholders("exit {code} at {when}"), vec!["code", "when"]);
|
||||
assert_eq!(placeholders("没有占位符"), Vec::<&str>::new());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_rows_are_diagnosed_in_plain_words() {
|
||||
// 抓得住:缺译诊断的**可读性**(必须点名语言、key 名与英文原文)——注入目录缺条时靠它定位。
|
||||
// 抓不住:内置目录真的缺译(内置表由 catalog! 结构保证,见上一条测试)。
|
||||
let partial = Catalog::from_entries(Lang::ZhCn, PARTIAL_ZH);
|
||||
assert_eq!(partial.missing().len(), Key::ALL.len() - PARTIAL_ZH.len());
|
||||
|
||||
let report = partial.diagnose().expect("应当报缺译");
|
||||
assert!(report.starts_with("zh-CN 缺 "), "{report}");
|
||||
assert!(report.contains("LaunchOutcomeSilent"), "{report}");
|
||||
assert!(
|
||||
report.contains("Suspected silent failure"),
|
||||
"诊断要带上英文原文当参考:{report}"
|
||||
);
|
||||
assert!(
|
||||
!report.contains("NavInstances"),
|
||||
"已译的 key 不该出现在报告里:{report}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_translation_never_falls_back_silently() {
|
||||
// 抓得住:缺译被静默顶替(回落英文 / 回落中文 / 返回空串)——那会产出「半句中文半句英文」的界面。
|
||||
// 抓不住:MISSING 标记真的被画到屏幕上(那是 UI 侧截图验收的事)。
|
||||
let partial = Catalog::from_entries(Lang::ZhCn, PARTIAL_ZH);
|
||||
assert_eq!(partial.get(Key::LaunchOutcomeSilent), None);
|
||||
assert_eq!(partial.text(Key::LaunchOutcomeSilent), MISSING);
|
||||
assert_eq!(
|
||||
partial.render(
|
||||
Key::LaunchFailedWithCode,
|
||||
&[("code", "0"), ("reason", "JVM 拒绝启动")]
|
||||
),
|
||||
"⟪missing:LaunchFailedWithCode⟫"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_substitutes_and_keeps_unfilled_placeholders_visible() {
|
||||
// 抓得住:占位符替换的回归(漏参时**保留** `{code}` 而不是清空、不 panic)。
|
||||
// 抓不住:调用方传没传对值(`("code", "0")` 是不是真的退出码)。
|
||||
let zh = Catalog::of(Lang::ZhCn);
|
||||
assert_eq!(
|
||||
zh.render(
|
||||
Key::LaunchFailedWithCode,
|
||||
&[("code", "0"), ("reason", "mod 冲突")]
|
||||
),
|
||||
"启动失败(退出码 0):mod 冲突"
|
||||
);
|
||||
assert_eq!(
|
||||
zh.render(Key::LaunchFailedWithCode, &[("code", "0")]),
|
||||
"启动失败(退出码 0):{reason}"
|
||||
);
|
||||
assert_eq!(zh.text(Key::InstancesNew), "新建实例");
|
||||
assert_eq!(zh.lang(), Lang::ZhCn);
|
||||
}
|
||||
}
|
||||
mod tests;
|
||||
Reference in new issue
Block a user