Guides

Linked messages

@:key references with upper, lower and capitalize modifiers.
locales/en.json
{
  "brand": "acme",
  "title": "Welcome to @:brand",
  "shout": "@.upper:brand",
  "intro": "@.capitalize:{'nav.home'}.",
  "greet": "Hi @:withName",
  "withName": "{name}!",
  "nav": { "home": "home" }
}
let i18n = I18n::builder().linked_messages(true).dir("locales").build()?;
i18n.t("title");                                       // "Welcome to acme"
i18n.t("shout");                                       // "ACME"
i18n.t("intro");                                       // "Home."
i18n.t_with("greet", &Args::new().str("name", "Ann")); // "Hi Ann!"

Off by default, because @: may already be plain text in your messages. The syntax is that of the Nuxt module's linkedMessages: true.

Syntax

  • @:key, @.upper:key, @.lower:key, @.capitalize:key (first letter only).
  • @:{'key'} for a key a bare link cannot spell.
  • A bare key runs to whitespace or one of { } @ % | ( ), dots and commas included: @:brand. names brand.. End a sentence with the quoted form: @:{'brand'}..
  • {name} placeholders of the linked text stay and are filled when the message is read.
  • Modifiers follow the locale's case rules (Turkish i → İ, and so on).

Rules

  • A link can point to a root key, a page key or a key of a fallback locale. A message read in a locale that falls back to English links that locale's words: with "brand" translated, the German title shows the German brand.
  • A missing key, a subtree, a cycle or an unknown modifier leaves the whole message as written. build() calls missing once for it, and check() lists it with the reason.
  • Messages added later with add_messages are not resolved.
  • Files loaded lazily or over the network resolve their links when they load. A link from an eagerly loaded file into a lazy one stays as written.