mf2 2.0.0

Unicode MessageFormat 2 for Rust, for Leptos web applications and native CLI and terminal applications: the one crate an application names — the call-site types, the Leptos layer, the native application support and its Ratatui text behind features, the formatter, and compile_str for ad-hoc messages.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
[package]
name = "mf2"
authors.workspace = true
repository.workspace = true
homepage.workspace = true
description = "Unicode MessageFormat 2 for Rust, for Leptos web applications and native CLI and terminal applications: the one crate an application names — the call-site types, the Leptos layer, the native application support and its Ratatui text behind features, the formatter, and compile_str for ad-hoc messages."
version.workspace = true
edition.workspace = true
rust-version.workspace = true
# `src/matching/cldr.rs`, CLDR's language-matching table, is derived from
# the Unicode CLDR (`LICENSE-UNICODE`), as `mf2-locale-data`'s tables are.
license = "MIT AND Unicode-3.0"
publish = true
readme = "README.md"
documentation = "https://docs.rs/mf2"
keywords = ["messageformat", "mf2", "i18n", "l10n", "leptos"]
categories = ["internationalization", "localization", "wasm", "web-programming"]
# The package\'s file list (`cargo xtask package`) is not part of it.
exclude = ["package.txt"]
# Its features reach the build script of the crate that includes the
# generated module as `DEP_MF2_V2_FEATURES` (`mf2_build::run()`, plans/19 §11).
# The major version is in the name, so that a 3.x resolves beside it.
links = "mf2-v2"
build = "build.rs"

