diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-01-13 15:27:05 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-01-13 15:27:05 +0100 |
| commit | 43632164dcacb3424ccb9ceba76ddfd7586cb59c (patch) | |
| tree | 5c8d42f793326fecef757a7e60eb94ad45c13511 /crates/cli/src/locale.rs | |
| parent | bb3bbcfd018816a80077a6c1f96f842d2bf5f3a4 (diff) | |
| parent | 472d7fb9d37ec838fc69692cf24c8cb4a68af47a (diff) | |
| download | mihi-43632164dcacb3424ccb9ceba76ddfd7586cb59c.tar.gz mihi-43632164dcacb3424ccb9ceba76ddfd7586cb59c.zip | |
Merge branch 'inflection'
Diffstat (limited to 'crates/cli/src/locale.rs')
| -rw-r--r-- | crates/cli/src/locale.rs | 38 |
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 + } +} |
