pub struct I18nPartial { /* private fields */ }Expand description
Represents translations for a single file.
Provides methods to access translated text with support for placeholders, plurals, and gendered translations.
§Example
use bevy::prelude::*;
use bevy_intl::I18n;
fn display_text(i18n: Res<I18n>) {
let t = i18n.translation("ui");
// Simple translation
let greeting = t.t("hello");
// With placeholder
let welcome = t.t_with_arg("welcome", &[&"John"]);
// Plural form
let items = t.t_with_plural("item_count", 5);
// Gendered translation
let title = t.t_with_gender("title", "male");
}Implementations§
Source§impl I18nPartial
impl I18nPartial
Sourcepub fn t_with_arg(&self, key: &str, args: &[&dyn ToString]) -> String
pub fn t_with_arg(&self, key: &str, args: &[&dyn ToString]) -> String
Gets a translated string with placeholder replacement.
Replaces {{}} placeholders in the translation with the provided arguments.
§Arguments
key- Translation key to look upargs- Values to replace placeholders with
§Returns
The translated string with placeholders replaced.
§Example
// JSON: "welcome": "Hello {{name}}!"
let text = i18n.translation("ui").t_with_arg("welcome", &[&"John"]);
// Result: "Hello John!"Sourcepub fn t_with_plural(&self, key: &str, count: usize) -> String
pub fn t_with_plural(&self, key: &str, count: usize) -> String
Gets a pluralized translation based on count.
Uses advanced plural rules with fallback priority:
- Exact count (“0”, “1”, “2”, etc.)
- ICU categories (“zero”, “one”, “two”, “few”, “many”)
- Basic fallback (“one” vs “other”)
§Arguments
key- Translation key to look upcount- Number to determine plural form
§Returns
The translated string with count placeholder replaced.
§Example
// JSON: "items": { "one": "One item", "many": "{{count}} items" }
let text = i18n.translation("ui").t_with_plural("items", 5);
// Result: "5 items"Sourcepub fn t_with_gender(&self, key: &str, gender: &str) -> String
pub fn t_with_gender(&self, key: &str, gender: &str) -> String
Gets a gendered translation.
§Arguments
key- Translation key to look upgender- Gender key (e.g., “male”, “female”, “neutral”)
§Returns
The translated string for the specified gender.
§Example
// JSON: "title": { "male": "Mr.", "female": "Ms." }
let text = i18n.translation("ui").t_with_gender("title", "female");
// Result: "Ms."Sourcepub fn t_with_gender_and_arg(
&self,
key: &str,
gender: &str,
args: &[&dyn ToString],
) -> String
pub fn t_with_gender_and_arg( &self, key: &str, gender: &str, args: &[&dyn ToString], ) -> String
Gets a gendered translation with placeholder replacement.
Combines gender selection and argument replacement.
§Arguments
key- Translation key to look upgender- Gender keyargs- Values to replace placeholders with
§Returns
The translated string for the gender with placeholders replaced.
§Example
// JSON: "greeting": { "male": "Hello Mr. {{name}}", "female": "Hello Ms. {{name}}" }
let text = i18n.translation("ui").t_with_gender_and_arg("greeting", "male", &[&"Smith"]);
// Result: "Hello Mr. Smith"Auto Trait Implementations§
impl Freeze for I18nPartial
impl RefUnwindSafe for I18nPartial
impl Send for I18nPartial
impl Sync for I18nPartial
impl Unpin for I18nPartial
impl UnwindSafe for I18nPartial
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
Return the
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.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
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
Converts
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>
Converts
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