[features]
default = []
# `compile_str`: parse, validate, analyze and write a one-message catalog
# (std, server and tests; never in a client).
compile = ["dep:mf2-syntax", "dep:mf2-locale-data", "mf2-catalog/writer"]
# Locale-aware numbers: symbols, grouping, numbering systems, :percent (and
# :currency, :unit) — mf2-fn-number.
fn-number = ["dep:mf2-fn-number"]
# Dates and times: :datetime, :date, :time and unannotated date/time values
# — mf2-fn-datetime. With a Leptos mode, also dates in the reader's time
# zone: the client reads the browser's zone, corrects a page rendered in
# another after hydrating, and writes the `mf2_tz` cookie the server renders
# the next page in; off, no byte of it is in the client.
fn-datetime = ["dep:mf2-fn-datetime"]
# The date backends, each implying `fn-datetime`: `datetime-icu` — ICU4X on
# client and server, data from the catalog's `icu.blob` (which `compile_str`
# then emits); `datetime-intl` — the browser's `Intl.DateTimeFormat` on
# wasm32-unknown-unknown, ICU4X with compiled data elsewhere.
# With `host-web`, each also gives the browser host its date methods: named
# zones from the browser's data (both), `Intl.DateTimeFormat` (`datetime-intl`).
datetime-icu = [
    "fn-datetime",
    "mf2-fn-datetime/datetime-icu",
    "mf2-host-web?/time-zones",
    "mf2-locale-data?/icu-blob",
]
datetime-intl = ["fn-datetime", "mf2-fn-datetime/datetime-intl", "mf2-host-web?/datetime-intl"]
# A Host: native (servers, tests, wasm32-wasip1) or the browser.
host-std = ["dep:mf2-host-std"]
host-web = ["dep:mf2-host-web"]
# A native application, a command-line tool or a terminal UI (`mf2::native`):
# one generated corpus's catalogs, embedded in the executable (read in place,
# `static-bytes`) or shipped beside it (checked against the content hash in
# their names, `content-hash`); the system's preferred languages
# (`sys-locale`) and time zone (jiff's `tz-system`). std, and never in a
# browser build: with `hydrate` or `csr` it is a compile error when
# compiling for `wasm32`; on the host the two compile together, as a
# workspace's check unifies them. Implies the native host. `dep:jiff` too,
# so that cargo adds no public feature `jiff`.
native = [
    "host-std",
    "dep:sys-locale",
    "dep:jiff",
    "jiff/std",
    "jiff/tz-system",
    "mf2-catalog/static-bytes",
    "mf2-catalog/content-hash",
]
# A terminal UI's text (`mf2::ratatui`): a message as owned Ratatui `Text`
# or `Line`, its markup (`{#name}…{/name}`) as the styles the application
# maps by name. Implies `native`, and adds `ratatui-core` alone, whose
# types `ratatui` re-exports. Never in a browser build: with `hydrate` or
# `csr` it is a compile error of its own when compiling for `wasm32`; on
# the host the two compile together, as `native` does.
ratatui = ["native", "dep:ratatui-core"]
# An Axum server (`mf2::axum`), with or without Leptos: locale negotiation,
# the catalogs served from the server binary (`/i18n/*`, precompressed), and
# the generated `Locale` as an extractor, with `Locale::format`. Never in a
# browser build: with `hydrate` or `csr` it is a compile error when compiling
# for `wasm32`; on the host the two compile together, as `native` does.
axum = [
    "host-std",
    "dep:axum",
    "dep:http",
    "dep:tower-layer",
    "dep:tower-service",
    "dep:brotli",
    "dep:flate2",
]
# `clap`: a generated `Locale` gets a value parser, so that `--lang` parses
# through the one matcher (`fr_CA.UTF-8` is French) and `--help` lists the
# tags. std; for a native application's command line.
clap = ["dep:clap"]
# The `intl` client option: on wasm32-unknown-unknown the numeric functions
# format and select through the browser's Intl.NumberFormat and
# Intl.PluralRules (mf2-host-web's NUMBERS_HOST), requiring
# Intl.NumberFormat v3; every other build (servers, wasm32-wasip1, tests)
# keeps the Rust path.
intl = ["mf2-runtime/intl", "mf2-fn-number?/intl", "mf2-host-web?/intl"]
# The Leptos line the layer renders with. `leptos` is Leptos 0.9, the
# default line; `leptos-0-8` is Leptos 0.8. Neither is a default feature: an
# application writes one on its `mf2` dependency, and a mode needs one. Both
# at once, or a mode with neither, is a compile error that says what to
# write. Each line is a dependency under a name of its own, with its helper
# crate of components (`mf2-leptos-ui-0-9`, `mf2-leptos-ui-0-8`).
leptos = ["dep:leptos_0_9", "dep:tachys_0_3", "dep:reactive_graph_0_3", "dep:mf2-leptos-ui-0-9"]
leptos-0-8 = [
    "dep:leptos_0_8",
    "dep:tachys_0_2",
    "dep:reactive_graph_0_2",
    "dep:mf2-leptos-ui-0-8",
]
# The three Leptos modes: the Leptos layer (`mf2::leptos`), rendered on the
# server (`ssr`), hydrated in the browser (`hydrate`) or built there
# (`csr`). An application turns exactly one on, in its own feature of the
# same name, beside Leptos's. Each implies its host.
ssr = [
    "host-std",
    "dep:oco_ref",
    "dep:js-sys",
    "dep:wasm-bindgen",
    "dep:web-sys",
    "leptos_0_9?/ssr",
    "tachys_0_3?/ssr",
    "mf2-leptos-ui-0-9?/ssr",
    "leptos_0_8?/ssr",
    "tachys_0_2?/ssr",
    "mf2-leptos-ui-0-8?/ssr",
]
hydrate = [
    "host-web",
    "dep:oco_ref",
    "dep:js-sys",
    "dep:wasm-bindgen",
    "dep:web-sys",
    "dep:any_spawner",
    "dep:wasm-bindgen-futures",
    "leptos_0_9?/hydrate",
    "tachys_0_3?/hydrate",
    "mf2-leptos-ui-0-9?/hydrate",
    "leptos_0_8?/hydrate",
    "tachys_0_2?/hydrate",
    "mf2-leptos-ui-0-8?/hydrate",
]
csr = [
    "host-web",
    "dep:oco_ref",
    "dep:js-sys",
    "dep:wasm-bindgen",
    "dep:web-sys",
    "dep:wasm-bindgen-futures",
    "leptos_0_9?/csr",
    "mf2-leptos-ui-0-9?/csr",
    "leptos_0_8?/csr",
    "mf2-leptos-ui-0-8?/csr",
]
# No live update: a locale switch is a cookie and a navigation. Rendered
# nodes then register nothing, which is the natural fit for islands.
static-locale = []
# WCAG 3.1.2, Language of Parts: text the catalog borrowed from a fallback
# locale renders inside a `<span lang>`, identically on server and client.
# Only a borrowed message in a view position (a text child, a rich
# fragment) is wrapped, so a page with no missing translation is unchanged;
# `dir` is added when the lender's direction differs from the page's.
# Attributes and strings cannot carry a `lang` of their own and stay
# unmarked. Off, nothing of it is compiled.
mark-fallback-lang = []

