Introducing a new way to review your PRs.

Read the announcement

generaltranslation / gt

Full-stack localization for every framework

View on GitHub

22 documents · Updated Nov 23, 2026

docs / payload-cms-integration

Payload CMS integration

The Payload CMS integration brings General Translation into the Payload admin panel. It uses Payload's localized fields as the source model, sends each document as translation work, and writes completed locales back as drafts or saved content without publishing them. The current package release is 0.1.7, with the General Translation dependency at 9.5.13.

Integration model

Locale configuration

The plugin uses Payload's localization settings as the source of truth. The default locale is the source language, and every other configured locale becomes a possible translation target only when General Translation recognizes its code.

Payload fields must also be marked localized: true for the plugin to find their content. A custom locale mapping can connect a Payload code to a General Translation code when the two systems use different names.

The plugin keeps the source locale out of target choices. It shows supported target locales with their Payload labels when available, and it leaves unsupported locales out of translation requests.

References: packages/…/locales.ts• L17-63 packages/…/plugin.ts• L285-303 packages/…/README.md• L27-65

Document targets

The integration treats a collection document or a global as a translation target. A collection target uses its collection and document ID. A global target uses its global slug, so each target remains stable across locale reads and writes.

The site workflow finds every non-Payload collection document and global that has translatable fields. It reads the latest source draft without falling back to another locale, and it applies the signed-in user's Payload access rules to reads and writes.

Before a user starts work on selected documents, the plugin checks update permission for every target. This prevents translation usage when the user cannot save all requested documents. Site runs still filter content through the same access-aware target and write paths.

References: packages/…/documents.ts• L17-75 packages/…/documents.ts• L78-132 packages/…/documents.ts• L211-249 packages/…/documents.ts• L323-379 packages/…/plugin.ts• L119-135 packages/…/plugin.test.ts• L270-349

Translation runs

A translation run is a saved unit of work that can continue after the browser closes. It records the targets, locales, pending work, remote jobs, progress, and failures in Payload, then advances in bounded steps.

The run follows this lifecycle:

flowchart LR
    A[Select documents and locales] --> B[Create saved run]
    B --> C[Read and serialize source]
    C --> D[Upload and queue translation]
    D --> E[Check remote job state]
    E --> F[Download completed locales]
    F --> G[Rebuild and save Payload locales]
    G --> H[Record progress and outcome]

The admin panel can step a run while it is open. Payload's job queue can also step it, and a later signed-in admin page can resume a stale run. A save run uses the same lifecycle but sends current local translations to General Translation instead of requesting new translations.

The optional Save local edits before translating action preserves edits already made in Payload or translations created before the plugin was installed. Text whose links no longer match the source cannot be safely sent as a translation; the integration reports it as unsaved and can keep it during the next translation.

Translation writes follow Payload's normal draft boundary. Collections and globals with drafts enabled receive drafts, while others receive direct locale updates. The plugin never publishes content.

References: packages/…/translation.ts• L159-210 packages/…/translation.ts• L509-603 packages/…/translation.ts• L622-747 packages/…/translation.ts• L788-842 packages/…/documents.ts• L109-132 packages/…/runs.test.ts• L83-214 packages/…/saveTranslations.ts• L49-157 packages/…/README.md• L67-85

Run locking

Locks protect the two shared resources that can be damaged by concurrent work: the run record and the document being saved. A unique lock key allows one worker to hold each resource at a time, while a time lease lets another worker take over after an abandoned worker stops renewing it.

The run lock prevents two steppers from changing the same run at once. The document lock prevents two runs from saving different locale results over one another. The stepper checks that it still owns its lease before it records progress, so a worker that lost the lease does not overwrite newer state.

The plugin stores runs and locks in hidden Payload collections. These collections are part of the Payload schema and need the same migration process as other schema changes.

References: packages/…/locks.ts• L8-25 packages/…/locks.ts• L27-96 packages/…/runs.ts• L1-5 packages/…/runs.ts• L291-337 packages/…/runs.ts• L341-439 packages/…/plugin.ts• L311-323 packages/…/runs.test.ts• L248-420

Content exchange

Field serialization

The integration converts the translatable parts of one Payload target into a keyed HTML document for General Translation. The same field walk creates source units, matches existing locale text, and rebuilds the target so a string keeps the same identity in both directions.

