pub struct FsTranslationsManager { /* private fields */ }
Expand description

The default translations manager. This will store static files in the specified location on disk, which should be suitable for the majority of use-cases, though users who want to store translations somewhere other than on the filesystem should use an alternative implementation. This mandates that translations be stored as files named as the locale they describe (e.g. ‘en-US.ftl’, ‘en-US.json’, etc.).

As this is used as the default translations manager by most apps, this also supports not using i18n at all (a dummy translations manager).

Note that this will cache translations upon initialization, meaning source files cannot be updated while the system is running.

Implementations§

source§

impl FsTranslationsManager

source

pub async fn new( root_path: String, locales_to_cache: Vec<String>, file_ext: String ) -> Self

Creates a new filesystem translations manager. You should provide a path like translations/ here. You should also provide the locales you want to cache, which will have their translations stored in memory. Any supported locales not specified here will not be cached, and must have their translations read from disk on every request. If fetching translations for any of the given locales fails, this will panic (locales to be cached should always be hardcoded).

Trait Implementations§

source§

impl Clone for FsTranslationsManager

source§

fn clone(&self) -> FsTranslationsManager

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for FsTranslationsManager

source§

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

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

impl TranslationsManager for FsTranslationsManager

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. Read more
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_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_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. Read more

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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.