PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
Add persisted English/Japanese interface language (#47)
midasdfc9d6d39071ed
diff --git a/ROADMAP.md b/ROADMAP.mdindex d7595042b..40d420bf5 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -127,6 +127,7 @@ M0 → M1 → M2 → M3 → M4 must happen in order. After M4, M5–M12 can runNewest first. One line per session: the date, what moved, and the new overall percentage.+- **2026-10-05 (community, #47):** Interface language: Preferences ▸ Interface language switches English/Japanese and persists (`ui.set language=ja|en`, reported by `ui.state`). Core menu labels are translated; dialogs, panels and more languages remain open (misc.prefs-language: partial).- **2026-10-05 (session 13):** Landed community PRs #3–#7 and the never-crash rollout (#11–#25); CI green on every job for the first time in 30+ runs (clippy 1.99, Windows line endings, perf-test noise); nightly fuzz job made to finish (child memory cap) and its findings fixed: 7 out-of-memory crashes (#27, #29, #30) and 11 hangs (in review); issue #8 (integrated GPU, keyboard save prompt); Help ▸ Check for updates (manual only). Added the honest assessment and gap list above. P0 88%, P1 52%; 804 features 49.5% shipped (53.3% weighted). ≈ 30–35%.- **2026-10-03 (session 12, later):** Forms (merge data into a spreadsheet, Actions tab, automatic field detection and naming), Compare files (new `compare` crate: text and visual differences, panel, report, comments), Action Wizard (built-in and custom actions over files), PDF/A verify and Save as PDF/A (new `preflight` crate), Export to Word/HTML/RTF (new `export` crate). P0 88%, P1 52%; 803 features 49.6% shipped (53.3% weighted). ≈ 39%.- **2026-10-03 (session 12):** Edit text and images in place (lines, paragraphs, formatting, existing images), Scan & OCR (new `ocr` crate on ocrs with CC-BY-SA models fetched by `cargo xtask models`: searchable image, page ranges, multiple files), Acrobat JavaScript (new `js` crate on boa: custom field scripts in Acrobat's event order, button scripts, document JavaScripts, console, Enable JavaScript preference, sandbox limits). 110+ tools; P0 88%, P1 48%; 803 features 47.9% shipped (51.1% weighted). ≈ 37%.diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rsindex e4fd0f410..ef7b5c4aa 100644--- a/crates/ui-egui/src/chrome.rs+++ b/crates/ui-egui/src/chrome.rs@@ -153,24 +153,25 @@ pub fn mode_bar(app: &mut PrintCraftApp, ui: &mut egui::Ui) {}fn main_menu(app: &mut PrintCraftApp, ui: &mut egui::Ui) {+ let language = app.language;let t = Tokens::get(ui.ctx());- let resp = widgets::ghost_button(ui, "panel-left", "Menu");+ let resp = widgets::ghost_button(ui, "panel-left", language.tr("Menu"));egui::Popup::menu(&resp).show(|ui| {ui.set_min_width(230.0);- ui.menu_button("File", |ui| crate::commands::registry_menu(app, ui, "File"));- ui.menu_button("Edit", |ui| crate::commands::registry_menu(app, ui, "Edit"));- ui.menu_button("Pages", |ui| crate::commands::registry_menu(app, ui, "Pages"));- ui.menu_button("View", |ui| {+ ui.menu_button(language.tr("File"), |ui| crate::commands::registry_menu(app, ui, "File"));+ ui.menu_button(language.tr("Edit"), |ui| crate::commands::registry_menu(app, ui, "Edit"));+ ui.menu_button(language.tr("Pages"), |ui| crate::commands::registry_menu(app, ui, "Pages"));+ ui.menu_button(language.tr("View"), |ui| {if let Some(i) = app.active {let v = &mut app.views[i];ui.label(egui::RichText::new("Zoom").color(t.text_faint).small());- if widgets::menu_item(ui, "Actual size", "⌘1").clicked() {+ if widgets::menu_item(ui, language.tr("Actual size"), "⌘1").clicked() {v.set_zoom(1.0);}- if widgets::menu_item(ui, "Zoom to page level", "⌘0").clicked() {+ if widgets::menu_item(ui, language.tr("Zoom to page level"), "⌘0").clicked() {v.fit = Fit::Page;}- if widgets::menu_item(ui, "Fit to width", "⌘2").clicked() {+ if widgets::menu_item(ui, language.tr("Fit to width"), "⌘2").clicked() {v.fit = Fit::Width;}if widgets::menu_item(ui, "Fit to height", "").clicked() {@@ -218,7 +219,7 @@ fn main_menu(app: &mut PrintCraftApp, ui: &mut egui::Ui) {ui.separator();}crate::commands::registry_menu(app, ui, "View");- ui.menu_button("Display theme", |ui| {+ ui.menu_button(language.tr("Display theme"), |ui| {let ctx = ui.ctx().clone();if ui.radio(app.follow_system_theme, "Use system setting").clicked() {app.follow_system_theme = true;@@ -232,7 +233,7 @@ fn main_menu(app: &mut PrintCraftApp, ui: &mut egui::Ui) {app.set_theme(&ctx, ThemeKind::Dark);}});- ui.menu_button("Side panels", |ui| {+ ui.menu_button(language.tr("Side panels"), |ui| {for (p, label) in [(RightPanel::Comments, "Comments"),(RightPanel::Bookmarks, "Bookmarks"),@@ -251,7 +252,7 @@ fn main_menu(app: &mut PrintCraftApp, ui: &mut egui::Ui) {}});});- ui.menu_button("Help", |ui| crate::commands::registry_menu(app, ui, "Help"));+ ui.menu_button(language.tr("Help"), |ui| crate::commands::registry_menu(app, ui, "Help"));});}diff --git a/crates/ui-egui/src/commands.rs b/crates/ui-egui/src/commands.rsindex 519cdbb3d..c1a0e8b53 100644--- a/crates/ui-egui/src/commands.rs+++ b/crates/ui-egui/src/commands.rs@@ -500,6 +500,7 @@ pub(crate) fn registry_menu(app: &mut PrintCraftApp, ui: &mut egui::Ui, menu: &slet mac = cfg!(target_os = "macos") || cfg!(target_arch = "wasm32");for spec in commands::menu(menu) {let label = commands::current_label(spec, &app.session, app.active_ids().map(|(_, id)| id));+ let label = app.language.tr(&label);let shortcut = spec.shortcut.map(|s| s.label(mac)).unwrap_or_default();let enabled = app.command_enabled(spec);let resp = ui.add_enabled(enabled, egui::Button::new(label).shortcut_text(shortcut));diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rsindex 9ca9ad842..ae3a255d4 100644--- a/crates/ui-egui/src/control.rs+++ b/crates/ui-egui/src/control.rs@@ -563,6 +563,7 @@ impl Host for crate::PrintCraftApp {"dialog": self.dialog.map(|d| format!("{d:?}")),"palette_open": self.palette_open,"theme": format!("{:?}", self.theme),+ "language": self.language,"notice": self.toast.as_ref().map(|t| t.0.clone()),"password_prompt": self.password_prompt.is_some(),"close_prompt": self.close_request.is_some(),diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rsnew file mode 100644index 000000000..de0fa3f29--- /dev/null+++ b/crates/ui-egui/src/i18n.rs@@ -0,0 +1,122 @@+//! Interface translations. Command ids, document text and file names remain stable.+//! Untranslated labels fall back to English so coverage can grow incrementally.++#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]+#[serde(rename_all = "lowercase")]+pub enum Language {+ #[default]+ En,+ Ja,+}++impl Language {+ pub const ALL: [Self; 2] = [Self::En, Self::Ja];++ pub fn name(self) -> &'static str {+ match self {+ Self::En => "English",+ Self::Ja => "日本語",+ }+ }++ pub fn parse(code: &str) -> Option<Self> {+ match code {+ "en" => Some(Self::En),+ "ja" => Some(Self::Ja),+ _ => None,+ }+ }++ pub fn tr(self, text: &str) -> &str {+ if self == Self::Ja+ && let Some((_, japanese)) = JAPANESE.iter().find(|(english, _)| *english == text)+ {+ return japanese;+ }+ text+ }+}++const JAPANESE: &[(&str, &str)] = &[+ ("Menu", "メニュー"),+ ("File", "ファイル"),+ ("Edit", "編集"),+ ("Pages", "ページ"),+ ("View", "表示"),+ ("Help", "ヘルプ"),+ ("Preferences", "環境設定"),+ ("Preferences…", "環境設定…"),+ ("Interface language", "表示言語"),+ ("Open…", "開く…"),+ ("New blank PDF", "空白の PDF を作成"),+ ("Create PDF from file…", "ファイルから PDF を作成…"),+ ("Create PDF from images…", "画像から PDF を作成…"),+ ("Create PDF from clipboard", "クリップボードから PDF を作成"),+ ("Combine files…", "ファイルを結合…"),+ ("Save", "保存"),+ ("Save as…", "別名で保存…"),+ ("Close file", "ファイルを閉じる"),+ ("Close all", "すべて閉じる"),+ ("Revert", "保存済みの状態に戻す"),+ ("Print…", "印刷…"),+ ("Document properties…", "文書のプロパティ…"),+ ("Undo", "取り消し"),+ ("Redo", "やり直し"),+ ("Find…", "検索…"),+ ("Advanced search…", "高度な検索…"),+ ("Copy pages", "ページをコピー"),+ ("Cut pages", "ページを切り取り"),+ ("Paste pages", "ページを貼り付け"),+ ("Fit visible", "表示範囲に合わせる"),+ ("Marquee zoom", "範囲指定ズーム"),+ ("Take a snapshot", "スナップショットを作成"),+ ("Full screen mode", "全画面表示"),+ ("Read mode", "閲覧モード"),+ ("Switch light / dark theme", "明るい/暗いテーマを切り替え"),+ ("Comments panel", "コメントパネル"),+ ("Form fields panel", "フォームフィールドパネル"),+ ("Clear form", "フォームをクリア"),+ ("Find tools and commands…", "ツールとコマンドを検索…"),+ ("Zoom", "ズーム"),+ ("Actual size", "実際のサイズ"),+ ("Zoom to page level", "ページ全体を表示"),+ ("Fit to width", "幅に合わせる"),+ ("Display theme", "表示テーマ"),+ ("Side panels", "サイドパネル"),+ ("Enable Acrobat JavaScript", "Acrobat JavaScript を有効にする"),+ ("OK", "OK"),+];++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn translations_are_unique_and_preserve_unknown_text() {+ for (i, (en, ja)) in JAPANESE.iter().enumerate() {+ assert!(!ja.is_empty());+ assert!(JAPANESE.iter().take(i).all(|(other, _)| en != other));+ assert_eq!(Language::En.tr(en), *en);+ }+ assert_eq!(Language::Ja.tr("File"), "ファイル");+ assert_eq!(Language::Ja.tr("日本語の文書.pdf"), "日本語の文書.pdf");+ assert_eq!(Language::parse("xx"), None);+ }++ #[test]+ fn language_persists_and_invalid_input_keeps_current_language() {+ let mut app = crate::PrintCraftApp::default();+ app.set_option("language", "ja").unwrap();+ assert_eq!(app.language, Language::Ja);+ assert!(app.set_option("language", "xx").is_err());+ assert_eq!(app.language, Language::Ja);+ let mut restored = crate::PrintCraftApp::default();+ restored.restore(&app.persist());+ assert_eq!(restored.language, Language::Ja);+ restored.restore(r#"{"language":"xx"}"#);+ assert_eq!(restored.language, Language::Ja);+ let mut legacy = crate::PrintCraftApp::default();+ legacy.restore("{}");+ assert_eq!(legacy.language, Language::En);+ }+}diff --git a/crates/ui-egui/src/js_ui.rs b/crates/ui-egui/src/js_ui.rsindex 880f358fd..c89067b27 100644--- a/crates/ui-egui/src/js_ui.rs+++ b/crates/ui-egui/src/js_ui.rs@@ -225,13 +225,21 @@ pub(crate) fn document_js_body(ui: &mut egui::Ui, app: &mut PrintCraftApp, t: &T/// Preferences (the JavaScript category for now). Returns `true` to close.pub(crate) fn preferences_body(ui: &mut egui::Ui, app: &mut PrintCraftApp, t: &Tokens) -> bool {- ui.label(egui::RichText::new("Preferences").font(theme::semibold(18.0)));+ ui.label(egui::RichText::new(app.language.tr("Preferences")).font(theme::semibold(18.0)));+ ui.horizontal(|ui| {+ ui.label(app.language.tr("Interface language"));+ egui::ComboBox::from_id_salt("interface-language").selected_text(app.language.name()).show_ui(ui, |ui| {+ for language in crate::i18n::Language::ALL {+ ui.selectable_value(&mut app.language, language, language.name());+ }+ });+ });ui.add_space(8.0);ui.label(egui::RichText::new("JavaScript").font(theme::semibold(13.0)));egui::Frame::new().fill(t.hover).corner_radius(egui::CornerRadius::same(6)).inner_margin(egui::Margin::same(10)).show(ui, |ui| {ui.set_width(ui.available_width());let mut on = app.session.javascript();- if ui.checkbox(&mut on, "Enable Acrobat JavaScript").changed() {+ if ui.checkbox(&mut on, app.language.tr("Enable Acrobat JavaScript")).changed() {app.session.set_javascript(on);}ui.label(diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex f404f2113..1af06c197 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -57,6 +57,7 @@ mod print_ui;pub use print_ui::{Handling as PrintHandling, PrintDraft, Which as PrintWhich};mod redact_ui;pub use redact_ui::{HiddenDraft, PagesDraft as RedactPagesDraft, RedactPrefs, SearchDraft as RedactSearchDraft};+pub mod i18n;mod protect;mod recovery;pub mod theme;@@ -278,6 +279,7 @@ pub struct PrintCraftApp {/// Comment author, per-tool colours and widths, pin.pub comment_prefs: comments::CommentPrefs,pub theme: ThemeKind,+ pub language: i18n::Language,/// Follow the operating system's light/dark setting.pub follow_system_theme: bool,pub dialog: Option<Dialog>,@@ -451,6 +453,7 @@ impl PrintCraftApp {quick_tool: QuickTool::Select,comment_prefs: Default::default(),theme: ThemeKind::Light,+ language: i18n::Language::default(),follow_system_theme: false,dialog: None,update_source: None,@@ -820,6 +823,7 @@ impl PrintCraftApp {serde_json::json!({"recent": self.recent,"theme": self.theme,+ "language": self.language,// Drawn signatures keep their original form (older settings read the same)."signature": match &self.signature { Some(fill_sign::SavedSig::Drawn(s)) => Some(s), _ => None },"signature_text": match &self.signature { Some(fill_sign::SavedSig::Typed(t)) => Some(t), _ => None },@@ -846,6 +850,9 @@ impl PrintCraftApp {if let Ok(t) = serde_json::from_value::<ThemeKind>(v["theme"].clone()) {self.theme = t;}+ if let Ok(language) = serde_json::from_value::<i18n::Language>(v["language"].clone()) {+ self.language = language;+ }if let Ok(s) = serde_json::from_value::<Vec<Vec<[f32; 2]>>>(v["signature"].clone())&& s.iter().all(|st| st.iter().all(|p| p.iter().all(|x| x.is_finite()))){@@ -882,6 +889,9 @@ impl PrintCraftApp {pub fn set_option(&mut self, key: &str, value: &str) -> Result<(), String> {let view = self.active.and_then(|i| self.views.get_mut(i));match (key, view) {+ ("language", _) => {+ self.language = i18n::Language::parse(value).ok_or("language must be en or ja")?;+ }("theme", _) => {self.follow_system_theme = value == "system";self.pending_theme = Some(if value == "dark" { ThemeKind::Dark } else { ThemeKind::Light });diff --git a/crates/ui-egui/src/theme.rs b/crates/ui-egui/src/theme.rsindex a0d2abba4..4360a607c 100644--- a/crates/ui-egui/src/theme.rs+++ b/crates/ui-egui/src/theme.rs@@ -117,6 +117,7 @@ pub fn install_fonts(ctx: &egui::Context) {fonts.families.entry(FontFamily::Proportional).or_default().insert(0, "Inter".to_owned());fonts.families.entry(FontFamily::Proportional).or_default().push("ShipporiMincho".to_owned());fonts.families.entry(FontFamily::Monospace).or_default().insert(0, "JetBrainsMono".to_owned());+ fonts.families.entry(FontFamily::Monospace).or_default().push("ShipporiMincho".to_owned());let fallback: Vec<String> = fonts.families[&FontFamily::Proportional].clone();for (fam, primary) in [("medium", "Inter-Medium"), ("semibold", "Inter-SemiBold")] {let mut stack = vec![primary.to_owned()];diff --git a/docs/localization.md b/docs/localization.mdnew file mode 100644index 000000000..278ae76d4--- /dev/null+++ b/docs/localization.md@@ -0,0 +1,13 @@+# Interface language++Choose **Edit > Preferences > Interface language** and select **English** or **日本語**. The change applies immediately and persists between launches. Command ids, document contents and file names are unchanged.++The control channel exposes the setting through `ui.set`:++```json+{"method":"ui.set","params":{"key":"language","value":"ja"}}+```++`ui.state` reports `language` as `en` or `ja`. Unknown language codes return an error without changing the current setting. Old preferences default to English.++This first translation pass covers the main menu and core registered menu commands. Untranslated labels use English. Vertical Japanese PDF rendering is an existing viewer feature; this change does not add vertical text editing.diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.tomlindex a40449f90..a3f706eb4 100644--- a/parity/acrobat-features.toml+++ b/parity/acrobat-features.toml@@ -9779,11 +9779,11 @@ title = "Preferences: language"area = "N"tier = "P1"milestone = "M14"-status = "planned"+status = "partial"commands = []tools = []-evidence = []-notes = ""+evidence = ["crates/ui-egui/src/i18n.rs::language_persists_and_invalid_input_keeps_current_language"]+notes = "Preferences switches English/Japanese and persists; ui.set language en|ja and ui.state expose it. Core menu labels translated; broader dialog/panel translations and additional languages remain open."[[feature]]id = "misc.prefs-reading"