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>) -> Localization
pub fn new(catalog: Catalog, system: Vec<Locale>) -> Localization
Creates an application scope with automatic system-language selection.
Sourcepub fn persistent(
catalog: Catalog,
system: Vec<Locale>,
store: impl LanguagePreferenceStore + 'static,
) -> Localization
pub fn persistent( catalog: Catalog, system: Vec<Locale>, store: impl LanguagePreferenceStore + 'static, ) -> Localization
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.
Trait Implementations§
Source§impl Clone for Localization
impl Clone for Localization
Source§fn clone(&self) -> Localization
fn clone(&self) -> Localization
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for Localization
impl !UnwindSafe for Localization
impl Freeze for Localization
impl Send for Localization
impl Sync for Localization
impl Unpin for Localization
impl UnsafeUnpin for Localization
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