aboutsummaryrefslogtreecommitdiff
path: root/crates/cli/src/locale.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/locale.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/locale.rs')
-rw-r--r--crates/cli/src/locale.rs38
1 files changed, 38 insertions, 0 deletions
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
+ }
+}