Lesson 2 of 9 · 26m
Message Catalogs, ICU Syntax, and Safe Interpolation
Design stable message IDs, expressive ICU messages, and interpolation boundaries that translators can understand and applications can validate.
The worst localization architecture I ever inherited had sentences assembled from fragments: "You have " + count + " new " + noun. It worked in English, then collapsed in every language with different word order, agreement, case, or plural behavior. A message is a complete unit of meaning. If you concatenate pieces, you are asking translators to repair grammar through a keyhole.
Catalogs map stable IDs to complete messages
A simple catalog looks flat, but each value is a full sentence or label in context:
{
"inbox.empty.title": "No messages yet",
"inbox.unread.count": "{count, plural, one {# unread message} other {# unread messages}}",
"billing.invoice.download": "Download invoice {invoiceNumber}",
"security.session.revoke": "Sign out of {deviceName}"
}The key is an identifier, not the English copy. English text can change for tone without forcing every translation to be reattached manually. Keys should describe where the meaning belongs, not merely duplicate the current wording.
ICU MessageFormat is the practical baseline
ICU gives translators a compact grammar for interpolation, pluralization, selection, dates, numbers, and formatted values:
{actor} changed {count, plural, one {# permission} other {# permissions}}
in {projectName} on {date, date, medium}.That one message preserves word order freedom. A translator can move {actor} to the end, omit a variable when grammar allows, or choose different text around it. Your code supplies values; the message owns presentation grammar.
Give variables meaningful names and types
{value1} is how catalog drift starts. Prefer semantic names and declare their types:
t("security.session.revoke", {
deviceName: session.deviceName,
lastSeen: new Date(session.lastSeenAt),
});A formatting layer can then render lastSeen according to the active locale while deviceName remains plain text. If variables are markup-bearing, be explicit. Never let translated text concatenate arbitrary HTML into the UI.
Context is part of the contract
Post can mean publish a post, a fence post, a postal item, or a job posting. Home can be a navigation label or a house type. Add translator context outside the message:
checkout.payment.method.card:
message: "Card"
context: "Payment method label, not a physical access card"Screenshots, character limits, audience, tone, and examples of variable values prevent a large share of translation defects before they happen.
Field notes
- Translators translate meaning, not variable soup. Send complete sentences and context.
- Reusing a generic key such as
common.okacross unlike contexts creates coupling; a short duplicate message is often cheaper. - Never put plural logic around interpolated fragments if the entire sentence grammar depends on the count.
- ICU syntax is powerful, not magical. Translators still need tooling that previews real values.
Was this lesson helpful?