pub struct Catalog { /* private fields */ }Expand description
An app-populated translation table: key → (language code → string), with a default language used
as a fallback. Build it once from string literals (e.g. behind a OnceLock) and read it in view.
Lookups fall back in two steps — the requested language, then the default language, then the key itself — so a missing translation degrades to something readable rather than blank.
Implementations§
Source§impl Catalog
impl Catalog
Sourcepub fn new(default_lang: &str) -> Self
pub fn new(default_lang: &str) -> Self
A new, empty catalog whose default_lang is the fallback when a requested language is missing.
Sourcepub fn with(
self,
key: &'static str,
langs: &[(&'static str, &'static str)],
) -> Self
pub fn with( self, key: &'static str, langs: &[(&'static str, &'static str)], ) -> Self
Add (or extend) the translations for key. Chainable, for building the catalog inline.
use mobiler_core::i18n::Catalog;
let c = Catalog::new("en")
.with("hello", &[("en", "Hello"), ("uk", "Привіт")])
.with("bye", &[("en", "Bye"), ("uk", "Бувай")]);
assert_eq!(c.tr("hello", "uk"), "Привіт");Trait Implementations§
Auto Trait Implementations§
impl Freeze for Catalog
impl RefUnwindSafe for Catalog
impl Send for Catalog
impl Sync for Catalog
impl Unpin for Catalog
impl UnsafeUnpin for Catalog
impl UnwindSafe for Catalog
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