fix(lang): pick Traditional Chinese for Hong Kong and Macao system locales (#16671)

* fix(lang): pick Traditional Chinese for Hong Kong and Macao system locales

With no language chosen in Settings, resolve_lang picks zh-tw only when the system locale contains tw. Hong Kong and Macao locales (zh_HK, zh-Hant-HK, zh_HK_#Hant, zh_MO) and a bare zh-Hant got Simplified Chinese, although they write Traditional Chinese. Pick zh-tw for them too, unless the locale names the Hans script.

* test(lang): cover a bare zh-Hant locale
This commit is contained in:
Lukas authored and GitHub committed 2026-10-23 16:49:51 +08:00
1 parent 25d2742273
commit f7b0af78cb
1 file changed
+15
+15
View File
@@ -143,6 +143,10 @@ fn resolve_lang(saved_lang: &str, locale: &str, cjk_fallback: bool) -> String {
"zh-cn"
})
.to_owned();
// Hong Kong, Macao and the Hant script use Traditional Chinese.
if !locale.contains("hans") && ["hk", "mo", "hant"].iter().any(|x| locale.contains(x)) {
lang = "zh-tw".to_owned();
}
}
}
if lang.is_empty() {
@@ -381,4 +385,15 @@ mod test {
assert_eq!(f("", "ka_GE.UTF-8", false), "ge");
assert_eq!(f("", "ka-GE", false), "ge");
}
#[test]
fn test_resolve_lang_detects_traditional_chinese_for_hong_kong_and_macao() {
use super::resolve_lang as f;
assert_eq!(f("", "zh_HK.UTF-8", false), "zh-tw");
assert_eq!(f("", "zh-Hant-HK", false), "zh-tw");
assert_eq!(f("", "zh-Hant", false), "zh-tw");
assert_eq!(f("", "zh_MO", false), "zh-tw");
assert_eq!(f("", "zh-Hans-HK", false), "zh-cn");
}
}