pub struct Translator { /* private fields */ }Expand description
A lightweight, request-scoped translation helper.
Translator stores a locale identifier and forwards lookups to the global
Lang store without mutating the process-wide active locale. This makes
it a good fit for web handlers, jobs, and other code paths where locale is
part of the input rather than part of global application state.
§Examples
use lang_lib::{Lang, Translator};
Lang::load_from("en", "tests/fixtures/locales").unwrap();
let translator = Translator::new("en");
let title = translator.translate_with_fallback("welcome", "Welcome");
assert_eq!(title, "Welcome");Implementations§
Source§impl Translator
impl Translator
Sourcepub fn translate_with_fallback(&self, key: &str, fallback: &str) -> String
pub fn translate_with_fallback(&self, key: &str, fallback: &str) -> String
Translates a key using this translator’s locale and an inline fallback.
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 PartialEq for Translator
impl PartialEq for Translator
impl Eq for Translator
impl StructuralPartialEq 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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.