pub struct View { /* private fields */ }Expand description
A cheap view of an I18n: one page and/or another locale, with the same lookups.
Clone + Send + Sync + 'static; it reads the live catalog, so it sees later changes.
use i18n_next::I18n;
let i18n = I18n::builder()
.locale("en")
.messages("en", None, r#"{"title": "App", "ok": "OK"}"#)
.messages("en", Some("settings"), r#"{"title": "Settings"}"#)
.messages("de", Some("settings"), r#"{"title": "Einstellungen"}"#)
.build()?;
let settings = i18n.page("settings");
assert_eq!(settings.t("title"), "Settings");
assert_eq!(settings.t("ok"), "OK"); // page → root
assert_eq!(i18n.with_locale("de").page("settings").t("title"), "Einstellungen");Implementations§
Source§impl View
impl View
Sourcepub fn td_as(&self, t: impl Into<Timestamp>, name: &str) -> String
pub fn td_as(&self, t: impl Into<Timestamp>, name: &str) -> String
I18n::td_as in this view’s locale: the name is looked up by this locale’s code.
Sourcepub fn tdr_with(
&self,
t: impl Into<Timestamp>,
options: RelativeOptions,
) -> String
pub fn tdr_with( &self, t: impl Into<Timestamp>, options: RelativeOptions, ) -> String
I18n::tdr_with in this view’s locale.
Source§impl View
impl View
Sourcepub fn tc(&self, key: &str, count: impl Into<Count>) -> String
pub fn tc(&self, key: &str, count: impl Into<Count>) -> String
I18n::tc in this view: the plural rules of this view’s locale.
Sourcepub fn tc_with(
&self,
key: &str,
count: impl Into<Count>,
args: &Args<'_>,
) -> String
pub fn tc_with( &self, key: &str, count: impl Into<Count>, args: &Args<'_>, ) -> String
I18n::tc_with in this view.
Sourcepub fn has(&self, key: &str) -> bool
pub fn has(&self, key: &str) -> bool
I18n::has in this view: this view’s locale only, page then root.
Sourcepub fn with_locale(&self, code: &str) -> View
pub fn with_locale(&self, code: &str) -> View
The same view in another locale (see I18n::with_locale).
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for View
impl !UnwindSafe for View
impl Forget for View
impl Freeze for View
impl Move for View
impl Send for View
impl Sync for View
impl Unpin for View
impl UnsafeUnpin for View
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