Struct mas_i18n::Translator
source · pub struct Translator { /* private fields */ }
Expand description
A translator for a set of translations.
Implementations§
source§impl Translator
impl Translator
sourcepub fn new(translations: HashMap<DataLocale, TranslationTree>) -> Self
pub fn new(translations: HashMap<DataLocale, TranslationTree>) -> Self
Create a new translator from a set of translations.
sourcepub fn load_from_path(path: &Utf8Path) -> Result<Self, LoadError>
pub fn load_from_path(path: &Utf8Path) -> Result<Self, LoadError>
Load a set of translations from a directory.
The directory should contain one JSON file per locale, with the locale
being the filename without the extension, e.g. en-US.json
.
§Parameters
path
- The path to load from.
§Errors
Returns an error if the directory cannot be read, or if any of the files cannot be parsed.
sourcepub fn message_with_fallback(
&self,
locale: DataLocale,
key: &str,
) -> Option<(&Message, DataLocale)>
pub fn message_with_fallback( &self, locale: DataLocale, key: &str, ) -> Option<(&Message, DataLocale)>
Get a message from the tree by key, with locale fallback.
Returns the message and the locale it was found in.
If the message is not found, returns None
.
§Parameters
locale
- The locale to use.key
- The key to look up, which is a dot-separated path.
sourcepub fn plural_with_fallback(
&self,
locale: DataLocale,
key: &str,
count: usize,
) -> Option<(&Message, DataLocale)>
pub fn plural_with_fallback( &self, locale: DataLocale, key: &str, count: usize, ) -> Option<(&Message, DataLocale)>
Get a plural message from the tree by key, with locale fallback.
Returns the message and the locale it was found in.
If the message is not found, returns None
.
§Parameters
locale
- The locale to use.key
- The key to look up, which is a dot-separated path.count
- The count to use for pluralization.
sourcepub fn plural(
&self,
locale: &DataLocale,
key: &str,
count: usize,
) -> Result<&Message, PluralsError>
pub fn plural( &self, locale: &DataLocale, key: &str, count: usize, ) -> Result<&Message, PluralsError>
sourcepub fn and_list<'a, W: Writeable + 'a, I: Iterator<Item = W> + Clone + 'a>(
&'a self,
locale: &DataLocale,
items: I,
) -> Result<String, ListError>
pub fn and_list<'a, W: Writeable + 'a, I: Iterator<Item = W> + Clone + 'a>( &'a self, locale: &DataLocale, items: I, ) -> Result<String, ListError>
sourcepub fn or_list<'a, W: Writeable + 'a, I: Iterator<Item = W> + Clone + 'a>(
&'a self,
locale: &DataLocale,
items: I,
) -> Result<String, ListError>
pub fn or_list<'a, W: Writeable + 'a, I: Iterator<Item = W> + Clone + 'a>( &'a self, locale: &DataLocale, items: I, ) -> Result<String, ListError>
sourcepub fn relative_date(
&self,
locale: &DataLocale,
days: i64,
) -> Result<String, RelativeTimeError>
pub fn relative_date( &self, locale: &DataLocale, days: i64, ) -> Result<String, RelativeTimeError>
sourcepub fn short_time<T: IsoTimeInput>(
&self,
locale: &DataLocale,
time: &T,
) -> Result<String, DateTimeError>
pub fn short_time<T: IsoTimeInput>( &self, locale: &DataLocale, time: &T, ) -> Result<String, DateTimeError>
sourcepub fn available_locales(&self) -> Vec<&DataLocale>
pub fn available_locales(&self) -> Vec<&DataLocale>
Get a list of available locales.
sourcepub fn has_locale(&self, locale: &DataLocale) -> bool
pub fn has_locale(&self, locale: &DataLocale) -> bool
Check if a locale is available.
sourcepub fn choose_locale(
&self,
iter: impl Iterator<Item = DataLocale>,
) -> DataLocale
pub fn choose_locale( &self, iter: impl Iterator<Item = DataLocale>, ) -> DataLocale
Choose the best available locale from a list of candidates.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Translator
impl RefUnwindSafe for Translator
impl Send for Translator
impl Sync for Translator
impl Unpin for Translator
impl UnwindSafe for Translator
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> Filterable for T
impl<T> Filterable for T
source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
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