diff options
| author | 魏曹先生 <1992414357@qq.com> | 2025-11-10 09:24:32 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2025-11-10 09:24:32 +0800 |
| commit | 453dc1d8e0bdcf1af2ebbafc6ffecd02e6cd2c31 (patch) | |
| tree | f6f98637dd3c03a6e436e404fd5a52e761be0caf /src/utils/env.rs | |
| parent | 53a807af083e7def4e863baecee568eef6020fff (diff) | |
Add JV_LANG environment variable support and improve CLI structure
Diffstat (limited to 'src/utils/env.rs')
| -rw-r--r-- | src/utils/env.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/utils/env.rs b/src/utils/env.rs new file mode 100644 index 0000000..028995e --- /dev/null +++ b/src/utils/env.rs @@ -0,0 +1,28 @@ +// /// Returns the current locale string based on environment variables. +/// +/// The function checks for locale settings in the following order: +/// 1. JV_LANG environment variable +/// 2. APP_LANG environment variable +/// 3. LANG environment variable (extracts base language before dot and replaces underscores with hyphens) +/// 4. Defaults to "en" if no locale environment variables are found +/// +/// # Returns +/// A String containing the detected locale code +pub fn current_locales() -> String { + if let Ok(lang) = std::env::var("JV_LANG") { + return lang; + } + + if let Ok(lang) = std::env::var("APP_LANG") { + return lang; + } + + if let Ok(lang) = std::env::var("LANG") { + if let Some(base_lang) = lang.split('.').next() { + return base_lang.replace('_', "-"); + } + return lang; + } + + "en".to_string() +} |
