mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-08 02:52:07 +08:00
crate(i18n): add clash-verge-i18n crate and integrate localization support (#5961)
* crate(i18n): add clash-verge-i18n crate and integrate localization support * refactor(service): remove redundant reinstall_service functions for Windows, Linux, and macOS * chore(i18n): align i18n key * feat(i18n): unify scan roots and add backend Rust/YAML support to cleanup script * chore(i18n): add scripts to package.json * fix(tray): initialize i18n locale before setup * refactor(i18n): move locale initialization into Config::init_config * fix(i18n): refresh systray tooltip on language change and correct docs reference * fix(tray): remove unnecessary locale synchronization to improve performance --------- Co-authored-by: Tunglies <77394545+Tunglies@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use crate::{core::handle, utils::i18n};
|
||||
use crate::core::handle;
|
||||
use clash_verge_i18n;
|
||||
use tauri_plugin_notification::NotificationExt as _;
|
||||
|
||||
pub enum NotificationEvent<'a> {
|
||||
@@ -21,48 +22,49 @@ fn notify(title: &str, body: &str) {
|
||||
}
|
||||
|
||||
pub async fn notify_event<'a>(event: NotificationEvent<'a>) {
|
||||
i18n::sync_locale().await;
|
||||
// It cause to sync set-local everytime notify, so move it outside
|
||||
// i18n::sync_locale().await;
|
||||
|
||||
match event {
|
||||
NotificationEvent::DashboardToggled => {
|
||||
let title = rust_i18n::t!("notifications.dashboardToggled.title").to_string();
|
||||
let body = rust_i18n::t!("notifications.dashboardToggled.body").to_string();
|
||||
let title = clash_verge_i18n::t!("notifications.dashboardToggled.title");
|
||||
let body = clash_verge_i18n::t!("notifications.dashboardToggled.body");
|
||||
notify(&title, &body);
|
||||
}
|
||||
NotificationEvent::ClashModeChanged { mode } => {
|
||||
let title = rust_i18n::t!("notifications.clashModeChanged.title").to_string();
|
||||
let body = rust_i18n::t!("notifications.clashModeChanged.body").replace("{mode}", mode);
|
||||
let title = clash_verge_i18n::t!("notifications.clashModeChanged.title");
|
||||
let body = clash_verge_i18n::t!("notifications.clashModeChanged.body").replace("{mode}", mode);
|
||||
notify(&title, &body);
|
||||
}
|
||||
NotificationEvent::SystemProxyToggled => {
|
||||
let title = rust_i18n::t!("notifications.systemProxyToggled.title").to_string();
|
||||
let body = rust_i18n::t!("notifications.systemProxyToggled.body").to_string();
|
||||
let title = clash_verge_i18n::t!("notifications.systemProxyToggled.title");
|
||||
let body = clash_verge_i18n::t!("notifications.systemProxyToggled.body");
|
||||
notify(&title, &body);
|
||||
}
|
||||
NotificationEvent::TunModeToggled => {
|
||||
let title = rust_i18n::t!("notifications.tunModeToggled.title").to_string();
|
||||
let body = rust_i18n::t!("notifications.tunModeToggled.body").to_string();
|
||||
let title = clash_verge_i18n::t!("notifications.tunModeToggled.title");
|
||||
let body = clash_verge_i18n::t!("notifications.tunModeToggled.body");
|
||||
notify(&title, &body);
|
||||
}
|
||||
NotificationEvent::LightweightModeEntered => {
|
||||
let title = rust_i18n::t!("notifications.lightweightModeEntered.title").to_string();
|
||||
let body = rust_i18n::t!("notifications.lightweightModeEntered.body").to_string();
|
||||
let title = clash_verge_i18n::t!("notifications.lightweightModeEntered.title");
|
||||
let body = clash_verge_i18n::t!("notifications.lightweightModeEntered.body");
|
||||
notify(&title, &body);
|
||||
}
|
||||
NotificationEvent::ProfilesReactivated => {
|
||||
let title = rust_i18n::t!("notifications.profilesReactivated.title").to_string();
|
||||
let body = rust_i18n::t!("notifications.profilesReactivated.body").to_string();
|
||||
let title = clash_verge_i18n::t!("notifications.profilesReactivated.title");
|
||||
let body = clash_verge_i18n::t!("notifications.profilesReactivated.body");
|
||||
notify(&title, &body);
|
||||
}
|
||||
NotificationEvent::AppQuit => {
|
||||
let title = rust_i18n::t!("notifications.appQuit.title").to_string();
|
||||
let body = rust_i18n::t!("notifications.appQuit.body").to_string();
|
||||
let title = clash_verge_i18n::t!("notifications.appQuit.title");
|
||||
let body = clash_verge_i18n::t!("notifications.appQuit.body");
|
||||
notify(&title, &body);
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
NotificationEvent::AppHidden => {
|
||||
let title = rust_i18n::t!("notifications.appHidden.title").to_string();
|
||||
let body = rust_i18n::t!("notifications.appHidden.body").to_string();
|
||||
let title = clash_verge_i18n::t!("notifications.appHidden.title");
|
||||
let body = clash_verge_i18n::t!("notifications.appHidden.body");
|
||||
notify(&title, &body);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user