aboutsummaryrefslogtreecommitdiff
path: root/crates/cli/src/run.rs
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2025-08-11 09:28:57 +0200
committerMiquel Sabaté Solà <mssola@mssola.com>2025-10-27 10:26:37 +0100
commit76e4c5bd5016347dca083b6932e6adf03f398cad (patch)
tree816bd3f24e4f4dbc1f87f93bd91a3c91d88c0f44 /crates/cli/src/run.rs
parentab60cbfb64b43402e42e7cd823b53b03f651e535 (diff)
downloadmihi-76e4c5bd5016347dca083b6932e6adf03f398cad.tar.gz
mihi-76e4c5bd5016347dca083b6932e6adf03f398cad.zip
Provide initial implementation for word inflection
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à <mikisabate@gmail.com>
Diffstat (limited to 'crates/cli/src/run.rs')
-rw-r--r--crates/cli/src/run.rs37
1 files changed, 3 insertions, 34 deletions
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 <KIND>\t\tOnly ask for exercises for the given <KIND>.");
}
-// 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<Word>, locale: &Locale) -> i32 {
@@ -323,12 +297,7 @@ pub fn run(args: Vec<String>) {
}
}
- 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),