The field model covers localized text, textarea, and rich-text values inside groups, tabs, arrays, and blocks. It skips values that should remain structural or editor-controlled, such as row IDs, slugs, hidden or read-only fields, addresses such as URLs and email values, and fields marked with custom.gt.translate: false. Required fields that have no translation use the source value when Payload needs a value to save the locale.

Field paths become stable hashed keys in the exchange document. This lets the integration recognize removed or missing strings and report them instead of silently assigning a translation to the wrong field. Empty source values also clear the matching target value, which keeps a locale aligned with the source.

References: packages/…/fields.ts• L1-14 packages/…/fields.ts• L106-145 packages/…/fields.ts• L223-321 packages/…/fields.ts• L588-631 packages/…/file.ts• L16-31 packages/…/file.ts• L33-112 packages/…/address.test.ts• L5-41 packages/…/translateDocument.outgoing.ts• L20-139 packages/…/translateDocument.fieldRules.ts• L59-280

Rich-text serialization

Rich-text content keeps its document structure in Payload while its inline text crosses the translation boundary as marked HTML. The serializer represents formatting, links, line breaks, tables, lists, and other supported nodes in a form that lets translated text move without losing source link targets or text settings.

On import, the integration validates the returned markup against the source structure. Missing links, unknown markers, unexpected tags, or missing source formats cause that rich-text unit to remain unchanged rather than corrupting the editor value. Text may still be reported as skipped so an editor can correct the source or translation.

Plain text uses escaped HTML text with line breaks represented as breaks. Rich-text uses separate markers for links and text styles, which allows General Translation to reorder inline content while the integration restores Payload's rich-text nodes. Structural nodes such as relationships and dividers remain in place without becoming translation text.

References: packages/…/inline.ts• L1-6 packages/…/inline.ts• L152-185 packages/…/inline.ts• L300-347 packages/…/html.ts• L33-47 packages/…/translation.ts• L379-490 packages/…/richTextNodes.ts• L76-203 packages/…/translateDocument.apply.ts• L97-149

Length handling

The integration treats Payload field limits as save constraints and SEO plugin lengths as recommendations. It asks General Translation to shorten text that exceeds a relevant limit, then cuts only when a hard maxLength still cannot be met.

When a value cannot be applied safely, the locale keeps the prior value or the source value required for a valid document. Run progress counts skipped strings and unsaved local edits so the admin panel can distinguish a partial result from a complete translation.

References: packages/…/limits.ts• L1-120 packages/…/translation.ts• L405-490 packages/…/runs.ts• L28-43 packages/…/translateDocument.limits.ts• L54-119 packages/…/README.md• L87-104

Administrative interface

Document controls

The plugin adds a Translate control to collection documents and globals that contain translatable fields. The control opens a panel where an editor chooses target locales, starts a translation, or saves current local edits to General Translation.

The control is not added to Payload's own plugin collections or to content models with no translatable fields. It also blocks a run when the current document has unsaved form changes, which keeps the source sent to General Translation aligned with the source the editor sees.

References: packages/…/plugin.ts• L66-100 packages/…/plugin.ts• L233-282 packages/…/GtDocumentControls.tsx• L16-55 packages/…/TranslatePanel.tsx• L10-99 packages/…/plugin.test.ts• L387-447

Translation overview

The admin navigation includes a Translations page for site-wide work. Its coverage table shows each eligible document or global against each supported locale, with complete, partial, or empty status. Each cell links to the related Payload editor in that locale.

The overview starts a site run through the same run service as the document control. This keeps progress, access checks, locking, and save behavior consistent across both entry points.

References: packages/…/GtNavLink.tsx• L7-22 packages/…/GtTranslationsView.tsx• L7-30 packages/…/CoverageTable.tsx• L52-197 packages/…/api.ts• L30-67 packages/…/translateSite.test.ts• L257-460

Server and client components

The admin page uses a server component to place the translation view inside Payload's standard admin layout. Interactive locale selection, progress display, coverage loading, and run controls stay in client components that call the plugin's authenticated endpoints.

The plugin registers the server view at /translations, adds the navigation link and run provider, and exposes separate package entry points for the main plugin, client components, and server components. The server boundary supplies Payload's request, user, permissions, and layout context; the client boundary performs user actions and refreshes the view after a run. The package targets Payload 3.90 or later, Next.js 15.2.9 or later, and React 19 as peer dependencies.

