pub struct Translator { /* private fields */ }Expand description
Per-request translator handle.
Holds the resolved request locale and a handle to the shared
TranslationStore. Produced by I18nLayer and
extracted by handlers through the axum extractor impl below, or built
directly via I18n::translator for non-request
contexts.
Cheaply cloneable — TranslationStore is an Arc internally and locale
is a short String.
Implementations§
Source§impl Translator
impl Translator
Sourcepub fn t(&self, key: &str, kwargs: &[(&str, &str)]) -> String
pub fn t(&self, key: &str, kwargs: &[(&str, &str)]) -> String
Translates key, interpolating any {placeholder} values from kwargs.
Falls back to the default locale and then to the key itself if no entry is found. Never panics.
Sourcepub fn t_plural(&self, key: &str, count: i64, kwargs: &[(&str, &str)]) -> String
pub fn t_plural(&self, key: &str, count: i64, kwargs: &[(&str, &str)]) -> String
Translates key with plural-rule selection based on count.
count is also injected into kwargs under the name count.
Sourcepub fn store(&self) -> &TranslationStore
pub fn store(&self) -> &TranslationStore
Returns the shared TranslationStore this translator reads from.
Trait Implementations§
Source§impl Clone for Translator
impl Clone for Translator
Source§fn clone(&self) -> Translator
fn clone(&self) -> Translator
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Translator
impl Debug for Translator
Source§impl<S: Send + Sync> FromRequestParts<S> for Translator
impl<S: Send + Sync> FromRequestParts<S> for Translator
Auto Trait Implementations§
impl Freeze for Translator
impl RefUnwindSafe for Translator
impl Send for Translator
impl Sync for Translator
impl Unpin for Translator
impl UnsafeUnpin for Translator
impl UnwindSafe for Translator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
Source§type Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
If the extractor fails it’ll use this “rejection” type. A rejection is
a kind of error that can be converted into a response.
Source§fn from_request(
req: Request<Body>,
state: &S,
) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
Perform the extraction.