Struct i18nx::Dictionary

source ·
pub struct Dictionary {
    pub locale: Option<&'static str>,
    pub resource: HashMap<&'static str, HashMap<&'static str, &'static str>>,
}
Expand description

Dictionary holds current locale and a map of translations for each locale.

Example:

use i18nx::Dictionary;

let mut dict = Dictionary::from_ron(r#"{
  "Hello {name}!": {
    "de": "Hallo {name}!",
    "fr": "Bonjour {name}!",
  },
}"#).unwrap();
dict.locale = Some("fr");
assert_eq!(
    dict.get("Hello {name}!").unwrap(),
    "Bonjour {name}!"
);

Fields§

§locale: Option<&'static str>

Locale is a string that holds the current language.

§resource: HashMap<&'static str, HashMap<&'static str, &'static str>>

The resource is a HashMap of translations, where the key is the message and the value is a HashMap of translations for each locale.

Implementations§

Constructs empty dictionary.

Constructs dictionary from RON string.

Adds translations from RON string to the dictionary.

Lookup a translation for the given key and locale.

Trait Implementations§

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.