feat: add support for multi languages (#79)
* update backup settings description * add rust-i18n * translate * . * update translations * fix * update translate * .
This commit is contained in:
8
crates/i18n/Cargo.toml
Normal file
8
crates/i18n/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "i18n"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
publish.workspace = true
|
||||
|
||||
[dependencies]
|
||||
rust-i18n.workspace = true
|
||||
30
crates/i18n/src/lib.rs
Normal file
30
crates/i18n/src/lib.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use rust_i18n::Backend;
|
||||
|
||||
rust_i18n::i18n!("../../locales");
|
||||
|
||||
pub struct I18nBackend;
|
||||
|
||||
impl Backend for I18nBackend {
|
||||
fn available_locales(&self) -> Vec<&str> {
|
||||
_RUST_I18N_BACKEND.available_locales()
|
||||
}
|
||||
|
||||
fn translate(&self, locale: &str, key: &str) -> Option<&str> {
|
||||
let val = _RUST_I18N_BACKEND.translate(locale, key);
|
||||
if val.is_none() {
|
||||
_RUST_I18N_BACKEND.translate("en", key)
|
||||
} else {
|
||||
val
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! init {
|
||||
() => {
|
||||
rust_i18n::i18n!(backend = i18n::I18nBackend);
|
||||
};
|
||||
}
|
||||
|
||||
pub use rust_i18n::set_locale;
|
||||
pub use rust_i18n::t;
|
||||
Reference in New Issue
Block a user