mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 23:42:23 -04:00
wrap i18n struct in a shared mutex so we can start caching
This commit is contained in:
parent
f6a881f950
commit
8cd76bee92
1 changed files with 23 additions and 10 deletions
|
@ -25,6 +25,7 @@ macro_rules! tr_strs {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
pub use tr_strs;
|
pub use tr_strs;
|
||||||
|
|
||||||
/// All languages we (currently) support, excluding the fallback
|
/// All languages we (currently) support, excluding the fallback
|
||||||
|
@ -109,13 +110,9 @@ fn get_bundle(
|
||||||
Some(bundle)
|
Some(bundle)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct I18n {
|
pub struct I18n {
|
||||||
// language identifiers, used for date/time rendering
|
inner: Arc<Mutex<I18nInner>>,
|
||||||
langs: Vec<LanguageIdentifier>,
|
|
||||||
// languages supported by us
|
|
||||||
supported: Vec<LanguageDialect>,
|
|
||||||
|
|
||||||
locale_folder: PathBuf,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl I18n {
|
impl I18n {
|
||||||
|
@ -134,17 +131,33 @@ impl I18n {
|
||||||
langs.push("en_US".parse().unwrap());
|
langs.push("en_US".parse().unwrap());
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
langs,
|
inner: Arc::new(Mutex::new(I18nInner {
|
||||||
supported,
|
langs,
|
||||||
locale_folder: locale_folder.into(),
|
supported,
|
||||||
|
locale_folder: locale_folder.into(),
|
||||||
|
})),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&self, group: StringsGroup) -> I18nCategory {
|
pub fn get(&self, group: StringsGroup) -> I18nCategory {
|
||||||
I18nCategory::new(&*self.langs, &*self.supported, group, &self.locale_folder)
|
let inner = self.inner.lock().unwrap();
|
||||||
|
I18nCategory::new(
|
||||||
|
&*inner.langs,
|
||||||
|
&*inner.supported,
|
||||||
|
group,
|
||||||
|
&inner.locale_folder,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct I18nInner {
|
||||||
|
// language identifiers, used for date/time rendering
|
||||||
|
langs: Vec<LanguageIdentifier>,
|
||||||
|
// languages supported by us
|
||||||
|
supported: Vec<LanguageDialect>,
|
||||||
|
locale_folder: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct I18nCategory {
|
pub struct I18nCategory {
|
||||||
// bundles in preferred language order, with fallback English as the
|
// bundles in preferred language order, with fallback English as the
|
||||||
// last element
|
// last element
|
||||||
|
|
Loading…
Reference in a new issue