Struct EmbeddedCatalog
pub struct EmbeddedCatalog { /* private fields */ }Expand description
An application’s Fluent catalogues, embedded with include_str! and
loaded on first use on each thread.
Apps declare one static and route every string through it, so a
--shots render, a unit test and a live session resolve the same copy
with no build step or runtime file I/O:
static CATALOG: ui::i18n::EmbeddedCatalog = ui::i18n::EmbeddedCatalog::new(
"en-US",
&[("en-US", include_str!("../locales/en-US.ftl"))],
"chat-mention-agent-tag",
);
pub fn t(key: &str) -> String { CATALOG.t(key) }The manager is thread-local, so loading is per thread and idempotent. A host (the shell or the app runner) may already have installed a manager with the user’s locale; that one is never replaced — the catalogues are added to it. A fresh manager is installed only when the thread has none.
Implementations§
§impl EmbeddedCatalog
impl EmbeddedCatalog
pub const fn new(
source_locale: &'static str,
catalogs: &'static [(&'static str, &'static str)],
) -> EmbeddedCatalog
pub const fn new( source_locale: &'static str, catalogs: &'static [(&'static str, &'static str)], ) -> EmbeddedCatalog
Catalogues keyed by locale, one of which is source_locale.
A thread with no manager gets one selecting source_locale.
pub const fn with_system_locale(self) -> EmbeddedCatalog
pub const fn with_system_locale(self) -> EmbeddedCatalog
A thread with no manager gets one selecting the user’s locale from the
environment (see I18nManager::install_system).
pub const fn with_pinned_locale(self, locale: &'static str) -> EmbeddedCatalog
pub const fn with_pinned_locale(self, locale: &'static str) -> EmbeddedCatalog
Select locale whenever this catalogue loads on a thread, even over a
host’s choice. For test builds that assert source copy on any
developer or CI machine.
pub fn ensure(&self)
pub fn ensure(&self)
Load the catalogues on this thread if they are not loaded yet.
A key with no catalogue resolves to the key itself rather than
panicking, so a missed call degrades to something legible — but it
looks wrong, which is why string sites go through Self::t.
pub fn t_args(&self, key: &str, args: &[(&str, ArgValue)]) -> String
pub fn t_args(&self, key: &str, args: &[(&str, ArgValue)]) -> String
Resolve key, interpolating named variables.
The values are the app’s own words — a label, a participant’s name — so the sentence around them stays in the catalogue and only the nouns are substituted.
pub fn set_locale(&self, locale: &str)
pub fn set_locale(&self, locale: &str)
Select locale (BCP-47 or POSIX, e.g. de_DE.UTF-8) on this thread.
An unparseable value, C or POSIX selects the source locale.
pub fn current_locale(&self) -> String
pub fn current_locale(&self) -> String
The active locale’s BCP-47 tag on this thread.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EmbeddedCatalog
impl RefUnwindSafe for EmbeddedCatalog
impl Send for EmbeddedCatalog
impl Sync for EmbeddedCatalog
impl Unpin for EmbeddedCatalog
impl UnsafeUnpin for EmbeddedCatalog
impl UnwindSafe for EmbeddedCatalog
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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