Skip to content

Commit df871ba

Browse files
author
AENERV7
committed
fix: use macOS AppleLanguages instead of LANG env for system language detection
- LANG env var is unreliable in macOS GUI apps (usually en_US.UTF-8) - Read AppleLanguages via 'defaults read -g' for correct detection - Fixes menu staying English when language is set to auto on Chinese macOS
1 parent 7d40f10 commit df871ba

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

src-tauri/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/src/lib.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -895,13 +895,24 @@ pub fn run() {
895895
#[cfg(target_os = "macos")]
896896
let menu_lang = {
897897
let l = language.clone();
898-
if l.is_empty() || l == "auto" {
899-
// Detect from system
900-
let sys_lang = std::env::var("LANG").unwrap_or_default();
901-
if sys_lang.starts_with("zh_TW") || sys_lang.starts_with("zh_HK") { "zh-TW".to_string() }
902-
else if sys_lang.starts_with("zh") { "zh-CN".to_string() }
903-
else { "en-GB".to_string() }
904-
} else { l }
898+
if !l.is_empty() && l != "auto" {
899+
l
900+
} else {
901+
// On macOS, LANG env var is unreliable for GUI apps.
902+
// Read AppleLanguages from user defaults instead.
903+
let output = Command::new("defaults")
904+
.args(["read", "-g", "AppleLanguages"])
905+
.output()
906+
.map(|o| String::from_utf8_lossy(&o.stdout).to_string())
907+
.unwrap_or_default();
908+
if output.contains("zh-Hans") || output.contains("zh-CN") || output.contains("\"zh\"") {
909+
"zh-CN".to_string()
910+
} else if output.contains("zh-Hant") || output.contains("zh-TW") || output.contains("zh-HK") {
911+
"zh-TW".to_string()
912+
} else {
913+
"en-GB".to_string()
914+
}
915+
}
905916
};
906917

907918
tauri::Builder::default()

0 commit comments

Comments
 (0)