[][src]Trait i18n_embed::LanguageLoader

pub trait LanguageLoader {
    fn fallback_language(&self) -> &LanguageIdentifier;
fn domain(&self) -> &str;
fn language_file_name(&self) -> String;
fn current_language(&self) -> LanguageIdentifier;
fn load_languages(
        &self,
        i18n_assets: &dyn I18nAssets,
        language_ids: &[&LanguageIdentifier]
    ) -> Result<(), I18nEmbedError>; fn language_file<'a>(
        &self,
        language_id: &LanguageIdentifier,
        i18n_assets: &'a dyn I18nAssets
    ) -> (String, Option<Cow<'a, [u8]>>) { ... }
fn available_languages(
        &self,
        i18n_assets: &dyn I18nAssets
    ) -> Result<Vec<LanguageIdentifier>, I18nEmbedError> { ... } }

A trait used by I18nAssets to load a language file for a specific rust module using a specific localization system. The trait is designed such that the loader could be swapped during runtime, or contain state if required.

Required methods

fn fallback_language(&self) -> &LanguageIdentifier

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

fn domain(&self) -> &str

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

fn language_file_name(&self) -> String

The language file name to use for this loader's domain.

fn current_language(&self) -> LanguageIdentifier

Get the language which is currently loaded for this loader.

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_embed 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.

Loading content...

Provided methods

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.

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

Calculate the languages which are available to be loaded.

Loading content...

Implementors

impl LanguageLoader for FluentLanguageLoader[src]

fn fallback_language(&self) -> &LanguageIdentifier[src]

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

fn domain(&self) -> &str[src]

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

fn language_file_name(&self) -> String[src]

The language file name to use for this loader.

fn current_language(&self) -> LanguageIdentifier[src]

Get the language which is currently loaded for this loader.

fn load_languages(
    &self,
    i18n_assets: &dyn I18nAssets,
    language_ids: &[&LanguageIdentifier]
) -> Result<(), I18nEmbedError>
[src]

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.

impl LanguageLoader for GettextLanguageLoader[src]

fn fallback_language(&self) -> &LanguageIdentifier[src]

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

fn domain(&self) -> &'static str[src]

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

fn language_file_name(&self) -> String[src]

The language file name to use for this loader's domain.

fn current_language(&self) -> LanguageIdentifier[src]

Get the language which is currently loaded for this loader.

fn load_languages(
    &self,
    i18n_assets: &dyn I18nAssets,
    language_ids: &[&LanguageIdentifier]
) -> Result<(), I18nEmbedError>
[src]

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.

Note: Gettext doesn't support loading multiple languages as multiple fallbacks. We only load the first of the requested languages, and the fallback is the src language.

Loading content...