Internationalization
The library never translates. Components receive translated strings and return events; your application owns the language and the strings.
Translate at the call site
let t = |key: &str| translate(self.language, key);
if MenuButton::new(t("Open Folder…")).show(ui) {
commands.push(Command::OpenFolder);
}
TextField::new(&mut self.name).label(t("Name")).show(ui);Keep source strings in English. Do not put translated strings in the crate or in shared component code; they are product data.
Ellipsis
Keep the single character … in labels that open a dialog:
"Open Folder…" // correct
"Open Folder..." // wrongComponents truncate long labels with …; tests and snapshots expect the character.
Layout for longer text
Lay out for at least +40 % text length. The pseudo-locale [Ŏƥēň Ƒōľďēŕ ~~~] must not clip menus, settings rows, or tabs. Tabs truncate with …; menus set a minimum popup width; settings rows wrap descriptions.
Practical rules:
- Do not hard-code a label width. Use
ui.available_width()or a min/max range. - Use
horizontal_wrappedfor rows that can contain several controls. - Give settings rows a description column that wraps.
- Test at 640×480 and at 1920×1080.
- Keep icon-only buttons tooltipped; the tooltip is also the translated AccessKit name.
Language switching
pub enum Language {
Auto,
English,
Spanish,
Pseudo,
}Switch live: translate on the next frame; do not rebuild the app. Persist the preference alongside the theme. Auto reads the system locale; a missing translation falls back to English.
Numbers and dates
The plot formats tick labels and readouts itself, using . as the decimal separator and the 1-2-5 notation. If your product needs locale-aware numbers, format the strings before passing them to labels, or configure PlotConfig::decimals and provide your own ticks. The shell's status bar and tabs are plain strings.
Accessibility names
Every translated visible label is also the AccessKit name. Translate both by passing the same string:
let label = t("Name");
TextField::new(&mut self.name).label(label).show(ui);For icon-only buttons, translate the tooltip:
IconButton::new("save", t("Save")).show(ui, &mut icons);Tests
- Assert the translated label is present by AccessKit name.
- Run the pseudo-locale at a narrow size and check for clipping.
- Keep the English snapshots stable; add a pseudo-locale snapshot only for the screens that must not clip.
- Do not snapshot translated text that changes with the system locale.
What stays in English
- The
Commandenum and itsDebugoutput. - Source identifiers, log messages, and developer-facing errors.
- Stable setting values (
"compact","github-light") — never translate them.