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")(seePattern::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 keysegui_pop_core::stringsderives 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.
- Locale
Keys - 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::stringsderives: commands (title, description, category; a panel’sfocusandtogglecommands only their category, their texts being shared), panels, submenus (from the main menu andmenus), 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:
Nonewhencurrent(the file atpath) isfresh(whatenglishorupdatewrites now); else the failure message, sayingpathis out of date and listingunread(seeScan::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::Plainwhen it has none, else anEnglish::Patternwith every other brace escaped. - report
- Every locale of
catalogsagainst 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 scanover every.rsfile underdir(targetand hidden directories skipped), files in a stable order; origins are relative todir.- update
messagesmerged into the English cataloguesource: 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 unlessprune. The result is sorted likeenglish.- valid_
key - A key as Fluent allows it: an identifier, optionally
.attribute.
Type Aliases§
- Messages
- Keys with their English, deduplicated.