Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Rust MF2

Unicode MessageFormat 2 (MF2) for Rust applications: web applications with Leptos, and native command-line and terminal applications, including Ratatui. You write translations in MF2, the build checks them, and tr!("id", name = value) shows a message in the reader’s language.

One crate

An application depends on mf2, and on mf2-build for its build script. mf2’s features choose the rest:

FeatureFor
leptos (or leptos-0-8) with ssr, hydrate or csra Leptos application, server-rendered, hydrated or client-only
axumthe server: each request’s language, and the catalogs’ routes
nativea command-line tool, in the system’s language
ratatuia Ratatui terminal UI, with markup as styles
fn-number, fn-datetime and a date backendnumbers and dates in each language’s own way

The mf2 command (cargo install mf2-cli) makes starters, checks translations and exchanges them with translators.

What happens underneath. The build turns each language into one small binary catalog. A browser downloads a language’s catalog when it needs it, switches language without a reload, and its wasm carries none of the text. A native application embeds its catalogs or ships them beside the executable. How the crates fit together has the rest.

Where to start

Every sample is compiled. Each rust, toml and mf2 block in this book names the file of a small application it belongs to, and cargo xtask docs builds those applications in CI, for the targets they run on. The exceptions are marked: the migration page’s leptos-fluent code, which its commands convert; the upgrade page’s 1.x excerpts; and the reference pages’ fragments, which a test parses instead.