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

How the crates fit together

Rust MF2 is a family of crates for using Unicode MessageFormat 2 (MF2) from Rust, in Leptos web applications and in native command-line and terminal applications. An application names one of them, mf2, and turns on the integration for its kind as mf2’s features: leptos and axum on the web, native (and ratatui) natively. Its build script calls mf2-build, which checks the translation resources and writes the generated module the call sites use and one binary catalog (.mf2b) per language; at run time the runtime formats each call site against the catalog of the active locale.

build time:  .mf2 resources ──> mf2-build ──> generated module (tr!, ids)
                                          └─> one .mf2b catalog per language

run time:    application ──> call sites (tr!) ──> runtime ──> active catalog

The book explains how to use the system. Each crate’s rustdoc remains the reference for its exact API and feature flags.

Application-facing crates

CrateRole
mf2Application facade: the call-site API and the MF2 runtime, with features for the host and the formatting functions. With a Leptos line and mode, mf2::leptos: rendering, reactive arguments, markup, and switching language live. With axum, mf2::axum: each request’s language and the catalogs’ routes. With native, mf2::native: the catalogs embedded or shipped, and the system’s language. With ratatui, mf2::ratatui: messages as Ratatui text, markup as styles.
mf2-buildBuild-time validation and generation of manifests, catalogs, and the Rust module used by call sites.
mf2-cliThe mf2 command for making starters, checking resources, compiling catalogs, and converting or exchanging translations.

mf2 is the facade applications use to write and format messages; it is not just an index of package links. It defines the call-site types (Tr, TrArgs, TrRich, TrDyn, ArgValue, DateTimeValue, …), and each integration is a module of it built on those types and the runtime. Without a Leptos mode, mf2 compiles no Leptos code: no Leptos, no tachys, no reactive_graph. 1.x’s leptos-mf2, mf2-axum, mf2-native and mf2-ratatui are these features now (Upgrading from 1.x).

Supporting crates

These crates provide the implementation layers used by the application-facing crates. Most application code does not need to depend on them directly.

CrateRole
mf2-modelMF2 message data model and shared identifiers.
mf2-syntaxParsing, validation, analysis, and serialization of MF2 messages.
mf2-resourceReading and writing message resource files.
mf2-catalogBinary catalog format, reader, and writer.
mf2-runtimeMessage evaluation, formatting, and output sinks.
mf2-locale-dataLocale direction, plural rules, and compact locale data used during builds.
mf2-fn-numberLocalized number, currency, percent, and unit functions.
mf2-fn-datetimeDate and time functions with the selected backend.
mf2-host-stdNative host services for formatting.
mf2-host-webBrowser host services for formatting.
mf2-macrosProcedural macros used by generated translation modules and mf2.

Choose a path