Struct rust_i18n_support::SimpleBackend
source · pub struct SimpleBackend { /* private fields */ }Expand description
Simple KeyValue storage backend
Implementations§
source§impl SimpleBackend
impl SimpleBackend
sourcepub fn new(translations: HashMap<&str, &str>, locales: Vec<&str>) -> Self
pub fn new(translations: HashMap<&str, &str>, locales: Vec<&str>) -> Self
Create a new SimpleBackend.
In translations HashMap, the key is flatten key, like en.hello.world.
ⓘ
let trs = HashMap::<String, String>::new();
trs.insert("en.hello".into(), "Hello".into());
trs.insert("en.foo".into(), "Foo bar".into());
trs.insert("zh-CN.hello".into(), "你好".into());
trs.insert("zh-CN.foo".into(), "Foo 测试".into());
let locales = vec!["en", "zh-CN"];
let backend = SimpleBackend::new(trs, locales);sourcepub fn add_translations(&mut self, locale: &str, data: &HashMap<String, String>)
pub fn add_translations(&mut self, locale: &str, data: &HashMap<String, String>)
Add more translations for the given locale.
ⓘ
let trs = HashMap::<String, String>::new();
trs.insert("hello".into(), "Hello".into());
trs.insert("foo".into(), "Foo bar".into());
backend.add_translations("en", &data);Trait Implementations§
source§impl Backend for SimpleBackend
impl Backend for SimpleBackend
source§impl BackendExt for SimpleBackend
impl BackendExt for SimpleBackend
Auto Trait Implementations§
impl RefUnwindSafe for SimpleBackend
impl Send for SimpleBackend
impl Sync for SimpleBackend
impl Unpin for SimpleBackend
impl UnwindSafe for SimpleBackend
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more