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.
The API follows rust-i18n: i18n! configures the crate and t! translates, with the same names and most of the same syntax.
Why embedded-i18n?
- Zero runtime cost. Each
t!("key")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 with
available_localesand switch withset_locale("de"), still without allocation.
Example
locales/fr.json, next to Cargo.toml:
src/main.rs (or lib.rs):
use Write;
use t;
i18n!;
const TITLE: &str = t!; // "Paramètres", a literal in flash
Build the same code in another language with EMBEDDED_I18N_LOCALE=de cargo build --release.
The Getting Started tutorial walks through it, from an empty project to runtime language switching.
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 | ✅ (every locale) | ❌ | ❌ | ❌ |
| Plural forms | ✅ CLDR rules and gettext Plural-Forms |
Not built in | ✅ | ✅ |
| Message context / select variants | ✅ / ✅ | ❌ / ❌ | Message ids / ✅ | ✅ / ❌ |
| Runtime locale switching | Optional (available_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. See the comparison for details.
Documentation
The documentation follows the Diátaxis structure. It is also available on docs.rs, with every example compiled and tested.
Tutorials
- Getting Started: from an empty project to a program translated into two languages, without allocator.
How-to Guides
- Switch language at runtime
- Localize per request, with an explicit locale per call
- Build one firmware per language, with environment overrides and a CI matrix
- Use gettext PO files and other formats
- Ship complete translations, with strict mode
- Check translations in CI
- Pseudo-localize
- Support right-to-left languages
- Format dates and times
- Subset fonts
- Migrate from rust-i18n
- Migrate from 0.1
Reference
- The
t!macro: grammar, options, result types, placeholders, plural, select, context and compile errors - Catalog checker
- Configuration:
i18n!,[package.metadata.i18n], environment overrides, locale resolution and rebuild tracking - Locale files: JSON, YAML, TOML, PO, MO and Fluent, and their Cargo features
- Plural rules: CLDR categories, supported languages and gettext
Plural-Forms - Runtime API:
set_locale,Locale,locale!,available_locales!,system_locale - Date and time: tokens, supported languages and API
- Unicode ranges
- Features and
no_std: Cargo features, allocation and targets
Explanation
- How the checker complements the build
- How it works: compile-time expansion, why
i18n!comes first, and the ROM and RAM cost - The runtime locale model: locale identifiers, per-crate resolution and their limits
- Design choices: compile errors,
Displayvalues and one embedded locale by default - Comparison with other crates: rust-i18n, Fluent and gettext
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 system_locale() to read the locale of the operating system |
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.