LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge PR #564
Brandon Thomas53c056daf3d8
diff --cc crates/ui-egui/src/i18n.rsindex f40ce4702,941b12def..109accfa9--- a/crates/ui-egui/src/i18n.rs+++ b/crates/ui-egui/src/i18n.rs@@@ -124,7 -124,7 +124,8 @@@ language_table!Es, "es", "Español", "Latn", include_str!("../locales/es.json");De, "de", "Deutsch", "Latn", include_str!("../locales/de.json");Ru, "ru", "Русский", "Cyrl", include_str!("../locales/ru.json");+ Fr, "fr", "Français", "Latn", include_str!("../locales/fr.json");+ Uk, "uk", "Українська", "Cyrl", include_str!("../locales/uk.json");}// The settings file stores the BCP-47 code (`"zh-hans"`), never the Rust variant name, so a@@@ -699,125 -629,107 +701,226 @@@ mod tests}}+ /// Smart-album choice values read as words in every language (English "Public Domain", German+ /// "Gemeinfrei"), never as rule ids like `publicDomain`; an id the field doesn't know shows as+ /// written. Unlike other labels these must be translated: an untranslated one would be English+ /// in the middle of a translated rule.+ #[test]+ fn choice_values_read_as_words_in_every_language() {+ use lightcraft_catalog::rules::{FIELDS, Kind};+ assert_eq!(choice_text_in(Locale::En, "copyrightStatus", "publicDomain"), "Public Domain");+ assert_eq!(choice_text_in(Locale::De, "copyrightStatus", "publicDomain"), "Gemeinfrei");+ assert_eq!(choice_text_in(Locale::De, "copyrightStatus", "someday"), "someday");+ assert_eq!(choice_text_in(Locale::ZhHans, "treatment", "color"), "彩色", "in colour, not the colour noun");+ assert_eq!(choice_text_in(Locale::Ru, "treatment", "color"), "Цветное");+ assert_eq!(choice_text_in(Locale::Es, "label", "none"), "Sin etiqueta");+ // yes/no fields read Yes / No, never true / false+ assert_eq!((bool_text_in(Locale::En, true), bool_text_in(Locale::En, false)), ("Yes", "No"));+ assert_eq!(bool_text_in(Locale::De, false), "Nein");+ // Japanese answers はい / いいえ don't read as a rule's value: its own wording, あり / なし,+ // through a context, while the shared Yes / No keep their meaning everywhere else+ assert_eq!((bool_text_in(Locale::Ja, true), bool_text_in(Locale::Ja, false)), ("あり", "なし"));+ assert_eq!((Locale::Ja.tr("Yes"), Locale::Ja.tr("No")), ("はい", "いいえ"));+ assert_eq!(tr_ctx_in(Locale::Ja, "nope", "Yes"), "はい", "no contextual entry: the plain message");+ assert_eq!(tr_ctx_in(Locale::En, BOOL_CONTEXT, "Yes"), "Yes");+ // and the yes/no fields are named by plain nouns, so "編集 … なし" doesn't read "edits: yes … none"+ for (field, label, kind) in FIELDS {+ if *kind != Kind::Bool {+ continue;+ }+ let ja = Locale::Ja.catalog().get(*label).unwrap_or_else(|| panic!("ja lacks the {field} label {label:?}"));+ assert!(!ja.contains("あり") && !ja.contains("なし"), "{field}: {ja}");+ }+ // a contextual entry names a real value (a typo would silently fall back to はい / いいえ)+ let values = [lightcraft_catalog::rules::bool_label(true), lightcraft_catalog::rules::bool_label(false)];+ for language in Locale::ALL {+ for key in language.catalog().keys() {+ if let Some(value) = key.strip_prefix(BOOL_CONTEXT).and_then(|k| k.strip_prefix('|')) {+ assert!(values.contains(&value), "{}: {key:?} isn't a yes/no value", language.code());+ }+ }+ }+ for language in Locale::ALL.iter().filter(|language| **language != Locale::En) {+ for label in [lightcraft_catalog::rules::bool_label(true), lightcraft_catalog::rules::bool_label(false)] {+ assert!(language.catalog().contains_key(label), "{} lacks {label:?}", language.code());+ }+ }+ for language in Locale::ALL {+ for (field, _, kind) in FIELDS {+ let Kind::Choice(choices) = kind else { continue };+ for (id, label) in *choices {+ let text = choice_text_in(*language, field, id);+ assert_ne!(text, *id, "{}: {field} {id}", language.code());+ if *language != Locale::En {+ assert!(language.catalog().contains_key(*label), "{} lacks {label:?}", language.code());+ }+ }+ }+ }+ }++ /// A rule's problem reads as the field's name and the issue, in the editor's language ("Titel:+ /// braucht einen Suchbegriff …"); the sidebar's list puts the rule's position first. Every issue+ /// is translated in every language: an English one would stand out in a translated editor.+ #[test]+ fn problems_read_in_every_language() {+ use lightcraft_catalog::rules::Issue;+ let cat = lightcraft_catalog::Catalog::new();+ let problems = |rules: serde_json::Value| {+ serde_json::from_value::<lightcraft_catalog::RuleSet>(serde_json::json!({"rules": rules})).unwrap().check(&cat)+ };+ let p = problems(serde_json::json!([{"field": "rating", "op": "gte", "value": 3}, {"field": "title", "op": "contains", "value": ""}]));+ assert_eq!(problem_text_in(Locale::En, &p[0]), "Title: needs something to look for (or use “is empty”)");+ assert_eq!(problem_text_in(Locale::De, &p[0]), "Titel: braucht einen Suchbegriff (oder „ist leer“)");+ assert_eq!(problem_line_in(Locale::En, &p[0]), "#2 Title: needs something to look for (or use “is empty”)");+ // Japanese and Chinese join with a full-width colon, as their catalogs do+ assert_eq!(problem_text_in(Locale::Ja, &p[0]), "タイトル:検索する語句が必要です(または「が空」を使用)");+ // a problem with the album filter itself has no rule position to show+ let filter_loop =+ lightcraft_catalog::rules::Problem { path: Vec::new(), field: Some("album".into()), issue: Issue::AlbumLoop, message: String::new() };+ assert!(problem_line_in(Locale::En, &filter_loop).starts_with("Album: "), "{}", problem_line_in(Locale::En, &filter_loop));+ let g = problems(serde_json::json!([{"group": {"rules": []}}]));+ assert_eq!(problem_text_in(Locale::En, &g[0]), "This group is empty: add a rule or remove it.");+ // the issues, the operators their hints name and the album picker's words, in every language+ for language in Locale::ALL.iter().filter(|l| **l != Locale::En) {+ // the field menu: every field and every group, so it never mixes languages+ for label in lightcraft_catalog::rules::FIELDS.iter().map(|f| f.1).chain(lightcraft_catalog::rules::FIELD_GROUPS.iter().map(|g| g.0)) {+ assert!(language.catalog().contains_key(label), "{} lacks the rule label {label:?}", language.code());+ }+ for word in [+ "Choose an album…",+ "No albums yet",+ "Search albums",+ "No albums match",+ "This is the album you're editing",+ "It tests this album, so testing it back would loop",+ "Fix the marked rules to save this album.",+ ] {+ assert!(language.catalog().contains_key(word), "{} lacks {word:?}", language.code());+ }+ for issue in Issue::ALL {+ assert!(language.catalog().contains_key(issue.text()), "{} lacks {:?}", language.code(), issue.text());+ }+ for (_, _, kind) in lightcraft_catalog::rules::FIELDS {+ for (_, op) in lightcraft_catalog::rules::ops_for(*kind) {+ assert!(language.catalog().contains_key(*op), "{} lacks the operator {op:?}", language.code());+ }+ }+ }+ }++ /// The date picker's own words (its tooltip, the weekday headers) are in every language, as the+ /// month and day labels it borrows from the date headings are.+ #[test]+ fn date_picker_words_are_translated() {+ for language in Locale::ALL.iter().filter(|l| **l != Locale::En) {+ for word in crate::date_picker::WEEKDAY_SHORT.iter().chain(&["Pick a date", "Year", "Month", "Day"]) {+ assert!(language.catalog().contains_key(*word), "{} lacks {word:?}", language.code());+ }+ }+ }++ /// Ukrainian's coverage of every catalog message and display label. Gaps are reported, not failed+ /// (like `catalogs_agree_on_placeholders_and_report_gaps`): a feature PR that adds a label doesn't+ /// have to ship its Ukrainian text, which shows in English until the translation catches up.+ #[test]+ fn ukrainian_coverage_of_catalogs_commands_controls_and_rules_is_reported() {+ let catalog = Locale::Uk.catalog();+ let keys: std::collections::BTreeSet<&String> = Locale::ALL.iter().flat_map(|language| language.catalog().keys()).collect();+ let lacking: Vec<_> = keys.into_iter().filter(|key| !catalog.contains_key(key.as_str())).collect();+ if !lacking.is_empty() {+ eprintln!("uk lacks {} catalog message(s) (shown in English): {lacking:?}", lacking.len());+ }+ let mut labels: Vec<&str> = lightcraft_engine::command_specs().iter().map(|spec| spec.label).collect();+ labels.extend(crate::menus::ui_commands().map(|command| command.1).filter(|label| !Locale::ALL.iter().any(|locale| locale.name() == *label)));+ labels.extend(lightcraft_develop::CONTROLS.iter().map(|control| control.label));+ labels.extend(crate::panels::settings::TABS.iter().map(|(_, label)| *label));+ for (_, label, kind) in lightcraft_catalog::rules::FIELDS {+ labels.push(label);+ labels.extend(lightcraft_catalog::rules::ops_for(*kind).iter().map(|(_, label)| *label));+ }+ labels.extend(lightcraft_engine::rename::TOKENS.iter().map(|token| token.meaning));+ labels.extend(lightcraft_engine::rename::TEMPLATE_NOTES);+ let missing: Vec<_> = labels.into_iter().filter(|label| !catalog.contains_key(*label)).collect();+ if !missing.is_empty() {+ eprintln!("uk lacks {} display label(s) (shown in English): {missing:?}", missing.len());+ }+ }++ #[test]+ fn ukrainian_switches_persists_formats_dates_and_preserves_values() {+ use crate::control::{ControlRequest, Outcome};+ let mut app = crate::LightcraftApp::new(lightcraft_engine::Session::with_demo(), Default::default());+ app.run("app.language.ukrainian", serde_json::json!({})).unwrap();+ assert_eq!(app.ui.language, Locale::Uk);+ assert_eq!(crate::menubar::checked(&app, "app.language.ukrainian"), Some(true));+ assert_eq!(tr("Light"), "Світло");+ assert_eq!(tr("Landscape"), "Пейзаж");+ assert_eq!(tr("Home"), "Домашня тека");+ assert_eq!(date_group_label("2026-09-20", false), "Неділя, 20.09.2026");+ assert_eq!(date_group_label("2026-09", false), "09.2026");+ assert_eq!(display_time("2026-09-20T16:04:05"), "Неділя, 20.09.2026 16:04:05");+ // Count-neutral labels work for every Ukrainian integer category, with no English suffix.+ for n in [0, 1, 2, 5, 11, 21, 22, 25, 111] {+ assert_eq!(tr_format!("Imported {} photo{}", n, if n == 1 { "" } else { "s" }), format!("Імпортовано фото: {n}"));+ assert_eq!(tr_format!("{} files and {f} folder{}", n, "s", f = n), format!("Файлів: {n}, тек: {n}"));+ let noun = tr(if n == 1 { "cached picture" } else { "cached pictures" });+ assert_eq!(tr_format!("{n} {noun}", n = n, noun = noun), format!("Кешовані зображення: {n}"));+ }+ // This trailing argument is queue progress, not an English plural suffix.+ let queued = tr_format!(" · {queued} waiting", queued = 5);+ assert_eq!(+ tr_format!("Denoising {name}: {done} of {total} tiles{}", queued, name = "IMG.CR3", done = 1, total = 4),+ "Усунення шуму IMG.CR3: ділянки — 1 із 4 · очікують: 5"+ );+ let name = "Color {title} 日本語";+ assert_eq!(tr_format!("Added {n} photo{} to “{}”", "s", name, n = 22), format!("До «{name}» додано фото: 22"));+ assert_eq!(builtin_label("Warm Glow", false), "Warm Glow");+ assert_eq!(builtin_label("Warm Glow", true), "Тепле сяйво");+ assert_eq!(tr("photo-{title}.jpg"), "photo-{title}.jpg");+ assert_eq!(tr("develop.set"), "develop.set");+ let saved = serde_json::to_string(&app.ui).unwrap();+ assert!(saved.contains(r#""language":"uk""#));+ assert_eq!(serde_json::from_str::<crate::state::UiState>(&saved).unwrap().language, Locale::Uk);+ let ctx = egui::Context::default();+ for code in ["uk", "uk-UA", "uk_UA.UTF-8", "uk-Cyrl-UA"] {+ assert_eq!(Locale::parse_tag(code), Some(Locale::Uk));+ let (request, _) = ControlRequest::new("ui.set", serde_json::json!({"language": code}));+ let Outcome::Done(reply) = crate::control::handle(&mut app, &ctx, &request) else { panic!("expected reply") };+ assert_eq!(reply["ok"], true);+ assert_eq!(language(), Locale::Uk);+ }+ set_language(Locale::En);+ }++ #[test]+ fn ukrainian_panels_dialogs_and_letters_paint_with_bundled_fonts() {+ let ctx = fonts_ctx(&[]);+ let mut app = crate::LightcraftApp::new(lightcraft_engine::Session::with_demo(), Default::default());+ app.ui.left_panel = true;+ let text = painted_text(&ctx, &mut app, Locale::Uk);+ assert!(text.contains("Мої фото") && text.contains("Усі фото"), "{text}");+ for (command, title) in [("app.about", "Про LightCraft"), ("app.shortcuts", "Клавіатурні скорочення"), ("app.settings", "Налаштування")]+ {+ app.ui.dialog = None;+ app.run(command, serde_json::json!({})).unwrap();+ let text = painted_text(&ctx, &mut app, Locale::Uk);+ assert!(text.contains(title), "{command}: {text}");+ }+ ctx.fonts_mut(|fonts| {+ for family in [egui::FontFamily::Proportional, egui::FontFamily::Name(crate::theme::FONT_SEMIBOLD.into())] {+ let font = egui::FontId::new(13.0, family);+ for ch in "ҐґЄєІіЇї’«»"+ .chars()+ .chain(Locale::Uk.catalog().values().flat_map(|text| text.chars()).filter(|ch| ('\u{0400}'..='\u{04ff}').contains(ch)))+ {+ assert!(fonts.has_glyph(&font, ch), "missing Ukrainian glyph {ch}");+ }+ }+ });+ set_language(Locale::En);+ }+/// Every command, control, rule and rename label, and every line of What's New, is a message a/// catalog can translate. What a language lacks is reported, not failed (like/// `catalogs_agree_on_placeholders_and_report_gaps`): a feature PR doesn't have to ship everydiff --cc docs/parity.mdindex c09c2d232,6627b420c..10b85b999--- a/docs/parity.md+++ b/docs/parity.md@@@ -525,11 -525,10 +525,11 @@@ under the UI command that wraps it (a n| LR-BEHAV-PANEL-RESIZE | Resizable side panels | P1 | ✅ | `crates/ui-egui/src/panels/mod.rs` (`resizable_side`), `crates/ui-egui/src/state.rs` (`LEFT_WIDTH`, `RIGHT_WIDTH`), `crates/ui-egui/src/tests_panels.rs` | drag the left sidebar's right edge (200–480 pt) or the right panel's left edge (250–520 pt); the photo area keeps ≥ 360 pt; widths are kept across panels, views and restarts (`leftWidth` / `rightWidth` in the UI state); the Presets column stays fixed || LR-BEHAV-EMPTY-STATES | Empty states | P1 | ✅ | `crates/ui-egui/src/panels/mod.rs` (`empty_message`) | || LR-BEHAV-TOOLTIPS | Tooltips with shortcuts | P0 | ✅ | `crates/ui-egui/src/panels/bottombar.rs` | |+| LR-BEHAV-TEXTFIELD | Text fields behave alike | P1 | 🟡 | `crates/ui-egui/src/text_field.rs`, `crates/ui-egui/src/panels/topbar.rs`, `crates/ui-egui/src/widgets.rs`, `crates/ui-egui/src/panels/right.rs` (`meta_field`), `crates/ui-egui/src/panels/dialogs.rs`, `crates/ui-egui/src/panels/unnamed.rs` | one shared field: right-click Cut / Copy / Paste / Select All (no Paste in the browser), Esc gives back the text from before the edit, Return / leaving / Esc reported to the caller, optional select-on-focus; agents use `ui.clipboard` (MCP `clipboard`) and `ui.inspect` → `copied`. Used by Search Photos, slider values, the Info panel's metadata fields (multi-line captions), the one-field dialogs (New / Rename Album, New Smart Album, Rename / Merge Keywords, text prompts) and the unnamed faces' name field so far; the other text fields (most dialogs, import, settings, masking, keywords …) still use egui's own and have no menu || LR-BEHAV-HEADLESS | Headless UI snapshots | P2 | ✅ | `apps/lightcraft-cli/src/main.rs`, `crates/ui-egui/src/headless.rs`, `docs/control-protocol.md` | `snapshot` rasterizes the UI and defaults photo development to the CPU before the first frame, without adapter discovery; scaled dimensions are validated before allocation, and UI zoom preserves the requested physical viewport; JSON-lines control scripts are supported || LR-BEHAV-ACCESS | Accessibility | P2 | 🟡 | `crates/ui-egui/src/widgets.rs`, `crates/ui-egui/src/panels/grid.rs` | AccessKit (VoiceOver / Narrator / AT-SPI): sliders announce control and value, buttons / icon buttons / dropdowns / section headers / sources their labels and state, grid thumbnails file name, rating, flag and label; the canvas tools (crop, masks) are pointer-only; not audited with a screen reader |- | LR-BEHAV-LOCALE | Language options | P2 | ✅ | `cmd:app.language.english`, `cmd:app.language.simplifiedChinese`, `cmd:app.language.traditionalChinese`, `cmd:app.language.japanese`, `cmd:app.language.portuguese`, `cmd:app.language.french`, `cmd:app.language.spanish`, `cmd:app.language.german`, `cmd:app.language.russian` | Edit > Language lists every language in the table and the active one is checked; shared with Settings > General (docs/localization.md) |- | LR-BEHAV-LOCALIZE | Localisation | P2 | 🟡 | `crates/ui-egui/src/i18n.rs`, `crates/ui-egui/locales/`, `docs/localization.md`, `docs/localization-zh-hans.md`, `docs/localization-zh-hant.md`, `docs/localization-ja.md`, `docs/localization-pt-br.md`, `docs/localization-es.md`, `docs/localization-de.md`, `docs/localization-ru.md` | One table entry per language (code, endonym, ISO 15924 script, catalog): English, Simplified Chinese, Traditional Chinese (Taiwan), Japanese, Brazilian Portuguese, Spanish, German and Russian UI with a persisted language preference and craft-fonts regular/bold faces per script; menus, edit, crop/masks, settings, import/export and primary progress messages. Adding a language is a table entry plus two catalogs. Stock presets/profiles, history steps, library headings, date headings and capture times are localised (user-named items stay verbatim); the German catalog covers every existing catalog key, command/control label and rule-editor label; the other catalogs fall back to English for messages they lack. Technical errors remain English; release notes are translated in German; Traditional Chinese borrows the Simplified Chinese face (no TC face in craft-fonts yet), and the web build embeds the Japanese face in WASM while loading the Simplified Chinese face from a separate font file. |-| LR-BEHAV-LOCALE | Language options | P2 | ✅ | `cmd:app.language.english`, `cmd:app.language.simplifiedChinese`, `cmd:app.language.traditionalChinese`, `cmd:app.language.japanese`, `cmd:app.language.portuguese`, `cmd:app.language.spanish`, `cmd:app.language.german`, `cmd:app.language.russian`, `cmd:app.language.ukrainian` | Edit > Language lists every language in the table and the active one is checked; shared with Settings > General (docs/localization.md) |++| LR-BEHAV-LOCALE | Language options | P2 | ✅ | `cmd:app.language.english`, `cmd:app.language.simplifiedChinese`, `cmd:app.language.traditionalChinese`, `cmd:app.language.japanese`, `cmd:app.language.portuguese`, `cmd:app.language.french`, `cmd:app.language.spanish`, `cmd:app.language.german`, `cmd:app.language.russian`, `cmd:app.language.ukrainian` | Edit > Language lists every language in the table and the active one is checked; shared with Settings > General (docs/localization.md) |+ | LR-BEHAV-LOCALIZE | Localisation | P2 | 🟡 | `crates/ui-egui/src/i18n.rs`, `crates/ui-egui/locales/`, `docs/localization.md`, `docs/localization-zh-hans.md`, `docs/localization-zh-hant.md`, `docs/localization-ja.md`, `docs/localization-pt-br.md`, `docs/localization-es.md`, `docs/localization-de.md`, `docs/localization-ru.md` | One table entry per language (code, endonym, ISO 15924 script, catalog): English, Simplified Chinese, Traditional Chinese (Taiwan), Japanese, Brazilian Portuguese, Spanish, German, Russian and Ukrainian UI with a persisted language preference and craft-fonts regular/bold faces per script; menus, edit, crop/masks, settings, import/export and primary progress messages. Adding a language registers the locale and its language command, plus two catalogs. Stock presets/profiles, history steps, library headings, date headings and capture times are localised (user-named items stay verbatim); the Ukrainian catalog covers every existing catalog key, command/control label and rule-editor label; the German catalog reports newly added gaps; the other catalogs fall back to English for messages they lack. Technical errors remain English; release notes are translated in German and Ukrainian; Traditional Chinese borrows the Simplified Chinese face (no TC face in craft-fonts yet), and the web build embeds the Japanese face in WASM while loading the Simplified Chinese face from a separate font file. || LR-BEHAV-LEARN | Tutorials | OOS | 🚫 | | || LR-BEHAV-WHATSNEW | What's new | P2 | ✅ | `cmd:app.whatsNew`, `docs/whats-new.md` | Help ▸ What's New: release highlights || LR-BEHAV-AI-EA | Early-access badges | P2 | ⬜ | | |