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 theappearance.languagesetting, publisheslocale.changed, declares thei18n.resolvestep, adds thei18ndebug collector, and installs the interface’s strings provider so egui-pop’s own text and what plugins declare are translated (seeplugin).I18n: the catalogues and the locale, shared;t,textandtr!look text up. WithoutApp,installputs anI18nin an egui context for them and for egui-pop’s own text. A lookup tries the locale, its parents (fr-CA, thenfr), 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.extractandcheck: 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:
I18nPluginconnects anI18nto an application.
Macros§
- args
- Builds lookup arguments:
args![count = 3, name = "Ada"]. - tr
- The text of a key from the catalogues last installed, by
installor the connectedI18nPlugin(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!). - Fluent
Args - 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 anI18n, in one locale: installed in the egui context by the plugin, again whenever the locale changes.
Enums§
- Fluent
Value - The
FluentValueenum 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.