Localizing an app
How enzim apps use Fluent catalogs, how the locale is chosen, and the rules for adding and translating messages.
enzim apps use the enzUI framework's Fluent localization layer. Each app ships its own Fluent catalogs, embedded into the binary at build time, while the framework supplies translations for its shared widgets, CLDR plural rules, number and date formatting, and right-to-left layout.
Where catalogs live
Most apps keep their catalogs in a locales/ directory at the repository root, one .ftl file per language:
locales/
en-US.ftl
de.ftl
ar.ftlA few apps keep them elsewhere: Text uses src/i18n/, and Photos uses assets/locales/. English (en-US) is always the complete reference catalog and the fallback for anything missing.
| App | Catalogs |
|---|---|
| English, German, Arabic (core navigation) | |
| Messages | English, German, Arabic |
| Calendar | English, German |
| Photos | English, German and Arabic (main navigation and common controls) |
| Video | English, French and Arabic (main player and selected onboarding controls) |
| Reader | English, German and Arabic (core actions and dialogs) |
| Text | English, German |
| Terminal | English, Spanish |
| Files | English, German and Arabic (core navigation, actions and common refusals) |
| Task Manager | English, French and Arabic (main navigation, monitoring and actions) |
| Calculator | English, German, Arabic |
| Remote | English, German and Arabic (shell, connection form and transfers) |
Where a translation is partial, untranslated messages fall back to English.
Loading the catalogs
The catalogs are added to a CatalogBuilder with include_str!, so translations work offline and need no installed data files. Calculator's whole setup is a few lines:
use enzui_core::localization::{self, CatalogBuilder, Localizer};
pub(crate) fn from_environment() -> Localizer {
let mut catalog = CatalogBuilder::new();
for (locale, source) in [
("en-US", include_str!("../locales/en-US.ftl")),
("de", include_str!("../locales/de.ftl")),
("ar", include_str!("../locales/ar.ftl")),
] {
catalog
.add_resource(locale, source)
.expect("valid embedded calculator catalog");
}
Localizer::new(
catalog.build(),
localization::preferred_locales(),
localization::Locale::default(),
)
}The localizer is scoped over the app's boot, updates, views, subscriptions and accessibility tree through the framework's app services. Background workers capture the localizer explicitly so messages they produce resolve in the same language.
How the locale is chosen
The locale follows the desktop language preferences at launch, read from LC_ALL, LC_MESSAGES, LANG and LANGUAGE. Unsupported languages fall back to English, while text direction still follows the selected locale. Some apps take a command-line override, such as --locale TAG in Notes.
Formatting categories can differ from the message language. For example, Calendar lets LC_TIME choose date and week conventions independently of the interface language, and Task Manager formats readings with LC_NUMERIC and sorts names with LC_COLLATE.
Writing messages
Static labels resolve a stable key with enzui_core::localization::text. Dynamic sentences use the localized! macro with named arguments:
enzui_core::localized!("text-sent-the-first-pages-pages-to-the-4064f3", "pages" => pages)text-sent-the-first-pages-pages-to-the-4064f3 = Sent the first { $pages } pages to the printer. The document was too large to print in full.The rules that keep catalogs correct:
- Translate whole messages. Never assemble a translated sentence from English fragments. Translate every branch of a select expression and keep argument names unchanged.
- Keep numeric arguments numeric, so Fluent can select the right plural form and group digits for the locale.
- Keys are stable. Correcting a translation never changes its key.
- Isolate user data. Fluent wraps arguments in direction isolation; user-chosen names pass through a bounded display sanitizer first.
- Some data is never translated. File paths used for filesystem access, persisted keys, command and shortcut identifiers, D-Bus names, protocol identifiers, and user-authored content (mail, note titles, event titles, file names) keep their original values.
Some apps generate their catalogs from a message source. Files keeps locales/messages.json and locales/translations.json and regenerates the Fluent resources with python3 tools/update-locales.py; --check detects drift. Text records each message's English source and key in src/i18n/sources.json, and Calendar keeps a similar locales/keys.json.
Adding a message
Using Text's workflow as an example:
- Add the English source text and a unique stable key to the app's message source.
- Add the same key to
en-US.ftland to every other shipped catalog. - Use the key from code through
textorlocalized!. - Run the localization tests. Apps resolve every key in every shipped locale, and several also render real app surfaces in a subprocess running a non-English locale.
Reviewing translations visually
For visual review, run the app in German, in the framework's en-XA pseudolocale (which expands text to expose truncation), and in a right-to-left locale such as Arabic. App-owned rows and controls mirror in right-to-left layouts, and navigation uses semantic back and forward icons. English fallback in an unsupported locale is intentional; a missing app key or an unformatted argument is a defect.
See Visual capture and review for running these variants in an isolated session.