From 9d812580557cdc343378816cd65678b8aa75d944 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 12 Mar 2026 15:54:59 +0800 Subject: Add lang field to command context and reorganize utils modules --- utils/src/env/locales.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 utils/src/env/locales.rs (limited to 'utils/src/env/locales.rs') diff --git a/utils/src/env/locales.rs b/utils/src/env/locales.rs new file mode 100644 index 0000000..302c874 --- /dev/null +++ b/utils/src/env/locales.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() +} -- cgit