pub struct Catalog(/* private fields */);Expand description
Immutable, shareable parsed catalogs. Replacing a catalog replaces its cache identity.
Implementations§
Source§impl Catalog
impl Catalog
Sourcepub fn from_resources(
fallback: &str,
resources: &[Resource<'_>],
) -> Result<Catalog, LocalizationError>
pub fn from_resources( fallback: &str, resources: &[Resource<'_>], ) -> Result<Catalog, LocalizationError>
Parses catalogs once, rejecting malformed resources and duplicate definitions.
Missing translations fall back to fallback, then the message’s inline source.
Sourcepub fn with_languages(
self,
entries: &[(&str, &str)],
) -> Result<Catalog, LocalizationError>
pub fn with_languages( self, entries: &[(&str, &str)], ) -> Result<Catalog, LocalizationError>
Declares supported languages in presentation order with their native names. Every catalog language must occur exactly once; dependency catalogs do not add choices to an application’s language selector.
Sourcepub fn languages(&self) -> &[Language]
pub fn languages(&self) -> &[Language]
Supported application languages, in their declared presentation order.
Sourcepub fn with_fallback(self, library: &Catalog) -> Catalog
pub fn with_fallback(self, library: &Catalog) -> Catalog
Adds a library’s catalogs below application overrides without copying its resources. Lookup prefers an application message in the same language before the library’s.
Sourcepub fn translator(&self, locale: Locale) -> Translator
pub fn translator(&self, locale: Locale) -> Translator
Creates a thread-owned formatter for an explicit language.
Sourcepub fn negotiate(&self, preferences: &[Locale]) -> Translator
pub fn negotiate(&self, preferences: &[Locale]) -> Translator
Negotiates ordered user preferences, preserving script subtags. An empty list selects the catalog’s source language. The resulting formatter stays on the calling thread; pass a cloned catalog to background workers.
Sourcepub fn fallback_locale(&self) -> &Locale
pub fn fallback_locale(&self) -> &Locale
The source language used when no requested translation is available.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Catalog
impl RefUnwindSafe for Catalog
impl Send for Catalog
impl Sync for Catalog
impl Unpin for Catalog
impl UnsafeUnpin for Catalog
impl UnwindSafe for Catalog
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more