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/run.rs | 37 +++---------------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) (limited to 'crates/cli/src/run.rs') diff --git a/crates/cli/src/run.rs b/crates/cli/src/run.rs index 0046d47..3e1b866 100644 --- a/crates/cli/src/run.rs +++ b/crates/cli/src/run.rs @@ -6,6 +6,8 @@ use std::io::Write; use std::process::Command; use tempfile::NamedTempFile; +use crate::locale::{current_locale, Locale}; + // Maximum number of times a word has to be run in order to increase the number // of successful runs. const MAX_STEPS: usize = 5; @@ -26,34 +28,6 @@ fn help(msg: Option<&str>) { println!(" -k, --kind \t\tOnly ask for exercises for the given ."); } -// 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`. -enum Locale { - English, - Catalan, -} - -impl Locale { - // Returns the string representation for the locale's code. - 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à"), - } - } -} - // Run the quiz for all the given `words` while expecting answers to be // delivered in the given `locale`. fn run_words(words: Vec, locale: &Locale) -> i32 { @@ -323,12 +297,7 @@ pub fn run(args: Vec) { } } - let raw_locale = std::env::var("LC_ALL").unwrap_or("en".to_string()); - let locale = if raw_locale.starts_with("ca") { - Locale::Catalan - } else { - Locale::English - }; + let locale = current_locale(); let words = match category { Some(cat) => select_relevant_words(cat, &flags, 15), -- cgit v1.2.3