embedded-i18n 0.1.2

Compile-time i18n for embedded and no_std Rust: translations from JSON, YAML, TOML, gettext PO/MO or Fluent files compiled into ROM literals, with plurals, context, fallbacks and no allocator.
Documentation

embedded-i18n

crates.io docs.rs CI codecov License: MIT MSRV 1.85 no_std

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 embedded_i18n::{translate, translate_plural_write};

const TITLE: &str = translate!("Settings");        // EMBEDDED_I18N_LOCALE=fr -> "Paramètres"

translate_plural_write!(&mut display, "files", count)?; // "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, no std::fs, no libc. Builds for bare-metal targets such as thumbv7em-none-eabihf and thumbv6m-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 without libc.
  • 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)

  1. Add the crate:

    [dependencies]
    embedded-i18n = "0.1"
    
  2. Create locales/fr.json next to your Cargo.toml, and a locales/en.json with the same keys in English (the default fallback):

    {
      "Settings": "Paramètres",
      "Hello {name}!": "Bonjour {name} !",
      "files": { "one": "{count} fichier", "other": "{count} fichiers" }
    }
    
  3. Translate:

    use core::fmt::Write;
    use embedded_i18n::{translate, translate_plural_write, translate_write};
    
    embedded_i18n::track_locales!();
    
    fn render(display: &mut impl Write, name: &str, count: usize) -> core::fmt::Result {
        display.write_str(translate!("Settings"))?;
        translate_write!(display, "Hello {name}!")?;
        translate_plural_write!(display, "files", count)
    }
    
  4. Build for a language:

    EMBEDDED_I18N_LOCALE=fr cargo build --release
    

    Set 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!(context = "menu", "Open"); // "Ouvrir"
let state = translate!(context = "state", "Open"); // "Ouvert"

Plural forms with CLDR rules for 40 languages, or any gettext Plural-Forms expression. Guide

translate_plural_write!(&mut display, "files", count)?; // "1 plik", "3 pliki", "5 plików"

Select variants for genders, states and enums. Guide

let reply = translate_select!("replied", user.gender); // "Elle a répondu"

Formatting without allocation, with placeholders checked at compile time in every language. Guide

translate_write!(&mut display, "Hello {name}, you have {count} messages")?;

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("de")?;

Localized dates and times without libc: month and weekday names, AM/PM, date patterns and UTC offsets for 30 languages. Guide

DateTimeFormatter::new().write(&mut display, timestamp, "%A %d %B %Y")?; // "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.