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§
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>) -> Stringwhere
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>) -> Stringwhere 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_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>
) -> Stringwhere
S: Into<Cow<'a, str>> + Clone,
V: Into<FluentValue<'a>> + Clone,
pub fn get_attr_args<'a, S, V>( &self, message_id: &str, attribute_id: &str, args: HashMap<S, V> ) -> Stringwhere S: Into<Cow<'a, str>> + Clone, V: Into<FluentValue<'a>> + Clone,
Get a localized attribute referenced by the message_id
and attribute_id
, and
formatted with the specified args
.
sourcepub fn get_lang(&self, lang: &[&LanguageIdentifier], message_id: &str) -> String
👎Deprecated since 0.13.6: Please use select_languages(...).get(...)
instead
pub fn get_lang(&self, lang: &[&LanguageIdentifier], message_id: &str) -> String
select_languages(...).get(...)
insteadGet 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
👎Deprecated since 0.13.6: Please use select_languages(...).get_args_concrete(...)
instead
pub fn get_lang_args_concrete<'source>( &self, lang: &[&LanguageIdentifier], message_id: &str, args: HashMap<&'source str, FluentValue<'source>> ) -> String
select_languages(...).get_args_concrete(...)
insteadA 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
👎Deprecated since 0.13.6: Please use select_languages(...).get_args_fluent(...)
instead
pub fn get_lang_args_fluent<'args>( &self, lang: &[&LanguageIdentifier], message_id: &str, args: Option<&'args FluentArgs<'args>> ) -> String
select_languages(...).get_args_fluent(...)
insteadA 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>
) -> Stringwhere
S: Into<Cow<'a, str>> + Clone,
V: Into<FluentValue<'a>> + Clone,
👎Deprecated since 0.13.6: Please use select_languages(...).get_args(...)
instead
pub fn get_lang_args<'a, S, V>( &self, lang: &[&LanguageIdentifier], id: &str, args: HashMap<S, V> ) -> Stringwhere S: Into<Cow<'a, str>> + Clone, V: Into<FluentValue<'a>> + Clone,
select_languages(...).get_args(...)
insteadGet a localized message for the given language identifiers, referenced
by the message_id
and formatted with the specified args
.
sourcepub fn get_lang_attr(
&self,
lang: &[&LanguageIdentifier],
message_id: &str,
attribute_id: &str
) -> String
👎Deprecated since 0.13.6: Please use select_languages(...).get_attr(...)
instead
pub fn get_lang_attr( &self, lang: &[&LanguageIdentifier], message_id: &str, attribute_id: &str ) -> String
select_languages(...).get_attr(...)
insteadGet a localized attribute referenced by the Message_id
and attribute_id
.
sourcepub fn get_lang_attr_args_concrete<'source>(
&self,
lang: &[&LanguageIdentifier],
message_id: &str,
attribute_id: &str,
args: HashMap<&'source str, FluentValue<'source>>
) -> String
👎Deprecated since 0.13.6: Please use select_languages(...).get_attr_args_concrete(...)
instead
pub fn get_lang_attr_args_concrete<'source>( &self, lang: &[&LanguageIdentifier], message_id: &str, attribute_id: &str, args: HashMap<&'source str, FluentValue<'source>> ) -> String
select_languages(...).get_attr_args_concrete(...)
insteadA non-generic version of FluentLanguageLoader::get_lang_attr_args().
sourcepub fn get_lang_attr_args_fluent<'args>(
&self,
lang: &[&LanguageIdentifier],
message_id: &str,
attribute_id: &str,
args: Option<&'args FluentArgs<'args>>
) -> String
👎Deprecated since 0.13.6: Please use select_languages(...).get_attr_args_fluent(...)
instead
pub fn get_lang_attr_args_fluent<'args>( &self, lang: &[&LanguageIdentifier], message_id: &str, attribute_id: &str, args: Option<&'args FluentArgs<'args>> ) -> String
select_languages(...).get_attr_args_fluent(...)
insteadA non-generic version of FluentLanguageLoader::get_lang_attr_args() accepting [FluentArgs] instead of a HashMap.
sourcepub fn get_lang_attr_args<'a, S, V>(
&self,
lang: &[&LanguageIdentifier],
message_id: &str,
attribute_id: &str,
args: HashMap<S, V>
) -> Stringwhere
S: Into<Cow<'a, str>> + Clone,
V: Into<FluentValue<'a>> + Clone,
👎Deprecated since 0.13.6: Please use lang(...).get_attr_args(...)
instead
pub fn get_lang_attr_args<'a, S, V>( &self, lang: &[&LanguageIdentifier], message_id: &str, attribute_id: &str, args: HashMap<S, V> ) -> Stringwhere S: Into<Cow<'a, str>> + Clone, V: Into<FluentValue<'a>> + Clone,
lang(...).get_attr_args(...)
insteadGet a localized attribute referenced by the message_id
and attribute_id
and formatted with the 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_message_iter<OUT, C>(
&self,
language: &LanguageIdentifier,
closure: C
) -> OUTwhere
C: Fn(&mut dyn Iterator<Item = &Message<&str>>) -> OUT,
pub fn with_message_iter<OUT, C>( &self, language: &LanguageIdentifier, closure: C ) -> OUTwhere 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.
sourcepub fn lang<LI: AsRef<LanguageIdentifier>>(
&self,
languages: &[LI]
) -> FluentLanguageLoader
👎Deprecated since 0.13.7: Please use select_languages(...)
instead
pub fn lang<LI: AsRef<LanguageIdentifier>>( &self, languages: &[LI] ) -> FluentLanguageLoader
select_languages(...)
insteadCreate 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<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(
&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.
source§fn 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]>>)
Cow
of the file
itself if it exists.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()
.