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.

feat: add get_plugin_i18n command for retrieving plugin localization files

Tonho307b150c63f1
diff --git a/src-tauri/src/commands/plugins.rs b/src-tauri/src/commands/plugins.rs
index a5862ab8..b3ed7d89 100644
--- a/src-tauri/src/commands/plugins.rs
+++ b/src-tauri/src/commands/plugins.rs
@@ -124,6 +124,27 @@ pub fn get_loaded_plugin_manifests(
Ok(manager.loaded_manifests().into_iter().cloned().collect())
}
+#[tauri::command]
+pub fn get_plugin_i18n(
+ state: tauri::State<'_, Arc<tokio::sync::Mutex<PluginManager>>>,
+ plugin_id: String,
+ locale: String,
+) -> Result<serde_json::Value, String> {
+ let manager = state.blocking_lock();
+ let i18n_dir = manager.plugins_dir().join(&plugin_id).join("i18n");
+ let locale_file = i18n_dir.join(format!("{}.json", locale));
+ if !locale_file.exists() {
+ let fallback = i18n_dir.join("en.json");
+ if !fallback.exists() {
+ return Ok(serde_json::json!({}));
+ }
+ let content = std::fs::read_to_string(&fallback).map_err(|e| e.to_string())?;
+ return serde_json::from_str(&content).map_err(|e| e.to_string());
+ }
+ let content = std::fs::read_to_string(&locale_file).map_err(|e| e.to_string())?;
+ serde_json::from_str(&content).map_err(|e| e.to_string())
+}
+
#[tauri::command]
pub async fn plugin_command(
state: tauri::State<'_, Arc<tokio::sync::Mutex<PluginManager>>>,