pub struct Localizer {
initialized: bool,
data: HashMap<String, Rc<str>>,
}
Expand description
An object that localizes strings. It reads localization data from a directory and provides localized strings. If the localization data is not found, it will demangle the key using an algorithm that tries to approximate the intended text
Fields§
§initialized: bool
Whether at least a single file has been loaded
data: HashMap<String, Rc<str>>
Implementations§
Source§impl Localizer
impl Localizer
Sourcepub fn add_from_path<P: AsRef<Path>>(&mut self, path: P)
pub fn add_from_path<P: AsRef<Path>>(&mut self, path: P)
Adds localization data from a directory. The path may be invalid, in which case the function will simply do nothing
pub fn add_localization_file(&mut self, contents: &str)
pub fn remove_formatting(&mut self)
Trait Implementations§
Source§impl Localize<Rc<str>> for Localizer
impl Localize<Rc<str>> for Localizer
Source§fn lookup<K: AsRef<str>>(&self, key: K) -> Option<Rc<str>>
fn lookup<K: AsRef<str>>(&self, key: K) -> Option<Rc<str>>
A simple function that looks up raw value associated with the given localization key
fn is_empty(&self) -> bool
Source§fn localize<K: AsRef<str>>(&self, key: K) -> Result<T, LocalizationError>
fn localize<K: AsRef<str>>(&self, key: K) -> Result<T, LocalizationError>
A simple localization function that will return the localized string.
It assumes that the key is not complex and does not require any special handling.
Source§fn localize_provider<K: AsRef<str>>(
&self,
key: K,
provider: &str,
value: &str,
) -> Result<T, LocalizationError>
fn localize_provider<K: AsRef<str>>( &self, key: K, provider: &str, value: &str, ) -> Result<T, LocalizationError>
A localization function that will return the localized string.
It assumes a more complex key, resolving $provider$ into the value.
More complex keys will not be resolved.
Source§fn localize_query<K: AsRef<str>, S: AsRef<str>, F: Fn(&Vec<(String, Vec<String>)>) -> Option<S>>(
&self,
key: K,
query: F,
) -> Result<T, LocalizationError>
fn localize_query<K: AsRef<str>, S: AsRef<str>, F: Fn(&Vec<(String, Vec<String>)>) -> Option<S>>( &self, key: K, query: F, ) -> Result<T, LocalizationError>
A localization function that will return the localized string.
It allows for complete control over the complex key resolution.
Every time a $key$ or [function(arg)] is encountered, the query function will be called.
The query function should return the value in accordance to the provided stack, or None if the value is not found.
Whether None causes an error or not is up to the implementation.
Auto Trait Implementations§
impl Freeze for Localizer
impl RefUnwindSafe for Localizer
impl !Send for Localizer
impl !Sync for Localizer
impl Unpin for Localizer
impl UnwindSafe for Localizer
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian()
.