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, and none is on by default:

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
clapa --lang option parsed by clap
host-std or host-webmf2 with no framework
a number formatter and a date formatter per side, such as leptos-client-number-intl and leptos-server-number-builtin, leptos-client-datetime-intl and leptos-server-datetime-icunumbers and dates in each language’s own way
intl or builtin for numbers, intl or icu for dates; tzdb-bundledwhose locale data: the platform’s and a smaller build, or the same answer everywhere

Features of mf2 says what each does and what it costs.

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.