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

source

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.

source

pub fn current_languages(&self) -> Vec<LanguageIdentifier>

The languages associated with each actual currently loaded language bundle.

source

pub fn get(&self, message_id: &str) -> String

Get a localized message referenced by the message_id.

source

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().

source

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.

source

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.

source

pub fn get_attr(&self, message_id: &str, attribute_id: &str) -> String

Get a localized attribute referenced by the message_id and attribute_id.

source

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().

source

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.

source

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.

source

pub fn get_lang(&self, lang: &[&LanguageIdentifier], message_id: &str) -> String

👎Deprecated since 0.13.6: Please use select_languages(...).get(...) instead

Get a localized message referenced by the message_id.

source

pub 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

A non-generic version of FluentLanguageLoader::get_lang_args().

source

pub 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

A non-generic version of FluentLanguageLoader::get_lang_args() accepting [FluentArgs] instead of a HashMap.

source

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,

👎Deprecated since 0.13.6: Please use select_languages(...).get_args(...) instead

Get a localized message for the given language identifiers, referenced by the message_id and formatted with the specified args.

source

pub 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

Get a localized attribute referenced by the Message_id and attribute_id.

source

pub 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
source

pub 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

A non-generic version of FluentLanguageLoader::get_lang_attr_args() accepting [FluentArgs] instead of a HashMap.

source

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,

👎Deprecated since 0.13.6: Please use lang(...).get_attr_args(...) instead

Get a localized attribute referenced by the message_id and attribute_id and formatted with the args.

source

pub fn has(&self, message_id: &str) -> bool

available in any of the languages currently loaded (including the fallback language).

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn lang<LI: AsRef<LanguageIdentifier>>( &self, languages: &[LI] ) -> FluentLanguageLoader

👎Deprecated since 0.13.7: Please use select_languages(...) instead

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.

source

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.

source

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

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl LanguageLoader for FluentLanguageLoader

source§

fn fallback_language(&self) -> &LanguageIdentifier

The fallback language for the module this loader is responsible for.

source§

fn domain(&self) -> &str

The domain for the translation that this loader is associated with.

source§

fn language_file_name(&self) -> String

The language file name to use for this loader.

source§

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>

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]>>)

The computed path to the language file, and Cow of the file itself if it exists.
source§

fn available_languages( &self, i18n_assets: &dyn I18nAssets ) -> Result<Vec<LanguageIdentifier>, I18nEmbedError>

Calculate the languages which are available to be loaded.
source§

fn load_available_languages( &self, i18n_assets: &dyn I18nAssets ) -> Result<(), I18nEmbedError>

Load all available languages with LanguageLoader::load_languages().
source§

fn load_fallback_language( &self, i18n_assets: &dyn I18nAssets ) -> Result<(), I18nEmbedError>

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.