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

Methods

impl<'b> I18n<'b>
[src]

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);
}

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");
}

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
}

Auto Trait Implementations

impl<'b> Send for I18n<'b>

impl<'b> Sync for I18n<'b>