pub struct Lang { /* private fields */ }Expand description
The translation tables and the current language. Reach it through ctx.lang.
Implementations§
Source§impl Lang
impl Lang
Sourcepub fn load_dir(&mut self, dir: impl AsRef<Path>) -> usize
pub fn load_dir(&mut self, dir: impl AsRef<Path>) -> usize
Loads every <code>.txt in dir. Returns how many languages were loaded. A missing
folder is fine and loads nothing.
Sourcepub fn add_text(&mut self, code: &str, text: &str)
pub fn add_text(&mut self, code: &str, text: &str)
Adds the lines of a translation file (key = text) to a language. Later keys
replace earlier ones. Handy with include_str! to ship texts inside the executable.
Sourcepub fn insert(
&mut self,
code: &str,
key: impl Into<String>,
text: impl Into<String>,
)
pub fn insert( &mut self, code: &str, key: impl Into<String>, text: impl Into<String>, )
Adds or replaces one text.
Sourcepub fn set(&mut self, code: &str) -> bool
pub fn set(&mut self, code: &str) -> bool
Switches the language. "de-AT" falls back to "de". Returns false (and keeps the
current language) if no texts exist for it. English and German always exist, because
the engine’s own texts are built in. To remember the choice, use
Context::set_language(crate::Context::set_language) instead.
Sourcepub fn fallback(&self) -> &str
pub fn fallback(&self) -> &str
The language used for keys missing in the current one (default "en").
Sourcepub fn set_fallback(&mut self, code: &str)
pub fn set_fallback(&mut self, code: &str)
Changes the fallback language.
Sourcepub fn languages(&self) -> Vec<String>
pub fn languages(&self) -> Vec<String>
The languages with loaded texts, sorted by code. Built in engine texts do not count, so this lists exactly the languages your game was translated to.
Sourcepub fn name(&self, code: &str) -> String
pub fn name(&self, code: &str) -> String
The name of a language as written in its file (key language), else the code.
Sourcepub fn has(&self, key: &str) -> bool
pub fn has(&self, key: &str) -> bool
Whether key has a text in the current or the fallback language.
Sourcepub fn get(&self, key: &str) -> String
pub fn get(&self, key: &str) -> String
The text for key in the current language. See the module docs for what
happens when it is missing.
Sourcepub fn format(&self, key: &str, args: &[(&str, &dyn Display)]) -> String
pub fn format(&self, key: &str, args: &[(&str, &dyn Display)]) -> String
The text for key with {name} placeholders filled in.
// score = {player} has {points} points
let text = ctx.lang.format("score", &[("player", &"Anna"), ("points", &12)]);Sourcepub fn plural(&self, key: &str, n: i64) -> String
pub fn plural(&self, key: &str, n: i64) -> String
Picks key.one when n is 1 (or -1) and key.other otherwise, and fills in {n}.
Without those keys, key itself is used.
Sourcepub fn plural_with(
&self,
key: &str,
n: i64,
args: &[(&str, &dyn Display)],
) -> String
pub fn plural_with( &self, key: &str, n: i64, args: &[(&str, &dyn Display)], ) -> String
Like Lang::plural with more placeholders.
Sourcepub fn system() -> Option<String>
pub fn system() -> Option<String>
The player’s system language (e.g. "de"), if the system tells.
Sourcepub fn direction_name(&self, degrees: f32) -> String
pub fn direction_name(&self, degrees: f32) -> String
Like math::direction_name in the current language.
Sourcepub fn describe_position(&self, from: Vec3, yaw: f32, target: Vec3) -> String
pub fn describe_position(&self, from: Vec3, yaw: f32, target: Vec3) -> String
Like math::describe_position in the current
language, e.g. "3 Uhr, 12 Meter".
Sourcepub fn describe_speed(&self, vehicle: &Vehicle) -> String
pub fn describe_speed(&self, vehicle: &Vehicle) -> String
Like Vehicle::describe_speed in the current language.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Lang
impl !RefUnwindSafe for Lang
impl !Sync for Lang
impl Send for Lang
impl Unpin for Lang
impl UnsafeUnpin for Lang
impl UnwindSafe for Lang
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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.Source§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.Source§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.Source§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.