rustdesk/src/lang.rs

147 lines
3.4 KiB
Rust
Raw Normal View History

2021-12-25 16:45:22 +08:00
use std::ops::Deref;
2023-03-03 11:36:12 +08:00
mod ca;
2021-12-25 16:45:22 +08:00
mod cn;
mod cs;
mod da;
mod de;
2021-12-25 16:45:22 +08:00
mod en;
mod eo;
mod es;
2023-03-03 11:36:12 +08:00
mod fa;
2022-08-05 20:33:07 +08:00
mod fr;
mod el;
mod hu;
mod id;
2021-12-29 00:48:58 +08:00
mod it;
mod ja;
mod ko;
2023-03-03 11:36:12 +08:00
mod kz;
mod nl;
mod pl;
mod ptbr;
2023-01-24 23:59:31 +08:00
mod ro;
mod ru;
mod sk;
2023-03-03 11:36:12 +08:00
mod sl;
mod sq;
2022-12-15 20:16:20 +08:00
mod sr;
2023-03-03 11:36:12 +08:00
mod sv;
mod th;
2023-03-03 11:36:12 +08:00
mod tr;
mod tw;
mod ua;
mod vn;
2021-12-25 16:45:22 +08:00
2023-03-03 11:36:12 +08:00
pub const LANGS: &[(&str, &str)] = &[
("en", "English"),
("it", "Italiano"),
("fr", "Français"),
("de", "Deutsch"),
("nl", "Nederlands"),
2023-03-03 11:49:02 +08:00
("zh-cn", "简体中文"),
("zh-tw", "繁體中文"),
2023-03-03 11:36:12 +08:00
("pt", "Português"),
("es", "Español"),
("hu", "Magyar"),
("ru", "Русский"),
("sk", "Slovenčina"),
("id", "Indonesia"),
("cs", "Čeština"),
("da", "Dansk"),
("eo", "Esperanto"),
("tr", "Türkçe"),
("vn", "Tiếng Việt"),
("pl", "Polski"),
("ja", "日本語"),
("ko", "한국어"),
("kz", "Қазақ"),
("ua", "Українська"),
("fa", "فارسی"),
("ca", "Català"),
("el", "Ελληνικά"),
2023-03-03 11:36:12 +08:00
("sv", "Svenska"),
("sq", "Shqip"),
("sr", "Srpski"),
("th", "ภาษาไทย"),
("sl", "Slovenščina"),
("ro", "Română"),
];
2021-12-25 16:45:22 +08:00
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn translate(name: String) -> String {
let locale = sys_locale::get_locale().unwrap_or_default().to_lowercase();
translate_locale(name, &locale)
}
pub fn translate_locale(name: String, locale: &str) -> String {
2022-05-12 17:35:25 +08:00
let mut lang = hbb_common::config::LocalConfig::get_option("lang").to_lowercase();
if lang.is_empty() {
// zh_CN on Linux, zh-Hans-CN on mac, zh_CN_#Hans on Android
if locale.starts_with("zh") {
2023-03-03 11:49:02 +08:00
lang = (if locale.contains("tw") {
"zh-tw"
} else {
"zh-cn"
})
.to_owned();
2022-05-12 17:35:25 +08:00
}
}
2021-12-25 16:45:22 +08:00
if lang.is_empty() {
lang = locale
.split("-")
.next()
2022-06-10 18:43:53 +08:00
.map(|x| x.split("_").next().unwrap_or_default())
2021-12-25 16:45:22 +08:00
.unwrap_or_default()
.to_owned();
}
2022-01-17 12:05:06 +08:00
let lang = lang.to_lowercase();
let m = match lang.as_str() {
2021-12-25 16:45:22 +08:00
"fr" => fr::T.deref(),
2023-03-03 11:49:02 +08:00
"zh-cn" => cn::T.deref(),
2021-12-29 00:48:58 +08:00
"it" => it::T.deref(),
2023-03-03 11:49:02 +08:00
"zh-tw" => tw::T.deref(),
2022-02-17 07:08:18 +08:00
"de" => de::T.deref(),
"nl" => nl::T.deref(),
2022-06-23 07:26:03 +08:00
"es" => es::T.deref(),
2022-07-13 01:08:05 +08:00
"hu" => hu::T.deref(),
2022-02-17 07:05:24 +08:00
"ru" => ru::T.deref(),
2022-02-20 03:01:28 +08:00
"eo" => eo::T.deref(),
2022-05-12 17:35:25 +08:00
"id" => id::T.deref(),
2022-04-06 10:26:09 +08:00
"br" => ptbr::T.deref(),
"pt" => ptbr::T.deref(),
2022-05-13 21:38:49 +08:00
"tr" => tr::T.deref(),
2022-05-26 21:07:39 +08:00
"cs" => cs::T.deref(),
"da" => da::T.deref(),
2022-06-10 17:59:21 +08:00
"sk" => sk::T.deref(),
2022-07-28 16:54:17 +08:00
"vn" => vn::T.deref(),
2022-07-29 03:20:42 +08:00
"pl" => pl::T.deref(),
"ja" => ja::T.deref(),
"ko" => ko::T.deref(),
2022-09-13 17:00:59 +08:00
"kz" => kz::T.deref(),
2022-10-06 19:27:35 +08:00
"ua" => ua::T.deref(),
2022-11-08 15:52:41 +08:00
"fa" => fa::T.deref(),
"ca" => ca::T.deref(),
"el" => el::T.deref(),
"sv" => sv::T.deref(),
"sq" => sq::T.deref(),
2022-12-15 20:16:20 +08:00
"sr" => sr::T.deref(),
"th" => th::T.deref(),
"sl" => sl::T.deref(),
2023-01-24 23:59:31 +08:00
"ro" => ro::T.deref(),
2021-12-25 16:45:22 +08:00
_ => en::T.deref(),
};
if let Some(v) = m.get(&name as &str) {
if v.is_empty() {
if lang != "en" {
if let Some(v) = en::T.get(&name as &str) {
return v.to_string();
}
2022-01-17 12:05:06 +08:00
}
} else {
return v.to_string();
2022-01-17 12:05:06 +08:00
}
2021-12-25 16:45:22 +08:00
}
name
2021-12-25 16:45:22 +08:00
}