pub struct Localizer { /* private fields */ }Expand description
Locale-aware lookup and formatting.
Implementations§
Source§impl Localizer
impl Localizer
Sourcepub fn add_catalog(&mut self, locale: Locale, catalog: MessageCatalog)
pub fn add_catalog(&mut self, locale: Locale, catalog: MessageCatalog)
Registers (or replaces) the catalog for a locale.
Sourcepub fn default_locale(&self) -> &Locale
pub fn default_locale(&self) -> &Locale
The default locale used at the end of the fallback chain.
Sourcepub fn set_locale(&mut self, locale: Locale) -> bool
pub fn set_locale(&mut self, locale: Locale) -> bool
Switches the active locale; returns true when it changed.
Sourcepub fn tr(&mut self, key: &str) -> String
pub fn tr(&mut self, key: &str) -> String
Resolves key through the fallback chain: exact tag → language →
default exact → default language → the key itself (recorded as
missing). The key is returned when nothing matches.
Sourcepub fn trn(&mut self, key: &str, count: i64) -> String
pub fn trn(&mut self, key: &str, count: i64) -> String
Like Localizer::tr but renders the plural form for count.
Sourcepub fn missing_keys(&self) -> &[String]
pub fn missing_keys(&self) -> &[String]
Missing keys in first-seen order (deduplicated).
Sourcepub fn clear_missing_keys(&mut self)
pub fn clear_missing_keys(&mut self)
Clears the missing-key log.
Sourcepub fn format_number(&self, value: f64, decimals: usize) -> String
pub fn format_number(&self, value: f64, decimals: usize) -> String
Formats a number with the active locale’s separators.
Locale data is intentionally small and deterministic: de/es/it/
pt/ru/pl group with . and separate decimals with ,;
fr groups with a space; English-style locales group with , and
separate decimals with .. This is fixture-quality data for tests and
examples, not a full resource-format implementation.
Sourcepub fn format_date(&self, iso_date: &str) -> String
pub fn format_date(&self, iso_date: &str) -> String
Formats an ISO YYYY-MM-DD date with the active locale’s pattern:
en-US → MM/DD/YYYY, other en → DD/MM/YYYY, de/ru/pl →
DD.MM.YYYY, everything else → DD/MM/YYYY. Input that is not a
valid ISO date passes through unchanged.