From d90e47e60678ada60066b58af3faf27cab04ccfe Mon Sep 17 00:00:00 2001 From: Richard Wu Date: Wed, 28 Oct 2026 19:37:50 +0800 Subject: [PATCH] feat: make the UI English-only - Remove locale detection and the Chinese Strings set - Label the new-tab page New Tab instead of Home - Use Untitled defaults for Finder-created files - Drop the sys-locale dependency --- Cargo.lock | 10 ---- Cargo.toml | 1 - src/main.rs | 145 ++++++++++++++++++---------------------------------- 3 files changed, 49 insertions(+), 107 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d63852d..0ca0f4e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1684,7 +1684,6 @@ dependencies = [ "rfd", "serde", "serde_json", - "sys-locale", "tao", "url", "winreg", @@ -2822,15 +2821,6 @@ dependencies = [ "syn 2.0.117", ] -[[package]] -name = "sys-locale" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eab9a99a024a169fe8a903cf9d4a3b3601109bcc13bd9e3c6fff259138626c4" -dependencies = [ - "libc", -] - [[package]] name = "system-deps" version = "6.2.2" diff --git a/Cargo.toml b/Cargo.toml index c3391f3..df1ee90 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,6 @@ rfd = "0.15" notify = "7" open = "5" image = { version = "0.25", default-features = false, features = ["png", "ico"] } -sys-locale = "0.3" serde = { version = "1", features = ["derive"] } serde_json = "1" url = "2" diff --git a/src/main.rs b/src/main.rs index 8d1d3b2..b5f5730 100644 --- a/src/main.rs +++ b/src/main.rs @@ -170,24 +170,6 @@ fn print_help() { ); } -#[derive(Copy, Clone)] -enum Lang { - Zh, - En, -} - -fn detect_lang() -> Lang { - sys_locale::get_locale() - .map(|l| { - if l.to_lowercase().starts_with("zh") { - Lang::Zh - } else { - Lang::En - } - }) - .unwrap_or(Lang::En) -} - #[derive(Clone)] struct Strings { drop_hint: &'static str, @@ -219,64 +201,36 @@ struct Strings { } impl Strings { - fn for_lang(lang: Lang) -> Self { - match lang { - Lang::Zh => Strings { - drop_hint: "Drop a .md file here or press Cmd/Ctrl+O to open", - cannot_read: "无法读取文件", - open_file: "Open File", - new_file: "新建文件", - new_tab: "新建标签页", - home_tab: "首页", - recent_title: "Recent", - missing_title: "文件已移动或删除", - missing_body: "这个标签会继续保留。你可以重新定位文件,或关闭标签。", - locate_file: "重新定位", - close_tab: "关闭标签", - cannot_save: "修改无法保存(文件可能只读或被占用)。继续将丢弃这些修改,是否继续?", - btn_edit: "编辑 (Cmd/Ctrl+E)", - btn_preview: "预览 (Cmd/Ctrl+E)", - btn_new: "新建 Markdown (Cmd/Ctrl+N)", - btn_new_window: "在新窗口打开", - btn_open_location: "打开文件所在位置", - new_filename: "新建.md", - fold_toggle: "折叠/展开", - btn_zoom: "正文缩放", - btn_zoom_out: "缩小正文 (Cmd/Ctrl+-)", - btn_zoom_reset: "重置正文缩放 (Cmd/Ctrl+0)", - btn_zoom_in: "放大正文 (Cmd/Ctrl++)", - search_placeholder: "搜索", - stat_words: "字", - stat_chars: "字符", - }, - Lang::En => Strings { - drop_hint: "Drop a .md file here or press Cmd/Ctrl+O to open", - cannot_read: "Cannot read file", - open_file: "Open File", - new_file: "New File", - new_tab: "New Tab", - home_tab: "Home", - recent_title: "Recent", - missing_title: "File Moved or Deleted", - missing_body: "This tab is kept. Locate the file again or close the tab.", - locate_file: "Locate File", - close_tab: "Close Tab", - cannot_save: "This file could not be saved (read-only or locked). Continue and discard the unsaved changes?", - btn_edit: "Edit (Cmd/Ctrl+E)", - btn_preview: "Preview (Cmd/Ctrl+E)", - btn_new: "New Markdown (Cmd/Ctrl+N)", - btn_new_window: "Open in New Window", - btn_open_location: "Show in Explorer", - new_filename: "Untitled.md", - fold_toggle: "Collapse / Expand", - btn_zoom: "Content zoom", - btn_zoom_out: "Zoom out (Cmd/Ctrl+-)", - btn_zoom_reset: "Reset zoom (Cmd/Ctrl+0)", - btn_zoom_in: "Zoom in (Cmd/Ctrl++)", - search_placeholder: "Find", - stat_words: "non-space", - stat_chars: "chars", - }, + /// The app ships a single English UI. There is deliberately no locale + /// detection, so the interface never mixes Chinese and English labels. + fn english() -> Self { + Strings { + drop_hint: "Drop a .md file here or press Cmd/Ctrl+O to open", + cannot_read: "Cannot read file", + open_file: "Open File", + new_file: "New File", + new_tab: "New Tab", + home_tab: "New Tab", + recent_title: "Recent", + missing_title: "File Moved or Deleted", + missing_body: "This tab is kept. Locate the file again or close the tab.", + locate_file: "Locate File", + close_tab: "Close Tab", + cannot_save: "This file could not be saved (read-only or locked). Continue and discard the unsaved changes?", + btn_edit: "Edit (Cmd/Ctrl+E)", + btn_preview: "Preview (Cmd/Ctrl+E)", + btn_new: "New Markdown (Cmd/Ctrl+N)", + btn_new_window: "Open in New Window", + btn_open_location: "Show in Explorer", + new_filename: "Untitled.md", + fold_toggle: "Collapse / Expand", + btn_zoom: "Content zoom", + btn_zoom_out: "Zoom out (Cmd/Ctrl+-)", + btn_zoom_reset: "Reset zoom (Cmd/Ctrl+0)", + btn_zoom_in: "Zoom in (Cmd/Ctrl++)", + search_placeholder: "Find", + stat_words: "non-space", + stat_chars: "chars", } } } @@ -875,7 +829,7 @@ fn tabs_json(session: &DocumentSession) -> String { .tabs .iter() .map(|tab| { - // The page localizes the Home label; rust only flags the kind. + // The page owns the New Tab label; rust only flags the kind. let name = tab .file_path() .and_then(|path| path.file_name()) @@ -2423,7 +2377,7 @@ mod tests { fs::write(&file, "x".repeat(3 * 1024 * 1024)).unwrap(); let mut session = DocumentSession::default(); session.open(file, true); - let page = build_startup_page(&Strings::for_lang(Lang::En)); + let page = build_startup_page(&Strings::english()); assert!( page.len() < 2 * 1024 * 1024, "startup HTML has {} bytes", @@ -2768,7 +2722,7 @@ mod tests { #[test] fn page_blocks_native_preview_reload_paths() { - let strings = Strings::for_lang(Lang::En); + let strings = Strings::english(); let page = build_page( &md_to_html("# Hello"), "# Hello", @@ -2825,7 +2779,7 @@ mod tests { #[test] fn page_separates_new_file_from_open_and_debounces_autosave() { - let strings = Strings::for_lang(Lang::En); + let strings = Strings::english(); let page = build_page( &md_to_html("# Hello"), "# Hello", @@ -2843,7 +2797,7 @@ mod tests { assert!(page.contains("data-new-file")); assert!(page.contains("HIDE_SINGLE_HOME_TAB = true")); assert!(page.contains("tabs.length === 1 && !tabs[0].home")); - assert!(page.contains("L_HOME = 'Home'")); + assert!(page.contains("L_HOME = 'New Tab'")); assert!( page.matches("if (document.body.classList.contains('home')) return;") .count() @@ -2887,7 +2841,7 @@ mod tests { #[test] fn headings_get_hover_fold_toggles() { - let strings = Strings::for_lang(Lang::En); + let strings = Strings::english(); let page = build_page( &md_to_html("# A\n\n## B\n\ntext"), "# A\n\n## B\n\ntext", @@ -2907,7 +2861,7 @@ mod tests { #[test] fn closing_the_last_editing_tab_restores_the_empty_preview() { - let strings = Strings::for_lang(Lang::En); + let strings = Strings::english(); let page = build_page( &md_to_html("# Hello"), "# Hello", @@ -2942,7 +2896,7 @@ mod tests { #[test] fn page_expands_multi_column_tables() { - let strings = Strings::for_lang(Lang::En); + let strings = Strings::english(); let page = build_page( &md_to_html("| A | B | C | D |\n|---|---|---|---|\n| 1 | 2 | 3 | 4 |"), "", @@ -2959,7 +2913,7 @@ mod tests { #[test] fn empty_state_exposes_open_and_recent_files() { - let strings = Strings::for_lang(Lang::En); + let strings = Strings::english(); let recent = vec![PathBuf::from("/tmp/example.md")]; let html = home_preview_html(&strings, &recent); @@ -3122,11 +3076,11 @@ mod tests { #[test] fn finder_create_uses_non_conflicting_markdown_name() { let dir = temp_test_dir("finder-create"); - fs::write(dir.join("新建.md"), "existing").unwrap(); + fs::write(dir.join("Untitled.md"), "existing").unwrap(); let created = create_finder_file(&dir, "md").unwrap(); - assert_eq!(created.file_name().unwrap(), "新建 2.md"); + assert_eq!(created.file_name().unwrap(), "Untitled 2.md"); assert_eq!(fs::read_to_string(created).unwrap(), ""); let _ = fs::remove_dir_all(dir); } @@ -3141,7 +3095,7 @@ fn load_window_icon() -> Option { } #[cfg(target_os = "macos")] -fn register_as_default(_lang: Lang) { +fn register_as_default() { use std::process::Command; let marker = config_dir().join(".md-preview-registered"); if marker.exists() { @@ -3166,7 +3120,7 @@ fn register_as_default(_lang: Lang) { /// extensions so MD Preview shows up in the "Open with" list. Win8+ blocks /// silent default-handler changes — only the Settings app can confirm those. #[cfg(target_os = "windows")] -fn register_as_default(_lang: Lang) { +fn register_as_default() { use winreg::enums::HKEY_CURRENT_USER; use winreg::RegKey; @@ -3228,7 +3182,7 @@ fn register_as_default(_lang: Lang) { } #[cfg(not(any(target_os = "macos", target_os = "windows")))] -fn register_as_default(_lang: Lang) {} +fn register_as_default() {} #[cfg(target_os = "macos")] thread_local! { @@ -3833,14 +3787,14 @@ fn create_finder_file(folder: &Path, kind: &str) -> std::io::Result { "json" => ("json", b"{}\n"), "html" => ( "html", - b"\n\n\n \n \n\n\n\n\n", + b"\n\n\n \n \n\n\n\n\n", ), _ => ("md", b""), }; - let mut path = folder.join(format!("新建.{extension}")); + let mut path = folder.join(format!("Untitled.{extension}")); let mut index = 2; while path.exists() { - path = folder.join(format!("新建 {index}.{extension}")); + path = folder.join(format!("Untitled {index}.{extension}")); index += 1; } fs::write(&path, contents)?; @@ -4561,9 +4515,8 @@ fn main() { } }; - let lang = detect_lang(); - let strings = Strings::for_lang(lang); - register_as_default(lang); + let strings = Strings::english(); + register_as_default(); register_finder_extension(); bench_log("after_register");