DocsKey concepts

Translation maps

The JSON shape that carries translations between the service, your repository and your app.

On this page

A translation map is a flat JSON object for one locale. Keys are hashes; values are translated ICU messages.

{
  "3f1c0a9e5b7d42c18a6e0f9d2b4c7e11": "Hola <0>{name}</0>, bienvenido de nuevo.",
  "9be27d04c1a84f6f8f0e6a1d5c3b2a90": "Guardar",
  "c40d6a1f2e9b4b7786d1a3f05e8c9d42": "{count, plural, one {# archivo} other {# archivos}}"
}

That is the entire format. There is no nesting, no metadata and no source text. The same shape is used in three places:

Where What it is
public/_generic-translation/{locale}.json Local files written by the CLI (the output path in generic-translation.config.json).
GET /cdn/{projectId}/{locale}.json The published map served by the CDN.
GET /v1/projects/{projectId}/translations/{locale} The latest map from the API, including unpublished work.

How a library uses a map

When a component renders in a non-default locale, the library:

  1. Serializes the component’s children to a message (or takes the string given to t()).
  2. Computes the hash from the message and its context.
  3. Looks the hash up in the map for the active locale.
  4. If found, parses the translated message and renders it with the same variables and elements. If not found, renders the source.

Falling back to the source text is the important property: a missing translation is never a blank space or a raw key. A page that is 90% translated shows 10% of its strings in the source language until the next translation run.

Dictionaries use the same map

If you prefer keyed strings, you can keep a dictionary file: nested JSON whose leaves are messages.

{
  "nav": {
    "home": "Home",
    "pricing": "Pricing"
  },
  "cart": {
    "items": ["{count, plural, one {# item} other {# items}}", { "context": "Shopping cart badge" }]
  }
}

A leaf is either a message string or a two-element array of [message, { "context": "…" }]. The id is the dot path (nav.home, cart.items).

Dictionary entries are not stored by id. d("nav.home") looks up the source message for that id, hashes it with its context, and reads the translation from the same map as everything else. One map per locale serves <T>, t() and dictionaries. See dictionaries.

Local files or CDN

You choose where your app gets its maps from. Both can be used together.

Local files are written into your repository by generic-translation translate and shipped with your build.

  • Translations are versioned with your code and reviewed in pull requests.
  • No runtime dependency on any external service.
  • Changing a translation requires a new build and deploy.

The CDN serves whatever you last published.

  • Copy changes go live without a deploy.
  • Your app makes one extra request per locale, cacheable by ETag.
  • You depend on the availability of the CDN endpoint. During the preview there is no uptime guarantee, so prefer local files where that matters.

Branches

Batch submissions carry a branch (default main). It lets a long-lived feature branch accumulate its own strings and translations without them appearing in what main pulls. The CLI passes your git branch when asked to; the API accepts ?branch= on GET /translations/:locale.

Writing a map by hand

Nothing stops you. Compute the hash for each source message, write the translation, save the file where your provider loads it. This is a reasonable way to use the libraries with no service at all, or to patch one string in a hurry. Run the result through messagesCompatible from @generic-translation/core if you want the same safety check the service applies.

Something wrong or unclear on this page? Open an issue.

Type to search the documentation.