Skip to main content

Module extract

Module extract 

Source
Expand description

The extractor: which keys an application uses, with their English; the English catalogue written from them; and, per locale, the keys missing or unused.

Keys come from two places:

  • sources (scan, scan_tree): calls written in Rust with a literal key, tr!("key"), t(ctx, "key", …), text(ctx, "key", "English", …), StrKey::new("key", "English"), lookup(ctx, "key", "English") (see Pattern::DEFAULTS; an application adds its own), under any path (app::Message::new); a constructor call it cannot read is reported (Scan::unread);
  • declarations (declarations): what the plugins of a built application declare (commands, categories, panels, submenus, settings and their choices, plugins), under the keys egui_pop_core::strings derives from their ids.

english writes the English catalogue from them, sorted, so the same keys always give the same bytes; update merges them into an existing one, keeping the English written there for keys the code gives none; out_of_date checks a catalogue against them, listing the calls not read; report compares every locale with them.

use egui_pop_i18n::extract::{self, Pattern};

let src = r#"
    ui.label(tr!("welcome"));
    const SAVE: StrKey = StrKey::new("app-save", "Save { $name }");
"#;
let found = extract::scan_source(src, "src/lib.rs", Pattern::DEFAULTS);
let messages = extract::messages(&found).unwrap();
let ftl = extract::english(&messages, "");
assert!(ftl.contains("app-save = Save { $name }\n"));
assert!(ftl.contains("welcome = welcome\n"), "{ftl}");

Structs§

Found
A key found, with its English and where.
LocaleKeys
One locale against what the code uses.
Pattern
A call whose arguments hold a key, and maybe its English.
Scan
What a scan gives: the keys found, and the constructor calls that could not be read.
Unread
A call the scanner took for a message constructor but could not read: the message it declares is missing from what was found, or found without its English.
Updated
An English catalogue brought up to date.

Enums§

English
A key’s English, as found.

Constants§

COMMAND_TITLE_VARIABLES
The variables a command’s title may say ({ $application }, the application’s name), filled where the title is drawn.

Functions§

declarations
What a built application declares, under the keys egui_pop_core::strings derives: commands (title, description, category; a panel’s focus and toggle commands only their category, their texts being shared), panels, submenus (from the main menu and menus), settings (label, description, each choice), plugins (title) and the context stack’s frames (title).
english
The English catalogue of messages: sorted, the same keys giving the same bytes; a key without English reads as itself. header (a Fluent comment, # … lines) comes first.
escape
Text as a Fluent pattern that formats back to itself: braces are string literals, continuation lines indented, and a continuation line that would read as syntax quoted.
messages
What was found, by key. Refused when one key is given two different English texts (two ids that differ only by punctuation, one key used with two texts); categories, keyed by their English, keep the first.
out_of_date
The catalogue check of an English catalogue: None when current (the file at path) is fresh (what english or update writes now); else the failure message, saying path is out of date and listing unread (see Scan::unread), the calls whose messages are missing from it.
plain_with
Plain text in which the placeables of variables ({ $name } or {$name}) stay placeables: English::Plain when it has none, else an English::Pattern with every other brace escaped.
report
Every locale of catalogs against the keys the code uses.
scan
The keys a Rust source uses through patterns, with their English, and the constructor calls it could not read.
scan_dir
scan_tree’s keys, its unread calls only logged.
scan_source
The keys a Rust source uses through patterns, with their English: scan’s keys, its unread calls only logged.
scan_tree
scan over every .rs file under dir (target and hidden directories skipped), files in a stable order; origins are relative to dir.
update
messages merged into the English catalogue source: the code’s English wins; for a key the code gives none, the catalogue’s is kept (a new one reads as its key). Unused keys are kept unless prune. The result is sorted like english.
valid_key
A key as Fluent allows it: an identifier, optionally .attribute.

Type Aliases§

Messages
Keys with their English, deduplicated.