embedded-i18n
Compile-time internationalization (i18n) and localization (l10n) for embedded Rust, no_std firmware and microcontrollers.
embedded-i18n translates your strings at build time: translations from JSON, YAML, TOML, GNU gettext PO/MO or Fluent files are compiled into your binary as plain &'static str literals stored in flash/ROM. No runtime parser, no allocator, no file system, no heap, and a missing translation is a compile error, not a blank screen on a device in the field.
use ;
const TITLE: &str = translate!; // EMBEDDED_I18N_LOCALE=fr -> "Paramètres"
translate_plural_write!?; // "1 fichier", "3 fichiers"
Why embedded-i18n?
- Zero runtime cost. Each
translate!()expands to a string literal. Your firmware only contains the strings it uses, in the language you build for. - Fits on a microcontroller.
#![no_std], no allocator, nostd::fs, nolibc. Builds for bare-metal targets such asthumbv7em-none-eabihfandthumbv6m-none-eabi(no atomic compare-and-swap). - Mistakes caught by the compiler. Missing keys, missing plural forms, invalid locale files and format placeholders that do not match their arguments are reported as compile errors at the call site. An optional strict mode forbids falling back to another language.
- Real-world linguistics. CLDR plural rules for 40 languages, gettext
Plural-Forms, message context (msgctxt), select variants (gender, enums), locale fallback chains (fr-CA→fr→en), right-to-left bidi isolation and localized dates withoutlibc. - Use the files translators already know. JSON (nested keys), YAML, TOML, GNU gettext
.po/.mo, and Fluent.ftl, all parsed at compile time, so the formats add no code to the firmware. - Runtime language switching when you need it. Embed several locales and switch with
set_locale("de"), still without allocation.
Comparison
| embedded-i18n | rust-i18n | Fluent | gettext-rs | |
|---|---|---|---|---|
no_std, no allocator |
✅ | ❌ | ❌ | ❌ |
| Translations resolved | At compile time, as literals | Compile-time embedded, looked up at runtime | Parsed and resolved at runtime | Loaded from .mo files at runtime |
| Missing translation | Compile error | Runtime fallback | Runtime error / fallback | Runtime fallback to the source string |
| Format placeholders checked at compile time | ✅ (format_args!) |
❌ | ❌ | ❌ |
| Plural forms | ✅ CLDR rules and gettext Plural-Forms |
Not built in | ✅ | ✅ |
| Message context / select variants | ✅ / ✅ | ❌ / ❌ | Message ids / ✅ | ✅ / ❌ |
| Runtime locale switching | Optional (EMBEDDED_I18N_LOCALES) |
✅ | ✅ | ✅ |
| File formats | JSON, YAML, TOML, PO, MO, Fluent (subset) | YAML, JSON, TOML | Fluent | MO (via GNU gettext) |
Localized dates without libc |
✅ | ❌ | ❌ | ❌ |
Pick embedded-i18n when the binary must be small, deterministic and allocation-free, and the set of languages is known at build time. On desktop or server applications with downloadable language packs and full Fluent features (functions, parameterized terms), a runtime library is a better fit.
Quick start (60 seconds)
-
Add the crate:
[] = "0.1" -
Create
locales/fr.jsonnext to yourCargo.toml, and alocales/en.jsonwith the same keys in English (the default fallback): -
Translate:
use Write; use ; track_locales!; -
Build for a language:
EMBEDDED_I18N_LOCALE=frSet it once in
.cargo/config.toml([env] EMBEDDED_I18N_LOCALE = "fr") to avoid repeating it.
Features at a glance
Locale files in the formats translators already use: JSON with nested keys, YAML, TOML, GNU gettext .po / .mo and Fluent .ftl, parsed at compile time. Guide
Message context, to translate the same source string differently. Guide
let action = translate!; // "Ouvrir"
let state = translate!; // "Ouvert"
Plural forms with CLDR rules for 40 languages, or any gettext Plural-Forms expression. Guide
translate_plural_write!?; // "1 plik", "3 pliki", "5 plików"
Select variants for genders, states and enums. Guide
let reply = translate_select!; // "Elle a répondu"
Formatting without allocation, with placeholders checked at compile time in every language. Guide
translate_write!?;
Fallback chains and strict builds: fr-CA → fr → en, and EMBEDDED_I18N_STRICT=1 to fail the build on untranslated strings. Configuration, Coverage
Runtime language switching between locales embedded at build time, with one atomic and no allocation. Guide
set_locale?;
Localized dates and times without libc: month and weekday names, AM/PM, date patterns and UTC offsets for 30 languages. Guide
new.write?; // "mardi 13 octobre 2026"
Right-to-left languages, pseudo-localization and font subsetting: bidi isolation of placeholders, a pseudo locale to catch clipped and hardcoded strings, and the Unicode ranges of each language for font conversion tools. RTL, Pseudo-localization, Unicode ranges
Guide
| Topic | |
|---|---|
| Locale Files | JSON, YAML, TOML, PO, MO and Fluent files, and their Cargo features |
| Translating | translate!, C strings, lookup and compile errors |
| Message Context | Disambiguating identical source strings |
| Plural Forms | CLDR categories, gettext Plural-Forms and the supported languages |
| Select Variants | Gender, states and enums |
| Formatting | translate_write!, translate_args!, format! and defmt |
| Rebuild Tracking | Rebuilding when locale files change |
| Configuration | Environment variables, locale resolution, fallback chains and the locales directory |
| Runtime Locale Selection | Embedding several locales and switching at runtime |
| Translation Coverage | Strict mode for complete releases |
| Right-to-Left Languages | Text direction and bidi isolation |
| Pseudo-Localization | Testing layouts before translating |
| Date and Time | Localized strftime-style formatting |
| Unicode Ranges | Font subsetting for each language |
no_std Support |
Features, allocation and targets |
| Comparison | rust-i18n, Fluent and gettext, and how to migrate |
The guide is also available on docs.rs, with every example compiled and tested.
Cargo features
| Feature | Description |
|---|---|
backend-json |
Default. JSON locale files |
backend-yaml, backend-toml |
YAML and TOML locale files |
backend-po, backend-mo |
GNU gettext .po and compiled .mo locale files |
backend-fluent |
Fluent .ftl locale files (simple messages) |
alloc |
String / Vec returning helpers |
std |
Enables alloc, and environment getters for build scripts |
The backends only affect the procedural macros: they add no code and no dependency to the firmware.
Minimum Supported Rust Version
Rust 1.85 (edition 2024). Raising it is not considered a breaking change.
Contributing
Issues and pull requests are welcome. Pull request titles follow Conventional Commits (feat: ..., fix: ...), as they become the changelog; releases are automated, see RELEASING.md.
License
Licensed under the MIT License.
Developed by Alix ANNERAUD.