pub struct Localization(/* private fields */);Expand description
Shared application localization used by UI roots, workers, and native services. Each thread retains only its most recently used formatter. Language changes invalidate that formatter; repeated messages do not reconstruct Fluent bundles.
Implementations§
Source§impl Localization
impl Localization
Sourcepub fn new(catalog: Catalog, system: Vec<Locale>) -> Self
pub fn new(catalog: Catalog, system: Vec<Locale>) -> Self
Creates an application scope with automatic system-language selection.
Sourcepub fn persistent(
catalog: Catalog,
system: Vec<Locale>,
store: impl LanguagePreferenceStore + 'static,
) -> Self
pub fn persistent( catalog: Catalog, system: Vec<Locale>, store: impl LanguagePreferenceStore + 'static, ) -> Self
Creates an application scope backed by its own preference storage.
Sourcepub fn is_persistent(&self) -> bool
pub fn is_persistent(&self) -> bool
Whether preference changes access application storage. Without storage, selection is immediate and needs no worker runtime.
Sourcepub fn preference(&self) -> LanguagePreference
pub fn preference(&self) -> LanguagePreference
The current saved or explicitly selected preference.
Sourcepub fn revision(&self) -> u64
pub fn revision(&self) -> u64
A version that changes when the selected preference or host languages change.
Sourcepub fn load(&self) -> Result<(), LocalizationError>
pub fn load(&self) -> Result<(), LocalizationError>
Loads stored preferences without replacing a newer user selection. This can access storage; native applications should call it on a worker.
Sourcepub fn select(
&self,
preference: LanguagePreference,
) -> Result<(), LocalizationError>
pub fn select( &self, preference: LanguagePreference, ) -> Result<(), LocalizationError>
Persists a choice and publishes it only after storage succeeds. Calls are serialized; native applications should call this on a worker.
Sourcepub fn refresh_system(&self, system: &[Locale]) -> bool
pub fn refresh_system(&self, system: &[Locale]) -> bool
Updates the ordered host preferences without changing an explicit choice.
Sourcepub fn translator(&self) -> Translator
pub fn translator(&self) -> Translator
Creates a formatter for the current application choice on this thread.
Sourcepub fn format(
&self,
message: &DeferredMessage,
) -> Result<String, LocalizationError>
pub fn format( &self, message: &DeferredMessage, ) -> Result<String, LocalizationError>
Resolves a deferred message on any thread using its cached formatter.
Sourcepub fn text(&self, message: &DeferredMessage) -> String
pub fn text(&self, message: &DeferredMessage) -> String
Resolves native UI text, with readable source text if a runtime resource is malformed.