Options › Language names the proofing language at the caret (storytold/wordcraft#3150) (storytold/wordcraft#3177)

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 <noreply@anthropic.com>
Co-authored-by: aiongg <67543387+aiongg@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-10-23 17:24:46 -04:00
1 parent 1711c147cb
commit 36651e4df8
3 files changed
+48 -18

No files matched your search

+2 -1
View File
@@ -42,10 +42,11 @@ pub fn dictionary() -> Arc<AffixDict> {
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()
})
+44 -16
View File
@@ -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<bool> {
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);
}
+2 -1
View File
@@ -63,10 +63,11 @@ pub fn dictionary() -> Arc<AffixDict> {
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()
})