mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-11 00:41:21 +00:00
* build(i18n): embed the craft-i18n catalogs from a pinned checkout
- `craft-i18n.rev` pins storytold/craft-i18n at e45ddf7 (the PdfCraft cutover sync of
pdfcraft@ecdd1e6); `.gitattributes` keeps it LF.
- The `craft-i18n` crate (craft-libs 787a7a0, PdfCraft's existing pin) is a direct dependency
of the UI crate; it was already in the tree through craft-ui.
- `crates/ui-egui/build.rs` writes `CRAFT_I18N` from `CRAFT_I18N_DIR`: one (locale, common.tsv,
pdfcraft.tsv) entry per locale with a `pdfcraft.tsv`, paths written with `{:?}` and never
canonicalized. Unset it is empty (English only); `CRAFT_I18N_REQUIRED=1` makes a missing or
invalid checkout an error.
- Both flatpak manifests name the craft-i18n commit and `CRAFT_I18N_DIR`; a test keeps both
commits equal to the trimmed pin.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* feat(i18n): look strings up through craft-i18n behind a thin Lang wrapper
`i18n.rs` keeps PdfCraft's API (tr, tr_ctx, tr_id, trn, key_name, fmt,
Lang, LANGUAGES, detection) and hands lookups to the craft-i18n crate:
`get` for key names, `trn_plain` for plurals (no isolates, no digit
grouping), PdfCraft's own `fmt` (no FSI isolates). `@id` rows and the
"Undo {action}" template are read only where PdfCraft had them, so menus
and history labels read exactly as before.
Detection is unchanged (LC_ALL/LC_MESSAGES/LANG, macOS defaults,
sys_locale); the crate's match_tag would drop nb for no/nn, so PdfCraft's
own tag mapping stays, with one parity test per path.
Completeness tests become reports; tests that need catalogs skip with a
note when the build has none. Font coverage tests read the embedded
catalogs (shared and PdfCraft rows).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* chore(i18n): remove the in-repo catalogs; craft-i18n holds them
The 34 `crates/ui-egui/src/i18n/*.tsv` catalogs were migrated into
craft-i18n at pdfcraft@ecdd1e6 and are now embedded from the pinned
checkout. ATTRIBUTION.toml drops their 34 entries for one craft-i18n
`[[build_input]]` (craft-i18n's ATTRIBUTION.md credits the translators);
AGENTS.md and docs/localization.md describe the new system and how to
add a language.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(i18n): skip catalog tests without craft-i18n; drop the catalog hash exemption
Tests that switch to a non-English language skip with a note when the
build embeds no catalogs (CRAFT_I18N_DIR unset), so the English-only
build tests green. `skip_without_catalogs` moves to the integration
test support module.
With no catalogs left in the repository, `cargo xtask assets` no longer
exempts `crates/ui-egui/src/i18n/*.tsv` from hashing: every `[[asset]]`
carries a sha256 again, and a `.tsv` added back would need one.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* build(i18n): watch the locales directory before reading it
A CRAFT_I18N_DIR that doesn't exist yet now reruns the build script once it appears (review).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* build(i18n): pin craft-i18n dfbe955, the merge of storytold/craft-i18n#129
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(i18n): skip an @id row that changes the label's placeholders or ellipsis
craft-i18n checks placeholders and the trailing ellipsis on every row whose
source is English text, but not on @id rows, whose source is the command id.
The in-repo catalog test used to fail on such a row; since the cutover it only
prints it, while tr_id and menu_label still showed it. Both now use PdfCraft's
own @id row only when it keeps the label's shape (same_shape, the rule
craft-i18n applies elsewhere), and otherwise show the label's translation, as
bundled_catalogs_are_consistent says.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(i18n): reject an @id row with an open brace; list unused @id rows in the gaps report
same_shape skipped a `{` with no `}`, so an @id row such as "Öffnen {name…"
for "Open…" was still shown. It now counts as a changed shape.
bundled_catalogs_are_consistent printed the @id rows PdfCraft doesn't use, but
CI captures test output, so nobody saw them. translation_gaps_report, which
`cargo xtask i18n-report` runs with --nocapture, now lists them
(unused_id_rows).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(i18n): reject an @id row with a `}` that closes no placeholder
same_shape counted only the `}` that close a `{`, so "Öffnen name}…" for
"Open…" or "{name}} öffnen" for "Open {name}" still passed. A row whose `}`
count differs from its placeholders now counts as a changed shape.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(i18n): no braces in the assert messages of the brace test
assert! reads its message as a format string, so "a `}` without its `{`"
did not compile.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com>
115 lines
5.4 KiB
Rust
115 lines
5.4 KiB
Rust
//! State-based waits for native preparation, which completes between UI frames, and pointer
|
|
//! input in the frames the platform delivers it in ([`input`]), and the skip for tests whose text
|
|
//! the interface fonts cannot draw ([`skip_without_glyphs`]).
|
|
use std::collections::BTreeSet;
|
|
|
|
use egui::FontId;
|
|
use egui::epaint::text::{Fonts, TextOptions};
|
|
use egui_kittest::Harness;
|
|
use pdfcraft_ui_egui::{PdfCraftApp, i18n, theme};
|
|
|
|
pub mod input;
|
|
|
|
/// Step frames until `ready` holds or 30 seconds pass, and say whether it held. For background work
|
|
/// (a worker-thread open, page text arriving) that a test then asserts on itself: a frame count is
|
|
/// not a time, and a busy runner may not have finished the work within one. Sleeps briefly between
|
|
/// frames so the worker threads get the CPU.
|
|
#[must_use]
|
|
pub fn step_until(h: &mut Harness<'static, PdfCraftApp>, mut ready: impl FnMut(&mut Harness<'static, PdfCraftApp>) -> bool) -> bool {
|
|
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(30);
|
|
loop {
|
|
h.step();
|
|
if ready(h) {
|
|
return true;
|
|
}
|
|
if std::time::Instant::now() >= deadline {
|
|
return false;
|
|
}
|
|
std::thread::sleep(std::time::Duration::from_millis(5));
|
|
}
|
|
}
|
|
|
|
/// Step frames until nothing is waiting to be rendered, and fail the test if that takes over 30
|
|
/// seconds: what a test checks next is on the rendered page.
|
|
pub fn settle(h: &mut Harness<'static, PdfCraftApp>) {
|
|
let settled = step_until(h, |h| {
|
|
h.run_steps(1);
|
|
!h.state().render_pending()
|
|
});
|
|
assert!(settled, "pages rendered");
|
|
}
|
|
|
|
pub fn wait_until(h: &mut Harness<'static, PdfCraftApp>, what: &str, ready: impl Fn(&PdfCraftApp) -> bool) {
|
|
let held = step_until(h, |h| ready(h.state()));
|
|
assert!(
|
|
held,
|
|
"timed out waiting for {what}: views={}, active={:?}, password={:?}, toast={:?}",
|
|
h.state().views.len(),
|
|
h.state().active,
|
|
h.state().password_prompt.as_ref().map(|p| (&p.name, &p.error)),
|
|
h.state().toast
|
|
);
|
|
}
|
|
|
|
/// Open the in-window menu bar's `title` menu (File, Edit, View…).
|
|
pub fn open_menu(h: &mut Harness<'static, PdfCraftApp>, title: &str) {
|
|
use egui_kittest::kittest::Queryable;
|
|
h.get_by(|n| n.role() == egui::accesskit::Role::MenuItem && n.label().as_deref() == Some(title)).click();
|
|
h.run_steps(2);
|
|
}
|
|
|
|
/// The menu row labelled `label` in an open menu.
|
|
pub fn menu_row<'h>(h: &'h Harness<'static, PdfCraftApp>, label: &str) -> egui_kittest::Node<'h> {
|
|
use egui_kittest::kittest::Queryable;
|
|
let label = label.to_owned();
|
|
h.get_by(move |n| n.role() == egui::accesskit::Role::MenuItem && n.label().as_deref() == Some(label.as_str()))
|
|
}
|
|
|
|
/// The widget labelled `label` outside the menu bar, whose titles (File, Edit, Sign…) may share it.
|
|
pub fn outside_menus<'h>(h: &'h Harness<'static, PdfCraftApp>, label: &str) -> egui_kittest::Node<'h> {
|
|
use egui_kittest::kittest::Queryable;
|
|
let label = label.to_owned();
|
|
h.get_by(move |n| n.role() != egui::accesskit::Role::MenuItem && n.label().as_deref() == Some(label.as_str()))
|
|
}
|
|
|
|
/// Whether the test `name` must skip because the interface fonts lack a glyph for a character it
|
|
/// draws: one in `text` or in the catalog of the interface `language`. egui 0.37 test harnesses
|
|
/// panic on a missing glyph, and Japanese, Chinese and Thai faces come only from the optional
|
|
/// craft-fonts build input or a face installed on this machine. Prints the skip line.
|
|
///
|
|
/// The fonts are those the app installs for `language` and for the default CJK preference: a
|
|
/// switch to Chinese installs its fonts for the next frame, so the first frame in Chinese draws
|
|
/// with the fonts of the language before it.
|
|
///
|
|
/// A build that requires craft-fonts (`CRAFT_FONTS_REQUIRED=1`, as the CI gate sets) never skips:
|
|
/// a missing glyph there is a failure.
|
|
pub fn skip_without_glyphs(name: &str, language: &str, text: &str) -> bool {
|
|
if std::env::var("CRAFT_FONTS_REQUIRED").as_deref() == Ok("1") {
|
|
return false;
|
|
}
|
|
let catalogs: Vec<&str> = i18n::Lang::from_code(language).into_iter().flat_map(i18n::Lang::catalog_texts).collect();
|
|
let translations = catalogs.iter().flat_map(|c| c.lines()).filter(|l| !l.starts_with('#')).filter_map(|l| l.split('\t').nth(2));
|
|
let chars: BTreeSet<char> = std::iter::once(text).chain(translations).flat_map(str::chars).filter(|c| !c.is_control()).collect();
|
|
let cjk = theme::CjkPreference::for_language(language);
|
|
let missing = [theme::CjkPreference::Default, cjk].into_iter().find_map(|cjk| {
|
|
let defs = theme::installed_font_definitions(cjk);
|
|
let families: Vec<FontId> = defs.families.keys().map(|f| FontId::new(13.0, f.clone())).collect();
|
|
let mut fonts = Fonts::new(TextOptions::default(), defs);
|
|
chars.iter().copied().find(|c| families.iter().any(|id| !fonts.has_glyphs(id, &c.to_string())))
|
|
});
|
|
let Some(missing) = missing else {
|
|
return false;
|
|
};
|
|
eprintln!("skipping {name}: no interface font draws {missing:?} (set CRAFT_FONTS_DIR to a craft-fonts checkout with a face for it)");
|
|
true
|
|
}
|
|
|
|
/// Whether `name` is skipped because the build embeds no craft-i18n catalogs (English only).
|
|
pub fn skip_without_catalogs(name: &str) -> bool {
|
|
let skip = !pdfcraft_ui_egui::i18n::catalogs_embedded();
|
|
if skip {
|
|
eprintln!("skipping {name}: built without craft-i18n (set CRAFT_I18N_DIR to a craft-i18n checkout)");
|
|
}
|
|
skip
|
|
}
|