Translation operations and developer tools
Translation operations connect source content to General Translation and return localized content to applications, files, editors, and replay tools. The repository provides several user-facing paths around one source-locale and target-locale model: API calls, command-line work, CMS actions, project automation, session replay, and bundle checks.
Operational model
Source and translation lifecycle
The translation lifecycle starts with source content and a source locale. A tool sends that content to General Translation with one or more target locales. It then waits for completed work when needed and writes the result to mapped files or editor records.
Upload and download are separate actions. Teams can submit source content and existing translations together, or retrieve work that was approved or staged earlier. Large source files can use a separate storage-upload step before the service records their file references. Direct work joins submission and delivery in one action. Staged work leaves a review step between them.
The main flow is:
flowchart LR
A[Source content] --> B[Project settings]
B --> C[Upload source and existing translations]
C --> D[General Translation]
D --> E{Work mode}
E -->|Direct| F[Check job status]
E -->|Staged| G[Wait for approval]
G --> F
F --> H[Download target locales]
H --> I[Post-process and publish when enabled]
References: packages/…/openapi.json• L19-47 packages/…/sdk.gen.ts• L713-785 packages/…/types.gen.ts• L1617-1754 packages/…/fileUploads.ts• L59-86
File and editor boundaries
File workflows use a source file as the stable identity for translation work. A file mapping connects that identity to each locale's output path. This lets one service support common code and content formats without changing the user-facing workflow.
Editor workflows apply the same source-to-target relationship to content records. Sanity maps documents to translation files and imports results into drafts or localized fields. Payload provides document and site actions for localized fields. Design and Google Workspace integrations use the same service boundary while preserving the identity rules of their host editors.
References: packages/…/openapi.json• L90-113 packages/…/types.gen.ts• L1617-1754 packages/…/CHANGELOG.md• L3-8 packages/…/CHANGELOG.md• L3-19
API service boundary
Generated API client
The General Translation API is the shared service boundary for developer tools and integrations. Its contract covers projects, files, translations, context, jobs, editor plugins, and temporary CLI wizard sessions at https://api.gtx.dev. The generated TypeScript client turns that contract into typed request and response operations.
The generated contract is 2026-03-06.v1. Callers can select a supported contract version when they need a specific response shape. When no version is selected, the client uses the oldest supported version in the bundled contract list. Bearer credentials identify the caller. Project keys stay bound to one project. Organization keys can work across projects in their organization when the request names the target project.
The published @generaltranslation/api package is version 0.6.0. It exposes the generated client and shared request helpers. It also exposes typed API versions, project and organization API-key operations, batching, lazy pagination, job polling, retry policy types, and ApiError. The package now supports large source files through a storage-upload flow that records file references after the bytes are uploaded. A throwing call reports the HTTP status through ApiError; a non-throwing call keeps the decoded error body in error. When a service or gateway returns plain text, HTML, or no body, ApiError still gives the caller a useful message from the response status or status text. Its timeout boundary reliably aborts pending requests for both the built-in and custom fetch paths.
The large-file helpers use the newer 2026-10-08.v1 upload routes while the generated contract catches up. The storage service returns a short-lived upload permission, and the API service later receives the file's content reference. This keeps large content and large source context out of the request body without changing the source-file model used by the CLI and integrations.
The client contract includes formats such as SubRip and .NET resource files. It also covers reusable context groups, glossary terms, custom prompts, design-tool plugins, Google Workspace actions, and atomic file metadata updates. The CLI, Sanity, and editor clients can therefore use one service description while updating preview links for source files or translations.
References: packages/…/openapi.json• L1-18 packages/…/openapi.json• L80-113 packages/…/types.gen.ts• L14-49 packages/…/types.gen.ts• L1617-1754 packages/…/sdk.gen.ts• L439-457 packages/…/sdk.gen.ts• L1612-1632 packages/…/fileUploads.ts• L11-112 packages/…/package.json• L1-36 packages/…/CHANGELOG.md• L3-13
Service operation groups
The client presents translation work as related operation groups. Each group supports one part of the content lifecycle while keeping authentication, project scope, and response shapes at the service boundary.
| Operation group | System role |
|---|---|
| Project and access | Create projects, read project settings, and create project or organization keys. |
| Source and localized files | Upload, inspect, move, download, update metadata, and publish files. |
| Translation work | Translate runtime content, queue file work, and read status. |
| Project context | Generate translation context for later work. |
| Context management | Manage reusable context groups, glossary terms, and custom prompts. |
| Delivery and edits | Apply user edits and manage branches and version tags. |
| Editor integrations | Sync, queue, inspect, download, and import content for design and workspace tools. |
| CLI browser sessions | Support temporary browser-assisted project setup. |
Runtime translation returns per-entry results. File translation returns queued or job state that a caller checks before it downloads or publishes content. File metadata updates are safe to repeat and can add a preview page after an editor writes a localized record. Editor operations preserve the relationship between source file, locale, and version while adapting the actions to each host editor.
References: packages/…/sdk.gen.ts• L439-760 packages/…/sdk.gen.ts• L762-936 packages/…/sdk.gen.ts• L1062-1528 packages/…/types.gen.ts• L1617-1754
Request reliability boundary
The API package gives callers one boundary for authentication, API version, project scope, time limits, retries, batching, pagination, and job polling. These rules protect both short runtime calls and longer file jobs. Requests apply a timeout to each attempt inside the retry policy. Caller aborts stop both the request and any retry wait.
Authentication can use an explicit API key or a user token. An API key takes precedence over a configured user-token provider, and an explicit per-request authorization header stays in control. Otherwise, a user token can refresh once after a 401 response. Retry handling can repeat rate-limited requests, but it does not repeat unsafe work after server or network errors.
The boundary keeps throwing and non-throwing error paths distinct. It also keeps cursor traversal and job state explicit. A caller can therefore treat an incomplete, failed, or unknown job as work that still needs attention rather than as a successful translation.
References: packages/…/CHANGELOG.md• L3-15 packages/…/types.gen.ts• L1660-1725 packages/…/types.gen.ts• L1894-1983 packages/…/client.ts• L18-85 packages/…/fileUploads.ts• L89-112 packages/…/transport.ts• L19-50 packages/…/transport.ts• L100-141 packages/…/errors.ts• L12-34 packages/…/wrappers.test.ts• L16-135 packages/…/wrappers.test.ts• L138-324 packages/…/fileUploads.test.ts• L66-165
Developer command interface
Project setup and file operations
The gt command is the main developer interface for configuring a project and moving localized files through the service. Setup connects application settings, locale choices, credentials, file mappings, and output behavior to later translation commands.
The older gtx-cli package remains a compatibility wrapper for gt. Existing users can keep the old package while new work uses the current command package. The command family also supports local-edit submission and Git handling for generated translation files.
References: packages/…/package.json• L1-38 packages/…/package.json• L68-78 packages/…/CHANGELOG.md• L1-9
Development credentials
The gt init setup flow can connect a local app to an existing project or create a project when the user has access to an organization. It then creates a development key with runtime-translation permission and saves the project ID and key in .env.local; it does not print the secret.
The flow uses a configured project ID when one exists. Otherwise, an interactive user can choose a project or create one. A configured API key takes precedence over sign-in for API calls, so permission errors explain which credential must change instead of silently trying another credential. Local Vite and framework-specific settings receive the matching public variable names. Production runtime credentials remain a separate dashboard and hosting concern.
Startup reads .env, then .env.local, then .env.production. The later files override earlier values and the shell for the files that use override behavior. This gives local and production setup a defined precedence while keeping generated development credentials outside normal source files.
References: packages/…/developmentCredentials.ts• L19-23 packages/…/developmentCredentials.ts• L67-123 packages/…/developmentCredentials.ts• L173-301 packages/…/loadEnv.ts• L1-20 packages/…/initCredentials.test.ts• L168-357 packages/…/initCredentials.test.ts• L496-605
Translation state and delivery
Direct translation combines submission, status checks, download, and local post-processing. Staged work separates submission from delivery so a person can approve work before it reaches local files.
Download can retrieve staged versions without starting new work. Optional post-processing adapts locale-specific links, assets, imports, anchors, and file layout. Publishing remains a separate step so obtaining a translation does not automatically make it available to readers.
References: packages/…/sdk.gen.ts• L621-785 packages/…/types.gen.ts• L1894-1983 packages/…/CHANGELOG.md• L81-87
Editor and content interface
Sanity document translation
The Sanity integration brings translation operations into Sanity Studio. It gives editors a central Translations tool and document-level actions. The integration serializes selected documents for General Translation, tracks work by source version and locale, and imports completed results back into Sanity.
Sanity supports two content models:
- Document-level localization: each locale uses a separate document.
- Field-level localization: one document stores values for many locales through
sanity-plugin-internationalized-array.
The plugin can use document-level translation, field-level translation, or a mixed model for selected document types. It configures the reference field-level plugin when requested, while the host Studio still owns its schema and editor behavior. The current gt-sanity release is 4.0.37. It targets Sanity 6.9.2, @sanity/ui 4, React 19, and Node.js 22.12 or newer.
Translation groups define which document is an original. By default the configured source locale remains the source. With allowNonDefaultSourceLocales, an original written in another locale can be translated from its document action. Sanity records that original language in the group metadata. Other members of that group are translations and cannot become new sources. Translate All still covers only originals in the configured source locale.
The centralized Translations page and document view let editors select target locales before an action. The selection applies to translation, import, local-edit upload, reference patching, and publication. Each view excludes the document's source locale from its targets. A document written in a non-default source locale can target the configured source locale and all configured targets except its own language. Field-level localization always translates from the configured source locale.
The integration tracks work by the uploaded source version. It keeps polling work that started before a locale was deselected, and it rejects status responses from an older document, branch, version, or locale scope. A retranslation can deliberately replace an existing result, but its old completed result stays out of import until the new job completes. This keeps status rows tied to the operation the editor started.
References: packages/…/README.md• L45-65 packages/…/README.md• L129-162 packages/…/README.md• L164-203 packages/…/package.json• L1-5 packages/…/package.json• L66-117 packages/…/CHANGELOG.md• L3-10 packages/…/CHANGELOG.md• L25-38 packages/…/TranslationsProvider.tsx• L123-224 packages/…/TranslationsProvider.tsx• L778-1003 packages/…/TranslationsProvider.tsx• L1386-1519 packages/…/TranslationsProvider.test.ts• L461-665 packages/…/TranslationView.test.ts• L329-464
Sanity preview links
Sanity can attach a page URL to each source version and imported translation. A preview URL is resolved from the document type's configured location and the page language, then stored with the matching General Translation file so reviewers can open the content in context.
Source links use the published document. Imported translation links use the written draft because a new translation is usually not live yet. A missing page or failed URL update does not block translation or import; the workflow reports a warning and keeps the content without that link.
References: packages/…/CHANGELOG.md• L25-38 packages/…/previewUrls.ts• L16-43 packages/…/previewUrls.ts• L246-301 packages/…/updatePreviewUrls.ts• L15-45 packages/…/uploadFiles.ts• L17-43 packages/…/TranslationsProvider.tsx• L722-776 packages/…/TranslationsProvider.tsx• L1054-1102 packages/…/TranslationsProvider.test.ts• L394-459
Sanity content visibility
Sanity imports translated documents as drafts. An import can update an existing translated document, but it does not make new content live unless the editor enables automatic publishing.
When a translated document already exists as a published record, the import seeds a draft from that record and patches the draft instead of changing the live record. If translation metadata points to a deleted target, the import can create a replacement draft and repair the reference. A missing source document remains an error because there is no source content to translate.
Reference patching also stops at the draft boundary. Sanity maps source references to the matching target-locale documents, then writes changed references to a draft when the target has no draft. Publication only considers translation groups whose original document is published. It identifies the original through document references and the optional source-language marker rather than through a language label alone.
Re-import preserves a configured custom language field on the target. Locale browsing remains an editor concern: document-level translations can be grouped by locale, while field-level translations stay inside the source document.
References: packages/…/README.md• L177-200 packages/…/documentLevelPatch.ts• L48-178 packages/…/createI18nDocAndPatchMetadata.ts• L12-104 packages/…/index.ts• L18-61 packages/…/internationalizedArrayPatch.ts• L8-60 packages/…/importDocument.ts• L5-29 packages/…/strategy.ts• L12-87 packages/…/CHANGELOG.md• L20-30 packages/…/CHANGELOG.md• L208-220 packages/…/CHANGELOG.md• L339-351 packages/…/documentLevelPatch.test.ts• L90-274 packages/…/documentLevelPatch.test.ts• L314-451 packages/…/internationalizedArray.test.ts• L150-265
Payload content translation
The Payload integration brings translation actions into Payload CMS. Editors can translate localized fields for one document or for the whole site, then save edits made in Payload back to General Translation.
Payload sends readable text and rich text while leaving addresses, links, slugs, and other non-language values to the CMS. It writes target locales without changing the source. It can keep local edits as translation input, preserve fields that editors do not translate, and report failed locales without hiding successful ones. New translated content follows the host draft and publish rules.
The current gt-payload release is 0.1.7. The plugin runs inside the host Payload and Next.js environment. Its supported runtime is Payload 3.90 or newer with React 19 and Next.js 15.2.9 or newer.
References: packages/…/CHANGELOG.md• L3-15 packages/…/package.json• L1-20 packages/…/package.json• L54-80 packages/…/translateDocument.outgoing.ts• L20-139 packages/…/translateDocument.apply.ts• L39-168 packages/…/saveTranslations.ts• L49-140 packages/…/translateDocument.failures.ts• L34-109
Automation interfaces
Locadex project automation
Locadex is the AI agent entry point for projects that need more than a simple file command. Its command opens the Locadex area of the General Translation dashboard. The dashboard and connected repository flow then handle longer project setup and can prepare localization changes through a pull request.
Locadex is separate from direct gt commands. The CLI provides the launch and feedback surface. The dashboard provides the project automation flow. The current package release is 1.0.263 and it follows gt 2.28.4. Locadex operations covers its command and logging surface.
References: packages/…/package.json• L1-20 packages/…/CHANGELOG.md• L3-23
Localized session workflows
Recording and locale replay
The session recording workflow records one source-locale product session and prepares text overlays for other locales. It does not create translations. It loads the application's published translation dictionaries and matches translated text to recorded nodes. The current gt-rrweb package is 0.2.0 and expects the host application to provide compatible rrweb and React runtimes.
The result is a replay bundle with the event stream, locale list, and per-locale overlays. A replay can switch locales without a new recording or a locale-specific URL.
References: packages/…/package.json• L1-19 packages/…/types.ts• L3-19 packages/…/types.ts• L39-75 packages/…/harvest.ts• L336-418
Translation overlay boundaries
The overlay uses published application translations as its source of truth. Tagged component text can be matched directly. Bare strings require the same message-hash rule that the application uses. Variables keep their recorded values. Unmatched content stays in the source language.
This workflow is a presentation path for existing translations. It is not a translation job runner or a source-content editor. Session recording localization covers capture, harvesting, and replay.
References: packages/…/README.md• L1-7 packages/…/harvest.ts• L10-22 packages/…/harvest.ts• L274-333 packages/…/packageExports.test.ts• L9-23
Related operation guides
These surfaces are separate entry points around the same source-locale and target-locale model:
- Translation API client for shared service bindings and request rules.
- GTX command-line workflows for commands, settings, and framework helpers.
- Locadex operations for AI-agent launch and project automation.
- Sanity CMS integration for Studio documents and editor workflows.
- Payload CMS integration for Payload content and editor workflows.
- Session recording localization for recording, locale harvesting, and replay.
- Bundle analysis for bundle size and delivery checks around localized applications.
- CLI orchestration for the wider command lifecycle and coordination model.
Change checklist
When these files or sections are changed, remember to consider these:
- Keep API contract changes synchronized between packages/…/openapi.json, generated SDK types and operations, and higher-level CLI and Sanity callers.
- Keep large-file upload routes aligned across upload API versions, storage permissions, expiry handling, file hashes, and source-file reference submission.
- Keep contract error shapes aligned with
ApiErrormessage selection. JSON, plain text, gateway HTML, and empty responses must still produce useful diagnostics. - Keep authentication precedence aligned across explicit request headers, API keys, user tokens, and one-time 401 refresh behavior.
- Keep timeout and retry ownership aligned across the API client and custom fetch implementations. Unsafe requests must not be repeated.
- Keep supported file formats and locale aliases synchronized across the API contract, generated types, CLI names, CMS adapters, and output paths.
- Keep
gtx-cli, Locadex, andgtrelease versions aligned when their shared command surface changes. - Keep development credential permissions, project scope, and .env load order aligned with setup guidance.
- Keep Sanity's translation level aligned with its document-internationalization and internationalized-array setup. One document type must not use conflicting localization paths.
- Keep Sanity locale selection aligned across status polling, bulk actions, imports, reference patching, and publication. The source locale must remain excluded from target actions.
- Keep Sanity source-role rules aligned across translation metadata, document actions, bulk selection, and uploads. Only a group's original may be uploaded as a source.
- Keep Sanity retranslation state aligned across forced job tracking, completed-result timestamps, status polling, pending markers, and auto-import. A replaced result must not return before the new job completes.
- Keep Sanity serialization and merge rules aligned with nested fields, rich text, inline objects, annotations, whitespace, and custom serializers.
- Keep Sanity preview URL resolution aligned with document perspective and target language. Source links read published content. Imported links read the written draft.
- Keep Sanity draft and publish boundaries aligned when import, reference patching, or automatic actions change.
- Keep Payload host peer ranges aligned with Payload, Next.js, React, and UI versions.
- Keep Payload locale mapping, field rules, rich text handling, local-edit preservation, and draft behavior aligned across document and site actions.
- Keep rrweb message markers, message hashing, and the translation loader aligned. A mismatch must fall back to source text.
- Keep Locadex launch URLs and repository return paths aligned with the dashboard route.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The OpenAPI contract changes without regenerating the SDK | Callers send stale fields or misread valid responses | Regenerate the SDK and types with the contract change |
| A large file reference is submitted before its bytes reach storage | The service cannot resolve the source content | Finish storage upload and retain its content reference before submission |
| A file metadata update uses the wrong file version or locale | A preview link is attached to the wrong source or translation | Send the branch, file, version, and locale that belong to the written content |
| A caller selects an API version whose response shape differs from its generated types | The request succeeds but the caller reads the wrong result shape | Keep selected versions within the generated contract set |
| A throwing API call is handled as a decoded error body | Error handling misses the HTTP status | Catch ApiError for throwing calls and inspect result.error otherwise |
| A configured API key lacks project permission | Setup reports a denial and does not fix itself by signing in | Remove or replace the overriding key, or grant its required permission |
| Startup environment precedence changes unexpectedly | The CLI uses a different project or credential than the user expects | Preserve the documented .env, .env.local, and .env.production order |
Locadex and gt releases are out of sync | The agent may launch an incompatible command or service flow | Publish Locadex with the matching gt dependency version |
| Sanity treats a translation-group member as the original | Translation can create a second group or write over the wrong document | Resolve the group role before upload, import, patch, or publish |
| A selected Sanity locale is removed from polling while its job is pending | The job completes but its status never clears | Continue polling started work until it reports ready |
| A slow Sanity response arrives after the document or version changed | Old status replaces current status and can enable the wrong action | Accept responses only for the current document, branch, version, and locale scope |
| A retranslation sees the completed result that it is replacing | Auto-import writes the old translation back while the new job is still running | Track the forced job and require a later completion time before importing |
| A forced Sanity job fails or becomes unknown | The old translation can be lost from the status view or the run can remain pending | Settle failed jobs, clear their pending markers, and leave the replaced result in place |
| A Sanity import writes a published target directly | A live translation changes before editorial review | Seed or patch the target draft and publish only through the review boundary |
| Sanity preview resolution reads the wrong perspective or language | Reviewers see a source page, a stale page, or no usable link | Resolve source URLs from published content and target URLs from the written draft |
| Sanity and its host Studio use different runtime generations | Studio can load duplicate runtime packages or fail to load translation tools | Use the plugin generation that matches Sanity, React, and @sanity/ui |
| Payload host versions fall outside the plugin peer ranges | The CMS plugin may fail to load or behave incorrectly in the editor | Install compatible Payload, Next.js, React, and UI versions |
| A Payload locale mapping is applied only on the API side | Translation status uses one locale while CMS writes another | Map locales consistently at upload, status, download, and write boundaries |
| A recording uses a different hash function from the application dictionary | Replay stays in the source language or maps text incorrectly | Use the application's published loader and matching hash function |
Key files
| File | Why to read it |
|---|---|
| packages/…/openapi.json | Defines the service contract, authentication boundary, file formats, API versions, context operations, editor operations, and file metadata updates. |
| packages/…/sdk.gen.ts | Shows the typed service actions shared by developer tools and integrations. |
| packages/…/types.gen.ts | Shows request, response, locale, file, job, context, preview URL, and editor data shapes. |
| packages/…/client.ts | Shows default API-version selection, credential precedence, timeout ownership, retry transport, and token refresh. |
| packages/…/fileUploads.ts | Shows the large-file storage upload and source-file reference boundary. |
| packages/…/transport.ts | Defines request timeout and retry behavior at the shared transport boundary. |
| packages/…/errors.ts | Defines the status-aware error boundary used for JSON, text, HTML, or empty responses. |
| packages/…/package.json | Shows the compatibility command and shared gt dependency. |
| packages/…/developmentCredentials.ts | Shows how local setup selects or creates a project and provisions a limited development key. |
| packages/…/loadEnv.ts | Defines startup environment file order and override behavior. |
| packages/…/package.json | Shows the Locadex command, shared service dependency, and release surface. |
| packages/…/package.json | Defines the Payload plugin entry points and host peer boundaries. |
| packages/…/translation.ts | Defines the document and site translation boundary for Payload content. |
| packages/…/documents.test.ts | Groups the document translation guarantees for content, edits, locales, limits, and failures. |
| packages/…/package.json | Defines the Sanity 6, React 19, UI 4, Node.js, and peer-runtime boundaries for gt-sanity. |
| packages/…/index.ts | Defines the Sanity plugin contract and editor entry points. |
| packages/…/TranslationsProvider.tsx | Coordinates Sanity translation actions, selected locales, forced retranslation jobs, status checks, imports, preview links, reference patching, and publication. |
| packages/…/TranslationView.tsx | Shows the single-document workflow, retranslation confirmation, local-edit preservation, and editor controls. |
| packages/…/RetranslateDocumentDialog.tsx | Shows the document-level confirmation boundary for replacing existing translations. |
| packages/…/forcedJobs.ts | Tracks forced retranslation jobs until the new result can replace the old one. |
| packages/…/checkTranslationStatus.ts | Defines ready-result lookup and completion-time checks for translation status. |
| packages/…/strategy.ts | Shows how document-level and field-level localization share the service workflow. |
| packages/…/previewUrls.ts | Resolves document locations into source- and target-locale preview pages. |
| packages/…/uploadFiles.ts | Uploads serialized Sanity documents with their source locale and version. |
| packages/…/bulkSources.ts | Defines which documents bulk translation can use as sources. |
| packages/…/documentLevelPatch.ts | Defines draft imports, metadata repair, and source-role checks. |
| packages/…/index.ts | Defines the content form sent to the translation service. |
| packages/…/BaseDocumentDeserializer.ts | Defines how translated content returns to Sanity document data. |
| packages/…/BaseDocumentMerger.ts | Defines how translated values merge with source documents and localized fields. |
| packages/…/harvest.ts | Defines how published locale dictionaries become replay overlays. |
| packages/…/types.ts | Defines the recording bundle, locale list, loader contract, and overlay shape. |