Internationalization
Entity-level translations with locale linking.
CMS supports internationalization at the entity level — not the field level. Each translation is a separate record linked by a shared translationGroup UUID.
Setup
Define available locales in your config:
export default config({
i18n: {
locales: [
{ label: "English", value: "en" },
{ label: "Portuguese", value: "pt" },
{ label: "French", value: "fr" },
],
defaultLocale: "en",
},
// ...
});
Mark entities as translatable:
const pages = entity("pages", {
translatable: true,
fields: [
text("title", { required: true }),
slug("slug", { unique: true, required: true }),
object("body", { fields: [...] }),
],
});
Automatic fields
Translatable entities automatically get two extra fields:
locale— the entity’s locale ("en","pt", etc.)translationGroup— a UUID that links all locale variants together
You don’t define these fields — they’re injected automatically when translatable: true.
Querying by locale
Filter by locale to get content in a specific language:
GET /api/pages?filter[locale]=en
Translation links
Every translatable entity in the API response includes a _translations field with all sibling locales:
{
"data": {
"id": "uuid-en",
"title": "About Us",
"slug": "/en/about",
"locale": "en",
"translationGroup": "uuid-group",
"_translations": {
"pt": { "id": "uuid-pt", "slug": "/pt/sobre" },
"fr": { "id": "uuid-fr", "slug": "/fr/a-propos" }
}
}
}
This makes building SEO alternate links (hreflang) trivial — all the data is in a single response.
Creating translations
Translating is two steps: the engine prepares the translation, then you create it like any document.
1. Prepare. Ask for a copy of a document in the target locale. Nothing is saved:
GET /api/pages/:id/translate?locale=pt
{
"data": {
"title": "About",
"slug": "/pt/about",
"author": { "id": "uuid-of-the-pt-author", "_entity": "authors" },
"locale": "pt",
"translationOf": "uuid-of-the-en-page"
},
"warnings": ["relation 'tags[1]': no pt counterpart for ID … — kept source locale ID"]
}
The copy:
- holds every field the role can read and write; the others start empty, as in any create
- points each relation at the related document’s translation in the target locale (multiple relations keep their order); a relation whose target has no translation there keeps the original and adds a warning
- suggests a slug with the locale swapped or prefixed (e.g.
/en/about→/pt/about)
2. Create. Edit the copy as needed and send it to the normal create endpoint. translationOf puts the new document in the source’s translation group:
POST /api/pages
Content-Type: application/json
{ "title": "Sobre", "slug": "/pt/sobre", "locale": "pt", "translationOf": "uuid-of-the-en-page" }
The create runs like any other: validation, hooks, versions and permissions all apply, and a slug that’s taken is a 409 with an error on the slug field. A locale the document already has is a 409 with an error on locale; an unknown source, or one the role can’t read, is a 404. Each translation group holds one document per locale, which a unique (translation_group, locale) index enforces.
To do both in one call, as a seed script might, post to the translate endpoint. It prepares the copy and creates it unchanged, and returns the new document with the warnings:
POST /api/pages/:id/translate
Content-Type: application/json
{ "locale": "pt" }
Translating needs create on the entity and read on the source. A translatable global has no id, so it takes the source locale instead (from, default: the default locale), and needs update, like every other global write. Its translation is created by the locale’s first write, naming the source:
GET /api/settings/translate?locale=pt&from=en
PUT /api/settings?filter[locale]=pt { ...data, "translationOf": "uuid-of-the-en-settings" }
POST /api/settings/translate { "locale": "pt", "from": "en" }
Deleting translations
Each translation is its own row, so DELETE /api/pages/:id removes only that locale. The other translations stay, and the admin list shows the document as untranslated in that locale.
To delete a document in every locale, send its id to bulk delete with allLocales:
POST /api/pages/_bulk-delete
Content-Type: application/json
{ "ids": ["uuid-of-any-translation"], "allLocales": true }
The engine adds every row in the same translationGroup to the batch and deletes them in one transaction. beforeDelete and afterDelete run once per deleted row, so once per locale. Translations the role’s delete permission filter excludes are kept and come back in skipped. The default locale gets no special treatment: deleting its translation never deletes the others.
In the admin, deleting a document that exists in more than one locale asks which to delete: Only the locale you’re viewing (the default) or All locales. This applies to the row action, the bulk action bar and the edit page.
Shared fields
Some values are facts about the thing, not the language: a cheese’s cellar entry date, a SKU, a product reference. Mark those fields shared and editors set them once:
const productPage = entity("product_page", {
translatable: true,
versions: true,
fields: [
text("title"), // per locale, as usual
date("entry_date", { shared: true }),
],
});
A shared field is still stored on every translation. What changes is when it moves between them:
| Moment | What happens |
|---|---|
| Translate | Copied, like every field |
| Draft save | Stays in that draft only |
| Publish | Written to every other translation in the same transaction |
Without versions |
Every save counts as a publish |
On publish, each other translation gets the value where its editor would look for it:
- It has a pending draft (unpublished edits on a published page): the value goes into that draft. It goes live when that translation is published, so nobody’s unfinished work is published behind their back.
- Otherwise (published with no edits, or never published): the value is written to the translation directly.
Either way the translation gets a new version when a value changes, so its history shows the change; its updatedAt is left alone. Shared relations point at each translation’s locale counterpart, like the translate endpoint: an English page that links to an English author gives the French page the French author. When the target has no translation in that locale, the original id is kept. A shared multiple relation follows the same rule: it waits in a pending draft, and is written to the translation directly otherwise.
Writing to the other translations fires none of their hooks. Their afterPublish doesn’t run, so there’s no loop to guard.
Each translation the copy changes is still checked like a save of that translation:
- Validation and field rules run on the translation with the new values. A rule on one of its own fields can depend on a shared one (
videoUrlrequired when the sharedtypeis"video"); when the translation fails, the publish fails with a400whose message names that locale, and nothing is written. - Derived slugs follow: a slug whose
sourcereads a shared field is derived again in each translation, unless it was set by hand. - Permissions: the role must be allowed to update the translation. A role whose
updatefilter is{ locale: "fr" }can’t change a shared value, since that changes every other locale too: the publish fails with a403naming the locale it can’t write. Saves that leave the shared values alone are unaffected.
A bulk publish or update that includes several translations of one document copies shared values once, from the default locale’s translation (or, without it, the first in i18n.locales order), so the result doesn’t depend on row order. Publishing two translations at the same moment is safe: the second waits for the first.
The admin shows a Shared across languages badge on these fields.
Rules:
- Only top-level fields can be shared.
sharedon a field inside anobject,arrayorunionthrows; mark the containing field instead. - A
slugcan’t be shared, since every translation would hold the same value and slugs are unique across the project. Auniquefield can: unique rules hold per locale. - On an entity that isn’t translatable,
shareddoes nothing andconfig()warns. - On a translatable global, publishing one locale writes the value to every other locale. A locale’s first write, when another locale already has its document, takes the shared values it leaves out from the default locale’s document (or, without one, the first in
i18n.localesorder), as if it named it intranslationOf, so it never blanks them elsewhere.
Marking a field shared once translations already exist? cms migration generate lines the existing values up on the default locale’s, so the first publish doesn’t overwrite them. See Making an existing field shared.
Slug conventions
By convention, translatable slugs include the locale prefix:
/en/about
/pt/sobre
/fr/a-propos
A plain slug doesn’t enforce this — you control slug values in your content. But a prepared translation suggests the slug with the locale prefix swapped in. To have the server check each path carries its document’s locale prefix, and to read the locale back on your website, use path() with a locale-prefix scheme.
Previous
Assets
Next
Admin extensibility