pub struct I18n { /* private fields */ }Implementations§
Source§impl I18n
Inherent implementation of I18n.
impl I18n
Inherent implementation of I18n.
Sourcepub fn change_locale(&self, locale: &str)
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 astr.
Sourcepub fn change_fallback_locale(&self, locale: &str)
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 astr.
Sourcepub fn add_messages(&self, locale: &str, entries: &[MessageEntry])
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).
OPT 22 (tail): writes through the process-wide
[I18N_MESSAGES] lock instead of cloning the whole
table out of a Signal and re-setting it.
§Arguments
&str- Shared reference to astr.&[MessageEntry]- Shared reference to a[MessageEntry].
Sourcepub fn remove_locale(&self, locale: &str)
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.
OPT 22 (tail): see add_messages — writes through
the static lock.
§Arguments
&str- Shared reference to astr.
Sourcepub fn remove_message(&self, locale: &str, key: &str)
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.
OPT 22 (tail): see add_messages — writes through
the static lock.
§Arguments
&str- Shared reference to astr.&str- Shared reference to astr.
Sourcepub fn t(&self, key: &str) -> String
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. The messages table itself is not reactive
(it lives behind [I18N_MESSAGES]).
OPT 22 (tail): previously the read cloned the
entire translation table out of a Signal on every
call (a HashMap<String, HashMap<String, String>>
per t()). Now the read takes the read guard and
clones at most a single String (the message
itself) before dropping the guard.
§Arguments
&str- Shared reference to astr.
§Returns
String- AStringvalue.
Sourcepub fn t_with(
&self,
key: &str,
vars: &HashMap<&'static str, &'static str>,
) -> String
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 astr.&HashMap<&'static str, &'static str>- Shared reference to aHashMap<&'static str, &'static str>.
§Returns
String- AStringvalue.
Sourcepub fn locale_count(&self) -> usize
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).
OPT 22 (tail): borrows through [I18N_MESSAGES]
read guard instead of cloning the whole table.
§Returns
usize- Count of registered locales.
Sourcepub fn active_message_count(&self) -> usize
pub fn active_message_count(&self) -> usize
Returns the number of messages registered for the active locale.
OPT 22 (tail): borrows through [I18N_MESSAGES]
read guard instead of cloning the whole table.
§Returns
usize- Count of currently-registered messages.
Source§impl I18n
impl I18n
pub fn get_locale(&self) -> &Signal<String>
pub fn get_mut_locale(&mut self) -> &mut Signal<String>
pub fn set_locale(&mut self, val: Signal<String>) -> &mut Self
pub fn get_fallback_locale(&self) -> &Signal<String>
pub fn get_mut_fallback_locale(&mut self) -> &mut Signal<String>
pub fn set_fallback_locale(&mut self, val: Signal<String>) -> &mut Self
Trait Implementations§
impl Copy for I18n
I18n is Copy because every remaining field is a
Signal, which is already Copy — the registry hands
out cheap usize addresses for any `T: Clone + PartialEq
- ’static`.