Multilingual support via Fluent + Frontend improvements + Rewrite of ArcReactor
This commit is contained in:
parent
adec595cfa
commit
412acb7e2d
41 changed files with 2436 additions and 723 deletions
|
|
@ -1,7 +1,7 @@
|
|||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
use jarvis_core::{config, db, APP_CONFIG_DIR, APP_LOG_DIR, DB};
|
||||
use jarvis_core::{config, db, i18n, APP_CONFIG_DIR, APP_LOG_DIR, DB};
|
||||
|
||||
use parking_lot::RwLock;
|
||||
use std::sync::Arc;
|
||||
|
|
@ -26,6 +26,11 @@ fn main() {
|
|||
|
||||
// init db
|
||||
let settings = db::init_settings();
|
||||
|
||||
// init i18n
|
||||
i18n::init(&settings.language);
|
||||
|
||||
// set db
|
||||
DB.set(Arc::new(RwLock::new(settings)))
|
||||
.expect("DB already initialized");
|
||||
let db_arc = DB.get().unwrap().clone();
|
||||
|
|
@ -67,6 +72,13 @@ fn main() {
|
|||
|
||||
// vosk
|
||||
tauri_commands::list_vosk_models,
|
||||
|
||||
// i18n
|
||||
tauri_commands::get_translations,
|
||||
tauri_commands::translate,
|
||||
tauri_commands::get_current_language,
|
||||
tauri_commands::set_language,
|
||||
tauri_commands::get_supported_languages,
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
|
|
|||
|
|
@ -25,4 +25,8 @@ pub use sys::*;
|
|||
|
||||
// import STT commands
|
||||
mod stt;
|
||||
pub use stt::*;
|
||||
pub use stt::*;
|
||||
|
||||
// import i18n commands
|
||||
mod i18n;
|
||||
pub use i18n::*;
|
||||
|
|
@ -15,6 +15,7 @@ pub fn db_read(state: tauri::State<'_, AppState>, key: &str) -> String {
|
|||
"noise_suppression" => format!("{:?}", settings.noise_suppression),
|
||||
"vad" => format!("{:?}", settings.vad),
|
||||
"gain_normalizer" => settings.gain_normalizer.to_string(),
|
||||
"language" => settings.language.to_string(),
|
||||
"api_key__picovoice" => settings.api_keys.picovoice.clone(),
|
||||
"api_key__openai" => settings.api_keys.openai.clone(),
|
||||
_ => String::new(),
|
||||
|
|
@ -78,6 +79,9 @@ pub fn db_write(state: tauri::State<'_, AppState>, key: &str, val: &str) -> bool
|
|||
_ => return false,
|
||||
}
|
||||
}
|
||||
"language" => {
|
||||
settings.language = val.to_string();
|
||||
}
|
||||
"api_key__picovoice" => {
|
||||
settings.api_keys.picovoice = val.to_string();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,24 @@ pub fn get_tg_official_link() -> String {
|
|||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn get_boosty_link() -> String {
|
||||
if let Some(ver) = config::SUPPORT_BOOSTY_LINK {
|
||||
ver.to_string()
|
||||
} else {
|
||||
String::from("error")
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn get_patreon_link() -> String {
|
||||
if let Some(ver) = config::SUPPORT_PATREON_LINK {
|
||||
ver.to_string()
|
||||
} else {
|
||||
String::from("error")
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn get_feedback_link() -> String {
|
||||
if let Some(res) = config::FEEDBACK_LINK {
|
||||
|
|
|
|||
49
crates/jarvis-gui/src/tauri_commands/i18n.rs
Normal file
49
crates/jarvis-gui/src/tauri_commands/i18n.rs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
use jarvis_core::i18n;
|
||||
use std::collections::HashMap;
|
||||
use crate::AppState;
|
||||
|
||||
// Get all translations for frontend
|
||||
#[tauri::command]
|
||||
pub fn get_translations() -> HashMap<String, String> {
|
||||
i18n::get_all_translations()
|
||||
}
|
||||
|
||||
// Get single translation
|
||||
#[tauri::command]
|
||||
pub fn translate(key: &str) -> String {
|
||||
i18n::t(key)
|
||||
}
|
||||
|
||||
// Get current language
|
||||
#[tauri::command]
|
||||
pub fn get_current_language() -> String {
|
||||
i18n::get_language()
|
||||
}
|
||||
|
||||
// Set language and get new translations
|
||||
#[tauri::command]
|
||||
pub fn set_language(state: tauri::State<'_, AppState>, lang: &str) -> HashMap<String, String> {
|
||||
// update i18n
|
||||
i18n::set_language(lang);
|
||||
|
||||
// also save to db
|
||||
{
|
||||
let mut settings = state.db.write();
|
||||
settings.language = lang.to_string();
|
||||
}
|
||||
|
||||
// save to disk
|
||||
let snapshot = state.db.read().clone();
|
||||
if let Err(e) = jarvis_core::db::save_settings(&snapshot) {
|
||||
log::error!("Failed to save settings: {}", e);
|
||||
}
|
||||
|
||||
// return new translations
|
||||
i18n::get_all_translations()
|
||||
}
|
||||
|
||||
// Get supported languages
|
||||
#[tauri::command]
|
||||
pub fn get_supported_languages() -> Vec<&'static str> {
|
||||
i18n::SUPPORTED_LANGUAGES.to_vec()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue