Struct r_i18n::i18n::I18n [−][src]
pub struct I18n<'b> { pub config: &'b I18nConfig<'b>, pub current_lang: &'b str, pub translations: HashMap<String, JsonValue>, }
Fields
config: &'b I18nConfig<'b>
current_lang: &'b str
translations: HashMap<String, JsonValue>
Methods
impl<'b> I18n<'b>
[src]
impl<'b> I18n<'b>
pub fn configure(config: &'b I18nConfig<'b>) -> I18n<'b>
[src]
pub fn configure(config: &'b I18nConfig<'b>) -> I18n<'b>
Configures the library
Example
extern crate i18n;
use i18n::I18n;
use i18n::I18nConfig;
extern crate r_i18n;
use r_i18n::I18n;
use r_i18n::I18nConfig;
fn main() {
let config: I18nConfig = I18nConfig{locales: &["en", "fr", "es"], directory: "translations"};
let i18n: I18n = I18n::configure(&config);
}
pub fn set_current_lang(&mut self, lang: &'b str)
[src]
pub fn set_current_lang(&mut self, lang: &'b str)
Sets the current language
Example
extern crate r_i18n;
use r_i18n::I18n;
use r_i18n::I18nConfig;
fn main() {
let config: I18nConfig = I18nConfig{locales: &["en", "fr", "es"], directory: "translations"};
let mut r_i18n: I18n = I18n::configure(&config);
r_i18n.set_current_lang("fr");
}
pub fn t(&self, key: &'b str) -> &JsonValue
[src]
pub fn t(&self, key: &'b str) -> &JsonValue
Translates by the keyword
Example
extern crate i18n;
use i18n::I18n;
use i18n::I18nConfig;
extern crate r_i18n;
use r_i18n::I18n;
use r_i18n::I18nConfig;
fn main() {
let config: I18nConfig = I18nConfig{locales: &["en", "fr", "es"], directory: "translations"};
let mut i18n: I18n = I18n::configure(&config);
i18n.set_current_lang("fr");
i18n.t("introduction"); // output should be "Bonjour, mon nom est WebD
}