Skip to main content

install

Function install 

Source
pub fn install(ctx: &Context, i18n: &I18n)
Expand description

Installs catalogues in an egui context, for an application that does not use App and its I18nPlugin: t, text and of read them in this context, crate::tr! reads them through global, and egui-pop’s own text is translated through a Provider installed as the context’s strings provider. I18nPlugin installs its catalogues this way when it connects.

I18n is shared: a later I18n::set_locale or I18n::add shows at the next lookup, without installing again. The global is the process’s, so the last call wins when several contexts install different catalogues. The plugin’s other duties (the language setting, the i18n.resolve step, locale.changed) are left out: the application sets the locale itself.

use egui_pop_i18n::{I18n, args, install, t, tr};

let i18n = I18n::new("fr");
i18n.add("fr", "hello = Bonjour, { $name } !\n").unwrap();
let ctx = egui::Context::default();
install(&ctx, &i18n);
assert_eq!(t(&ctx, "hello", &args![name = "Ada"]), "Bonjour, Ada !");
assert_eq!(tr!("hello", name = "Ada"), "Bonjour, Ada !");