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;
|
2022-06-05 18:02:54 +08:00
|
|
|
mod cs;
|
|
|
|
mod da;
|
|
|
|
mod de;
|
2023-03-31 14:18:55 +08:00
|
|
|
mod el;
|
2021-12-25 16:45:22 +08:00
|
|
|
mod en;
|
2022-06-05 18:02:54 +08:00
|
|
|
mod eo;
|
2022-06-30 01:19:38 +08:00
|
|
|
mod es;
|
2023-03-03 11:36:12 +08:00
|
|
|
mod fa;
|
2022-08-05 20:33:07 +08:00
|
|
|
mod fr;
|
2022-08-05 23:32:51 +08:00
|
|
|
mod hu;
|
2022-06-05 18:02:54 +08:00
|
|
|
mod id;
|
2021-12-29 00:48:58 +08:00
|
|
|
mod it;
|
2022-08-05 23:32:51 +08:00
|
|
|
mod ja;
|
2022-08-16 09:55:24 +08:00
|
|
|
mod ko;
|
2023-03-03 11:36:12 +08:00
|
|
|
mod kz;
|
2023-02-14 17:05:47 +08:00
|
|
|
mod nl;
|
2022-08-05 23:32:51 +08:00
|
|
|
mod pl;
|
2022-04-06 06:04:41 +08:00
|
|
|
mod ptbr;
|
2023-01-24 23:59:31 +08:00
|
|
|
mod ro;
|
2022-06-05 18:02:54 +08:00
|
|
|
mod ru;
|
2022-06-30 01:19:38 +08:00
|
|
|
mod sk;
|
2023-03-03 11:36:12 +08:00
|
|
|
mod sl;
|
2022-12-01 00:37:52 +08:00
|
|
|
mod sq;
|
2022-12-15 20:16:20 +08:00
|
|
|
mod sr;
|
2023-03-03 11:36:12 +08:00
|
|
|
mod sv;
|
2022-12-29 03:05:10 +08:00
|
|
|
mod th;
|
2023-03-03 11:36:12 +08:00
|
|
|
mod tr;
|
|
|
|
mod tw;
|
|
|
|
mod ua;
|
|
|
|
mod vn;
|
2023-04-04 01:21:50 +08:00
|
|
|
mod lt;
|
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à"),
|
2023-03-08 02:13:38 +08:00
|
|
|
("el", "Ελληνικά"),
|
2023-03-03 11:36:12 +08:00
|
|
|
("sv", "Svenska"),
|
|
|
|
("sq", "Shqip"),
|
|
|
|
("sr", "Srpski"),
|
|
|
|
("th", "ภาษาไทย"),
|
|
|
|
("sl", "Slovenščina"),
|
|
|
|
("ro", "Română"),
|
2023-04-04 01:21:50 +08:00
|
|
|
("lt", "Lietuvių"),
|
2023-03-03 11:36:12 +08:00
|
|
|
];
|
2022-06-30 01:19:38 +08:00
|
|
|
|
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
|
2022-06-05 18:02:54 +08:00
|
|
|
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("-")
|
2022-06-05 18:02:54 +08:00
|
|
|
.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(),
|
2023-02-14 17:05:47 +08:00
|
|
|
"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(),
|
2022-06-05 18:02:54 +08:00
|
|
|
"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(),
|
2022-08-05 23:32:51 +08:00
|
|
|
"ja" => ja::T.deref(),
|
2022-08-16 13:51:10 +08:00
|
|
|
"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(),
|
2022-11-16 18:28:37 +08:00
|
|
|
"ca" => ca::T.deref(),
|
2023-03-08 02:13:38 +08:00
|
|
|
"el" => el::T.deref(),
|
2022-11-29 22:00:27 +08:00
|
|
|
"sv" => sv::T.deref(),
|
2022-12-01 00:37:52 +08:00
|
|
|
"sq" => sq::T.deref(),
|
2022-12-15 20:16:20 +08:00
|
|
|
"sr" => sr::T.deref(),
|
2022-12-29 03:05:10 +08:00
|
|
|
"th" => th::T.deref(),
|
2023-01-05 20:01:11 +08:00
|
|
|
"sl" => sl::T.deref(),
|
2023-01-24 23:59:31 +08:00
|
|
|
"ro" => ro::T.deref(),
|
2023-04-04 01:21:50 +08:00
|
|
|
"lt" => lt::T.deref(),
|
2021-12-25 16:45:22 +08:00
|
|
|
_ => en::T.deref(),
|
|
|
|
};
|
|
|
|
if let Some(v) = m.get(&name as &str) {
|
2022-08-05 23:32:51 +08:00
|
|
|
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
|
|
|
}
|
2022-08-05 23:32:51 +08:00
|
|
|
} else {
|
|
|
|
return v.to_string();
|
2022-01-17 12:05:06 +08:00
|
|
|
}
|
2021-12-25 16:45:22 +08:00
|
|
|
}
|
2022-08-05 23:32:51 +08:00
|
|
|
name
|
2021-12-25 16:45:22 +08:00
|
|
|
}
|