diff --git a/qt/launcher-gui/src-tauri/src/lang.rs b/qt/launcher-gui/src-tauri/src/lang.rs index dc61b0817..bf8b5c94a 100644 --- a/qt/launcher-gui/src-tauri/src/lang.rs +++ b/qt/launcher-gui/src-tauri/src/lang.rs @@ -8,23 +8,29 @@ use anyhow::Result; use phf::phf_map; use phf::phf_ordered_map; use phf::phf_set; -use tauri::AppHandle; use tauri::Manager; use tauri::Runtime; pub type I18n = anki_i18n::I18n; pub type Tr = RwLock>; -pub fn setup_i18n(app: &AppHandle, locales: &[&str]) { - *app.state::().write().expect("tr lock was poisoned!") = Some(I18n::new(locales)); +pub trait I18nExt { + fn setup_tr(&self, locales: &[&str]); + fn tr(&self) -> Result; } -pub fn get_tr(app: &AppHandle) -> Result { - let tr_state = app.state::(); - let guard = tr_state.read().expect("tr lock was poisoned!"); - guard - .clone() - .ok_or_else(|| anyhow!("tr was not initialised!")) +impl> I18nExt for T { + fn setup_tr(&self, locales: &[&str]) { + *self.state::().write().expect("tr lock was poisoned!") = Some(I18n::new(locales)); + } + + fn tr(&self) -> Result { + let tr_state = self.state::(); + let guard = tr_state.read().expect("tr lock was poisoned!"); + guard + .clone() + .ok_or_else(|| anyhow!("tr was not initialised!")) + } } pub const LANGS: phf::OrderedMap<&'static str, &'static str> = phf_ordered_map! {