pub struct AppI18n { /* private fields */ }Expand description
One app’s own translator, formatter and locale switch, held in its world.
The hooks above are process-wide, which is what a script host needs and all it can reach. Markup is spawned from a world, so it reads this instead: a process hosting two Lumen apps renders each app’s text in its own locale, and switching one app’s locale leaves the other where it was.
The handles are the same opaque ones. Core forwards a key, or a spec and a value, or a locale tag, and returns what came back; the locale side of the seam is what the runtime installs here.
Implementations§
Source§impl AppI18n
impl AppI18n
Sourcepub fn new(
translator: Translator,
formatter: Formatter,
set_locale: LocaleSetter,
) -> Self
pub fn new( translator: Translator, formatter: Formatter, set_locale: LocaleSetter, ) -> Self
Pair a translator, a formatter and a locale switch for one app.
Sourcepub fn try_translate(&self, key: &str) -> Option<String>
pub fn try_translate(&self, key: &str) -> Option<String>
Resolve key against this app’s catalogue, or None on a miss.
Sourcepub fn format(&self, spec: &str, value: &str) -> Option<String>
pub fn format(&self, spec: &str, value: &str) -> Option<String>
Format value per spec for this app’s locale, or None when
the spec is not one it knows or the value is not what that spec
expects. A caller shows value unchanged then.
Sourcepub fn set_locale(&self, tag: &str) -> Option<LocaleChange>
pub fn set_locale(&self, tag: &str) -> Option<LocaleChange>
Switch this app to tag, answering with the locale it is now in
and the writing direction to read it in. None means tag is
not a locale tag and nothing changed.
Reach this through a ResMut<AppI18n> borrow: the systems that
rebuild an app’s text wake on the resource being marked changed.
Trait Implementations§
Source§impl Component for AppI18n
impl Component for AppI18n
Source§const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::SparseSet
const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::SparseSet
Source§type Mutability = Mutable
type Mutability = Mutable
Component<Mutability = Mutable>,
while immutable components will instead have Component<Mutability = Immutable>. Read moreSource§fn register_required_components(
_requiree: ComponentId,
required_components: &mut RequiredComponentsRegistrator<'_, '_>,
)
fn register_required_components( _requiree: ComponentId, required_components: &mut RequiredComponentsRegistrator<'_, '_>, )
Source§fn clone_behavior() -> ComponentCloneBehavior
fn clone_behavior() -> ComponentCloneBehavior
Source§fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Self>>
fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Self>>
ComponentRelationshipAccessor] required for working with relationships in dynamic contexts. Read more§fn on_discard() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_discard() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
§fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
§fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
EntityMapper. This is used to remap entities in contexts like scenes and entity cloning.
When deriving Component, this is populated by annotating fields containing entities with #[entities] Read more