Skip to main content

Localizer

Struct Localizer 

Source
pub struct Localizer { /* private fields */ }
Expand description

Locale-aware lookup and formatting.

Implementations§

Source§

impl Localizer

Source

pub fn new(default: Locale) -> Self

Creates a localizer with a default locale and no catalogs.

Source

pub fn add_catalog(&mut self, locale: Locale, catalog: MessageCatalog)

Registers (or replaces) the catalog for a locale.

Source

pub fn locale(&self) -> &Locale

The active locale.

Source

pub fn default_locale(&self) -> &Locale

The default locale used at the end of the fallback chain.

Source

pub fn set_locale(&mut self, locale: Locale) -> bool

Switches the active locale; returns true when it changed.

Source

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.

Source

pub fn trn(&mut self, key: &str, count: i64) -> String

Like Localizer::tr but renders the plural form for count.

Source

pub fn missing_keys(&self) -> &[String]

Missing keys in first-seen order (deduplicated).

Source

pub fn clear_missing_keys(&mut self)

Clears the missing-key log.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for Localizer

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> 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, 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.