Skip to main content

View

Struct View 

Source
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

Source

pub fn td(&self, t: impl Into<Timestamp>) -> String

I18n::td in this view’s locale.

Source

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.

Source

pub fn tdr(&self, t: impl Into<Timestamp>) -> String

I18n::tdr in this view’s locale.

Source

pub fn tdr_with( &self, t: impl Into<Timestamp>, options: RelativeOptions, ) -> String

I18n::tdr_with in this view’s locale.

Source

pub fn tn(&self, n: impl Into<Number>) -> String

I18n::tn in this view’s locale.

Source

pub fn tn_as(&self, n: impl Into<Number>, name: &str) -> String

I18n::tn_as in this view’s locale: the name is looked up by this locale’s code.

Source§

impl View

Source

pub fn t<'k>(&self, key: &'k str) -> &'k str

I18n::t in this view.

Source

pub fn t_with(&self, key: &str, args: &Args<'_>) -> String

I18n::t_with in this view.

Source

pub fn tc(&self, key: &str, count: impl Into<Count>) -> String

I18n::tc in this view: the plural rules of this view’s locale.

Source

pub fn tc_with( &self, key: &str, count: impl Into<Count>, args: &Args<'_>, ) -> String

I18n::tc_with in this view.

Source

pub fn get(&self, key: &str) -> Option<&'static str>

I18n::get in this view.

Source

pub fn has(&self, key: &str) -> bool

I18n::has in this view: this view’s locale only, page then root.

Source

pub fn page(&self, name: &str) -> View

The same view on another page.

Source

pub fn with_locale(&self, code: &str) -> View

The same view in another locale (see I18n::with_locale).

Source

pub fn locale(&self) -> Arc<str> ⓘ

The locale this view reads: its own, or the active one. Shared: no allocation.

Source§

impl View

Source

pub fn text(&self, key: impl Into<Cow<'static, str>>) -> Text

A Text of key in this view’s locale and page.

Trait Implementations§

Source§

impl Clone for View

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for View

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.