mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-11 15:27:21 +00:00
Improved logging (#678)
Build and Release / Read metadata (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
Build and Release / Read metadata (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
This commit is contained in:
1 parent
09df19e6f5
commit
685f95245b
7 files changed
+169
-39
No files matched your search
+55
-18
@@ -15,6 +15,9 @@ pub static DATA_DIRECTORY: OnceLock<String> = OnceLock::new();
|
||||
/// The config directory where the application stores its configuration.
|
||||
pub static CONFIG_DIRECTORY: OnceLock<String> = OnceLock::new();
|
||||
|
||||
/// The user language cached once per runtime process.
|
||||
static USER_LANGUAGE: OnceLock<String> = OnceLock::new();
|
||||
|
||||
/// Returns the config directory.
|
||||
#[get("/system/directories/config")]
|
||||
pub fn get_config_directory(_token: APIToken) -> String {
|
||||
@@ -87,12 +90,11 @@ fn normalize_locale_tag(locale: &str) -> Option<String> {
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn read_locale_from_environment() -> Option<String> {
|
||||
fn read_locale_from_environment() -> Option<(String, &'static str)> {
|
||||
if let Ok(language) = env::var("LANGUAGE") {
|
||||
for candidate in language.split(':') {
|
||||
if let Some(locale) = normalize_locale_tag(candidate) {
|
||||
info!("Detected user language from Linux environment variable 'LANGUAGE': '{}'.", locale);
|
||||
return Some(locale);
|
||||
return Some((locale, "LANGUAGE"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,8 +102,7 @@ fn read_locale_from_environment() -> Option<String> {
|
||||
for key in ["LC_ALL", "LC_MESSAGES", "LANG"] {
|
||||
if let Ok(value) = env::var(key) {
|
||||
if let Some(locale) = normalize_locale_tag(&value) {
|
||||
info!("Detected user language from Linux environment variable '{}': '{}'.", key, locale);
|
||||
return Some(locale);
|
||||
return Some((locale, key));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,10 +111,35 @@ fn read_locale_from_environment() -> Option<String> {
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
fn read_locale_from_environment() -> Option<String> {
|
||||
fn read_locale_from_environment() -> Option<(String, &'static str)> {
|
||||
None
|
||||
}
|
||||
|
||||
enum LanguageDetectionSource {
|
||||
SysLocale,
|
||||
LinuxEnvironmentVariable(&'static str),
|
||||
DefaultLanguage,
|
||||
}
|
||||
|
||||
fn detect_user_language() -> (String, LanguageDetectionSource) {
|
||||
if let Some(locale) = get_locale() {
|
||||
if let Some(normalized_locale) = normalize_locale_tag(&locale) {
|
||||
return (normalized_locale, LanguageDetectionSource::SysLocale);
|
||||
}
|
||||
|
||||
warn!("sys-locale returned an unusable locale value: '{}'.", locale);
|
||||
}
|
||||
|
||||
if let Some((locale, key)) = read_locale_from_environment() {
|
||||
return (locale, LanguageDetectionSource::LinuxEnvironmentVariable(key));
|
||||
}
|
||||
|
||||
(
|
||||
String::from(DEFAULT_LANGUAGE),
|
||||
LanguageDetectionSource::DefaultLanguage,
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::normalize_locale_tag;
|
||||
@@ -137,21 +163,32 @@ mod tests {
|
||||
|
||||
#[get("/system/language")]
|
||||
pub fn read_user_language(_token: APIToken) -> String {
|
||||
if let Some(locale) = get_locale() {
|
||||
if let Some(normalized_locale) = normalize_locale_tag(&locale) {
|
||||
info!("Detected user language from sys-locale: '{}'.", normalized_locale);
|
||||
return normalized_locale;
|
||||
}
|
||||
USER_LANGUAGE
|
||||
.get_or_init(|| {
|
||||
let (user_language, source) = detect_user_language();
|
||||
match source {
|
||||
LanguageDetectionSource::SysLocale => {
|
||||
info!("Detected user language from sys-locale: '{}'.", user_language);
|
||||
},
|
||||
|
||||
warn!("sys-locale returned an unusable locale value: '{}'.", locale);
|
||||
}
|
||||
LanguageDetectionSource::LinuxEnvironmentVariable(key) => {
|
||||
info!(
|
||||
"Detected user language from Linux environment variable '{}': '{}'.",
|
||||
key, user_language
|
||||
);
|
||||
},
|
||||
|
||||
if let Some(locale) = read_locale_from_environment() {
|
||||
return locale;
|
||||
}
|
||||
LanguageDetectionSource::DefaultLanguage => {
|
||||
warn!(
|
||||
"Could not determine the system language. Use default '{}'.",
|
||||
DEFAULT_LANGUAGE
|
||||
);
|
||||
},
|
||||
}
|
||||
|
||||
warn!("Could not determine the system language. Use default '{}'.", DEFAULT_LANGUAGE);
|
||||
String::from(DEFAULT_LANGUAGE)
|
||||
user_language
|
||||
})
|
||||
.clone()
|
||||
}
|
||||
|
||||
#[get("/system/enterprise/config/id")]
|
||||
|
||||
Reference in new issue
Block a user