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<Self, LocalizationError>
pub fn from_resources( fallback: &str, resources: &[Resource<'_>], ) -> Result<Self, 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<Self, LocalizationError>
pub fn with_languages( self, entries: &[(&str, &str)], ) -> Result<Self, 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) -> Self
pub fn with_fallback(self, library: &Catalog) -> Self
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.