mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 17:15:38 +08:00
perf(tray): improve menu handling localization support
refactor(tray): replace string literals with MenuIds for menu event handling
This commit is contained in:
@@ -34,6 +34,16 @@ pub fn get_supported_languages() -> Vec<String> {
|
||||
languages
|
||||
}
|
||||
|
||||
pub async fn current_language() -> String {
|
||||
Config::verge()
|
||||
.await
|
||||
.latest_ref()
|
||||
.language
|
||||
.as_deref()
|
||||
.map(String::from)
|
||||
.unwrap_or_else(get_system_language)
|
||||
}
|
||||
|
||||
static TRANSLATIONS: Lazy<RwLock<(String, Value)>> = Lazy::new(|| {
|
||||
let lang = get_system_language();
|
||||
let json = load_lang_file(&lang).unwrap_or_else(|| Value::Object(Default::default()));
|
||||
@@ -57,13 +67,7 @@ fn get_system_language() -> String {
|
||||
}
|
||||
|
||||
pub async fn t(key: &str) -> String {
|
||||
let current_lang = Config::verge()
|
||||
.await
|
||||
.latest_ref()
|
||||
.language
|
||||
.as_deref()
|
||||
.map(String::from)
|
||||
.unwrap_or_else(get_system_language);
|
||||
let current_lang = current_language().await;
|
||||
|
||||
{
|
||||
if let Ok(cache) = TRANSLATIONS.read()
|
||||
|
||||
Reference in New Issue
Block a user