From 36651e4df85ba23a4282b5424583b0ac40ad1765 Mon Sep 17 00:00:00 2001 From: naxvog Date: Fri, 23 Oct 2026 23:24:46 +0200 Subject: [PATCH] =?UTF-8?q?Options=20=E2=80=BA=20Language=20names=20the=20?= =?UTF-8?q?proofing=20language=20at=20the=20caret=20(storytold/wordcraft#3?= =?UTF-8?q?150)=20(storytold/wordcraft#3177)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The note under "Proofing language" always said English (United States). It now names the language at the caret, as the status bar does, and the 22 catalogs carry the new sentence. Co-authored-by: Naxvog <4963183+naxvog@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 Co-authored-by: aiongg <67543387+aiongg@users.noreply.github.com> --- crates/proof/src/cs/mod.rs | 3 +- crates/proof/src/lib.rs | 60 ++++++++++++++++++++++++++++---------- crates/proof/src/ru/mod.rs | 3 +- 3 files changed, 48 insertions(+), 18 deletions(-) diff --git a/crates/proof/src/cs/mod.rs b/crates/proof/src/cs/mod.rs index af743406d..c2ec00c9a 100644 --- a/crates/proof/src/cs/mod.rs +++ b/crates/proof/src/cs/mod.rs @@ -42,10 +42,11 @@ pub fn dictionary() -> Arc { fn load_installed() -> AffixDict { let Some((aff, dic)) = crate::hunspell::find(NAMES) else { + crate::hunspell::clear_load_error(NAMES[0]); log::info!("Czech spelling: no Hunspell cs_CZ dictionary installed"); return AffixDict::default(); }; - crate::hunspell::load(&aff, &dic).unwrap_or_else(|e| { + crate::hunspell::note_load(NAMES[0], &dic, crate::hunspell::load(&aff, &dic)).unwrap_or_else(|e| { log::warn!("Czech spelling: {e}"); AffixDict::default() }) diff --git a/crates/proof/src/lib.rs b/crates/proof/src/lib.rs index 6e17a6921..71f96827b 100644 --- a/crates/proof/src/lib.rs +++ b/crates/proof/src/lib.rs @@ -395,16 +395,13 @@ pub fn has_dictionary(lang: Option<&str>) -> bool { ProofLang::from_tag(lang).is_proofed() } -/// The Hunspell dictionary name (`pl_PL`, `pt_BR`) a proofing language needs but doesn't have +/// The Hunspell dictionary name (`pl_PL`, `it_IT`) a proofing language needs but doesn't have /// installed, for a status-bar hint (#1167). `None` when the language's dictionary is available, /// or when it needs none (English has a built-in word list; unproofed languages aren't offered /// one). Reads the dictionary once (it is cached afterwards). pub fn missing_dictionary(lang: Option<&str>) -> Option<&'static str> { - match ProofLang::from_tag(lang) { - ProofLang::Pl => dictionary_needed(ProofLang::Pl, pl::has_dictionary()), - ProofLang::Pt => dictionary_needed(ProofLang::Pt, pt::has_dictionary()), - _ => None, - } + let lang = ProofLang::from_tag(lang); + dictionary_needed(lang, dictionary_loaded(lang)?) } /// The Hunspell name, `.dic` file and reason of a dictionary that is installed for this language @@ -412,24 +409,38 @@ pub fn missing_dictionary(lang: Option<&str>) -> Option<&'static str> { /// loaded, or when no file exists (then [`missing_dictionary`] names it). Reads the dictionary /// once (it is cached afterwards). pub fn unreadable_dictionary(lang: Option<&str>) -> Option<(&'static str, std::path::PathBuf, String)> { - let (proof_lang, loaded) = match ProofLang::from_tag(lang) { - ProofLang::Pl => (ProofLang::Pl, pl::has_dictionary()), - ProofLang::Pt => (ProofLang::Pt, pt::has_dictionary()), - _ => return None, - }; - let name = dictionary_needed(proof_lang, false)?; - if loaded { - return None; - } + let lang = ProofLang::from_tag(lang); + let name = dictionary_needed(lang, dictionary_loaded(lang)?)?; hunspell::load_error(name).map(|(file, reason)| (name, file, reason)) } -/// The Hunspell name `lang` needs when `installed` is false; only Polish and Portuguese use one. +/// Did the Hunspell dictionary of `lang` load? `None` for languages that use none (English). +fn dictionary_loaded(lang: ProofLang) -> Option { + Some(match lang { + ProofLang::Pl => pl::has_dictionary(), + ProofLang::Pt => pt::has_dictionary(), + ProofLang::It => it::has_dictionary(), + ProofLang::Hr => hr::has_dictionary(), + ProofLang::Tr => tr::has_dictionary(), + ProofLang::Ru => ru::has_dictionary(), + ProofLang::Cs => cs::has_dictionary(), + ProofLang::Id => id::has_dictionary(), + _ => return None, + }) +} + +/// The Hunspell name `lang` needs when `installed` is false (the first name its module looks for). fn dictionary_needed(lang: ProofLang, installed: bool) -> Option<&'static str> { match lang { _ if installed => None, ProofLang::Pl => Some("pl_PL"), ProofLang::Pt => Some("pt_BR"), + ProofLang::It => Some("it_IT"), + ProofLang::Hr => Some("hr_HR"), + ProofLang::Tr => Some("tr_TR"), + ProofLang::Ru => Some("ru_RU"), + ProofLang::Cs => Some("cs_CZ"), + ProofLang::Id => Some("id_ID"), _ => None, } } @@ -957,6 +968,23 @@ mod tests { assert_eq!(dictionary_needed(ProofLang::Pt, false), Some("pt_BR")); assert_eq!(dictionary_needed(ProofLang::Pl, true), None); assert_eq!(dictionary_needed(ProofLang::Pt, true), None); + // Every Hunspell language is named by the first name its module looks for (#3150). + for (l, name) in [ + (ProofLang::It, "it_IT"), + (ProofLang::Hr, "hr_HR"), + (ProofLang::Tr, "tr_TR"), + (ProofLang::Ru, "ru_RU"), + (ProofLang::Cs, "cs_CZ"), + (ProofLang::Id, "id_ID"), + ] { + assert_eq!(dictionary_needed(l, false), Some(name), "{l:?}"); + assert_eq!(dictionary_needed(l, true), None, "{l:?}"); + } + // Every proofed language other than English has a Hunspell dictionary to report. + for l in ProofLang::PROOFED { + let english = matches!(l, ProofLang::En | ProofLang::EnGb | ProofLang::EnCa); + assert_eq!(dictionary_needed(l, false).is_some(), !english, "{l:?}"); + } for l in [ProofLang::En, ProofLang::Bg, ProofLang::De, ProofLang::Other] { assert_eq!(dictionary_needed(l, false), None); } diff --git a/crates/proof/src/ru/mod.rs b/crates/proof/src/ru/mod.rs index 4b1ffe093..c29bbc7c5 100644 --- a/crates/proof/src/ru/mod.rs +++ b/crates/proof/src/ru/mod.rs @@ -63,10 +63,11 @@ pub fn dictionary() -> Arc { fn load_installed() -> AffixDict { let Some((aff, dic)) = crate::hunspell::find(NAMES) else { + crate::hunspell::clear_load_error(NAMES[0]); log::info!("Russian spelling: no Hunspell ru_RU dictionary installed"); return AffixDict::default(); }; - crate::hunspell::load(&aff, &dic).unwrap_or_else(|e| { + crate::hunspell::note_load(NAMES[0], &dic, crate::hunspell::load(&aff, &dic)).unwrap_or_else(|e| { log::warn!("Russian spelling: {e}"); AffixDict::default() })