Localizer

Struct Localizer 

Source
pub struct Localizer<'this> { /* private fields */ }
Expand description

Heart and soul of this crated. Intended to be initialized once.

Implementations§

Source§

impl<'this> Localizer<'this>

Source

pub fn new(locales_path: impl AsRef<Path>) -> Self

Creates new Localizer and searches for available locales in specified folder.

Source

pub fn precache_all(self) -> Self

Loads all available locales into internal cache.

Source

pub fn debug(self, enable: bool) -> Self

Enables debug mode. This mostly means that Localizer will prefer fetching locales from disk rather than cache.

Source

pub fn default_locale(self, default_locale: &'static str) -> Self

Source

pub fn localize<'w>(&mut self, tag: &'w str) -> Result<&Locale, LocaleError>
where 'w: 'this,

§Normal mode

Looks up cache for tag. If not found fetches locale from disk and overwrites old value in cache, returns a reference to new locale afterwards. Otherwise returns cached value.

§Debug mode

Looks up available locales on disk for specified tag. If found, overwrites locale in cache with value from disk and returns a reference to it. Otherwise tries to fetch the locale from cache.

Source

pub fn localize_no_cache<'w>( &self, tag: &'w str, ) -> Result<Cow<'_, Locale>, LocaleError>
where 'w: 'this,

§Normal mode

Looks up cache for tag. If not found fetches locale from disk and returns borrowed value of it. Otherwise returns cached value.

§Debug mode

Looks up available locales for specified tag. If found fetches locale from disk and returns owned value of it. Otherwise returns an error.

Auto Trait Implementations§

§

impl<'this> Freeze for Localizer<'this>

§

impl<'this> RefUnwindSafe for Localizer<'this>

§

impl<'this> Send for Localizer<'this>

§

impl<'this> Sync for Localizer<'this>

§

impl<'this> !Unpin for Localizer<'this>

§

impl<'this> UnwindSafe for Localizer<'this>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.