pub struct FsTranslationsManager { /* private fields */ }
Expand description
The default translations manager. This will store static files in the specified location on disk. This should be suitable for nearly all development and serverful use-cases. Serverless is another matter though (more development needs to be done). 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.
Implementations
sourceimpl FsTranslationsManager
impl FsTranslationsManager
sourcepub async fn new(
root_path: String,
locales_to_cache: Vec<String>,
file_ext: String
) -> Self
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
sourceimpl Clone for FsTranslationsManager
impl Clone for FsTranslationsManager
sourcefn clone(&self) -> FsTranslationsManager
fn clone(&self) -> FsTranslationsManager
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for FsTranslationsManager
impl Debug for FsTranslationsManager
sourceimpl TranslationsManager for FsTranslationsManager
impl TranslationsManager for FsTranslationsManager
sourcefn new_dummy() -> Self
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
sourcefn get_translations_str_for_locale<'life0, 'async_trait>(
&'life0 self,
locale: String
) -> Pin<Box<dyn Future<Output = Result<String, TranslationsManagerError>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: '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
'life0: 'async_trait,
Self: '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. Read more
sourcefn get_translator_for_locale<'life0, 'async_trait>(
&'life0 self,
locale: String
) -> Pin<Box<dyn Future<Output = Result<Translator, TranslationsManagerError>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
fn get_translator_for_locale<'life0, 'async_trait>(
&'life0 self,
locale: String
) -> Pin<Box<dyn Future<Output = Result<Translator, TranslationsManagerError>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
Gets a translator for the given locale. If i18n is disabled, this should return an empty string.
Auto Trait Implementations
impl RefUnwindSafe for FsTranslationsManager
impl Send for FsTranslationsManager
impl Sync for FsTranslationsManager
impl Unpin for FsTranslationsManager
impl UnwindSafe for FsTranslationsManager
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more