Skip to content

Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.

fix(tray): localize the tray menu and tooltip (#70)

xJaroslav691b376036d992
diff --git a/src-tauri/src/commands/mod.rs b/src-tauri/src/commands/mod.rs
index 11931f94..7304e462 100644
--- a/src-tauri/src/commands/mod.rs
+++ b/src-tauri/src/commands/mod.rs
@@ -24,6 +24,7 @@ pub mod settings;
pub mod smart_speed;
pub mod subtitle_ws;
pub mod torrent_playback;
+pub mod tray;
pub mod video_ops;
pub mod yt_templates;
diff --git a/src-tauri/src/commands/tray.rs b/src-tauri/src/commands/tray.rs
new file mode 100644
index 00000000..74d69a21
--- /dev/null
+++ b/src-tauri/src/commands/tray.rs
@@ -0,0 +1,14 @@
+//! Localization bridge for the native tray menu.
+//!
+//! The tray is built in Rust (`crate::tray`), where the Svelte `$t` helper is
+//! not reachable, so its labels used to be hardcoded in English. The webview
+//! now resolves the strings for the active locale and pushes them here on boot
+//! and whenever the user switches language.
+
+use crate::tray::{self, TrayLabels};
+
+#[tauri::command]
+pub fn sync_tray_labels(app: tauri::AppHandle, labels: TrayLabels) -> Result<(), String> {
+ tray::apply_labels(&app, labels);
+ Ok(())
+}
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index a67eab31..f75502fd 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -1102,6 +1102,7 @@ pub fn run() {
commands::channels::channel_update,
commands::channels::channel_check_now,
commands::channels::sync_channels_tray,
+ commands::tray::sync_tray_labels,
commands::ai::ai_get_config,
commands::ai::ai_set_config,
commands::ai::ai_test,
diff --git a/src-tauri/src/tray.rs b/src-tauri/src/tray.rs
index 5c532346..04c53e42 100644
--- a/src-tauri/src/tray.rs
+++ b/src-tauri/src/tray.rs
@@ -15,6 +15,8 @@ use tauri::{
static DOWNLOADS_ITEM: OnceLock<MenuItem<Wry>> = OnceLock::new();
static CHANNELS_SUBMENU: OnceLock<Submenu<Wry>> = OnceLock::new();
+static QUIT_ITEM: OnceLock<MenuItem<Wry>> = OnceLock::new();
+static TRAY_LABELS: OnceLock<Mutex<TrayLabels>> = OnceLock::new();
static BASE_ICON: OnceLock<(Vec<u8>, u32, u32)> = OnceLock::new();
static LAST_ACTIVE: AtomicU32 = AtomicU32::new(0);
static ICON_COUNT: AtomicU32 = AtomicU32::new(0);
@@ -24,6 +26,108 @@ static LAST_SPEED_BUCKET: AtomicU64 = AtomicU64::new(u64::MAX);
const SPEED_TOOLTIP_MIN_INTERVAL_MS: u64 = 2000;
static BADGE_CACHE: OnceLock<Mutex<BadgeCache>> = OnceLock::new();
+/// Labels for the native tray menu and its tooltip.
+///
+/// The tray is built in Rust, where the Svelte `$t` helper is not reachable,
+/// so the webview resolves the strings for the active locale and pushes them
+/// here on boot and on every language switch (`sync_tray_labels`). Defaults
+/// are English so the tray still renders if the webview never reports in.
+#[derive(Clone, Debug, serde::Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct TrayLabels {
+ pub quit: String,
+ pub channels: String,
+ pub no_active_downloads: String,
+ pub downloads_label: String,
+ /// Rendered right after the count: `Downloads: 3 active` / `Загрузки: 3 в работе`.
+ pub active_suffix: String,
+ pub speed_unit_kb: String,
+ pub speed_unit_mb: String,
+ pub decimal_separator: String,
+}
+
+impl Default for TrayLabels {
+ fn default() -> Self {
+ Self {
+ quit: "Quit".into(),
+ channels: "Channels".into(),
+ no_active_downloads: "No active downloads".into(),
+ downloads_label: "Downloads".into(),
+ active_suffix: " active".into(),
+ speed_unit_kb: "KB/s".into(),
+ speed_unit_mb: "MB/s".into(),
+ decimal_separator: ".".into(),
+ }
+ }
+}
+
+fn labels() -> TrayLabels {
+ TRAY_LABELS
+ .get_or_init(|| Mutex::new(TrayLabels::default()))
+ .lock()
+ .unwrap_or_else(|poisoned| poisoned.into_inner())
+ .clone()
+}
+
+fn active_label_for(labels: &TrayLabels, count: u32) -> String {
+ if count == 0 {
+ labels.no_active_downloads.clone()
+ } else {
+ format!(
+ "{}: {}{}",
+ labels.downloads_label, count, labels.active_suffix
+ )
+ }
+}
+
+fn format_speed(bps: f64, labels: &TrayLabels) -> String {
+ if bps < 1024.0 * 1024.0 {
+ format!("{:.0} {}", bps / 1024.0, labels.speed_unit_kb)
+ } else {
+ let value =
+ format!("{:.1}", bps / (1024.0 * 1024.0)).replace('.', &labels.decimal_separator);
+ format!("{} {}", value, labels.speed_unit_mb)
+ }
+}
+
+fn tooltip_for(labels: &TrayLabels, count: u32, speed_bps: Option<f64>) -> String {
+ if count == 0 {
+ return "OmniGet".into();
+ }
+ let mut tooltip = format!("OmniGet — {}{}", count, labels.active_suffix);
+ if let Some(bps) = speed_bps.filter(|bps| *bps > 0.0) {
+ tooltip.push_str(" · ");
+ tooltip.push_str(&format_speed(bps, labels));
+ }
+ tooltip
+}
+
+/// Applies labels resolved by the frontend and refreshes every native string
+/// that is already on screen, so switching language updates the tray without
+/// a restart.
+pub fn apply_labels(app: &AppHandle, new_labels: TrayLabels) {
+ let count = LAST_ACTIVE.load(Ordering::Relaxed);
+
+ if let Some(item) = QUIT_ITEM.get() {
+ let _ = item.set_text(new_labels.quit.as_str());
+ }
+ if let Some(item) = DOWNLOADS_ITEM.get() {
+ let _ = item.set_text(active_label_for(&new_labels, count));
+ }
+ if let Some(submenu) = CHANNELS_SUBMENU.get() {
+ let _ = submenu.set_text(new_labels.channels.as_str());
+ }
+ if let Some(tray) = app.tray_by_id("main-tray") {
+ let _ = tray.set_tooltip(Some(&tooltip_for(&new_labels, count, None)));
+ }
+
+ let mut current = TRAY_LABELS
+ .get_or_init(|| Mutex::new(TrayLabels::default()))
+ .lock()
+ .unwrap_or_else(|poisoned| poisoned.into_inner());
+ *current = new_labels;
+}
+
struct BadgeCache {
cache: HashMap<(u32, u32, u32), Vec<u8>>,
icon_base_hash: u64,
@@ -59,16 +163,18 @@ impl BadgeCache {
}
pub fn setup(app: &AppHandle) -> tauri::Result<()> {
+ let labels = labels();
let open_item = MenuItemBuilder::with_id("open", "OmniGet").build(app)?;
- let downloads_item = MenuItemBuilder::with_id("downloads", active_label(0))
+ let downloads_item = MenuItemBuilder::with_id("downloads", active_label_for(&labels, 0))
.enabled(false)
.build(app)?;
DOWNLOADS_ITEM.set(downloads_item.clone()).ok();
- let quit_item = MenuItemBuilder::with_id("quit", "Quit").build(app)?;
+ let quit_item = MenuItemBuilder::with_id("quit", labels.quit.as_str()).build(app)?;
+ QUIT_ITEM.set(quit_item.clone()).ok();
// Empty, hidden until the frontend pushes localized channel labels via
// sync_channels_tray (the tray menu is native — $t is not reachable here).
- let channels_submenu = SubmenuBuilder::new(app, "Channels").build()?;
+ let channels_submenu = SubmenuBuilder::new(app, labels.channels.as_str()).build()?;
channels_submenu.set_enabled(false).ok();
CHANNELS_SUBMENU.set(channels_submenu.clone()).ok();
@@ -149,8 +255,9 @@ pub fn rebuild_menu(
}
pub fn update_active_count(app: &AppHandle, count: u32) {
+ let labels = labels();
if let Some(item) = DOWNLOADS_ITEM.get() {
- let _ = item.set_text(active_label(count));
+ let _ = item.set_text(active_label_for(&labels, count));
}
let prev = ICON_COUNT.swap(count, Ordering::Relaxed);
@@ -162,11 +269,7 @@ pub fn update_active_count(app: &AppHandle, count: u32) {
}
if let Some(tray) = app.tray_by_id("main-tray") {
- let tooltip = if count > 0 {
- format!("OmniGet — {} active", count)
- } else {
- "OmniGet".into()
- };
+ let tooltip = tooltip_for(&labels, count, None);
let _ = tray.set_tooltip(Some(&tooltip));
if let Some((base, w, h)) = BASE_ICON.get() {
@@ -192,14 +295,6 @@ fn now_ms() -> u64 {
.unwrap_or(0)
}
-fn format_speed(bps: f64) -> String {
- if bps < 1024.0 * 1024.0 {
- format!("{:.0} KB/s", bps / 1024.0)
- } else {
- format!("{:.1} MB/s", bps / (1024.0 * 1024.0))
- }
-}
-
// Speed lives only in the tooltip (the discreet channel) — the icon stays
// count-gated because icon re-render is expensive. Writes are hard-throttled
// and deduped so frequent progress ticks can't flood the system tray.
@@ -223,15 +318,7 @@ pub fn update_speed_tooltip(app: &AppHandle, count: u32, total_speed_bps: f64) {
LAST_TOOLTIP_MS.store(now, Ordering::Relaxed);
if let Some(tray) = app.tray_by_id("main-tray") {
- let tooltip = if total_speed_bps > 0.0 {
- format!(
- "OmniGet — {} active · {}",
- count,
- format_speed(total_speed_bps)
- )
- } else {
- format!("OmniGet — {} active", count)
- };
+ let tooltip = tooltip_for(&labels(), count, Some(total_speed_bps));
let _ = tray.set_tooltip(Some(&tooltip));
}
}
@@ -257,14 +344,6 @@ pub fn compute_total_active(app: &AppHandle) -> u32 {
total
}
-fn active_label(count: u32) -> String {
- if count == 0 {
- "No active downloads".into()
- } else {
- format!("Downloads: {} active", count)
- }
-}
-
pub fn show_window(app: &AppHandle) {
if let Some(window) = app.get_webview_window("main") {
let _ = window.show();
@@ -590,3 +669,55 @@ pub fn update_taskbar_badge(app: &AppHandle, active_count: u32, _avg_percent: f6
}
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::{active_label_for, format_speed, tooltip_for, TrayLabels};
+
+ fn russian() -> TrayLabels {
+ TrayLabels {
+ quit: "Выход".into(),
+ channels: "Каналы".into(),
+ no_active_downloads: "Нет активных загрузок".into(),
+ downloads_label: "Загрузки".into(),
+ active_suffix: " в работе".into(),
+ speed_unit_kb: "КБ/с".into(),
+ speed_unit_mb: "МБ/с".into(),
+ decimal_separator: ",".into(),
+ }
+ }
+
+ #[test]
+ fn active_label_is_localized() {
+ let labels = russian();
+ assert_eq!(active_label_for(&labels, 0), "Нет активных загрузок");
+ assert_eq!(active_label_for(&labels, 3), "Загрузки: 3 в работе");
+ }
+
+ #[test]
+ fn speed_uses_the_locale_units_and_decimal_separator() {
+ let labels = russian();
+ assert_eq!(format_speed(512.0 * 1024.0, &labels), "512 КБ/с");
+ assert_eq!(format_speed(3.5 * 1024.0 * 1024.0, &labels), "3,5 МБ/с");
+ }
+
+ #[test]
+ fn tooltip_switches_between_count_and_speed() {
+ let labels = TrayLabels::default();
+ assert_eq!(tooltip_for(&labels, 0, Some(1024.0)), "OmniGet");
+ assert_eq!(tooltip_for(&labels, 2, None), "OmniGet — 2 active");
+ assert_eq!(
+ tooltip_for(&labels, 1, Some(2.0 * 1024.0 * 1024.0)),
+ "OmniGet — 1 active · 2.0 MB/s"
+ );
+ }
+
+ #[test]
+ fn labels_deserialize_from_the_frontend_payload() {
+ let labels: TrayLabels = serde_json::from_str(
+ r#"{"quit":"Quit","channels":"Channels","noActiveDownloads":"No active downloads","downloadsLabel":"Downloads","activeSuffix":" active","speedUnitKb":"KB/s","speedUnitMb":"MB/s","decimalSeparator":"."}"#,
+ )
+ .expect("tray labels payload must deserialize");
+ assert_eq!(active_label_for(&labels, 1), "Downloads: 1 active");
+ }
+}
diff --git a/src/components/onboarding/OnboardingWizard.svelte b/src/components/onboarding/OnboardingWizard.svelte
index a2215c33..a62d4c93 100644
--- a/src/components/onboarding/OnboardingWizard.svelte
+++ b/src/components/onboarding/OnboardingWizard.svelte
@@ -2,6 +2,7 @@
import { invoke } from "@tauri-apps/api/core";
import { open } from "@tauri-apps/plugin-dialog";
import { t, locale, loadTranslations } from "$lib/i18n";
+ import { syncTrayLabels } from "$lib/tray-labels";
import { getSettings, updateSettings } from "$lib/stores/settings-store.svelte";
import { completeOnboarding } from "$lib/stores/onboarding-store.svelte";
import { refreshYtdlpStatus } from "$lib/stores/dependency-store.svelte";
@@ -84,6 +85,7 @@
await updateSettings({ appearance: { language: value } });
await loadTranslations(value, "/");
locale.set(value);
+ await syncTrayLabels();
}
async function chooseFolder() {
diff --git a/src/components/settings/settings-helpers.ts b/src/components/settings/settings-helpers.ts
index 62cbfef5..fb44c008 100644
--- a/src/components/settings/settings-helpers.ts
+++ b/src/components/settings/settings-helpers.ts
@@ -2,6 +2,7 @@ import { invoke } from "@tauri-apps/api/core";
import { open } from "@tauri-apps/plugin-dialog";
import { updateSettings, getSettings } from "$lib/stores/settings-store.svelte";
import { loadTranslations, locale, t } from "$lib/i18n";
+import { syncTrayLabels } from "$lib/tray-labels";
import { showToast } from "$lib/stores/toast-store.svelte";
import { get } from "svelte/store";
@@ -36,6 +37,7 @@ export async function changeLanguage(e: Event) {
await updateSettings({ appearance: { language: value } });
await loadTranslations(value, "/settings");
locale.set(value);
+ await syncTrayLabels();
}
export async function toggleBool(section: string, key: string, current: boolean) {
diff --git a/src/lib/i18n/el.json b/src/lib/i18n/el.json
index c4032f4a..39ded688 100644
--- a/src/lib/i18n/el.json
+++ b/src/lib/i18n/el.json
@@ -8375,5 +8375,13 @@
"tracking_title": "Parcel tracking",
"tracking_desc": "Follow packages from 8 Brazilian carriers in one place, refreshed automatically."
}
+ },
+ "tray": {
+ "quit": "Quit",
+ "no_active_downloads": "No active downloads",
+ "active_suffix": " active",
+ "speed_unit_kb": "KB/s",
+ "speed_unit_mb": "MB/s",
+ "decimal_separator": "."
}
}
diff --git a/src/lib/i18n/en.json b/src/lib/i18n/en.json
index 1ff117ce..22c11465 100644
--- a/src/lib/i18n/en.json
+++ b/src/lib/i18n/en.json
@@ -8375,5 +8375,13 @@
"tracking_title": "Parcel tracking",
"tracking_desc": "Follow packages from 8 Brazilian carriers in one place, refreshed automatically."
}
+ },
+ "tray": {
+ "quit": "Quit",
+ "no_active_downloads": "No active downloads",
+ "active_suffix": " active",
+ "speed_unit_kb": "KB/s",
+ "speed_unit_mb": "MB/s",
+ "decimal_separator": "."
}
}
diff --git a/src/lib/i18n/es.json b/src/lib/i18n/es.json
index 30540c0a..8b2ba216 100644
--- a/src/lib/i18n/es.json
+++ b/src/lib/i18n/es.json
@@ -8375,5 +8375,13 @@
"tracking_title": "Parcel tracking",
"tracking_desc": "Follow packages from 8 Brazilian carriers in one place, refreshed automatically."
}
+ },
+ "tray": {
+ "quit": "Quit",
+ "no_active_downloads": "No active downloads",
+ "active_suffix": " active",
+ "speed_unit_kb": "KB/s",
+ "speed_unit_mb": "MB/s",
+ "decimal_separator": "."
}
}
diff --git a/src/lib/i18n/fa.json b/src/lib/i18n/fa.json
index 1bfbc077..a3b33ba8 100644
--- a/src/lib/i18n/fa.json
+++ b/src/lib/i18n/fa.json
@@ -8375,5 +8375,13 @@
"tracking_title": "Parcel tracking",
"tracking_desc": "Follow packages from 8 Brazilian carriers in one place, refreshed automatically."
}
+ },
+ "tray": {
+ "quit": "Quit",
+ "no_active_downloads": "No active downloads",
+ "active_suffix": " active",
+ "speed_unit_kb": "KB/s",
+ "speed_unit_mb": "MB/s",
+ "decimal_separator": "."
}
}
diff --git a/src/lib/i18n/fr.json b/src/lib/i18n/fr.json
index d2d44945..d96d0c33 100644
--- a/src/lib/i18n/fr.json
+++ b/src/lib/i18n/fr.json
@@ -8375,5 +8375,13 @@
"tracking_title": "Parcel tracking",
"tracking_desc": "Follow packages from 8 Brazilian carriers in one place, refreshed automatically."
}
+ },
+ "tray": {
+ "quit": "Quit",
+ "no_active_downloads": "No active downloads",
+ "active_suffix": " active",
+ "speed_unit_kb": "KB/s",
+ "speed_unit_mb": "MB/s",
+ "decimal_separator": "."
}
}
diff --git a/src/lib/i18n/it.json b/src/lib/i18n/it.json
index c4e6a4bb..1dbfb9fe 100644
--- a/src/lib/i18n/it.json
+++ b/src/lib/i18n/it.json
@@ -8375,5 +8375,13 @@
"tracking_title": "Parcel tracking",
"tracking_desc": "Follow packages from 8 Brazilian carriers in one place, refreshed automatically."
}
+ },
+ "tray": {
+ "quit": "Quit",
+ "no_active_downloads": "No active downloads",
+ "active_suffix": " active",
+ "speed_unit_kb": "KB/s",
+ "speed_unit_mb": "MB/s",
+ "decimal_separator": "."
}
}
diff --git a/src/lib/i18n/ja.json b/src/lib/i18n/ja.json
index 49b69198..bfafb5cd 100644
--- a/src/lib/i18n/ja.json
+++ b/src/lib/i18n/ja.json
@@ -8375,5 +8375,13 @@
"tracking_title": "Parcel tracking",
"tracking_desc": "Follow packages from 8 Brazilian carriers in one place, refreshed automatically."
}
+ },
+ "tray": {
+ "quit": "Quit",
+ "no_active_downloads": "No active downloads",
+ "active_suffix": " active",
+ "speed_unit_kb": "KB/s",
+ "speed_unit_mb": "MB/s",
+ "decimal_separator": "."
}
}
diff --git a/src/lib/i18n/keys.ts b/src/lib/i18n/keys.ts
index 28524429..4adb7b3c 100644
--- a/src/lib/i18n/keys.ts
+++ b/src/lib/i18n/keys.ts
@@ -7476,6 +7476,13 @@ export type TranslationKeys =
| 'tracking.toast.status_changed'
| 'tracking.toast.unarchived'
+ | 'tray.active_suffix'
+ | 'tray.decimal_separator'
+ | 'tray.no_active_downloads'
+ | 'tray.quit'
+ | 'tray.speed_unit_kb'
+ | 'tray.speed_unit_mb'
+
| 'udemy.authenticating'
| 'udemy.checking_session'
| 'udemy.choose_folder'
diff --git a/src/lib/i18n/lo.json b/src/lib/i18n/lo.json
index eaef3125..a56a38b5 100644
--- a/src/lib/i18n/lo.json
+++ b/src/lib/i18n/lo.json
@@ -8375,5 +8375,13 @@
"tracking_title": "ຕິດຕາມພັດສະດຸ",
"tracking_desc": "ຕິດຕາມພັດສະດຸຈາກ 8 ບໍລິສັດຂົນສົ່ງຂອງບຣາຊິວໃນບ່ອນດຽວ, ອັບເດດອັດຕະໂນມັດ."
}
+ },
+ "tray": {
+ "quit": "Quit",
+ "no_active_downloads": "No active downloads",
+ "active_suffix": " active",
+ "speed_unit_kb": "KB/s",
+ "speed_unit_mb": "MB/s",
+ "decimal_separator": "."
}
}
diff --git a/src/lib/i18n/pt.json b/src/lib/i18n/pt.json
index af01059d..43a34e99 100644
--- a/src/lib/i18n/pt.json
+++ b/src/lib/i18n/pt.json
@@ -8375,5 +8375,13 @@
"tracking_title": "Parcel tracking",
"tracking_desc": "Follow packages from 8 Brazilian carriers in one place, refreshed automatically."
}
+ },
+ "tray": {
+ "quit": "Quit",
+ "no_active_downloads": "No active downloads",
+ "active_suffix": " active",
+ "speed_unit_kb": "KB/s",
+ "speed_unit_mb": "MB/s",
+ "decimal_separator": "."
}
}
diff --git a/src/lib/i18n/ru.json b/src/lib/i18n/ru.json
index febb0f95..8ace7636 100644
--- a/src/lib/i18n/ru.json
+++ b/src/lib/i18n/ru.json
@@ -8375,5 +8375,13 @@
"tracking_title": "Отслеживание посылок",
"tracking_desc": "Следите за посылками 8 бразильских перевозчиков в одном месте — обновления автоматические."
}
+ },
+ "tray": {
+ "quit": "Выход",
+ "no_active_downloads": "Нет активных загрузок",
+ "active_suffix": " в работе",
+ "speed_unit_kb": "КБ/с",
+ "speed_unit_mb": "МБ/с",
+ "decimal_separator": ","
}
}
diff --git a/src/lib/i18n/zh-TW.json b/src/lib/i18n/zh-TW.json
index 31f3ccde..45dc84bb 100644
--- a/src/lib/i18n/zh-TW.json
+++ b/src/lib/i18n/zh-TW.json
@@ -8375,5 +8375,13 @@
"tracking_title": "Parcel tracking",
"tracking_desc": "Follow packages from 8 Brazilian carriers in one place, refreshed automatically."
}
+ },
+ "tray": {
+ "quit": "Quit",
+ "no_active_downloads": "No active downloads",
+ "active_suffix": " active",
+ "speed_unit_kb": "KB/s",
+ "speed_unit_mb": "MB/s",
+ "decimal_separator": "."
}
}
diff --git a/src/lib/i18n/zh.json b/src/lib/i18n/zh.json
index 99582494..7d67f4e2 100644
--- a/src/lib/i18n/zh.json
+++ b/src/lib/i18n/zh.json
@@ -8375,5 +8375,13 @@
"tracking_title": "Parcel tracking",
"tracking_desc": "Follow packages from 8 Brazilian carriers in one place, refreshed automatically."
}
+ },
+ "tray": {
+ "quit": "Quit",
+ "no_active_downloads": "No active downloads",
+ "active_suffix": " active",
+ "speed_unit_kb": "KB/s",
+ "speed_unit_mb": "MB/s",
+ "decimal_separator": "."
}
}
diff --git a/src/lib/tray-labels.ts b/src/lib/tray-labels.ts
new file mode 100644
index 00000000..2a5fef6e
--- /dev/null
+++ b/src/lib/tray-labels.ts
@@ -0,0 +1,54 @@
+import { get } from "svelte/store";
+import { invoke } from "@tauri-apps/api/core";
+import { t, locale } from "$lib/i18n";
+
+type Translate = (key: string, values?: Record<string, unknown>) => string;
+
+export type TrayLabels = {
+ quit: string;
+ channels: string;
+ noActiveDownloads: string;
+ downloadsLabel: string;
+ activeSuffix: string;
+ speedUnitKb: string;
+ speedUnitMb: string;
+ decimalSeparator: string;
+};
+
+/**
+ * The tray menu is built in the Rust process, where the Svelte `$t` helper is
+ * not reachable — that is why its labels used to stay English no matter which
+ * language the rest of the app used. This resolves the strings for the active
+ * locale and pushes them to the backend, which re-renders the native menu in
+ * place (no restart needed).
+ */
+export function currentTrayLabels(): TrayLabels {
+ const tr = get(t) as Translate;
+ return {
+ quit: tr("tray.quit"),
+ channels: tr("settings.channels.tray_header"),
+ noActiveDownloads: tr("tray.no_active_downloads"),
+ downloadsLabel: tr("nav.downloads"),
+ activeSuffix: tr("tray.active_suffix"),
+ speedUnitKb: tr("tray.speed_unit_kb"),
+ speedUnitMb: tr("tray.speed_unit_mb"),
+ decimalSeparator: tr("tray.decimal_separator"),
+ };
+}
+
+let syncedLocale: string | null = null;
+
+/** Pushes the labels for the active locale to the native tray. */
+export async function syncTrayLabels(force = false): Promise<void> {
+ const active = get(locale);
+ if (!force && active === syncedLocale) {
+ return;
+ }
+ syncedLocale = active;
+ try {
+ await invoke("sync_tray_labels", { labels: currentTrayLabels() });
+ } catch (e) {
+ // The tray is a desktop-only nicety: never let it break the UI.
+ console.warn("[tray] could not sync labels:", e);
+ }
+}
diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts
index 0ff3e9c0..33a58176 100644
--- a/src/routes/+layout.ts
+++ b/src/routes/+layout.ts
@@ -1,4 +1,5 @@
import { loadTranslations, defaultLocale } from "$lib/i18n";
+import { syncTrayLabels } from "$lib/tray-labels";
import { loadSettings } from "$lib/stores/settings-store.svelte";
export const ssr = false;
@@ -17,5 +18,7 @@ export const load = async ({ url }) => {
// O inglês estático em `$lib/i18n` segura a UI; só registra o motivo.
console.warn(`[i18n] could not load "${lang}":`, e);
}
+ // The native tray has its own strings; push the ones for the active locale.
+ await syncTrayLabels();
return {};
};
diff --git a/src/routes/settings/+page.svelte b/src/routes/settings/+page.svelte
index 05002d7e..a19d71eb 100644
--- a/src/routes/settings/+page.svelte
+++ b/src/routes/settings/+page.svelte
@@ -3,6 +3,7 @@
import { invoke } from "@tauri-apps/api/core";
import { open } from "@tauri-apps/plugin-dialog";
import { t, locale, loadTranslations } from "$lib/i18n";
+ import { syncTrayLabels } from "$lib/tray-labels";
import { getSettings, updateSettings, resetSettings } from "$lib/stores/settings-store.svelte";
import { getUpdateInfo, getIsUpdating, performUpdate } from "$lib/stores/update-store.svelte";
import { showToast } from "$lib/stores/toast-store.svelte";
@@ -119,6 +120,7 @@
await updateSettings({ appearance: { language: value } });
await loadTranslations(value, "/settings");
locale.set(value);
+ await syncTrayLabels();
}
async function chooseFolder() {