Skip to main content

Crate egui_pop_i18n

Crate egui_pop_i18n 

Source
Expand description

Translations for egui-pop applications, over Fluent.

  • I18nPlugin: the plugin. It loads catalogues (egui-pop’s own, the application’s, an override directory), declares the appearance.language setting, publishes locale.changed, declares the i18n.resolve step, adds the i18n debug collector, and installs the interface’s strings provider so egui-pop’s own text and what plugins declare are translated (see plugin).
  • I18n: the catalogues and the locale, shared; t, text and tr! look text up. Without App, install puts an I18n in an egui context for them and for egui-pop’s own text. A lookup tries the locale, its parents (fr-CA, then fr), then English; a key missing everywhere shows the English written in the code, else the key.
  • format: numbers, dates and plurals for the locale, in Rust and in catalogues (NUMBER, DATETIME).
  • locale: tags, the locale to use, fallback chains.
  • extract and check: for tools, the keys the code uses, the English catalogue written from them, and per locale the keys missing, unused or changed since translated.
use egui_pop_api::App;
use egui_pop_i18n::{Catalogue, I18nPlugin, args, plugin, t};

static CATALOGUES: &[Catalogue] = &[
    Catalogue::new("en", "app.ftl", "hello = Hello, { $name }!\n"),
    Catalogue::new("fr", "app.ftl", "hello = Bonjour, { $name } !\n"),
];

let ctx = egui::Context::default();
let mut app = App::builder()
    .plugin(I18nPlugin::new().catalogues(CATALOGUES))
    .build(&ctx)
    .unwrap();
plugin::set_language(app.handle(), "fr").unwrap();
let mut said = String::new();
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| {
    app.show(ui);
    said = t(ui.ctx(), "hello", &args![name = "Ada"]);
});
out.textures_delta.clear();
assert_eq!(said, "Bonjour, Ada !");

Re-exports§

pub use plugin::I18nPlugin;
pub use plugin::ShowKeys;
pub use plugin::global;
pub use plugin::install;
pub use plugin::t;
pub use plugin::text;

Modules§

catalog
Looking text up: one Fluent bundle per locale and a fallback chain ending in English.
check
Checks a directory of catalogues (<dir>/<locale>/*.ftl): per locale, coverage, missing and orphan keys, and keys whose English changed since they were translated; across them, the faults that must fail a build.
extract
The extractor: which keys an application uses, with their English; the English catalogue written from them; and, per locale, the keys missing or unused.
format
Locale-aware numbers and dates, for Rust code and for catalogues.
locale
Locale tags: their canonical form, which one to use, and the chain a lookup falls back along.
plugin
The plugin: I18nPlugin connects an I18n to an application.

Macros§

args
Builds lookup arguments: args![count = 3, name = "Ada"].
tr
The text of a key from the catalogues last installed, by install or the connected I18nPlugin (global), with named arguments; the key itself when no catalogue has it. The extractor finds its literal keys.

Structs§

Catalogue
One catalogue file built into the application: its locale, a name for messages, and its Fluent source (usually include_str!).
FluentArgs
Fluent messages can use arguments in order to programmatically add values to a translated string. For instance, in a localized application you may wish to display a user’s email count. This could be done with the following message.
I18n
The application’s catalogues and its locale. Cheap to clone: clones share them.
Provider
The interface’s strings (egui_pop_core::strings) read from an I18n, in one locale: installed in the egui context by the plugin, again whenever the locale changes.

Enums§

FluentValue
The FluentValue enum represents values which can be formatted to a String.

Constants§

EGUI_POP
egui-pop’s own catalogues: the interface’s strings and what its plugins declare, in English and French.

Type Aliases§

Args
Arguments of a lookup, by name.