pub struct FluentLanguageLoader { /* private fields */ }Expand description
LanguageLoader implementation 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§
Source§impl 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>
pub fn current_languages(&self) -> Vec<LanguageIdentifier>
The languages associated with each actual currently 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
pub fn get_args<'a, S, V>(&self, id: &str, args: HashMap<S, V>) -> String
Get a localized message referenced by the message_id, and
formatted with the specified args.
Sourcepub fn get_attr(&self, message_id: &str, attribute_id: &str) -> String
pub fn get_attr(&self, message_id: &str, attribute_id: &str) -> String
Get a localized attribute referenced by the message_id and attribute_id.
Sourcepub fn get_attr_args_concrete<'args>(
&self,
message_id: &str,
attribute_id: &str,
args: HashMap<&'args str, FluentValue<'args>>,
) -> String
pub fn get_attr_args_concrete<'args>( &self, message_id: &str, attribute_id: &str, args: HashMap<&'args str, FluentValue<'args>>, ) -> String
A non-generic version of FluentLanguageLoader::get_attr_args().
Sourcepub fn get_attr_args_fluent<'args>(
&self,
message_id: &str,
attribute_id: &str,
args: Option<&'args FluentArgs<'args>>,
) -> String
pub fn get_attr_args_fluent<'args>( &self, message_id: &str, attribute_id: &str, args: Option<&'args FluentArgs<'args>>, ) -> String
A non-generic version of FluentLanguageLoader::get_attr_args() accepting FluentArgs instead of a HashMap.
Sourcepub fn get_attr_args<'a, S, V>(
&self,
message_id: &str,
attribute_id: &str,
args: HashMap<S, V>,
) -> String
pub fn get_attr_args<'a, S, V>( &self, message_id: &str, attribute_id: &str, args: HashMap<S, V>, ) -> String
Get a localized attribute referenced by the message_id and attribute_id, and
formatted with the specified args.
Sourcepub fn has(&self, message_id: &str) -> bool
pub fn has(&self, message_id: &str) -> bool
available in any of the languages currently loaded (including the fallback language).
Sourcepub fn has_attr(&self, message_id: &str, attribute_id: &str) -> bool
pub fn has_attr(&self, message_id: &str, attribute_id: &str) -> bool
Determines if an attribute associated with the specified message_id
is available in any of the currently loaded languages, including the fallback language.
Returns true if at least one available instance was found, false otherwise.
Note that this also returns false if the message_id could not be found;
use FluentLanguageLoader::has() to determine if the message_id is available.
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_fluent_message_and_bundle<OUT, C>(
&self,
message_id: &str,
closure: C,
) -> Option<OUT>
pub fn with_fluent_message_and_bundle<OUT, C>( &self, message_id: &str, closure: C, ) -> Option<OUT>
Searches for a message named message_id in all languages that
are currently loaded, including the fallback language. If the
message is found, invokes the closure with the:
Returns Some of 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
pub fn with_message_iter<OUT, C>( &self, language: &LanguageIdentifier, closure: C, ) -> 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)
pub fn with_bundles_mut<F>(&self, f: F)
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.
Sourcepub fn select_languages<LI: AsRef<LanguageIdentifier>>(
&self,
languages: &[LI],
) -> FluentLanguageLoader
pub fn select_languages<LI: AsRef<LanguageIdentifier>>( &self, languages: &[LI], ) -> FluentLanguageLoader
Create a new loader with a subset of currently loaded languages. This is a rather cheap operation and does not require any extensive copy operations. Cheap does not mean free so you should not call this message repeatedly in order to translate multiple strings for the same language.
Sourcepub fn select_languages_negotiate<LI: AsRef<LanguageIdentifier>>(
&self,
languages: &[LI],
strategy: NegotiationStrategy,
) -> FluentLanguageLoader
pub fn select_languages_negotiate<LI: AsRef<LanguageIdentifier>>( &self, languages: &[LI], strategy: NegotiationStrategy, ) -> FluentLanguageLoader
Select the requested languages from the currently loaded languages using the supplied
NegotiationStrategy.
Trait Implementations§
Source§impl Debug for FluentLanguageLoader
impl Debug for FluentLanguageLoader
Source§impl LanguageLoader for FluentLanguageLoader
impl LanguageLoader for FluentLanguageLoader
Source§fn fallback_language(&self) -> &LanguageIdentifier
fn fallback_language(&self) -> &LanguageIdentifier
The fallback language for the module this loader is responsible for.
Source§fn language_file_name(&self) -> String
fn language_file_name(&self) -> String
The language file name to use for this loader.
Source§fn current_language(&self) -> LanguageIdentifier
fn current_language(&self) -> LanguageIdentifier
Get the language which is currently selected for this loader.
Source§fn load_languages<'a>(
&self,
i18n_assets: &dyn I18nAssets,
language_ids: &[LanguageIdentifier],
) -> Result<(), I18nEmbedError>
fn load_languages<'a>( &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.
Source§fn reload(&self, i18n_assets: &dyn I18nAssets) -> Result<(), I18nEmbedError>
fn reload(&self, i18n_assets: &dyn I18nAssets) -> Result<(), I18nEmbedError>
Source§fn language_files<'a>(
&self,
language_id: &LanguageIdentifier,
i18n_assets: &'a dyn I18nAssets,
) -> (String, Vec<Cow<'a, [u8]>>)
fn language_files<'a>( &self, language_id: &LanguageIdentifier, i18n_assets: &'a dyn I18nAssets, ) -> (String, Vec<Cow<'a, [u8]>>)
Source§fn available_languages(
&self,
i18n_assets: &dyn I18nAssets,
) -> Result<Vec<LanguageIdentifier>, I18nEmbedError>
fn available_languages( &self, i18n_assets: &dyn I18nAssets, ) -> Result<Vec<LanguageIdentifier>, I18nEmbedError>
Source§fn load_available_languages(
&self,
i18n_assets: &dyn I18nAssets,
) -> Result<(), I18nEmbedError>
fn load_available_languages( &self, i18n_assets: &dyn I18nAssets, ) -> Result<(), I18nEmbedError>
LanguageLoader::load_languages().