use crate::ui::i18n::lng_list::LngList;
pub fn detect_os_lang() -> LngList {
let raw = sys_locale::get_locale().unwrap_or_default();
let lc = raw.to_lowercase();
let mut it = lc.split(|c| c == '-' || c == '_');
let primary = it.next().unwrap_or("");
match primary {
"uk" => return LngList::Uk,
"ru" => return LngList::Ru,
"sc" => return LngList::Zh, "tc" => return LngList::Tc, "yue" => return LngList::Tc, _ => {}
}
if primary == "zh" {
let subtags: Vec<&str> = it.collect();
let is_traditional = lc.contains("hant")
|| subtags
.iter()
.any(|s| matches!(*s, "tw" | "hk" | "mo"))
|| lc.contains("cht")
|| lc.contains("yue");
if is_traditional {
return LngList::Tc;
}
let is_simplified = lc.contains("hans")
|| subtags
.iter()
.any(|s| matches!(*s, "cn" | "sg"))
|| lc.contains("chs");
if is_simplified {
return LngList::Zh;
}
return LngList::Zh;
}
LngList::En
}