Using heartbeat api instead

This commit is contained in:
Marco De Araujo 2025-12-22 10:51:58 -04:00
parent 4cedb17b60
commit d024280878
10 changed files with 319 additions and 40 deletions

14
src/i18n/loader.rs Normal file
View file

@ -0,0 +1,14 @@
use anyhow::Ok;
use fluent_templates::static_loader;
static_loader! {
pub static LOCALES = {
locales: "./src/locales",
fallback_language: "pt-BR",
customise: |bundle| bundle.set_use_isolating(false),
};
}
pub fn init_locales() -> anyhow::Result<()> {
Ok(())
}

5
src/i18n/mod.rs Normal file
View file

@ -0,0 +1,5 @@
pub mod loader;
pub mod translate;
pub use loader::init_locales;
pub use translate::t;

13
src/i18n/translate.rs Normal file
View file

@ -0,0 +1,13 @@
use crate::i18n::loader::LOCALES;
use fluent_templates::Loader;
use std::str::FromStr;
use unic_langid::LanguageIdentifier;
fn get_sys_locale() -> LanguageIdentifier {
let sys_lang = sys_locale::get_locale().unwrap_or_else(|| String::from("pt-BR"));
LanguageIdentifier::from_str(&sys_lang).expect("Invalid language")
}
pub fn t(key: &str) -> String {
LOCALES.lookup(&get_sys_locale(), key)
}