[dependencies]
mf2-catalog.workspace = true
mf2-fn-number = { workspace = true, optional = true }
mf2-fn-datetime = { workspace = true, optional = true }
mf2-host-std = { workspace = true, optional = true }
mf2-host-web = { workspace = true, optional = true }
mf2-locale-data = { workspace = true, optional = true }
mf2-macros.workspace = true
mf2-model.workspace = true
mf2-runtime.workspace = true
mf2-syntax = { workspace = true, optional = true }
thiserror.workspace = true

# The native module (`native`): the system's preferred languages, and its
# time zone (formatting uses mf2-host-std's bundled database).
sys-locale = { workspace = true, optional = true }
jiff = { workspace = true, optional = true }

# The Ratatui module (`ratatui`): the text and style types, which `ratatui`
# re-exports.
ratatui-core = { workspace = true, optional = true }

# The Axum module (`axum`): the router, the request's parts, the
# negotiation's tower layer, and the catalogs' precompressed variants.
# `original-uri`: the mark of a request the router served, which the
# start-up route list's made-up request lacks (E4).
axum = { workspace = true, optional = true, features = ["original-uri"] }
http = { workspace = true, optional = true }
tower-layer = { workspace = true, optional = true }
tower-service = { workspace = true, optional = true }
brotli = { workspace = true, optional = true }
flate2 = { workspace = true, optional = true }

# `clap`: the generated `Locale`'s value parser.
clap = { workspace = true, optional = true }

# The Leptos layer: each line under names of its own, and its helper.
leptos_0_9 = { workspace = true, optional = true }
tachys_0_3 = { workspace = true, optional = true }
reactive_graph_0_3 = { workspace = true, optional = true }
mf2-leptos-ui-0-9 = { workspace = true, optional = true }
leptos_0_8 = { workspace = true, optional = true }
tachys_0_2 = { workspace = true, optional = true }
reactive_graph_0_2 = { workspace = true, optional = true }
mf2-leptos-ui-0-8 = { workspace = true, optional = true }
oco_ref = { workspace = true, optional = true }
# The client half: the hydration cursor's nodes, the catalog fetch, one
# console diagnostic. No `#[wasm_bindgen]` item of ours, so
# `forbid(unsafe_code)` holds.
any_spawner = { workspace = true, optional = true }
js-sys = { workspace = true, optional = true }
wasm-bindgen-futures = { workspace = true, optional = true }
wasm-bindgen = { workspace = true, optional = true }
web-sys = { workspace = true, optional = true }

[dev-dependencies]
# `tests/churn.rs` runs the client's effects natively.
any_spawner = { workspace = true, features = ["futures-executor"] }
# `tests/fallback_lang.rs` writes catalogs that borrow a message from another
# locale, which `compile_str` (one locale, nothing missing) never does.
mf2-catalog = { workspace = true, features = ["writer"] }
# `tests/matching.rs` cuts CLDR's language-matching table to a corpus, as
# `mf2-build` does, and checks the cut against the whole.
mf2-locale-data.workspace = true
mf2-syntax.workspace = true
# The E4 warning's unit test builds the server as the web starter does:
# the route list at start-up, then requests through the router.
leptos_axum.workspace = true
tower.workspace = true
tokio = { workspace = true, features = ["rt"] }

# The call-site core formats against a catalog the caller supplies: the test
# builds one with `compile_str` and formats it through the native host.
[[test]]
name = "call_site"
required-features = ["compile", "host-std", "fn-datetime"]

# What a `tr!` argument may be: each `IntoArg` conversion through a catalog
# `compile_str` writes, and the dispatch the macro expands an argument to.
[[test]]
name = "arguments"
required-features = ["compile", "host-std", "fn-datetime"]

# Rendering a description through the view types, on the server. Each of
# these also needs a Leptos line, which a mode requires anyway.
[[test]]
name = "render"
required-features = ["ssr", "compile"]

[[test]]
name = "time_zone"
required-features = ["ssr", "compile", "fn-datetime"]

# The client half, natively.
[[test]]
name = "churn"
required-features = ["csr", "compile", "host-std"]

[[test]]
name = "fallback_lang"
required-features = ["ssr", "mark-fallback-lang"]

# A native application's catalogs, embedded or read from files, and its
# locale: `compile_str` writes the catalogs.
[[test]]
name = "native"
required-features = ["native", "compile"]

