pub struct Localizer { /* private fields */ }Expand description
Resolve localization messages for a specific locale.
The loader eagerly falls back to en-GB when the requested locale is not
recognized. This mirrors the planned lookup order that surfaces explicit
configuration, environment overrides, and finally the bundled fallback.
Implementations§
Source§impl Localizer
impl Localizer
Sourcepub fn new(locale: Option<&str>) -> Self
pub fn new(locale: Option<&str>) -> Self
Create a localizer for locale, falling back to crate::i18n::FALLBACK_LOCALE.
use whitaker_common::i18n::{available_locales, Localizer};
let locale = Localizer::new(Some("cy"));
assert!(available_locales().contains(&"cy".to_string()));
assert_eq!(locale.locale(), "cy");
assert!(!locale.used_fallback());
let fallback = Localizer::new(Some("zz"));
assert_eq!(fallback.locale(), "en-GB");
assert!(fallback.used_fallback());Sourcepub fn language(&self) -> &LanguageIdentifier
pub fn language(&self) -> &LanguageIdentifier
Return the resolved locale identifier.
Sourcepub fn used_fallback(&self) -> bool
pub fn used_fallback(&self) -> bool
Whether the fallback locale was used.
Sourcepub fn message(&self, key: &str) -> Result<String, I18nError>
pub fn message(&self, key: &str) -> Result<String, I18nError>
Fetch the translated message for key.
Sourcepub fn message_with_args(
&self,
key: &str,
args: &Arguments<'_>,
) -> Result<String, I18nError>
pub fn message_with_args( &self, key: &str, args: &Arguments<'_>, ) -> Result<String, I18nError>
Fetch the translated message with Fluent arguments.
Trait Implementations§
Source§impl BundleLookup for Localizer
impl BundleLookup for Localizer
Auto Trait Implementations§
impl Freeze for Localizer
impl RefUnwindSafe for Localizer
impl Send for Localizer
impl Sync for Localizer
impl Unpin for Localizer
impl UnsafeUnpin for Localizer
impl UnwindSafe for Localizer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more