pub trait TranslationsManager: Debug + Clone + Send + Sync {
    // Required methods
    fn get_translator_for_locale<'life0, 'async_trait>(
        &'life0 self,
        locale: String
    ) -> Pin<Box<dyn Future<Output = Result<Translator, TranslationsManagerError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get_translations_str_for_locale<'life0, 'async_trait>(
        &'life0 self,
        locale: String
    ) -> Pin<Box<dyn Future<Output = Result<String, TranslationsManagerError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get_translator_for_translations_str<'life0, 'async_trait>(
        &'life0 self,
        locale: String,
        translations_str: String
    ) -> Pin<Box<dyn Future<Output = Result<Translator, TranslationsManagerError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn new_dummy() -> Self;
}
Expand description

A trait for systems that manage where to put translations. At simplest, we’ll just write them to static files, but they might also be stored in a CMS. It is strongly advised that any implementations use some form of caching, guided by FsTranslationsManager.

Required Methods§

source

fn get_translator_for_locale<'life0, 'async_trait>( &'life0 self, locale: String ) -> Pin<Box<dyn Future<Output = Result<Translator, TranslationsManagerError>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Gets a translator for the given locale. If i18n is disabled, this should return an empty string.

source

fn get_translations_str_for_locale<'life0, 'async_trait>( &'life0 self, locale: String ) -> Pin<Box<dyn Future<Output = Result<String, TranslationsManagerError>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Gets the translations in string format for the given locale (avoids deserialize-then-serialize). If i18n is disabled, this should return a translator for the given locale with no translation string.

source

fn get_translator_for_translations_str<'life0, 'async_trait>( &'life0 self, locale: String, translations_str: String ) -> Pin<Box<dyn Future<Output = Result<Translator, TranslationsManagerError>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Gets a translator for the given locale and translations string. This is intended as an internal convenience method to minimize extra computation when both a translations string and a translator are required for the same locale.

Warning: providing a mismatched translations string and locale to this function will lead to chaos.

source

fn new_dummy() -> Self

Creates a new instance of this translations manager, as a dummy for apps that aren’t using i18n at all. This may seem pointless, but it’s needed for trait completeness and to support certain engine middleware use-cases. In general, this should simply create an empty instance of the manager, and all other functions should do nothing if it is empty.

Notably, this must be synchronous.

Implementors§