# The native store: `install`, the app-wide language and a thread's own, the
# settings, and the ambient forms (`Display`, `to_string`, `to_cow`) read
# through it; `Catalogs`, the explicit form. Each of the next three is a
# binary of its own, since the store is process-wide: before `install`;
# `install_from_directory`; the system's zone, in a child process whose
# `TZ` is a POSIX rule.
[[test]]
name = "ambient"
required-features = ["native", "compile"]

[[test]]
name = "uninstalled"
required-features = ["native", "compile"]

[[test]]
name = "from_directory"
required-features = ["native", "compile"]

[[test]]
name = "system_zone"
required-features = ["native", "compile", "fn-datetime"]

# Phase 10 C3: choosing a language reads the tag where it lies; a binary of
# its own, whose allocator counts.
[[test]]
name = "locale_allocations"
required-features = ["native", "compile"]

# The one lookup with a Leptos mode beside `native`, on the host: the
# request's or the page's catalog first, then the store's. It needs a mode
# (and its line) too; with none it is empty.
[[test]]
name = "lookup"
required-features = ["native", "compile"]

# A message as Ratatui text, its markup as styles, formatted through a
# native application's catalogs.
[[test]]
name = "ratatui"
required-features = ["ratatui", "compile"]

# The one locale matcher over CLDR's whole table, which a server and a
# native application carry (`host-std`).
[[test]]
name = "matching"
required-features = ["host-std"]

# docs.rs, as `cargo xtask docs-rs` builds it. `cargo xtask api` lists this
# crate's public API per mode instead ([package.metadata.api], below).
[package.metadata.docs.rs]
# The server on Leptos 0.9, and the native, Ratatui and Axum modules, which
# compile beside it: the modes exclude each other, and `mf2::leptos` names what the
# client modes add.
features = [
    "compile",
    "fn-number",
    "datetime-icu",
    "host-std",
    "leptos",
    "ssr",
    "static-locale",
    "mark-fallback-lang",
    "native",
    "ratatui",
    "axum",
]
targets = ["x86_64-unknown-linux-gnu"]

# The public API per mode: `cargo xtask api` lists each as `api/<mode>.txt`,
# and `cargo xtask release` compares each with the last release
# (cargo-semver-checks). No one feature set shows it all: the Leptos modes
# exclude each other. `core` is a build with no mode; each other mode adds
# its own features to `core`'s, which are the options docs.rs shows.
[package.metadata.api.modes]
core = ["compile", "fn-number", "datetime-icu", "host-std"]
ssr = [
    "compile",
    "fn-number",
    "datetime-icu",
    "host-std",
    "leptos",
    "ssr",
    "static-locale",
    "mark-fallback-lang",
]
hydrate = [
    "compile",
    "fn-number",
    "datetime-icu",
    "host-std",
    "leptos",
    "hydrate",
    "static-locale",
    "mark-fallback-lang",
]
csr = [
    "compile",
    "fn-number",
    "datetime-icu",
    "host-std",
    "leptos",
    "csr",
    "static-locale",
    "mark-fallback-lang",
]
native = ["compile", "fn-number", "datetime-icu", "host-std", "native"]
ratatui = ["compile", "fn-number", "datetime-icu", "host-std", "ratatui"]
axum = ["compile", "fn-number", "datetime-icu", "host-std", "axum"]

# How 1.0.0 spelled the modes it had, for `cargo xtask release`'s comparison
# with it: its `leptos` was the layer, which a mode implied, and the Leptos
# line came from `leptos-mf2` (`leptos-mf2/leptos-0-9`). It had no `native`,
# no `ratatui` (1.x's native crates were never published) and no `axum`
# (1.x's was the crate `mf2-axum`), so those three are not compared with it.
[package.metadata.api.baseline."1.0.0"]
core = ["compile", "fn-number", "datetime-icu", "host-std"]
ssr = [
    "compile",
    "fn-number",
    "datetime-icu",
    "host-std",
    "ssr",
    "static-locale",
    "mark-fallback-lang",
    "leptos-mf2/leptos-0-9",
]
hydrate = [
    "compile",
    "fn-number",
    "datetime-icu",
    "host-std",
    "hydrate",
    "static-locale",
    "mark-fallback-lang",
    "leptos-mf2/leptos-0-9",
]
csr = [
    "compile",
    "fn-number",
    "datetime-icu",
    "host-std",
    "csr",
    "static-locale",
    "mark-fallback-lang",
    "leptos-mf2/leptos-0-9",
]

[lints]
workspace = true