pub struct TranslationStore { /* private fields */ }Expand description
In-memory store of translation entries loaded from YAML files on disk.
Cheaply cloneable — wraps an Arc internally. Created by TranslationStore::load.
Used by the Translator extractor and the template
engine’s t() function (registered by
make_t_function).
Implementations§
Source§impl TranslationStore
impl TranslationStore
Sourcepub fn translate(
&self,
locale: &str,
key: &str,
kwargs: &[(&str, &str)],
) -> Result<String>
pub fn translate( &self, locale: &str, key: &str, kwargs: &[(&str, &str)], ) -> Result<String>
Translates key for the given locale, interpolating any {placeholder}
values found in kwargs.
Falls back to the default locale and finally to the key itself if no entry is found.
Sourcepub fn translate_plural(
&self,
locale: &str,
key: &str,
count: i64,
kwargs: &[(&str, &str)],
) -> Result<String>
pub fn translate_plural( &self, locale: &str, key: &str, count: i64, kwargs: &[(&str, &str)], ) -> Result<String>
Translates key with plural-rule selection based on count.
count is also injected into kwargs under the name count.
§Cross-locale fallback
When an entry is missing in the requested locale, the default locale’s
entry is used. Plural rule selection still uses the requesting
locale’s rules (e.g., Ukrainian FEW / MANY categories applied
against English one / other forms map to other). This keeps
grammatical selection consistent with the user’s language even though
the fallback copy is authored for a different one.
Sourcepub fn available_locales(&self) -> Vec<String>
pub fn available_locales(&self) -> Vec<String>
Returns the list of locales discovered on disk (unordered).
Sourcepub fn default_locale(&self) -> &str
pub fn default_locale(&self) -> &str
Returns the configured default locale.
Trait Implementations§
Source§impl Clone for TranslationStore
impl Clone for TranslationStore
Source§fn clone(&self) -> TranslationStore
fn clone(&self) -> TranslationStore
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more