Translates localized text, textarea and rich-text fields in the collections you choose, at any depth inside groups, arrays, blocks and tabs. Editors start translations from the document edit view, the collection list or a single field, and jobs run through Payload Jobs or inline. It ships an OpenAI-compatible adapter, requires Payload 3.90 or later with localization enabled, and depends on the guard plugin and an access policy.
Translation plugin for Payload CMS 3.x. Automatically translate your localized content using any translation provider.
Installation
npm i @focus-reactive/payload-plugin-translator37
Stars
5
Forks
33
Open Issues
Today
Last Updated
3.9k
Weekly Downloads
v0.20.1
npm Version
846.4 KB
Unpacked Size
9
Dependencies
37+22 since Sep 7
| Date | Stars |
|---|---|
| Dec 6, 2026 | 37 |
| Dec 5, 2026 | 37 |
| Dec 4, 2026 | 37 |
| Dec 3, 2026 | 37 |
| Dec 2, 2026 | 37 |
| Dec 1, 2026 | 36 |
| Nov 30, 2026 | 35 |
| Nov 29, 2026 | 35 |
| Nov 28, 2026 | 34 |
| Nov 27, 2026 | 34 |
| Nov 26, 2026 | 34 |
| Nov 25, 2026 | 34 |
| Nov 24, 2026 | 34 |
| Nov 23, 2026 | 34 |
| Nov 22, 2026 | 34 |
| Nov 21, 2026 | 34 |
| Nov 20, 2026 | 33 |
| Nov 19, 2026 | 32 |
| Nov 18, 2026 | 32 |
| Nov 17, 2026 | 32 |
| Nov 16, 2026 | 32 |
| Nov 15, 2026 | 32 |
| Nov 14, 2026 | 32 |
| Nov 13, 2026 | 32 |
| Nov 12, 2026 | 32 |
| Nov 11, 2026 | 32 |
| Nov 10, 2026 | 32 |
| Nov 9, 2026 | 31 |
| Nov 8, 2026 | 31 |
| Nov 7, 2026 | 31 |
| Nov 6, 2026 | 31 |
| Nov 5, 2026 | 31 |
| Nov 4, 2026 | 30 |
| Nov 3, 2026 | 30 |
| Nov 2, 2026 | 30 |
| Nov 1, 2026 | 30 |
| Oct 31, 2026 | 30 |
| Oct 30, 2026 | 30 |
| Oct 29, 2026 | 30 |
| Oct 28, 2026 | 30 |
| Oct 27, 2026 | 30 |
| Oct 26, 2026 | 30 |
| Oct 25, 2026 | 30 |
| Oct 24, 2026 | 29 |
| Oct 23, 2026 | 29 |
| Oct 22, 2026 | 29 |
| Oct 21, 2026 | 29 |
| Oct 20, 2026 | 29 |
| Oct 19, 2026 | 29 |
| Oct 18, 2026 | 29 |
| Oct 17, 2026 | 27 |
| Oct 16, 2026 | 26 |
| Oct 15, 2026 | 26 |
| Oct 14, 2026 | 26 |
| Oct 13, 2026 | 25 |
| Oct 12, 2026 | 25 |
| Oct 11, 2026 | 25 |
| Oct 10, 2026 | 25 |
| Oct 9, 2026 | 25 |
| Oct 8, 2026 | 25 |
| Oct 7, 2026 | 25 |
| Oct 6, 2026 | 24 |
| Oct 5, 2026 | 24 |
| Oct 4, 2026 | 24 |
| Oct 3, 2026 | 23 |
| Oct 2, 2026 | 22 |
| Oct 1, 2026 | 22 |
| Sep 30, 2026 | 20 |
| Sep 29, 2026 | 20 |
| Sep 28, 2026 | 20 |
| Sep 27, 2026 | 20 |
| Sep 26, 2026 | 19 |
| Sep 25, 2026 | 18 |
| Sep 24, 2026 | 18 |
| Sep 23, 2026 | 18 |
| Sep 22, 2026 | 18 |
| Sep 21, 2026 | 18 |
| Sep 20, 2026 | 18 |
| Sep 19, 2026 | 18 |
| Sep 18, 2026 | 18 |
| Sep 17, 2026 | 18 |
| Sep 16, 2026 | 18 |
| Sep 15, 2026 | 18 |
| Sep 14, 2026 | 18 |
| Sep 13, 2026 | 17 |
| Sep 12, 2026 | 17 |
| Sep 11, 2026 | 17 |
| Sep 10, 2026 | 16 |
| Sep 9, 2026 | 16 |
| Sep 8, 2026 | 16 |
| Sep 7, 2026 | 15 |
Shared by 15 plugins in focusreactive/payload-plugins.
3.4K+1.8K since Sep 7
| Date | Weekly downloads |
|---|---|
| Dec 6, 2026 | 3,438 |
| Dec 5, 2026 | 3,164 |
| Dec 4, 2026 | 2,912 |
| Dec 3, 2026 | 2,688 |
| Dec 2, 2026 | 2,531 |
| Dec 1, 2026 | 1,994 |
| Nov 30, 2026 | 2,000 |
| Nov 29, 2026 | 1,879 |
| Nov 28, 2026 | 1,788 |
| Nov 27, 2026 | 1,765 |
| Nov 26, 2026 | 1,758 |
| Nov 25, 2026 | 1,759 |
| Nov 24, 2026 | 1,819 |
| Nov 23, 2026 | 1,873 |
| Nov 22, 2026 | 1,928 |
| Nov 21, 2026 | 1,947 |
| Nov 20, 2026 | 1,851 |
| Nov 19, 2026 | 1,637 |
| Nov 18, 2026 | 1,743 |
| Nov 17, 2026 | 1,709 |
| Nov 16, 2026 | 1,651 |
| Nov 15, 2026 | 1,786 |
| Nov 14, 2026 | 1,964 |
| Nov 13, 2026 | 1,837 |
| Nov 12, 2026 | 1,917 |
| Nov 11, 2026 | 1,767 |
| Nov 10, 2026 | 1,978 |
| Nov 9, 2026 | 2,064 |
| Nov 8, 2026 | 1,928 |
| Nov 7, 2026 | 1,869 |
| Nov 6, 2026 | 2,082 |
| Nov 5, 2026 | 2,010 |
| Nov 4, 2026 | 2,143 |
| Nov 3, 2026 | 1,926 |
| Nov 2, 2026 | 2,008 |
| Nov 1, 2026 | 2,221 |
| Oct 31, 2026 | 2,404 |
| Oct 30, 2026 | 2,328 |
| Oct 29, 2026 | 2,107 |
| Oct 28, 2026 | 1,721 |
| Oct 27, 2026 | 1,722 |
| Oct 26, 2026 | 1,562 |
| Oct 25, 2026 | 1,260 |
| Oct 24, 2026 | 1,038 |
| Oct 23, 2026 | 628 |
| Oct 22, 2026 | 870 |
| Oct 21, 2026 | 1,298 |
| Oct 20, 2026 | 1,286 |
| Oct 19, 2026 | 1,259 |
| Oct 18, 2026 | 1,298 |
| Oct 17, 2026 | 1,291 |
| Oct 16, 2026 | 1,539 |
| Oct 15, 2026 | 1,573 |
| Oct 14, 2026 | 1,660 |
| Oct 13, 2026 | 1,651 |
| Oct 12, 2026 | 1,700 |
| Oct 11, 2026 | 1,985 |
| Oct 10, 2026 | 1,966 |
| Oct 9, 2026 | 1,986 |
| Oct 8, 2026 | 2,136 |
| Oct 7, 2026 | 2,073 |
| Oct 6, 2026 | 2,111 |
| Oct 5, 2026 | 2,431 |
| Oct 4, 2026 | 2,242 |
| Oct 3, 2026 | 2,197 |
| Oct 2, 2026 | 2,082 |
| Oct 1, 2026 | 1,878 |
| Sep 30, 2026 | 1,575 |
| Sep 29, 2026 | 1,578 |
| Sep 28, 2026 | 1,211 |
| Sep 27, 2026 | 1,070 |
| Sep 26, 2026 | 990 |
| Sep 25, 2026 | 1,051 |
| Sep 24, 2026 | 1,302 |
| Sep 23, 2026 | 1,484 |
| Sep 22, 2026 | 1,484 |
| Sep 21, 2026 | 1,677 |
| Sep 20, 2026 | 1,971 |
| Sep 19, 2026 | 2,185 |
| Sep 18, 2026 | 2,212 |
| Sep 17, 2026 | 2,008 |
| Sep 16, 2026 | 1,879 |
| Sep 15, 2026 | 1,899 |
| Sep 14, 2026 | 1,725 |
| Sep 13, 2026 | 1,692 |
| Sep 12, 2026 | 1,431 |
| Sep 11, 2026 | 1,524 |
| Sep 10, 2026 | 1,567 |
| Sep 9, 2026 | 1,693 |
| Sep 8, 2026 | 1,646 |
| Sep 7, 2026 | 1,667 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1177993877-payload-plugin-translator)<a href="https://payloaddirectory.dev/plugins/1177993877-payload-plugin-translator"><img src="https://payloaddirectory.dev/badge/1177993877-payload-plugin-translator.svg" alt="Payload Directory"></a>README
Translate localized Payload CMS content with an AI provider, without leaving the admin panel
Pick a source locale and one or more targets; a background job fills in every localized text, textarea and rich-text field.
Payload localizes your content but does not translate it — an editor still copies text between locales by hand. This plugin closes that gap: every localized field gets translated, however deeply it sits inside groups, arrays, blocks and tabs, by a translation service you choose.
The plugin is built on @focus-reactive/payload-plugin-guard.
Your project's access policy file decides who may translate, translate in bulk, publish translations and manage other people's jobs, and every translation reads and writes with the requesting user's own Payload rights.
Requirements: Payload ^3.90.0, @focus-reactive/payload-plugin-guard, and a config wrapped in withAccessPolicy.
Copy and paste this prompt into your AI assistant (Cursor, Claude, etc.) to integrate the plugin into an existing Payload project.
I want to add AI translation of localized content to my Payload CMS v3 project using
@focus-reactive/payload-plugin-translator. Follow these steps in order, and stop to ask me where a step says so.
## Rules you must follow
- Never write an access rule that admits every logged-in user: no `Boolean(req.user)`, no `() => true`,
no `({ req }) => !!req.user`. A rule names a role, or it is `nobody`.
- Do not invent roles. Ask me which roles may do each thing listed in step 2.
- Do not add `overrideAccess: true` anywhere, and do not add `access` to the plugin's provenance collection.
- Never put an API key in code. The provider key comes from an environment variable.
## How it works
The plugin translates every localized text, textarea and rich-text field of the collections I name,
through a translation provider (an OpenAI-compatible adapter ships with it). Editors start a
translation from the document edit view, the collection list or a single field; a collection wrapped
in `withAutoTranslate` queues its own translations when its source locale is saved by an admin user.
Translations run as Payload jobs in the `translations` queue, or inline with `createSyncRunner()`.
Every translation reads the source and writes the target with the requesting user's own Payload
rights, and a queued job re-checks that user's rights when it runs.
It declares four capabilities that the project grants in its access policy:
- `translate`: translate one document or one field, see translation status, run or cancel your own jobs.
- `translateInBulk`: queue more than one document in one request, including "select all", and cancel
your own jobs across a whole collection.
- `publish`: publish the target locale once it is translated.
- `manageJobs`: run or cancel jobs other users queued.
## Step 1: install
pnpm add @focus-reactive/payload-plugin-translator @focus-reactive/payload-plugin-guard openai
Check that `payload` is 3.90 or later; if it is not, upgrade it first.
Check that `localization` is enabled in the Payload config and that the fields to translate are
marked `localized: true`.
## Step 2: ask me about roles
Look at the auth collection named in `admin.user` and the roles it has.
Ask me: "Which roles may translate a document?", "Which roles may translate many documents at once?",
"Which roles may publish translations?" and "Which roles may run or cancel other people's translation jobs?"
Wait for my answers. Write each answer as a gate in the policy file in step 3.
## Step 3: the access policy file
Open `src/access.policy.ts`, or create it if the project has none, following the guard README
(`defineAccessPolicy`, `gate`, `filter`, `nobody`, `anyone`, checked with `satisfies AccessPolicy<Config>`).
If you create it, every collection and global of the config needs an entry: move each existing
`access` of the project into the file, and ask me for every rule you cannot read from the code.
Add these entries for this plugin:
collections: {
"translator-provenance": { create: nobody, read: nobody, update: nobody, delete: nobody },
"payload-jobs": "payload-default",
},
jobs: { run: <an admin gate, or a cron-secret gate>, queue: <an admin gate>, cancel: <an admin gate> },
plugins: {
translator: {
translate: <the gate from my first answer>,
translateInBulk: <the gate from my second answer>,
publish: <the gate from my third answer>,
manageJobs: <the gate from my fourth answer>,
},
},
Keep the `translator-provenance` entry only if you turn `provenance` on in step 4.
## Step 4: register the plugin and wrap the config
// payload.config.ts
import OpenAI from 'openai'
import { buildConfig } from 'payload'
import { withAccessPolicy } from '@focus-reactive/payload-plugin-guard'
import {
createPayloadJobsRunner,
createTranslationProvider,
openAIComplete,
translatorPlugin,
} from '@focus-reactive/payload-plugin-translator'
import { accessPolicy } from './access.policy'
export default withAccessPolicy(
accessPolicy,
buildConfig({
// ...the existing config
plugins: [
translatorPlugin({
collections: [Posts],
access: accessPolicy.plugins.translator,
translationProvider: createTranslationProvider({
complete: openAIComplete({
client: new OpenAI({ apiKey: process.env.OPENAI_API_KEY }),
model: 'gpt-5.4-mini',
}),
}),
runner: createPayloadJobsRunner(),
provenance: true,
}),
],
})
)
Pass the same collection objects that `buildConfig` receives, not sanitized ones.
Run `payload generate:importmap` and `payload generate:types`, create a migration if the database is
SQL (`payload migrate:create`), then start the app.
A missing or wrong policy entry stops the boot with a list of what to fix.
Fix each item; never loosen a rule to make an error go away.
## Step 5: verify, and show me the output
With the app running, send each request and show me the status code.
Every one of them must be refused. If one succeeds, the policy is wrong: stop and tell me.
1. Anonymous enqueue, expect 401:
curl -i -X POST http://localhost:3000/api/translator/enqueue -H 'Content-Type: application/json' -d '{"source_lng":"en","target_lng":"de","collection_slug":"posts","collection_id":["<post id>"]}'
2. The same request with the session cookie of a user whose role may not translate, expect 403.
3. The same request by a translator for a post that user may not update, expect 403.
4. Anonymous write to the provenance collection, expect 403:
curl -i -X POST http://localhost:3000/api/translator-provenance -H 'Content-Type: application/json' -d '{}'
5. Anonymous queue run, expect 401:
curl -i http://localhost:3000/api/payload-jobs/run?queue=translations
Then, as a user who may translate, open a post, translate it from `en` to `de`, and check the German locale.
npm install @focus-reactive/payload-plugin-translator @focus-reactive/payload-plugin-guard openai
openai is optional — it backs the recipe below, and any OpenAI-compatible endpoint works in its place.
| Requirement | Version |
|---|---|
payload | ^3.90.0 |
@payloadcms/ui | ^3.90.0 |
@payloadcms/richtext-lexical | ^3.90.0 |
react | ^19 — the plugin accepts ^18 too, but current @payloadcms/ui and @payloadcms/richtext-lexical builds require 19 |
openai | ^4.50.0 (optional) |
Your Payload config must have localization enabled, and the fields you want translated must be marked localized: true.
[!NOTE] Coming from
0.19or earlier? Migrating from 0.19 lists what to change. Versioning has the terms and the list of what is already going.
Hand the plugin the same collection objects you pass to buildConfig, not the sanitized ones from payload.collections. The originals still carry localized: true on nested fields.
This is a whole config so that it runs as shown; in your project keep your own database adapter, and set PAYLOAD_SECRET in the environment before starting.
The access policy grants each capability to a role of the users collection; the guard README covers the policy file in full.
// access.policy.ts
import { defineAccessPolicy, gate, nobody, panelUser } from '@focus-reactive/payload-plugin-guard'
const hasRole = (...roles: string[]) =>
gate(({ req }) => roles.includes((req.user as { role?: string } | null)?.role ?? ''))
const isAdmin = hasRole('admin')
const isEditor = hasRole('admin', 'editor')
export const accessPolicy = defineAccessPolicy({
collections: {
users: { create: isAdmin, read: panelUser, update: isAdmin, delete: isAdmin, admin: isEditor },
posts: { create: isEditor, read: isEditor, update: isEditor, delete: isAdmin },
'payload-jobs': 'payload-default',
'payload-kv': 'payload-default',
'payload-locked-documents': 'payload-default',
'payload-preferences': 'payload-default',
'payload-migrations': { create: nobody, read: isAdmin, update: nobody, delete: nobody },
},
globals: {},
jobs: { run: isAdmin, queue: isAdmin, cancel: isAdmin },
plugins: {
translator: { translate: isEditor, translateInBulk: isEditor, publish: isAdmin, manageJobs: isAdmin },
},
})
// payload.config.ts
import { withAccessPolicy } from '@focus-reactive/payload-plugin-guard'
import { sqliteAdapter } from '@payloadcms/db-sqlite'
import OpenAI from 'openai'
import { buildConfig } from 'payload'
import type { CollectionConfig } from 'payload'
import {
createPayloadJobsRunner,
createTranslationProvider,
openAIComplete,
translatorPlugin,
} from '@focus-reactive/payload-plugin-translator'
import { accessPolicy } from './access.policy'
const Users: CollectionConfig = {
slug: 'users',
auth: true,
fields: [{ name: 'role', type: 'select', options: ['admin', 'editor'] }],
}
const Posts: CollectionConfig = {
slug: 'posts',
fields: [
{ name: 'title', type: 'text', localized: true },
{ name: 'summary', type: 'textarea', localized: true },
],
}
export default withAccessPolicy(
accessPolicy,
buildConfig({
admin: { user: 'users' },
collections: [Users, Posts],
db: sqliteAdapter({ client: { url: 'file:./payload.db' } }),
localization: { defaultLocale: 'en', locales: ['en', 'de', 'fr'] },
secret: process.env.PAYLOAD_SECRET ?? '',
plugins: [
translatorPlugin({
collections: [Posts],
access: accessPolicy.plugins.translator,
translationProvider: createTranslationProvider({
complete: openAIComplete({
client: new OpenAI({ apiKey: process.env.OPENAI_API_KEY }),
model: 'gpt-5.4-mini',
}),
}),
runner: createPayloadJobsRunner(),
}),
],
})
)
Regenerate the admin import map so Payload picks up the plugin's components:
npx payload generate:importmap
Sign in as an editor and open a posts document. A Translate control now sits beside the document controls: choose en as the source and de as the target, and the German locale is filled in within a minute.
[!TIP] Rerun
payload generate:importmapafter adding or removingdocumentLevel()orcollectionLevel(), or the admin renders without their controls.fieldLevel()adds no admin component, so it needs no regeneration.
targetSelection: 'multi' turns the target field on both the document and the collection surfaces into a multi-select, and every selected document is translated into every locale you picked. The default is one locale per run.fieldLevel() in levels and withFieldTranslation on the field.withAutoTranslate(collection, { targets }) and editing the source locale queues its own translations, with no one pressing anything. On a collection with drafts enabled it waits until the document is published; without drafts it fires on every save. Rapid edits are coalesced into one run.skip_existing strategy fills only empty target fields, and withFieldTranslation(field, { exclude: true }) keeps a field out of translation entirely.systemPrompt replaces the instruction sent with every request, so tone, register, a glossary, or brand names that must stay untranslated are yours to set.createSyncRunner() translates inline instead, for tests and scripts.localized container, where each locale owns its own rows and gets fresh ones.provenance on, the admin flags the locales whose source has changed since they were translated, and an editor can dismiss a flag without re-translating.What travels: localized text, textarea and richText fields, at any depth inside groups, arrays, tabs and blocks. Every other field type reaches the target locale unchanged.
[!NOTE] Inside a rich-text paragraph, word order follows the source language and inline emphasis can land on the wrong word once the target language reorders the sentence. Container mode, available since
0.13.0behind an opt-in flag, fixes both.
[!IMPORTANT] Mark each leaf field
localized: trueyourself. Payload lets a wrapper (group, array, blocks, tabs) carrylocalizedand have nested fields inherit it, and a leaf without it of its own is left alone.// Skipped — the nested title is not explicitly localized { name: 'meta', type: 'group', localized: true, fields: [{ name: 'title', type: 'text' }] } // Translated { name: 'meta', type: 'group', localized: true, fields: [{ name: 'title', type: 'text', localized: true }] }
translatorPlugin(config: TranslatorPluginConfig)
| Option | Type | Default | Description |
|---|---|---|---|
collections | CollectionConfig[] | — | Required. Original collection configs to make translatable. |
translationProvider | TranslationProvider | — | Required. What actually translates the text. |
runner | TaskRunnerProvider | — | Required. What runs the translation — in the background, or inline. |
levels | TranslationLevel[] | [documentLevel(), collectionLevel()] | Which translation surfaces to enable. |
access | Record<'translate' | 'translateInBulk' | 'publish' | 'manageJobs', Gate> | - | Required, no default. One gate from your access policy per capability, usually accessPolicy.plugins.translator. See Access control. Since v0.20.0. |
maxDocumentsPerRequest | number | 500 | The most documents one enqueue request may queue, picked one by one or with "select all". A larger request is refused with 400. Since v0.20.0. |
targetSelection | 'single' | 'multi' | 'single' | 'multi' lets an editor pick several target locales for one run. Since v0.10.0. |
provenance | boolean | { slug?: string } | false | Adds a collection recording what each locale was translated from, so the admin can flag stale ones. Default slug translator-provenance. |
lifecycle | TranslationLifecycleCallbacks | {} | Server-side onQueued / onCompleted / onFailed callbacks. |
Since v0.5.0; fieldLevel() since v0.6.0.
Levels are the surfaces the plugin adds. List the ones you want; each should appear at most once.
| Level | What it adds |
|---|---|
documentLevel() | A Translate popup on the document edit view. |
collectionLevel() | A bulk translation dashboard above the list table. |
fieldLevel() | Turns on the per-field control. Not in the default set. |
import { documentLevel, collectionLevel, fieldLevel } from '@focus-reactive/payload-plugin-translator'
translatorPlugin({
collections: [Posts],
translationProvider,
runner,
levels: [documentLevel(), collectionLevel(), fieldLevel()],
})
fieldLevel() on its own shows nothing: the control appears only on the fields you wrap with withFieldTranslation.
import { withFieldTranslation } from '@focus-reactive/payload-plugin-translator'
export const Posts: CollectionConfig = {
slug: 'posts',
fields: [
// A Translate control appears above this input (text, textarea, richText)
withFieldTranslation({ name: 'title', type: 'text', localized: true }),
// Never sent to the translation provider (any field type)
withFieldTranslation({ name: 'sku', type: 'text', localized: true }, { exclude: true }),
],
}
The control translates from a source locale you pick, reading the saved document's value in that locale and writing the result into the locale you are editing. Unsaved edits in the form are invisible to it.
The control is an icon button above the input. It opens a small popup showing the direction — a source-locale select, an arrow, then the locale you are editing as the fixed target (en → fr). You choose the source; the target is always where you stand. Note this is the opposite direction from the document and collection controls, which translate out of the locale you are in.
The control needs a saved document, so it stays hidden while you are creating one. The result lands in the form unsaved — no save, no queue — and an Undo restores the previous value.
withFieldTranslation accepts text, textarea and richText; any other type is a compile error, so pass { exclude: true } for those. Fields inside blocks are supported.
[!WARNING] A localized
blocksorarraycontainer has no per-field translation. Wrap the leaves, not the container. When the container itself is localized, each locale holds its own order and content, so there is no single field to translate across them: the control answers with a notice telling you to translate the whole document instead, which handles this case.
{ exclude: true } means never send this field to the provider — not leave it untouched. An excluded field keeps its target value when it has one, is filled from the source locale when the target is empty (so a required field does not fail validation on save), and is never sent for translation. Exclusion wins over the overwrite strategy.
Since v0.9.0.
Wrap a collection and edits to the source locale queue their own translations. On a collection with versions.drafts enabled this waits until the document is published; without drafts every save triggers it. Off unless you opt in, and a save that touched no translatable content queues nothing.
import { withAutoTranslate } from '@focus-reactive/payload-plugin-translator'
translatorPlugin({
collections: [withAutoTranslate(Articles, { targets: ['de', 'fr'], debounceMs: 2000 })],
translationProvider,
runner,
})
| Key | Type | Default | Description |
|---|---|---|---|
targets | string[] | — | Required. Locales to translate into. The source locale is always excluded. |
strategy | 'overwrite' | 'skip_existing' | 'overwrite' | Replace every target field, or only fill empty ones. |
debounceMs | number | 0 | Delay before the queued job runs, coalescing rapid edits. |
sourceLocale | string | localization.defaultLocale | Source locale override for this collection. |
[!IMPORTANT] Auto-translate only schedules the work. Nothing is translated unless your runner actually runs it — see Task runners.
Auto-translate acts as the admin-panel user who saved the source, and with that user's rights. Since v0.20.0.
A save by a user without the translate capability, by a user of another auth collection, or with no user at all (a script, a seed, a Local API call without user) queues nothing.
The job records who saved, and when it runs it checks that user's current capabilities and document rights again; if the user is gone or has lost them, nothing is written.
[!WARNING] Auto-translate publishes what it writes when the saver holds
publish. A translation it queues off a published save by such a user is published in turn, not left as a draft. A save by a user withoutpublishqueues translations that stay drafts.
Applies to every trigger: the admin controls, POST /api/translator/enqueue, and auto-translate.
Publishing on translation needs the publish capability and the requester's right to publish the document.
Everything below describes a collection with versions.drafts enabled. Without drafts there is nothing to stage: a translation is written straight to the live document, and asking to publish on translation does nothing, silently.
Without publish-on-translation the translation is written as a draft version. The document's published state is untouched: a live page stays live, an unpublished one stays unpublished, and the new locale does not reach the public site until someone publishes it.
With publish-on-translation the translation is written as a draft and the target locale is then published — which happens whether or not any field actually needed translating. Only the translated locale is published; other locales keep the state they were in. Translating a document that is not currently published does make it live, carrying just that locale's content.
The source is the source locale's own current content — the newer draft when one exists, otherwise the published version, never a value Payload substitutes from another locale. Translating from a locale you have not filled in therefore translates nothing.
Two consequences worth knowing before relying on it:
skip_existing counts anything non-empty as translated. A translation waiting unpublished in a draft counts, so a reviewer's corrected text is published as it stands rather than re-translated. It has no notion of reviewed, and a locale the admin flags as out of date is still skipped (#118).Since v0.11.0.
A provider is one method: take { 0: "Hello", 1: "World" } plus a source and target language, and return the same keys translated. Build one from a single request function with createTranslationProvider:
import { createTranslationProvider } from '@focus-reactive/payload-plugin-translator'
const provider = createTranslationProvider({
complete: async ({ systemPrompt, userContent, responseSchema }) => {
const reply = await myService.chat({ systemPrompt, userContent, schema: responseSchema })
return reply.text // return the reply as it came; the plugin reads it
},
})
Or implement the TranslationProvider interface directly if you need full control.
systemPrompt replaces the instruction sent with every translation request — the place for tone, register, a glossary, or brand terms that must survive untranslated. It receives the source and target language codes plus the prompt the plugin would have sent, so you can extend rather than replace:
createTranslationProvider({
complete: openAIComplete({ client, model: 'gpt-5.4-mini' }),
systemPrompt: ({ sourceLang, targetLang, defaultPrompt }) =>
`${defaultPrompt}\nUse formal register. Leave product names in ${sourceLang} unchanged.`,
})
sourceLang is empty when the provider is expected to detect the language itself.
openAIComplete works with any client exposing a Chat Completions chat.completions.create — the OpenAI SDK, Azure OpenAI, OpenRouter, a corporate proxy. You construct the client, so the SDK version is yours to choose.
createTranslationProvider({
complete: openAIComplete({
client: new OpenAI({
apiKey: process.env.OPENROUTER_API_KEY,
baseURL: 'https://openrouter.ai/api/v1',
}),
model: 'anthropic/claude-sonnet-4.5',
sampling: { temperature: 0 },
structuredOutput: 'json_object',
}),
})
structuredOutput picks how the reply is asked for:
'json_schema' (default) — the reply must satisfy a schema, so a compliant model cannot drop a field. Older models and some gateways reject it with a 400, and the schema has a per-model property ceiling that a very large document can exceed.'json_object' — asks only for valid JSON. No ceiling, but a field the model drops surfaces as a failed translation afterwards instead of being prevented.sampling is sent only if you set it — several models reject the parameters outright. Pass { temperature: 0 } when you want translations to come out the same way twice.
[!NOTE]
createOpenAIProvider({ apiKey })still exists and builds the client for you. It is deprecated in favour of the two lines above — see Deprecated aliases.
Provider failures arrive as typed errors, each with a code and the original failure on cause.
| Error | code |
|---|---|
NoContentError | no-content |
UnparseableReplyError | unparseable-reply |
KeySetMismatchError | key-set-mismatch |
TransportError | transport |
ProviderConfigurationError | config |
All extend TranslationProviderError; the union of codes is exported as TranslationFailureCode.
There is no built-in fake — supply your own complete, which reaches nothing and needs no API key:
const fake = createTranslationProvider({
complete: async ({ userContent }) => {
const input: Record<string, string> = JSON.parse(userContent)
return JSON.stringify(
Object.fromEntries(Object.entries(input).map(([k, v]) => [k, `[de] ${v}`]))
)
},
})
| Runner | Behaviour |
|---|---|
createPayloadJobsRunner(options?) | Translates in the background, one Payload Job per document. The normal choice. |
createSyncRunner(options?) | Translates immediately, before the call returns. No queue to run — handy in tests and scripts. |
PayloadJobsRunnerOptions:
| Option | Type | Default |
|---|---|---|
taskName | string | 'translate_document' |
queueName | string | 'translations' |
jobsCollection | CollectionSlug | 'payload-jobs' |
autoRun | false | { cron?: string; limit?: number } | { cron: '* * * * *', limit: 50 } |
staleJobTimeoutMs | number | 300000 |
retries | { attempts?: number; backoff?: { delay?: number; type: 'exponential' | 'fixed' } } | { attempts: 3, backoff: { type: 'exponential', delay: 5000 } } |
[!WARNING]
staleJobTimeoutMsmust exceed the longest a single document translation can legitimately take. Set it too low and a translation still running is started again — the document is translated twice, and billed twice.
[!IMPORTANT] Cron autorun does not fire on serverless hosts such as Vercel, so jobs queue and wait. Pass
createPayloadJobsRunner({ autoRun: false })and drive the queue from your own cron through Payload'sGET /api/payload-jobs/run?queue=translations, which your policy'sjobs.rungate guards (see Jobs and the queue).POST /api/translator/runruns one job now for a signed-in user.
createSyncRunner keeps the status of what it ran in memory — the last 100 tasks, for an hour, adjustable with maxSize and ttlMs. A restart forgets them. Nothing is lost but the reporting: the translations themselves are already written.
Payload deletes a job the moment it completes, so the "Completed" state never appears in the status panels. Set jobs: { deleteJobOnComplete: false } in your Payload config to keep them — it is Payload's option, not the plugin's, and pruning what accumulates is yours to manage the same way.
Since v0.20.0.
The plugin declares four capabilities.
Your access policy grants each one with a gate, and access: accessPolicy.plugins.translator hands them to the plugin.
There is no default: a missing or partial access stops the boot.
// access.policy.ts
plugins: {
translator: {
translate: isEditor,
translateInBulk: isEditor,
publish: isAdmin,
manageJobs: isAdmin,
},
},
| Capability | Lets a user | Also needs |
|---|---|---|
translate | translate one document or one field, read translation status and staleness, run or cancel their own jobs | read on the source locale and update on the target locale of each document |
translateInBulk | queue more than one document in one request, including "select all", and cancel their own jobs across a collection | the same rights, on every document |
publish | publish the target locale after translating it | the right to publish the document |
manageJobs | run or cancel jobs other users queued | update on the job's document, or nothing to cancel a job whose document was deleted |
The capability says who may act at all.
The document rights come from the policy entries you already wrote for the collection: a user who cannot update a post cannot translate into it, whatever capabilities they hold.
The admin shows the document's Translate control and the field-level translate button only to a user who holds translate and may update the document, and a refused request is shown as a message instead of being dropped.
The bulk dashboard above a list shows only to a user who holds translate and translateInBulk and may update documents in that collection.
When the user may not update every selected document, the dashboard says how many it queued, or that it queued nothing.
A job in a document's translation status offers Retry, Run now and Cancel only to a user the server would let run and cancel it.
The bulk Cancel translations button shows only when the user may cancel at least one queued translation in the collection, because without manageJobs it cancels only the user's own; afterwards the admin says how many it cancelled.
admin.user whose access.admin allows them) can call the plugin.
Anonymous callers get 401; users of another auth collection and users without the capability get 403.POST /api/translator/run, so its provider budget is not spent again; queue a new translation instead.manageJobs, and is never run.collections with 400.maxDocumentsPerRequest documents per enqueue (default 500), 100 ids per cancel, 256 KB per field value sent to the provider, and the request body size the guard allows.
Errors carry a generic message; details go to the server log.GET /api/translator/capabilities answers an admin-panel user with { "translate": boolean, "translateInBulk": boolean, "publish": boolean, "manageJobs": boolean }, so custom admin UI can hide controls; the server still checks every request.| Slug | Kind | Written by | Read by |
|---|---|---|---|
translator-provenance (with provenance on) | collection | the plugin only | your policy's read; nobody is the usual answer, since the admin reads it through the plugin |
The collection needs an entry in your policy, and its create, update and delete are refused over REST, GraphQL and the Local API with overrideAccess: false, for every user.
With createPayloadJobsRunner(), translations are Payload jobs in the translations queue, so the policy's jobs entry and the payload-jobs collection apply.
'payload-jobs': 'payload-default' in the policy.jobs.run guards Payload's own GET /api/payload-jobs/run.
Grant it to admins, and on a serverless host to your cron, for example with a gate that compares a bearer token to CRON_SECRET using safeEqual from the guard.
Whoever triggers the run, each translation job still acts as the user who queued it, with that user's current rights.jobs.queue and jobs.cancel guard Payload's own queue and cancel operations; the plugin queues and cancels through its own endpoints, which check the capabilities above.Since v0.7.0.
Nothing to set up beyond the config — no collection, no migration. A callback that throws is logged and never fails the translation.
translatorPlugin({
collections,
translationProvider,
runner,
lifecycle: {
onQueued: (task) => log.info(task, 'translation queued'),
onCompleted: (task) => log.info(task, 'translation done'),
onFailed: (task, error) => log.error({ task, error }, 'translation failed'),
onCancelled: (task) => log.info(task, 'translation cancelled'),
},
})
Each task carries { collection, id, sourceLng, targetLng, strategy, handle }. handle names the run translating that locale: the value the enqueue answer gave, and the one DELETE /api/translator/cancel takes back. Since v0.16.0.
Each callback fires at most once per target locale, never per attempt: onQueued when the runner takes the work, then one of onCompleted, onFailed or onCancelled. onFailed means the locale will not be translated — retries are the runner's own business and are not reported, so there is no need to disable them. Since v0.16.0; onFailed previously fired on every failed attempt.
Two notes on "at most once". A second request for a locale a live run already covers joins that run instead of starting another, so both requests see the same handle and one set of events. And a locale already being translated when its run is cancelled is announced onCancelled and may still finish as onCompleted.
Since v0.7.0.
Set provenance: true and the plugin adds a collection that records, for each document and target locale, what the source looked like when that locale was translated. The admin uses it to flag locales whose source has changed since, and an editor can dismiss a flag without re-translating. The record type is exported as TranslationProvenanceRecord if you want to read it yourself.
[!IMPORTANT] On a SQL database this adds a table. Generate and run a migration (
payload migrate:create, thenpayload migrate; dev push works in development). MongoDB infers it with no migration. Leavingprovenanceoff means no collection, no migration and no behaviour change.
[!NOTE] Upgrading from below 0.11.1. A locale can read as out of date once after the upgrade with nothing actually needing re-translation. Dismissing the flag or re-translating settles it.
Every endpoint lives under /api/translator/ and answers only an admin-panel user who holds the capability named below. Since v0.20.0.
Requests with a body must send Content-Type: application/json.
| Method | Path | Capability | When you need it |
|---|---|---|---|
POST | /api/translator/enqueue | translate; translateInBulk for more than one document; publish with publish_on_translation | Start translations from your own code: a migration, an import, any script running as a user. |
POST | /api/translator/run | translate, and the job is yours or you hold manageJobs | Run a queued job now. |
POST | /api/translator/field | translate | Translate one field and get the result back. Mounted only when levels includes fieldLevel(). |
GET | /api/translator/capabilities | none | What the signed-in user may do. |
POST /enqueue takes source_lng, target_lng (one locale or a list), collection_slug and collection_id[], plus optional select_all, strategy ('overwrite' | 'skip_existing', default 'overwrite') and publish_on_translation (default false). Field names are snake_case.
If the caller may not translate one of the collection_id documents, the answer is 403 and nothing is queued.
It answers { "data": { "success": true, "queued": <translations>, "documents": <documents> } }.
With select_all it queues only the documents the caller may update, so documents can be lower than the number of documents in the collection.
A script calls these endpoints as a user of admin.user: it signs in with POST /api/<admin user slug>/login and sends Authorization: JWT <token>.
An API key is refused, because the endpoints accept only the session channel.
POST /run takes { "id": "<job id>" }.
POST /field takes collection_slug, doc_id, field_path, source_lng and target_lng.
The field must be localized and the two locales must differ.
[!NOTE] The plugin mounts further routes under
/api/translator/to serve its own admin panels: status, cancel and staleness. They are not part of the published contract and may change in any release; drive the plugin through the endpoints above.
| Export | Kind | Purpose |
|---|---|---|
translatorPlugin | function | The plugin itself. |
documentLevel, collectionLevel, fieldLevel | functions | Translation surfaces for levels. |
withFieldTranslation | function | Attach a per-field control, or exclude a field. |
withAutoTranslate | function | Opt a collection into auto-translation. |
createTranslationProvider | function | Build a provider from one complete function. |
openAIComplete | function | Chat Completions complete for a client you construct. |
createPayloadJobsRunner, createSyncRunner | functions | The two ways to run a translation. |
toTaskFilter | function | Builds the document filter a runner accepts. |
TranslationProviderError and subclasses | classes | Typed provider failures. |
TranslatorPluginConfig | type | Plugin configuration. |
TranslationProvider, TranslationInput, TranslationOutput | types | The provider contract. |
CompletionFn, CompletionRequest, TranslationProviderConfig | types | The complete contract. |
SystemPromptBuilder, SystemPromptContext, JsonSchemaObject | types | Prompt and schema customization. |
OpenAIClientShape, OpenAISamplingParams, OpenAIStructuredOutput | types | OpenAI adapter. |
TaskRunnerProvider, PayloadJobsRunnerOptions, TaskFilter | types | Task runners. |
TranslationLevel, TargetSelectionMode | types | Surfaces and target selection. |
AutoTranslateConfig, AutoTranslateStrategy, FieldTranslationConfig | types | Collection and field configuration. |
TranslationTask, TranslationLifecycleCallbacks | types | Lifecycle callbacks. |
TranslationProvenanceRecord | type | One stored provenance record. |
[!WARNING] Shipped in
0.13.0behindexperimental: { inlineMarks: true }, off by default, and deprecated on arrival — the next major removes the flag and makes container mode the only mode. Treat it as a schedule, not a permanent switch: do not build on the option itself.
With the flag off, a translated sentence keeps the source language's word order, and bold or a link can end up on the wrong word. a **red** car into French comes back as un rouge voiture — ungrammatical, with the emphasis misplaced.
With the flag on, the whole container — a paragraph, a heading, one list item — goes as a single string with its formatting written as numbered marks:
<1>a </1><2>red</2><3> car</3>
Your provider must return those markers intact — translated and reordered as the target language needs, but neither translated themselves nor dropped. The same sentence then comes back as une voiture rouge: the emphasis stays on the word it belonged to, and links travel with theirs.
The flag does nothing unless your provider declares that it can handle the markers:
createTranslationProvider({
complete: openAIComplete({ client, model: 'gpt-5.4-mini' }),
capabilities: { inlineMarks: true },
})
Declare it only for a service you trust to return the markers untouched — a plain machine-translation API would translate or drop them. A container whose reply comes back with broken markers is left in its source language rather than written back half-translated.
Switching the flag back off changes only future translations; documents already translated under it keep the structure they have.
0.20.0 moves the plugin onto @focus-reactive/payload-plugin-guard.
[!IMPORTANT] In versions up to and including
0.13.4, leaving outaccessleft the translation endpoints open to anyone, signed in or not. If you ran one of those versions withoutaccess, review the translations, thepayload-jobsrows and your translation provider's usage from that period, and upgrade. From0.19.1, a request without a session gets401whatever the guard. From0.20.0,accesshas no default and every endpoint refuses anonymous callers.
@focus-reactive/payload-plugin-guard.src/access.policy.ts if the project has none, or extend it, with the translator entry from Access control, a translator-provenance entry when provenance is on, 'payload-jobs': 'payload-default' and a jobs entry, and wrap the config with withAccessPolicy.access: { check } or new AnyAccessGuard() with access: accessPolicy.plugins.translator.
AccessGuard, AccessGuardRequest and AnyAccessGuard are gone.basePath is gone: the endpoints live at /api/translator/... instead of /api/translate/....
POST /run/:id became POST /api/translator/run with { "id": "<job id>" }.
DELETE /cancel-by-collection/:collection_slug became DELETE /api/translator/cancel-by-collection with { "collection_slug": "<slug>" }.
Requests with a body must send Content-Type: application/json.403 for a document they cannot update.
Bulk requests need translateInBulk, publishing needs publish, and acting on someone else's job needs manageJobs.translate.
Seeds and scripts that relied on it must call POST /api/translator/enqueue as a user, or save with user set.0.19 or earlier that name no requester write nothing when they run; queue them again.maxDocumentsPerRequest documents (default 500), a field value sent to the provider is capped at 256 KB, and a job that has given up is not revived by POST /run.TaskRunnerProvider must implement findByIds(taskIds) on its task runner, which the run and cancel endpoints use to check each job before acting.0.20.0 moved the plugin onto the guard; Migrating from 0.19 lists what changed. The surface still moves, and a later major will take a fair amount away. What it will not do is move silently. The terms are:
docs/DEPRECATIONS.md records why each one is going.0.5.0 says which release it arrived in — as a Since note beside the feature here, and as an @since tag in its JSDoc, so your editor answers the question too. Older API predates the convention and carries no marker.Already scheduled for a later major: everything in Deprecated aliases, and the experimental.inlineMarks flag, when container mode becomes the only mode.
0.20.0 removed none of them.
Still exported, removed in a later major. The reasoning behind each is in docs/DEPRECATIONS.md.
| Deprecated | Use instead |
|---|---|
createTranslatePlugin, TranslateCollectionPlugin | translatorPlugin |
TranslateCollectionPluginConfig | TranslatorPluginConfig |
translateKitField | withFieldTranslation |
TranslateKitFieldConfig | FieldTranslationConfig |
OpenAITranslationProvider, createOpenAIProvider | createTranslationProvider + openAIComplete |
dryRun on a provider config | Your own complete function |
The Translate control does not appear. Run payload generate:importmap after registering the plugin, and restart the dev server.
Nested localized fields are skipped. You passed sanitized configs. collections must receive the same objects you give buildConfig — Payload's sanitizer strips localized from fields nested under a localized ancestor.
Jobs stay queued forever. Nothing is draining the queue. Check that autorun is enabled, or call Payload's GET /api/payload-jobs/run?queue=translations from a cron your policy's jobs.run admits, on platforms where autorun does not fire.
A job runs but writes nothing. A job writes only what the user who queued it may still write. Check that the user still exists, still holds translate (and publish if the job publishes), and may update the target locale; the server log names the reason.
Auto-translate queues nothing after a save. Only a save by an admin-panel user holding translate queues translations. A Local API write without user queues none.
The boot stops with "the access policy does not match the config". Add the entries it lists to your policy: the translator plugin entry, translator-provenance when provenance is on, and payload-jobs.
ProviderConfigurationError saying the model does not support the json_schema response format, or that the schema was rejected. The model or gateway would not accept the schema request, or the document was too large for it. Switch to structuredOutput: 'json_object'.
A per-field control on a field that is not text. withFieldTranslation adds a control only to text, textarea and richText; any other field type must be passed { exclude: true }.
MIT © Focus Reactive
Topics
Tags
payload plugin translator
AI translation of localized fields in collections and globals, saved as drafts without overwriting hand-edited text
74356/wk1v3
payload plugin scheduling
Schedule future publication of drafts on collections and globals with a secured cron endpoint
77783/wk37v3
payload plugin guard
Central access policy file, typed predicates and guarded endpoints for Payload plugins and Local API calls
73664/wk37v3
payload plugin json form builder
Edit a Payload json field as real admin fields, with the form shape built in the admin panel
72441/wk37v3
payload plugin audit log
Append-only audit log of document, global and auth changes with CSV and NDJSON export
72394/wk37v3
payload plugin seo
Live Yoast-powered SEO analysis drawer in the Payload document editor without adding fields to documents
70884/wk37v3