From 76e4c5bd5016347dca083b6932e6adf03f398cad Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 11 Aug 2025 09:28:57 +0200 Subject: Provide initial implementation for word inflection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Word inflection for nouns, adjectives has been added so it can be initially be used in commands like 'words show'. Word categories which have no inflections (e.g. adverbs, conjunctions, et al) are skipped. Signed-off-by: Miquel Sabaté Solà --- crates/cli/src/locale.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 crates/cli/src/locale.rs (limited to 'crates/cli/src/locale.rs') diff --git a/crates/cli/src/locale.rs b/crates/cli/src/locale.rs new file mode 100644 index 0000000..f9d42b6 --- /dev/null +++ b/crates/cli/src/locale.rs @@ -0,0 +1,38 @@ +// Locale represents the locales accepted for delivering answers on this +// tool. That is, it's not about i18n on the strings for this application. but +// rather the different translations accepted in places like +// `Word.translations`. +pub enum Locale { + English, + Catalan, +} + +impl Locale { + // Returns the string representation for the locale's code. + pub fn to_code(&self) -> &str { + match self { + Self::English => "en", + Self::Catalan => "ca", + } + } +} + +impl std::fmt::Display for Locale { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + Self::English => write!(f, "english"), + Self::Catalan => write!(f, "català"), + } + } +} + +/// Fetches the Locale object that is suitable for the current environment. +pub fn current_locale() -> Locale { + let raw_locale = std::env::var("LC_ALL").unwrap_or("en".to_string()); + + if raw_locale.starts_with("ca") { + Locale::Catalan + } else { + Locale::English + } +} -- cgit v1.2.3