Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

Merge remote-tracking branch 'origin/main' into feat/all-tools-expand-view

alehel7e469b9961cc
diff --cc crates/ui-egui/src/i18n/mod.rs
index 24c875bfb,8f17a8aca..ab5e45042
--- a/crates/ui-egui/src/i18n/mod.rs
+++ b/crates/ui-egui/src/i18n/mod.rs
@@@ -4192,6 -1768,93 +1768,94 @@@ mod tests
}
}
+ /// The translation gaps report (`cargo xtask i18n-report`, a step of `cargo xtask ci`): for
+ /// each language, how many English strings it has no translation for, and the first few.
+ /// It never fails: a missing string shows in English.
+ ///
+ /// The English strings are the UI source's literals, the commands, All tools, the engine's
+ /// own wordings, and every key of every bundled catalog (which covers contextual, plural and
+ /// dynamically looked-up strings the scan can't see).
+ #[test]
+ fn translation_gaps_report() {
+ use std::collections::BTreeSet;
+ const SHOWN: usize = 3;
+ let mut plain: BTreeSet<String> = ui_literals();
+ let mut add = |s: &str| {
+ plain.insert(s.to_string());
+ };
+ for command in pdfcraft_engine::commands::COMMANDS {
+ add(command.label);
+ command.menu.into_iter().for_each(&mut add);
+ }
+ for group in pdfcraft_engine::catalog::TOOL_GROUPS {
+ add(group.label);
+ for section in group.sections {
+ add(section.title);
+ section.items.iter().for_each(|item| add(item.label));
+ }
+ }
++ pdfcraft_engine::catalog::TOOL_CATEGORIES.iter().for_each(|category| add(category.label));
+ let engine: [&[&str]; 9] = [
+ pdfcraft_engine::a11y::WORDINGS,
+ pdfcraft_engine::a11y::REPORT_WORDS,
+ pdfcraft_engine::pdfa::WORDINGS,
+ pdfcraft_engine::sign::pdf::WORDINGS,
+ pdfcraft_engine::sign::pdf::kind::ALL,
+ pdfcraft_engine::print::WORDINGS,
+ pdfcraft_engine::EDIT_LABELS,
+ pdfcraft_engine::BATCH_LABELS,
+ pdfcraft_engine::field_table::WORDINGS,
+ ];
+ engine.into_iter().flatten().for_each(|s| add(s));
+ pdfcraft_engine::sign::AppearanceLabels::default().fields().into_iter().for_each(|(_, label)| add(label));
+ crate::credits::NameMode::ALL.iter().for_each(|mode| add(mode.label()));
+ for key in crate::credits::SortKey::ALL {
+ let (label, header) = key.label();
+ add(label);
+ add(header);
+ }
+ crate::credits::MODEL_COLUMNS.iter().for_each(|s| add(s));
+ // (context, source) keys; `@id` rows only reword a command label, which is in `plain`.
+ let mut keys: BTreeSet<(String, String)> = plain.into_iter().map(|s| (String::new(), s)).collect();
+ for language in &LANGUAGES {
+ let (entries, _) = parse_entries(language.source, language.plural_forms());
+ keys.extend(entries.into_iter().filter(|e| e.context != "@id").map(|e| (e.context, e.source)));
+ }
+ let mut report = format!("Translation gaps: {} English strings\n", keys.len());
+ for lang in Lang::all().filter(|l| *l != Lang::EN) {
+ let catalog = lang.catalog();
+ let missing: Vec<&(String, String)> = keys
+ .iter()
+ .filter(|(context, source)| match context.as_str() {
+ "" => catalog.plain(source).is_none(),
+ "@plural" => source.split_once('|').is_none_or(|(one, other)| catalog.plural(one, other, 0).is_none()),
+ // A contextual lookup falls back to the plain translation.
+ context => catalog.contextual(context, source).is_none() && catalog.plain(source).is_none(),
+ })
+ .collect();
+ let mut line = format!(" {:<8} {:>5} missing", lang.code(), missing.len());
+ for (i, (context, source)) in missing.iter().take(SHOWN).enumerate() {
+ let mut shown: String = source.chars().take(48).collect();
+ if shown.len() < source.len() {
+ shown.push('…');
+ }
+ let key = if context.is_empty() { format!("{shown:?}") } else { format!("{context} / {shown:?}") };
+ line.push_str(if i == 0 { ": " } else { ", " });
+ line.push_str(&key);
+ }
+ if missing.len() > SHOWN {
+ line.push_str(", …");
+ }
+ report.push_str(&line);
+ report.push('\n');
+ }
+ println!("{REPORT_START}\n{report}{REPORT_END}");
+ }
+
+ /// The lines `cargo xtask i18n-report` prints from the test output lie between these.
+ const REPORT_START: &str = "=== translation gaps ===";
+ const REPORT_END: &str = "=== end of translation gaps ===";
+
/// Preferences ▸ Date format ▸ Language offers exactly the interface languages, in order.
#[test]
fn date_languages_are_the_interface_languages() {