References: packages/…/plugin.ts• L59-64 packages/…/plugin.ts• L320-344 packages/…/GtTranslationsView.tsx• L1-30 packages/…/GtRunsProvider.tsx• L11-51 packages/…/package.json• L14-28 packages/…/package.json• L54-65

The Payload integration shares the wider translation service boundary with the translation API client. For adjacent workflows, see GTX command-line workflows, Locadex operations, Sanity CMS integration, session recording localization, and bundle analysis. The parent guide is translation operations.

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep Payload locale codes, the default source locale, custom mappings, the locale picker, and endpoint target filtering aligned.
  • Keep target identity rules aligned across collection documents, globals, site coverage, translation runs, and locale editor links.
  • Keep access checks aligned between target discovery, run start, source reads, and locale writes so a site run cannot spend usage on content the user cannot save.
  • Keep run state, job payloads, step progress, stale-run recovery, and Payload job-queue input compatible when run fields change.
  • Keep run locks and document locks around every path that can step or save a translation. A lease change must still protect the final progress write.
  • Keep field walking and file-key generation symmetric. A changed field path or row identity rule can apply a valid translation to the wrong value.
  • Keep rich-text marker rules aligned between encoding and decoding. Link order, formatting, and unsupported nodes must fail safe rather than alter editor structure.
  • Keep draft behavior aligned with Payload's write rules. Translation completion must not publish content or bypass the signed-in user's update access.
  • Keep the registered server view, client entry point, import map, and admin component paths aligned when admin controls move.
  • Keep the supported Payload, Next.js, and React peer ranges aligned with the package entry points and the host application's admin runtime.

Important failure modes

TriggerConsequenceGuard
A Payload locale code is not recognized and has no custom mappingThe locale is not offered or sent as a translation targetAdd a valid mapping and check the supported locale list before a run
An editor starts a run with unsaved source changesThe run translates an older saved documentSave the document first; the document control disables translation while the form is modified
The user cannot update one requested documentTranslation usage can be spent before the run can save all requested targetsCheck update access for every selected target before starting
Two workers step one run or save one document at the same timeRun progress or locale values can overwrite newer workUse the run and document leases and verify ownership before writing progress
The browser closes during a run and no job worker is activeWork stays incomplete until another admin page resumes itEnable Payload job processing or open a signed-in admin panel to resume stale runs
A translated rich-text response drops a source link or uses invalid markupThat rich-text unit is left unchanged and counted as skippedValidate markers against the source and review skipped strings
A local translation changes a source linkThe edit cannot be safely uploaded as the matching translationKeep the original links or review the unsaved edit warning
A translation exceeds a hard field limit after the shortening attemptPayload may reject the locale write or the text may lose its intended endingApply the field limit and word-boundary cut before saving
The Payload import map or schema migration is stale after plugin setupAdmin components or hidden run and lock collections do not load correctlyRegenerate the import map and create the required Payload migration
The host app does not meet the package's Payload, Next.js, or React peer rangeThe plugin can fail to load or the admin view can break at runtimeUse supported peer versions before enabling the plugin

Key files

FileWhy to read it
packages/…/README.mdDefines setup, locale requirements, admin actions, draft behavior, and the supported content scope.
packages/…/CHANGELOG.mdRecords the plugin release history and its high-level product purpose.
packages/…/plugin.tsShows how the plugin connects Payload localization, endpoints, collections, jobs, and admin components.
packages/…/locales.tsDefines supported target locale discovery and custom locale mapping.
packages/…/documents.tsDefines target identity, access-aware reads and writes, and site target discovery.
packages/…/translation.tsDefines the source upload, job completion, locale rebuild, local-edit save, and site translation lifecycle.
packages/…/runs.tsDefines persisted run progress, bounded stepping, stale recovery, and Payload job-queue continuation.
packages/…/locks.tsDefines the lease-based coordination used by runs and document saves.
packages/…/fields.tsDefines which Payload fields are translatable and how nested content is walked.
packages/…/file.tsDefines keyed HTML exchange files for source and locale text.
packages/…/inline.tsDefines rich-text inline encoding, marker validation, and node restoration.
packages/…/TranslatePanel.tsxShows the editor actions for locale selection, translation, and saving local edits.
packages/…/CoverageTable.tsxShows the site-wide locale coverage and locale-specific editor links.
packages/…/GtTranslationsView.tsxShows the server-side admin view boundary for the translation overview.
packages/…/package.jsonDefines the package entry points, current version, General Translation dependency, and supported peer boundary.