Struct i18n_embed::fluent::FluentLanguageLoader
source · [−]pub struct FluentLanguageLoader { /* private fields */ }Expand description
LanguageLoader implemenation for the fluent localization
system. Also provides methods to access localizations which have
been loaded.
⚠️ This API requires the following crate features to be activated: fluent-system.
Implementations
sourceimpl FluentLanguageLoader
impl FluentLanguageLoader
sourcepub fn new<S: Into<String>>(
domain: S,
fallback_language: LanguageIdentifier
) -> Self
pub fn new<S: Into<String>>(
domain: S,
fallback_language: LanguageIdentifier
) -> Self
Create a new FluentLanguageLoader, which loads messages for
the specified domain, and relies on the specified
fallback_language for any messages that do not exist for the
current language.
sourcepub fn current_languages(&self) -> Vec<LanguageIdentifier>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn current_languages(&self) -> Vec<LanguageIdentifier>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
The languages associated with each actual loaded language bundle.
sourcepub fn get(&self, message_id: &str) -> String
pub fn get(&self, message_id: &str) -> String
Get a localized message referenced by the message_id.
sourcepub fn get_args_concrete<'args>(
&self,
message_id: &str,
args: HashMap<&'args str, FluentValue<'args>>
) -> String
pub fn get_args_concrete<'args>(
&self,
message_id: &str,
args: HashMap<&'args str, FluentValue<'args>>
) -> String
A non-generic version of FluentLanguageLoader::get_args().
sourcepub fn get_args_fluent<'args>(
&self,
message_id: &str,
args: Option<&'args FluentArgs<'args>>
) -> String
pub fn get_args_fluent<'args>(
&self,
message_id: &str,
args: Option<&'args FluentArgs<'args>>
) -> String
A non-generic version of FluentLanguageLoader::get_args() accepting [FluentArgs] instead of a HashMap.
sourcepub fn get_args<'a, S, V>(&self, id: &str, args: HashMap<S, V>) -> String where
S: Into<Cow<'a, str>> + Clone,
V: Into<FluentValue<'a>> + Clone,
pub fn get_args<'a, S, V>(&self, id: &str, args: HashMap<S, V>) -> String where
S: Into<Cow<'a, str>> + Clone,
V: Into<FluentValue<'a>> + Clone,
Get a localized message referenced by the message_id, and
formatted with the specified args.
sourcepub fn get_lang(&self, lang: &[&LanguageIdentifier], message_id: &str) -> String
pub fn get_lang(&self, lang: &[&LanguageIdentifier], message_id: &str) -> String
Get a localized message referenced by the message_id.
sourcepub fn get_lang_args_concrete<'source>(
&self,
lang: &[&LanguageIdentifier],
message_id: &str,
args: HashMap<&'source str, FluentValue<'source>>
) -> String
pub fn get_lang_args_concrete<'source>(
&self,
lang: &[&LanguageIdentifier],
message_id: &str,
args: HashMap<&'source str, FluentValue<'source>>
) -> String
A non-generic version of FluentLanguageLoader::get_lang_args().
sourcepub fn get_lang_args_fluent<'args>(
&self,
lang: &[&LanguageIdentifier],
message_id: &str,
args: Option<&'args FluentArgs<'args>>
) -> String
pub fn get_lang_args_fluent<'args>(
&self,
lang: &[&LanguageIdentifier],
message_id: &str,
args: Option<&'args FluentArgs<'args>>
) -> String
A non-generic version of FluentLanguageLoader::get_lang_args() accepting [FluentArgs] instead of a HashMap.
sourcepub fn get_lang_args<'a, S, V>(
&self,
lang: &[&LanguageIdentifier],
id: &str,
args: HashMap<S, V>
) -> String where
S: Into<Cow<'a, str>> + Clone,
V: Into<FluentValue<'a>> + Clone,
pub fn get_lang_args<'a, S, V>(
&self,
lang: &[&LanguageIdentifier],
id: &str,
args: HashMap<S, V>
) -> String where
S: Into<Cow<'a, str>> + Clone,
V: Into<FluentValue<'a>> + Clone,
Get a localized message for the given language identifiers, referenced
by the message_id and formatted with the specified args.
sourcepub fn has(&self, message_id: &str) -> bool
pub fn has(&self, message_id: &str) -> bool
Returns true if a message with the specified message_id is
available in any of the languages currently loaded (including
the fallback language).
sourcepub fn with_fluent_message<OUT, C>(
&self,
message_id: &str,
closure: C
) -> Option<OUT> where
C: Fn(FluentMessage<'_>) -> OUT,
pub fn with_fluent_message<OUT, C>(
&self,
message_id: &str,
closure: C
) -> Option<OUT> where
C: Fn(FluentMessage<'_>) -> OUT,
Run the closure with the message that matches the specified
message_id (if it is available in any of the languages
currently loaded, including the fallback language). Returns
Some of whatever whatever the closure returns, or None if
no messages were found matching the message_id.
sourcepub fn with_message_iter<OUT, C>(
&self,
language: &LanguageIdentifier,
closure: C
) -> OUT where
C: Fn(&mut dyn Iterator<Item = &Message<&str>>) -> OUT,
pub fn with_message_iter<OUT, C>(
&self,
language: &LanguageIdentifier,
closure: C
) -> OUT where
C: Fn(&mut dyn Iterator<Item = &Message<&str>>) -> OUT,
Runs the provided closure with an iterator over the messages
available for the specified language. There may be duplicate
messages when they are duplicated in resources applicable to
the language. Returns the result of the closure.
sourcepub fn set_use_isolating(&self, value: bool)
pub fn set_use_isolating(&self, value: bool)
Set whether the underlying Fluent logic should insert Unicode Directionality Isolation Marks around placeables.
See [fluent::bundle::FluentBundleBase::set_use_isolating] for more
information.
Note: This function will have no effect if
LanguageLoader::load_languages has not been called first.
Default: true.
sourcepub fn with_bundles_mut<F>(&self, f: F) where
F: Fn(&mut FluentBundle<Arc<FluentResource>, IntlLangMemoizer>),
pub fn with_bundles_mut<F>(&self, f: F) where
F: Fn(&mut FluentBundle<Arc<FluentResource>, IntlLangMemoizer>),
Apply some configuration to each budle in this loader.
Note: This function will have no effect if
LanguageLoader::load_languages has not been called first.
Trait Implementations
sourceimpl Debug for FluentLanguageLoader
impl Debug for FluentLanguageLoader
sourceimpl LanguageLoader for FluentLanguageLoader
impl LanguageLoader for FluentLanguageLoader
sourcefn fallback_language(&self) -> &LanguageIdentifier
fn fallback_language(&self) -> &LanguageIdentifier
The fallback language for the module this loader is responsible for.
sourcefn language_file_name(&self) -> String
fn language_file_name(&self) -> String
The language file name to use for this loader.
sourcefn current_language(&self) -> LanguageIdentifier
fn current_language(&self) -> LanguageIdentifier
Get the language which is currently loaded for this loader.
sourcefn load_languages(
&self,
i18n_assets: &dyn I18nAssets,
language_ids: &[&LanguageIdentifier]
) -> Result<(), I18nEmbedError>
fn load_languages(
&self,
i18n_assets: &dyn I18nAssets,
language_ids: &[&LanguageIdentifier]
) -> Result<(), I18nEmbedError>
Load the languages language_ids using the resources packaged
in the i18n_assets in order of fallback preference. This
also sets the LanguageLoader::current_language() to the
first in the language_ids slice. You can use
select() to determine which fallbacks are
actually available for an arbitrary slice of preferences.
sourcefn language_file<'a>(
&self,
language_id: &LanguageIdentifier,
i18n_assets: &'a dyn I18nAssets
) -> (String, Option<Cow<'a, [u8]>>)
fn language_file<'a>(
&self,
language_id: &LanguageIdentifier,
i18n_assets: &'a dyn I18nAssets
) -> (String, Option<Cow<'a, [u8]>>)
The computed path to the language file, and Cow of the file
itself if it exists. Read more
sourcefn available_languages(
&self,
i18n_assets: &dyn I18nAssets
) -> Result<Vec<LanguageIdentifier>, I18nEmbedError>
fn available_languages(
&self,
i18n_assets: &dyn I18nAssets
) -> Result<Vec<LanguageIdentifier>, I18nEmbedError>
Calculate the languages which are available to be loaded.
sourcefn load_fallback_language(
&self,
i18n_assets: &dyn I18nAssets
) -> Result<(), I18nEmbedError>
fn load_fallback_language(
&self,
i18n_assets: &dyn I18nAssets
) -> Result<(), I18nEmbedError>
Load the LanguageLoader::fallback_language().
Auto Trait Implementations
impl !RefUnwindSafe for FluentLanguageLoader
impl Send for FluentLanguageLoader
impl Sync for FluentLanguageLoader
impl Unpin for FluentLanguageLoader
impl !UnwindSafe for FluentLanguageLoader
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more