From f7b0af78cbbfc90aa5403fbace93b4fa99c1abbb Mon Sep 17 00:00:00 2001 From: Lukas <103962359+L4XB@users.noreply.github.com> Date: Fri, 23 Oct 2026 10:49:51 +0200 Subject: [PATCH] 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 --- src/lang.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/lang.rs b/src/lang.rs index 5af8b7035..19209d005 100644 --- a/src/lang.rs +++ b/src/lang.rs @@ -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"); + } }