MessageFormat 2 framework for Rust
  • Rust 93.5%
  • JavaScript 4.7%
  • Shell 1.5%
  • HTML 0.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Evan Carroll d598787b23
Some checks failed
ci / lint-and-test (push) Successful in 16m45s
ci / release-dry-run (push) Failing after 16m50s
ci / browser-wasm-budgets (push) Successful in 6m41s
ci / parser-vs-ox (push) Successful in 3m55s
ci / tui-allocs-vs-pseudotrippy (push) Failing after 2m32s
ci / catalog-size (push) Successful in 2m50s
ci / native-no-heavy-crates (push) Successful in 3m38s
ci / codegen-all-features (push) Successful in 6m6s
ci / wasi-matches-native (push) Successful in 17m34s
ci / msrv (push) Successful in 4m27s
ci / docs-examples-compile (push) Successful in 9m48s
ci / docs-rs (push) Successful in 4m17s
ci / report (push) Failing after 1m0s
verify / checks (push) Failing after 1h20m2s
verify / report (push) Successful in 59s
The pointer crates are gone
`pointers/` held 2.0.0 releases of `leptos-mf2` and `mf2-axum` that were each a
README and a `compile_error!` naming the `mf2` feature to turn on. They were
never published, and nothing uses either crate (owner, 2026-10-08):
`mf2-axum` is deleted from crates.io; `leptos-mf2` cannot be, `mf2` 1.0.0
requiring it, and is yanked with `mf2` 1.0.0 instead. The root workspace no
longer excludes the directory, and 23.4's first question records the answer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 00:54:40 -05:00
.cargo Phase 0 and Phase 1: plans, probes, harnesses, mf2-model, mf2-syntax 2026-09-21 15:22:58 -05:00
.forgejo/workflows The fuzz steps install the pinned nightly, and the two plans say they are built 2026-10-07 06:11:51 -05:00
.github/workflows The user guide as an mdBook, built and deployed to GitHub Pages 2026-09-27 19:21:31 -05:00
bench The reader's report is uploaded from where the check writes it 2026-10-07 03:06:37 -05:00
conformance The WASI runner's binary is where its manifest says 2026-10-07 01:51:43 -05:00
crates Every gate is named for what it checks, and a standard-library helper is not a leak 2026-10-07 00:39:05 -05:00
devops Reapply "The time-zone database is checked where the tools are" 2026-10-06 06:25:12 -05:00
docs The recorded mf2 check output quotes the figure the tool prints now 2026-10-06 16:10:41 -05:00
examples demo-csr's wasm-bindgen version comes from its lock, not Trunk.toml 2026-10-07 16:37:43 -05:00
fuzz Numbers name a formatter per side, as dates do 2026-10-05 13:28:20 -05:00
plan The pointer crates are gone 2026-10-08 00:54:40 -05:00
third_party 21.2: the records the generators write, for Phases 16-19's code 2026-10-04 03:10:14 -05:00
tools The fuzz steps install the pinned nightly, and the two plans say they are built 2026-10-07 06:11:51 -05:00
xtask A server-only component is judged on code, data and raw bytes, not brotli 2026-10-07 06:14:10 -05:00
.gitignore Phase 0 and Phase 1: plans, probes, harnesses, mf2-model, mf2-syntax 2026-09-21 15:22:58 -05:00
book.toml docs: one-crate landing page, Getting started first, upgrading from 1.x (F5) 2026-09-30 10:23:56 -05:00
Cargo.toml The pointer crates are gone 2026-10-08 00:54:40 -05:00
CHANGELOG.md 3.0.0's entry no longer says it is unpublished, and the release is seventeen crates 2026-10-07 14:37:38 -05:00
CLAUDE.md CLAUDE.md: backwards compatibility is not a constraint 2026-10-05 07:41:19 -05:00
clippy.toml Phase 0 and Phase 1: plans, probes, harnesses, mf2-model, mf2-syntax 2026-09-21 15:22:58 -05:00
LICENSE Phase 0 and Phase 1: plans, probes, harnesses, mf2-model, mf2-syntax 2026-09-21 15:22:58 -05:00
README.md Every published size figure is brotli, measured on the runner 2026-10-06 14:54:40 -05:00
rust-toolchain.toml Phase 0 and Phase 1: plans, probes, harnesses, mf2-model, mf2-syntax 2026-09-21 15:22:58 -05:00

Rust MF2

Unicode MessageFormat 2 (MF2) for Rust applications, including Leptos, native CLI tools and Ratatui TUIs: the full specification, one small binary catalog per language loaded when it is needed, and a wasm that contains none of the text.

#[component]
pub fn Overview(name: String, count: RwSignal<u32>) -> impl IntoView {
    view! {
        <h1>{tr!("signature.text", name = name)}</h1>
        <input type="search" placeholder=tr!("search.placeholder") />
        // A signal as an argument: the text follows the count and the language.
        <p role="status">{tr!("cart.items", count = count)}</p>
        // Markup in the message becomes elements, wherever the translation puts them.
        <p>
            {tr!(
                "terms.accept",
                link = |c: AnyView| view! { <a href="/terms">{c}</a> },
                strong = |c: AnyView| view! { <strong>{c}</strong> },
            )}
        </p>
    }
}

