Skip to main content

I18n

Struct I18n 

Source
pub struct I18n { /* private fields */ }

Implementations§

Source§

impl I18n

Inherent implementation of I18n.

Source

pub fn change_locale(&self, locale: &str)

Sets the active locale to locale. Triggers a reactive update so any reactive t(key) read re-evaluates.

Named change_locale (not set_locale) to avoid colliding with the set_locale getter generated by #[derive(Data)] on the struct field.

§Arguments
  • &str - Shared reference to a str.
Source

pub fn change_fallback_locale(&self, locale: &str)

Sets the fallback locale. Trigger a reactive update for any t(key) whose key is missing in the active locale — they may now resolve to a different fallback value.

Named change_fallback_locale (not set_fallback_locale) for the same reason as change_locale.

§Arguments
  • &str - Shared reference to a str.
Source

pub fn add_messages(&self, locale: &str, entries: &[MessageEntry])

Adds a batch of (key, message) entries to the translation table for locale. Existing entries for that locale are overwritten (last-write-wins).

§Arguments
  • &str - Shared reference to a str.
  • &[MessageEntry] - Shared reference to a [MessageEntry].
Source

pub fn remove_locale(&self, locale: &str)

Removes every entry for locale. After this call, t(key) for any key will skip this locale in its lookup chain.

§Arguments
  • &str - Shared reference to a str.
Source

pub fn remove_message(&self, locale: &str, key: &str)

Removes a single message from a locale. After this call, t(key) for this key in this locale will fall back to fallback_locale.

§Arguments
  • &str - Shared reference to a str.
  • &str - Shared reference to a str.
Source

pub fn t(&self, key: &str) -> String

Translates key to a string under the active locale, falling back to fallback_locale if the active locale has no entry. Returns key itself if neither locale has an entry (debug-friendly).

This is the reactive read — calling it inside a render closure subscribes that closure to locale changes (and to any subsequent edits to the messages map for the active or fallback locale).

§Arguments
  • &str - Shared reference to a str.
§Returns
  • String - A String value.
Source

pub fn t_with( &self, key: &str, vars: &HashMap<&'static str, &'static str>, ) -> String

Translates key and substitutes {name}-style placeholders from vars.

Placeholders that are present in vars are replaced with their corresponding value. Placeholders that are missing from vars are left as the literal {name} token — matching the i18next default behavior. No escaping is supported; add it when a real use case shows up.

§Arguments
  • &str - Shared reference to a str.
  • &HashMap<&'static str, &'static str> - Shared reference to a HashMap<&'static str, &'static str>.
§Returns
  • String - A String value.
Source

pub fn locale_count(&self) -> usize

Returns the number of locales currently registered (i.e. the number of distinct keys in the messages map’s outer level).

§Returns
  • usize - Count of registered locales.
Source

pub fn active_message_count(&self) -> usize

Returns the number of messages registered for the active locale.

§Returns
  • usize - Count of currently-registered messages.
Source§

impl I18n

Source

pub fn get_locale(&self) -> &Signal<String>

Source

pub fn get_mut_locale(&mut self) -> &mut Signal<String>

Source

pub fn set_locale(&mut self, val: Signal<String>) -> &mut Self

Source

pub fn get_fallback_locale(&self) -> &Signal<String>

Source

pub fn get_mut_fallback_locale(&mut self) -> &mut Signal<String>

Source

pub fn set_fallback_locale(&mut self, val: Signal<String>) -> &mut Self

Source

pub fn get_messages(&self) -> &Signal<HashMap<String, HashMap<String, String>>>

Source

pub fn get_mut_messages( &mut self, ) -> &mut Signal<HashMap<String, HashMap<String, String>>>

Source

pub fn set_messages( &mut self, val: Signal<HashMap<String, HashMap<String, String>>>, ) -> &mut Self

Source§

impl I18n

Source

pub fn new( locale: Signal<String>, fallback_locale: Signal<String>, messages: Signal<HashMap<String, HashMap<String, String>>>, ) -> Self

Trait Implementations§

Source§

impl Clone for I18n

Source§

fn clone(&self) -> I18n

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 Copy for I18n

The aggregate i18n state.

Constructed once per app via App::use_i18n(), threaded through any code that needs to render translated text. Cheap to Clone (the internal signal is Copy-by-pointer).

§Storage

Messages are stored in a Signal<HashMap<String, HashMap<String, String>>> keyed by locale → (key → message). The map is intentionally two-level: it matches how translation files are typically organized (en.json is one flat key/value map, zh-CN.json is another, etc.) and it lets add_messages(locale, &[(k, v), ...]) build the inner map by direct insertion without the user having to allocate one HashMap per locale. I18n is Copy because every field is a Signal, which is already Copy — the registry hands out cheap usize addresses for any T: Clone + PartialEq + 'static.

Auto Trait Implementations§

§

impl Freeze for I18n

§

impl RefUnwindSafe for I18n

§

impl Send for I18n

§

impl Sync for I18n

§

impl Unpin for I18n

§

impl UnsafeUnpin for I18n

§

impl UnwindSafe for I18n

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, <T as TryFrom<U>>::Error>

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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more