pub struct I18n { /* private fields */ }Expand description
The application’s catalogues and its locale. Cheap to clone: clones share them.
use egui_pop_i18n::{I18n, args};
let i18n = I18n::new("fr");
i18n.add("fr", "files = { $count ->\n [one] { $count } fichier\n *[other] { $count } fichiers\n}\n").unwrap();
i18n.add("en", "files = { $count ->\n [one] { $count } file\n *[other] { $count } files\n}\n").unwrap();
assert_eq!(i18n.t("files", &args![count = 1]), "1 fichier");
assert_eq!(i18n.t("files", &args![count = 1500]), "1\u{202f}500 fichiers");
i18n.set_locale("en");
assert_eq!(i18n.t("files", &args![count = 0]), "0 files");
// Missing everywhere: the key itself.
assert_eq!(i18n.t("nowhere", &[]), "nowhere");Implementations§
Source§impl I18n
impl I18n
Sourcepub fn with_egui_pop(locale: &str) -> Self
pub fn with_egui_pop(locale: &str) -> Self
egui-pop’s own catalogues (EGUI_POP), in locale.
Sourcepub fn add(&self, locale: &str, source: &str) -> Result<(), String>
pub fn add(&self, locale: &str, source: &str) -> Result<(), String>
Adds Fluent source to a locale. Refused, with nothing added, when it does not parse or defines a message already there.
Sourcepub fn add_owned(
&self,
owner: &str,
locale: &str,
source: &str,
) -> Result<(), String>
pub fn add_owned( &self, owner: &str, locale: &str, source: &str, ) -> Result<(), String>
Adds a plugin’s Fluent source: every message must belong to
owner (see crate::catalog::owned_by).
Sourcepub fn add_catalogues(&self, catalogues: &[Catalogue]) -> Result<(), String>
pub fn add_catalogues(&self, catalogues: &[Catalogue]) -> Result<(), String>
Adds catalogues built into the application.
Sourcepub fn overridden(&self) -> Vec<(String, String)>
pub fn overridden(&self) -> Vec<(String, String)>
egui-pop’s messages an application’s catalogue overrode: (locale,
id). The plugin publishes each as an i18n.overridden warning.
Sourcepub fn add_dir(&self, dir: &Path) -> Result<usize, String>
pub fn add_dir(&self, dir: &Path) -> Result<usize, String>
Reads dir/<locale>/*.ftl over what is loaded: their messages
replace those of the same id (translators try their work without
rebuilding). Returns how many files were read; a missing
directory reads none.
Sourcepub fn set_locale(&self, tag: &str)
pub fn set_locale(&self, tag: &str)
Switches the locale (fr, fr_FR.UTF-8, x-pseudo); a tag
naming no language selects English.
Sourcepub fn generation(&self) -> u64
pub fn generation(&self) -> u64
Changes whenever the text shown may change: a locale switched, a catalogue added. Caches of translated text compare it.
Sourcepub fn get(&self, key: &str, args: &Args<'_>) -> Option<String>
pub fn get(&self, key: &str, args: &Args<'_>) -> Option<String>
The text of key in the current locale, along its chain and
English; None when no catalogue has it. Goes through the
i18n.resolve step when a plugin hooks it, and counts a key the
locale’s own language lacks as missing.
Sourcepub fn text(&self, key: &str, english: &str, args: &Args<'_>) -> String
pub fn text(&self, key: &str, english: &str, args: &Args<'_>) -> String
The text of key, else english (a Fluent pattern when there
are arguments), else the key itself.
Sourcepub fn get_in(&self, locale: &str, key: &str, args: &Args<'_>) -> Option<String>
pub fn get_in(&self, locale: &str, key: &str, args: &Args<'_>) -> Option<String>
The text of key in one locale, without the step: what the
i18n.resolve step does by default.
Sourcepub fn missing(&self) -> BTreeMap<String, BTreeSet<String>>
pub fn missing(&self) -> BTreeMap<String, BTreeSet<String>>
Keys looked up and missing in each locale’s own language (they
showed English or the key), since the last I18n::clear_missing.
Sourcepub fn clear_missing(&self)
pub fn clear_missing(&self)
Forgets the missing keys seen so far.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for I18n
impl RefUnwindSafe for I18n
impl Send for I18n
impl Sync for I18n
impl Unpin for I18n
impl UnsafeUnpin for I18n
impl UnwindSafe for I18n
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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