One macro works in every position: text, attributes, props, strings and const tables. Each call is checked against the messages when it compiles. (This sample is compiled too: it belongs to the library that call sites builds.)

  • Server-rendered and hydrated is the default. The server renders each page in the reader's language, and the browser hydrates it and switches language live, without a reload. The page stays correct and readable before the wasm arrives, and if it never does.
  • Islands give the smallest download. A server-only component costs the wasm nothing, however many messages it uses: the code section was 185,925 bytes with and without one full of call sites (cargo xtask islands-zero, 2026-09-23).
  • Client-only applications and lazy routes are supported too.
  • Native CLI and Ratatui apps use the same messages and the same tr!, through mf2's native feature: the catalogs embedded in the executable or shipped beside it, the system's language and time zone. With ratatui, a message is Ratatui text, its MF2 markup drawn by a theme set once.
  • No locale data in the wasm: no message text, ids, argument names or plural rules. A translation edit leaves the wasm byte-for-byte the same, so readers keep their cached copy. The library's client code costs 28,046 bytes brotli, plus 2.6 bytes a call site: 32,956 bytes for an application with 1,860 call sites (cargo xtask size, 2026-10-06).
  • The whole specification: the MF2 working group's test suite passes at every layer, from the parser to the browser, and every normative statement has a test (conformance/REPORT.md, conformance/COVERAGE.md).
  • WCAG 2.2 AA: <html lang dir> follows the language, the switcher is a labelled form that applies a choice on a button, and bidi isolation is on where a person reads the text.

Status: 1.0.0 is on crates.io for all sixteen crates of the web family. 1.1.0 was not published and will not be: its fixes ship in 2.0.0, the next release, where the native and terminal support are mf2's native and ratatui features. What each release contains, what it measures and its known limitations are in CHANGELOG.md; what 2.x promises is in docs/versioning.md.

Install

Rust 1.88 or later and the mf2 command, plus the browser target for a web application:

cargo install mf2-cli             # the `mf2` command
rustup target add wasm32-unknown-unknown

A Leptos application is one crate too: its messages sit in locales/, its build script is mf2_build::run(), and it names mf2 with leptos and the functions its messages call, forwarding its ssr feature to mf2/ssr and mf2/axum, and hydrate to mf2/hydrate:

cargo add mf2 --features leptos,leptos-client-number-intl,leptos-server-number-builtin   # leptos-0-8 on Leptos 0.8
cargo add --build mf2-build

mf2 init --ssr (or --islands, --csr) writes a complete one, and Getting started builds one step by step.

A native application is the same shape: its messages sit in locales/, its build script is mf2_build::run(), and it names mf2 with native — or ratatui, for a terminal UI — and the functions its messages call:

cargo add mf2 --features native,native-number-builtin   # or ratatui,native-number-builtin
cargo add --build mf2-build

mf2 init --cli or mf2 init --tui writes a complete one; Native CLI and Ratatui apps explains every file. Both are on crates.io at 2.0.0.

Documentation

The Rust MF2 book explains the ecosystem, crate roles, application workflows and integrations. Its source and chapter links are in docs/. Start with getting started, then choose a path: how the crates fit together, call sites, delivery modes, switching language, accessibility, native CLI and TUI apps, migrating from leptos-fluent, upgrading from 1.x and versions; what changed, CHANGELOG.md. mdbook build renders the book; cargo xtask docs compiles its application examples for native and browser targets. Each crate's API reference remains in rustdoc.

The web examples: examples/demo-ssr (server-rendered, with a lazy route), examples/demo-islands and examples/demo-csr. The native example — a CLI with a Ratatui mode — is the application Native CLI and Ratatui apps builds, compiled by cargo xtask docs.

Developing

  • Current plans: plan/. Start with plan/01-size-and-features.md.
  • The plans and results of phases 0–10, kept as history: plan/archive/.
  • Vendored, pinned inputs (read-only): third_party/. The MF2 specification text is not among them: its license does not allow public redistribution, so cargo xtask spec-sync fetches it, at the pinned commit and checked against recorded digests, into target/xtask-cache/. The conformance tests need it; run the command once after cloning. UTS #35 Part 1, whose language-matching rules the locale matcher follows, is fetched the same way by cargo xtask uts35-sync; nothing builds from it.
  • Continuous integration: .forgejo/workflows/README.md says what runs on every push, what runs nightly, and what the runner cannot do. It has no browser engines, so the browser conformance layers and the demo checks are run by hand — tools/ci/local-only.txt lists them with their commands, and every run names them in its report. Each run uploads one mf2-report artifact: every figure, and the tool versions that produced it. Everything native is built on musl there, so a native size figure from CI is not comparable with one taken on a glibc machine; wasm figures are.
cargo xtask spec-sync          # fetch the MF2 specification text (once)
cargo check --workspace        # the toolchain is pinned in rust-toolchain.toml
cargo xtask ci                 # everything the `ci` job runs, locally
cargo xtask docs               # compile every sample in docs/

License

MIT — see LICENSE. mf2 and mf2-locale-data ship data from Unicode's CLDR, so they are MIT AND Unicode-3.0 (each has its LICENSE-UNICODE). Vendored material under third_party/ keeps its own license (Unicode License v3), stated in each directory.