I18nPartial

Struct I18nPartial 

Source
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

Source

pub fn t(&self, key: &str) -> String

Gets a translated string for the given key.

Falls back to the fallback language if the key is not found in the current language.

§Arguments
  • key - Translation key to look up
§Returns

The translated string, or “Missing translation” if not found.

§Example
let text = i18n.translation("ui").t("hello");
Source

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 up
  • args - 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!"
Source

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:

  1. Exact count (“0”, “1”, “2”, etc.)
  2. ICU categories (“zero”, “one”, “two”, “few”, “many”)
  3. Basic fallback (“one” vs “other”)
§Arguments
  • key - Translation key to look up
  • count - 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"
Source

pub fn t_with_gender(&self, key: &str, gender: &str) -> String

Gets a gendered translation.

§Arguments
  • key - Translation key to look up
  • gender - 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."
Source

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 up
  • gender - Gender key
  • args - 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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

Source§

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> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

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>

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)

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)

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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> Settings for T
where T: 'static + Send + Sync,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,