From 4bdbc3490ff3ecabb2bedaac398defd946566227 Mon Sep 17 00:00:00 2001 From: Kneemund Date: Sat, 2 Nov 2024 01:58:12 +0100 Subject: [PATCH] fix: pick default language from available languages --- crates/rnote-engine/src/engine/mod.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/crates/rnote-engine/src/engine/mod.rs b/crates/rnote-engine/src/engine/mod.rs index a9b2306784..1ac92ee5ae 100644 --- a/crates/rnote-engine/src/engine/mod.rs +++ b/crates/rnote-engine/src/engine/mod.rs @@ -35,7 +35,7 @@ use std::fmt::Debug; use std::path::PathBuf; use std::sync::Arc; use std::time::Instant; -use tracing::error; +use tracing::{debug, error}; pub struct Spellchecker { broker: enchant::Broker, @@ -44,9 +44,22 @@ pub struct Spellchecker { impl Spellchecker { pub fn default_language() -> Option { - glib::language_names() - .get(0) - .map(|language| language.to_string()) + let available_languages = Self::available_languages(); + + for system_language in glib::language_names() { + for available_language in &available_languages { + if system_language.contains(available_language) { + debug!( + "found default spellcheck language: {:?}", + available_language + ); + + return Some(available_language.to_string()); + } + } + } + + None } pub fn available_languages() -> Vec {