Counts read in the singular for one thing; parts build two-count messages (R2.11)

This commit is contained in:
ZacharyZhang-NY committed 2026-10-09 03:07:13 -04:00
1 parent d4c5f90c87
commit 6f90a7dc53
22 files changed
+130 -49

No files matched your search

+44 -6
View File
@@ -134,6 +134,16 @@ pub fn install(cx: &mut App) {
let tag = locale_tag(cx);
let locale = resolve(&tag);
log::info!("i18n: locale {tag} -> {locale}");
let (en, zh) = catalogs();
cx.set_global(
I18n::new(locale)
.catalog("en-US", &en)
.catalog("zh-CN", &zh),
);
}
/// The English and Chinese catalogs, every module's messages.
fn catalogs() -> (Vec<(&'static str, &'static str)>, Vec<(&'static str, &'static str)>) {
let en: Vec<_> = EN
.iter()
.chain(office::EN)
@@ -182,11 +192,7 @@ pub fn install(cx: &mut App) {
.chain(settings::ZH_CN)
.copied()
.collect();
cx.set_global(
I18n::new(locale)
.catalog("en-US", &en)
.catalog("zh-CN", &zh),
);
(en, zh)
}
/// `ELY_LOCALE`, then the language setting, then the system's.
@@ -203,9 +209,41 @@ pub fn text(cx: &App, key: &str, args: &[(&str, &str)]) -> SharedString {
cx.global::<I18n>().text(key, args)
}
/// The message for `n` things: `key.one` when one, else `key`.
pub fn counted(cx: &App, key: &str, n: u64, args: &[(&str, &str)]) -> SharedString {
text(cx, &count_key(key, n), args)
}
fn count_key(key: &str, n: u64) -> String {
match n {
1 => format!("{key}.one"),
_ => key.to_string(),
}
}
#[cfg(test)]
mod tests {
use super::resolve;
use super::{catalogs, count_key, resolve};
use std::collections::BTreeSet;
#[test]
fn one_thing_takes_the_singular() {
assert_eq!(count_key("tree.changed", 1), "tree.changed.one");
for n in [0, 2, 21] {
assert_eq!(count_key("tree.changed", n), "tree.changed", "{n}");
}
}
#[test]
fn both_catalogs_hold_the_same_keys_and_singulars() {
let (en, zh) = catalogs();
let keys = |list: &[(&str, &str)]| list.iter().map(|(key, _)| key.to_string()).collect::<BTreeSet<_>>();
let (en, zh) = (keys(&en), keys(&zh));
assert_eq!(en.symmetric_difference(&zh).collect::<Vec<_>>(), Vec::<&String>::new());
for key in en.iter().filter_map(|key| key.strip_suffix(".one")) {
assert!(en.contains(key), "{key}.one has no plural");
}
}
#[test]
fn zh_variants_pick_zh_cn_others_pick_en() {
+2 -2
View File
@@ -70,7 +70,7 @@ pub(super) const EN: &[(&str, &str)] = &[
("table.columns.space", "Space"),
("table.columns.other", "Other"),
("table.columns.go", "Split"),
("table.columns.one", "Select cells in one column."),
("table.columns.same", "Select cells in one column."),
("table.filter.title", "Column {column}"),
("table.filter.up", "Sort A to Z"),
("table.filter.down", "Sort Z to A"),
@@ -230,7 +230,7 @@ pub(super) const ZH_CN: &[(&str, &str)] = &[
("table.columns.space", "空格"),
("table.columns.other", "其他"),
("table.columns.go", "分列"),
("table.columns.one", "请选同一列中的单元格。"),
("table.columns.same", "请选同一列中的单元格。"),
("table.filter.title", "{column} 列"),
("table.filter.up", "升序排序"),
("table.filter.down", "降序排序"),
+10
View File
@@ -36,6 +36,7 @@ pub(super) const EN: &[(&str, &str)] = &[
("pdf.side.marks", "Bookmarks"),
("pdf.page.label", "Page {n}"),
("pdf.crop.title", "Crop {count} pages"),
("pdf.crop.title.one", "Crop 1 page"),
("pdf.crop.top", "Top"),
("pdf.crop.right", "Right"),
("pdf.crop.bottom", "Bottom"),
@@ -45,6 +46,7 @@ pub(super) const EN: &[(&str, &str)] = &[
("pdf.split.every", "Pages per file"),
("pdf.split.go", "Choose Folder…"),
("pdf.split.done", "{count} files written"),
("pdf.split.done.one", "1 file written"),
("pdf.extract.taken", "{name} is open; choose another name"),
("pdf.extract.done", "Pages written to {name}"),
("pdf.font.original", "The document's font"),
@@ -167,6 +169,7 @@ pub(super) const EN: &[(&str, &str)] = &[
"pdf.ocr.done",
"Recognized {read} pages; skipped {skipped}.",
),
("pdf.ocr.done.one", "Recognized 1 page; skipped {skipped}."),
("pdf.mark.add", "Add Bookmark"),
("pdf.mark.rename", "Rename Bookmark"),
("pdf.mark.delete", "Delete Bookmark"),
@@ -195,11 +198,13 @@ pub(super) const EN: &[(&str, &str)] = &[
"pdf.redact.count",
"{count} marked regions are removed for good.",
),
("pdf.redact.count.one", "1 marked region is removed for good."),
("pdf.redact.tail", "redacted"),
(
"pdf.redact.done",
"Saved {name}: {count} regions removed and checked.",
),
("pdf.redact.done.one", "Saved {name}: 1 region removed and checked."),
("pdf.clean.open", "Clean Document…"),
("pdf.clean.title", "Clean {name}"),
("pdf.clean.meta", "Properties and metadata ({count})"),
@@ -254,6 +259,7 @@ pub(super) const ZH_CN: &[(&str, &str)] = &[
("pdf.side.marks", "书签"),
("pdf.page.label", "第 {n} 页"),
("pdf.crop.title", "裁剪 {count} 页"),
("pdf.crop.title.one", "裁剪 1 页"),
("pdf.crop.top", "上"),
("pdf.crop.right", "右"),
("pdf.crop.bottom", "下"),
@@ -263,6 +269,7 @@ pub(super) const ZH_CN: &[(&str, &str)] = &[
("pdf.split.every", "每个文件的页数"),
("pdf.split.go", "选择文件夹…"),
("pdf.split.done", "已写入 {count} 个文件"),
("pdf.split.done.one", "已写入 1 个文件"),
("pdf.extract.taken", "{name} 已打开,请换一个名称"),
("pdf.extract.done", "页面已写入 {name}"),
("pdf.font.original", "文档自带字体"),
@@ -370,6 +377,7 @@ pub(super) const ZH_CN: &[(&str, &str)] = &[
("pdf.ocr.replace", "重新识别,替换 Ely 此前的文字层"),
("pdf.ocr.reading", "正在识别第 {n} 页,共 {count} 页"),
("pdf.ocr.done", "识别了 {read} 页,跳过 {skipped} 页。"),
("pdf.ocr.done.one", "识别了 1 页,跳过 {skipped} 页。"),
("pdf.mark.add", "添加书签"),
("pdf.mark.rename", "重命名书签"),
("pdf.mark.delete", "删除书签"),
@@ -392,11 +400,13 @@ pub(super) const ZH_CN: &[(&str, &str)] = &[
("pdf.redact.title", "删除 {name} 中标记的内容"),
("pdf.redact.none", "请先标记要删除的文字或区域。"),
("pdf.redact.count", "将彻底删除 {count} 处标记。"),
("pdf.redact.count.one", "将彻底删除 1 处标记。"),
("pdf.redact.tail", "已删除"),
(
"pdf.redact.done",
"已保存 {name}:删除并核对了 {count} 处。",
),
("pdf.redact.done.one", "已保存 {name}:删除并核对了 1 处。"),
("pdf.clean.open", "清理文档…"),
("pdf.clean.title", "清理 {name}"),
("pdf.clean.meta", "属性与元数据({count})"),
+2
View File
@@ -44,6 +44,7 @@ pub(super) const EN: &[(&str, &str)] = &[
"show.output.pictures_done",
"Wrote {n} pictures to {folder}",
),
("show.output.pictures_done.one", "Wrote 1 picture to {folder}"),
("show.output.failed", "Output failed: {error}"),
("show.check.menu", "Check Presentation…"),
("show.check.title", "Presentation Check"),
@@ -97,6 +98,7 @@ pub(super) const ZH_CN: &[(&str, &str)] = &[
("show.output.taken", "{name} 已存在,未写入任何文件"),
("show.output.done", "已导出 {name}"),
("show.output.pictures_done", "已写入 {n} 张图片到 {folder}"),
("show.output.pictures_done.one", "已写入 1 张图片到 {folder}"),
("show.output.failed", "输出失败:{error}"),
("show.check.menu", "检查演示…"),
("show.check.title", "演示检查"),
+2
View File
@@ -126,6 +126,7 @@ pub(super) const EN: &[(&str, &str)] = &[
("pdf.export.tail", "optimized"),
("pdf.export.done", "Saved {name}."),
("pdf.export.images_done", "Saved {count} page images."),
("pdf.export.images_done.one", "Saved 1 page image."),
(
"pdf.export.optimized_done",
"Saved {name}: {before} → {after}.",
@@ -246,6 +247,7 @@ pub(super) const ZH_CN: &[(&str, &str)] = &[
("pdf.export.tail", "已优化"),
("pdf.export.done", "已保存 {name}。"),
("pdf.export.images_done", "已保存 {count} 张页面图片。"),
("pdf.export.images_done.one", "已保存 1 张页面图片。"),
(
"pdf.export.optimized_done",
"已保存 {name}:{before} → {after}。",
+12 -2
View File
@@ -33,12 +33,17 @@ pub(super) const EN: &[(&str, &str)] = &[
),
(
"table.delete.refs",
"{formulas} formulas on other sheets, first {first}, and {names} named ranges refer to it; they will show #REF!.",
"{formulas} on other sheets, first {first}, and {names} refer to it; they will show #REF!.",
),
("table.delete.formulas", "{n} formulas"),
("table.delete.formulas.one", "1 formula"),
("table.delete.names", "{n} named ranges"),
("table.delete.names.one", "1 named range"),
(
"table.delete.dynamic",
"{count} formulas or names use INDIRECT; what they point to is known only when they run, so they may break too.",
),
("table.delete.dynamic.one", "1 formula or name uses INDIRECT; what it points to is known only when it runs, so it may break too."),
("table.delete.go", "Delete"),
("table.cells.rows_above", "Insert Rows Above"),
("table.cells.rows_below", "Insert Rows Below"),
@@ -119,12 +124,17 @@ pub(super) const ZH_CN: &[(&str, &str)] = &[
),
(
"table.delete.refs",
"其他工作表上有 {formulas} 个公式(第一个在 {first})和 {names} 个命名区域引用它;删除后它们显示 #REF!。",
"其他工作表上有 {formulas}(第一个在 {first})和 {names}引用它;删除后它们显示 #REF!。",
),
("table.delete.formulas", "{n} 个公式"),
("table.delete.formulas.one", "1 个公式"),
("table.delete.names", "{n} 个命名区域"),
("table.delete.names.one", "1 个命名区域"),
(
"table.delete.dynamic",
"另有 {count} 个公式或名称用 INDIRECT,指向何处要运行时才知道,删除后也可能出错。",
),
("table.delete.dynamic.one", "另有 1 个公式或名称用 INDIRECT,指向何处要运行时才知道,删除后也可能出错。"),
("table.delete.go", "删除"),
("table.cells.rows_above", "在上方插入行"),
("table.cells.rows_below", "在下方插入行"),
+14 -2
View File
@@ -2,8 +2,13 @@
pub(super) const EN: &[(&str, &str)] = &[
("menu.tools", "Tools"),
("doc.count.words", "{words} words, {characters} characters"),
("doc.count.words", "{words}, {characters}"),
("doc.count.selected", "{selected} of {words} words"),
("doc.count.selected.one", "{selected} of 1 word"),
("doc.count.word", "{n} words"),
("doc.count.word.one", "1 word"),
("doc.count.character", "{n} characters"),
("doc.count.character.one", "1 character"),
("office.find.open", "Find and Replace"),
("office.find.stale", "Edited. Enter counts again."),
("doc.spell.ignore_all", "Ignore All"),
@@ -50,6 +55,7 @@ pub(super) const EN: &[(&str, &str)] = &[
("doc.merge.unreadable", "{name} cannot be read: {error}"),
("doc.merge.exists", "{name} exists. Nothing was written."),
("doc.merge.done", "Wrote {n} files to {folder}"),
("doc.merge.done.one", "Wrote 1 file to {folder}"),
(
"doc.merge.failed",
"The merge stopped at record {n}: {error}",
@@ -58,8 +64,13 @@ pub(super) const EN: &[(&str, &str)] = &[
pub(super) const ZH_CN: &[(&str, &str)] = &[
("menu.tools", "工具"),
("doc.count.words", "{words} 字,{characters} 字符"),
("doc.count.words", "{words},{characters}"),
("doc.count.selected", "已选 {selected} / {words} 字"),
("doc.count.selected.one", "已选 {selected} / 1 字"),
("doc.count.word", "{n} 字"),
("doc.count.word.one", "1 字"),
("doc.count.character", "{n} 字符"),
("doc.count.character.one", "1 字符"),
("office.find.open", "查找和替换"),
("office.find.stale", "已改动,回车重新计数"),
("doc.spell.ignore_all", "全部忽略"),
@@ -103,5 +114,6 @@ pub(super) const ZH_CN: &[(&str, &str)] = &[
("doc.merge.unreadable", "无法读取 {name}:{error}"),
("doc.merge.exists", "{name} 已存在,未写入任何文件。"),
("doc.merge.done", "已写入 {n} 个文件到 {folder}"),
("doc.merge.done.one", "已写入 1 个文件到 {folder}"),
("doc.merge.failed", "合并在第 {n} 条停止:{error}"),
];
+6
View File
@@ -17,6 +17,7 @@ pub(super) const EN: &[(&str, &str)] = &[
("tree.clone.busy", "A clone is already running."),
("tree.clean", "Nothing to commit"),
("tree.changed", "{n} files changed"),
("tree.changed.one", "1 file changed"),
("tree.no_git", "Git is not available"),
("tree.unreadable", "This repository could not be read"),
("tree.branch.detached", "Detached at {oid}"),
@@ -62,7 +63,9 @@ pub(super) const EN: &[(&str, &str)] = &[
("tree.layout.unified", "Unified"),
("tree.layout.split", "Side by Side"),
("tree.lines.stage", "Stage {n} Lines"),
("tree.lines.stage.one", "Stage 1 Line"),
("tree.lines.unstage", "Unstage {n} Lines"),
("tree.lines.unstage.one", "Unstage 1 Line"),
("tree.hunk.stage", "Stage Hunk"),
("tree.hunk.unstage", "Unstage Hunk"),
("tree.open_file", "Open File"),
@@ -144,6 +147,7 @@ pub(super) const ZH_CN: &[(&str, &str)] = &[
("tree.clone.busy", "已有克隆正在进行。"),
("tree.clean", "没有要提交的改动"),
("tree.changed", "{n} 个文件有改动"),
("tree.changed.one", "1 个文件有改动"),
("tree.no_git", "Git 不可用"),
("tree.unreadable", "无法读取此仓库"),
("tree.branch.detached", "游离于 {oid}"),
@@ -183,7 +187,9 @@ pub(super) const ZH_CN: &[(&str, &str)] = &[
("tree.layout.unified", "行内"),
("tree.layout.split", "并排"),
("tree.lines.stage", "暂存 {n} 行"),
("tree.lines.stage.one", "暂存 1 行"),
("tree.lines.unstage", "取消暂存 {n} 行"),
("tree.lines.unstage.one", "取消暂存 1 行"),
("tree.hunk.stage", "暂存此块"),
("tree.hunk.unstage", "取消暂存此块"),
("tree.open_file", "打开文件"),
+4
View File
@@ -46,6 +46,7 @@ pub(super) const EN: &[(&str, &str)] = &[
"tree.force.lost",
"These {n} commits on the remote would be overwritten:\n{commits}",
),
("tree.force.lost.one", "This commit on the remote would be overwritten:\n{commits}"),
("tree.stash.open", "Stash Changes…"),
("tree.stash.title", "Stash changes"),
("tree.stash.message", "Message"),
@@ -131,6 +132,7 @@ pub(super) const EN: &[(&str, &str)] = &[
"tree.move.left",
"These {n} commits leave it; the reflog still finds them:\n{commits}",
),
("tree.move.left.one", "This commit leaves it; the reflog still finds it:\n{commits}"),
("tree.clean.open", "Clean Untracked Files…"),
("tree.clean.title", "Clean untracked files"),
("tree.clean.ignored", "Include ignored files"),
@@ -186,6 +188,7 @@ pub(super) const ZH_CN: &[(&str, &str)] = &[
),
("tree.force.nothing", "远端没有本分支缺少的提交。"),
("tree.force.lost", "远端这 {n} 个提交会被覆盖:\n{commits}"),
("tree.force.lost.one", "远端这 1 个提交会被覆盖:\n{commits}"),
("tree.stash.open", "储藏改动…"),
("tree.stash.title", "储藏改动"),
("tree.stash.message", "说明"),
@@ -265,6 +268,7 @@ pub(super) const ZH_CN: &[(&str, &str)] = &[
"tree.move.left",
"这 {n} 个提交将离开该分支,引用日志里仍可找回:\n{commits}",
),
("tree.move.left.one", "这 1 个提交将离开该分支,引用日志里仍可找回:\n{commits}"),
("tree.clean.open", "清理未跟踪的文件…"),
("tree.clean.title", "清理未跟踪的文件"),
("tree.clean.ignored", "包括被忽略的文件"),