
Translation Key Architecture for Web i18n
Translation keys are an API: rename one casually and paid translations break in every locale. The naming, namespace, context, and lifecycle decisions that make a catalog durable.
TL;DR: Translation keys are an API, not labels — the contract between your code, your translators, and every future feature. This article covers the decisions that make that contract durable: semantic versus natural-language keys, the one-string-one-key rule, namespace organization, the context that travels with each string, and the lifecycle disciplines that keep a catalog trustworthy as the codebase grows.
Keys are an API, not labels
The first surface of any internationalization layer is the moment a string leaves the code. What replaces it is a key, and the full set of keys — the catalog — quietly becomes an interface that much of the product depends on. Application code looks strings up by key. Translators receive work addressed by key. Reviewers diff changes key by key. Future features extend the scheme whatever it happens to be. Rename a key casually and every translation attached to it is orphaned, in every locale at once — the same blast radius as renaming a field in a public API, except the broken clients are paid translation work.
Treating keys as an API changes how they get designed. APIs get naming conventions, deprecation policies, and review; keys deserve the same, and the place to establish that is before the second locale exists, when the catalog is small and every decision is cheap.
The first decision is what a key actually names, and there are two schools. Semantic keys name the string's place and role — checkout.summary.title, account.form.email.error.invalid. They are stable under copy changes: rewrite the English and the key survives, so every other locale's translation survives too — and, where the translation tooling tracks source changes, can be flagged for review rather than destroyed. Their cost is discipline — someone has to invent and maintain the scheme, and the key alone tells a translator nothing about the text. Natural-language keys use the source string itself as the key — the English text is the address. They are self-documenting and frictionless to author, and they carry a structural trap: edit the English, even to fix a typo, and the key changes, orphaning every existing translation unless tooling migrates it.
| Axis | Semantic keys | Natural-language keys |
|---|---|---|
| Copy edits | Key survives; translations kept (review flags depend on tooling) | Key changes; translations orphaned without tooling |
| Authoring friction | Higher — a scheme to follow | Near zero — the string is the key |
| Readability in code | Requires the catalog for context | Immediate |
| Duplicate contexts | Distinct keys natural | Same string collapses to one entry unless a context field (gettext `msgctxt`) separates it |
| Tooling dependency | Moderate | High — survival depends on migration tooling |
Both schools ship real products. Our team's default is semantic keys for application UI: when product copy changes more often than component structure, a scheme that survives copy edits protects work the pipeline has already paid for — completed translations. Whichever school a team picks, the choice should be explicit, written down, and uniform; a catalog that mixes both is the worst of each.
One string, one key
Two sins make code unlocalizable, and both are committed in the name of tidiness.
The first is concatenation — building sentences from fragments:
// Unlocalizable: word order is hardcoded in the join
const msg = t('cart.youHave') + ' ' + count + ' ' + t('cart.items')
// Localizable: one key, one complete message, named placeholder
const msg = t('cart.itemCount', { count })The fragment version works in English and fails in many other languages, because word order, agreement, and pluralization differ per language and the join order is frozen in code. The W3C's article on composite messages walks through how such fragments break in translation. On how to arrange a message, it recommends a topic-comment approach whenever possible; avoiding sentence-like arrangements whose substrings are predefined translatable text or numbers; and using sentence-like arrangements only with care, for runtime text that is neither numeric nor translatable (and not for proper nouns), implemented so the text and substrings can be repositioned in any order — in code, usually by giving each variable a unique identifier. ICU's user guide states the complementary rule for formatted messages: for this to work in many languages, a message has to be written and translated as a single unit, typically a string with placeholder syntax for the variable elements. Every complete sentence gets one key; the grammar — plurals, gender, variants — moves inside the message, which is ICU MessageFormat's job and the subject of its own article on this topic.
The second sin is key reuse across contexts. One common.save key shared by every save button looks like healthy deduplication — until one locale needs different words in different contexts. German alone might want Speichern on a document and Sichern in a security setting; grammatical gender can force different forms of the "same" adjective depending on what it modifies. Deduplicating strings is a translation decision that only a translator per locale can make safely. In the catalog, distinct contexts get distinct keys even when the English happens to coincide; if two contexts are genuinely, permanently the same utterance, sharing is a deliberate exception, not a default.
Two smaller rules ride along. Placeholders are named, not positional — {itemCount} tells the translator what fills the slot, while a numbered {0} can be moved just as freely but says nothing about what it holds; an unnumbered specifier such as %s is worse, since it cannot be reordered without ambiguity. And the catalog's reach extends to strings that are easy to miss: validation errors, aria-label values, page titles, empty states, tooltips, and email subjects are all user-facing text. A string that never entered the catalog is a string no translator can ever fix — and finding those is exactly what the pseudo-localization gate later within this topic exists to do.
Namespaces and file organization
A catalog with forty keys needs no organization. A catalog with four thousand needs it badly, and the organizing axis is a real decision because it becomes the loading design too.
The main options: organize by feature or route (checkout.json, account.json) so that catalogs align with how the application code-splits; organize by component library when a design system owns most of the visible text; or keep one flat catalog, which stays viable only for small surfaces and, as a rule of thumb, degrades into a junk drawer past a few hundred keys. Feature-aligned namespaces are a natural default for applications, for a plainly mechanical reason: the catalog a route needs is the catalog that loads with it, and the performance article on this topic builds directly on that alignment.
A worked fragment, library-neutral, showing the shape the rules above produce:
{
"checkout.summary.title": {
"message": "Order summary",
"description": "Heading above the cart summary on the checkout page"
},
"checkout.summary.itemCount": {
"message": "{count, plural, one {# item} other {# items}}",
"description": "Item total under the heading; {count} is the number of cart items"
},
"checkout.actions.placeOrder": {
"message": "Place order",
"description": "Primary button; max ~20 characters to fit the button"
}
}Two tensions are worth deciding explicitly. First, shared versus local: a small common namespace earns its place for genuinely global strings — the product name, canonical actions — but the bias should lean toward local duplication, because un-sharing a key later is a migration across every locale, while two duplicate strings are merely two lines. Second, nesting depth: as a rule of thumb, two or three levels (feature.section.role) stays navigable; deeper trees turn keys into paths nobody can recall or review. Whatever the convention, it belongs in a written style rule and, ideally, a lint check — naming conventions enforced by memory decay as the team grows.
Context that travels to the translator
A bare key and a source string under-specify the translation. checkout.actions.placeOrder plus "Place order" leaves a translator guessing: Is it a button or a heading? How much room is there? Is "order" a noun or a verb here? Every guess is a coin flip repeated across every locale you ship.
The fix is cheap and structural: context rides with the key, written at authoring time by the person who knows the answer. The useful set is short — a description of where the string appears and what role it plays; a length hint where the layout constrains it (with the honest caveat that characters are a proxy — rendered width varies by script, which is the text-expansion article's territory); an explanation of each placeholder, because {count} of what is not self-evident; and a screenshot or usage note for anything genuinely ambiguous. Formats built for translation carry these fields natively, and the message-catalog article on this topic covers which formats carry what.
The timing matters more than the format. The developer writing the string knows its context completely, for about as long as the pull request is open. Reconstructing the same context much later — for a translator's question routed through a coordinator — costs more than typing one sentence at authoring time. Context metadata is not documentation overhead; it is the difference between a catalog that can be translated well by someone who has never seen the product and one that generates a question queue per locale.
Where that context goes after it ships — translator workflows, review practice, vendor coordination — is the localization operation's territory, deliberately outside this article. The engineering responsibility ends at a precise line: everything the code knows about a string travels with it.
Keeping the catalog trustworthy
A catalog is trustworthy when what it contains matches what the code uses, and that property erodes by default.
Dead keys accumulate silently. Features are removed; their strings are not. Each dead key is small, but the aggregate is translation spend on text nobody renders and noise in every translator's queue. The durable answer is mechanical: extraction tooling that diffs the keys used in code against the keys present in the catalog, run in CI, flagging both directions — used-but-missing and present-but-unused. Manual audits work exactly once; the diff runs forever.
Renames are deprecations. Because keys are an API, a rename is handled like one: tooling migrates the attached translations with the key, or the rename is batched into a deliberate migration with the translation files updated in the same change. What must never happen is the quiet rename that recreates a key as "new" — silently discarding completed work in every locale and re-buying it from the translation budget.
Missing keys need a decided policy per environment. In development, loudly — render the key or a marker so the gap is visible. In CI, structurally — a release locale with missing keys fails the gate, which is the catalog pipeline's job. In production, gracefully — fall back rather than break the page, along the chain the locale-fallback article designs. All three behaviors are defensible; what is not defensible is whatever behavior the library happened to default to, discovered in production by a user in your newest market.
None of this is glamorous, and that is rather the point. Key architecture is the plumbing of the entire multilingual product — decided once, inherited by every locale, every feature, and every translator you will ever pay. Teams that treat the catalog as an API, keep grammar inside messages, ship context with every string, and let CI hold the whole thing honest spend their localization budget on translation. The rest risk spending it on rework.