GTX command-line workflows
GTX is the developer-facing command line for preparing an application for localization and moving source content and translations between the application and the General Translation service. The published gtx-cli package is a compatibility wrapper around gt; version 2.25.2 follows the shared CLI through its workspace dependency. packages/…/package.json packages/…/package.json packages/…/CHANGELOG.md
CLI command model
Entry point and adapter selection
The CLI starts from the project directory and selects a command adapter from the installed localization libraries and project files. This lets one command surface support React, Next.js, Node, Vue, Python, and other project types while each adapter applies the right setup and content rules. packages/…/main.ts delegates to gt, and packages/…/index.ts selects the adapter.
Framework selection gives the CLI two key behaviors. It chooses the right inline-content rules for commands such as translate and validate, then detects the project library from its package manifest before it uses broader file-based behavior. packages/…/index.ts defines this selection order.
References: packages/…/main.ts• L1-13 packages/…/package.json• L68-71 packages/…/index.ts• L11-41 packages/…/index.ts• L26-82
Command groups
The command set covers the developer path from first setup to ongoing translation work. The main groups are:
- Project setup:
init,configure,auth, andsetupcreate project settings, connect credentials, and prepare source files. - Translation work:
translate,stage,enqueue, anddownloadsend content for translation and bring completed work back. - File exchange:
uploadsends source files and existing translations without starting a normal translation run. - Local and source checks:
generatecreates source-language templates,validatechecks inline content, andsave-localsends local edits without enqueueing a translation. - Source control support:
git setupconfigures merge handling for generated translation files.
The root command also provides shared controls for configuration, credentials, project identity, locale selection, dry runs, branch choice, publishing, and download safety. These controls shape a run without changing the core purpose of its command. packages/…/base.ts registers the shared command surface, while packages/…/flags.ts defines the common options.
References: packages/…/base.ts• L150-205 packages/…/base.ts• L216-309 packages/…/base.ts• L311-415 packages/…/base.ts• L539-729 packages/…/flags.ts• L7-127
Translation workflows
Setup and project registration
Project setup establishes the link between local files and a General Translation project. The CLI resolves project settings, selects or creates the active branch, uploads source files, and asks the service to register those files for later translation. packages/…/setupProject.ts owns this high-level sequence.
The interactive init path adds a guided layer for new projects. It detects the framework, can install the matching runtime package, and can update application configuration for supported React and Next.js projects. It also offers a Locadex handoff for project types that support agent-led setup. packages/…/base.ts and packages/…/wizard.ts define this developer entry path.
References: packages/…/setupProject.ts• L14-62 packages/…/base.ts• L604-719 packages/…/wizard.ts• L21-77 packages/…/detectFramework.ts• L23-78
Translation lifecycle
The translation lifecycle separates safe submission from result retrieval. stage submits work that needs human approval, while translate normally submits work and waits for completed translations. A staged run stores enough state for a later download command to retrieve approved results. packages/…/base.ts describes this user-facing distinction.
The submission flow resolves a branch, uploads source files, records local edits when enabled, prepares the project, and enqueues only the work that needs translation. The retrieval flow polls active jobs, keeps completed results when a wait times out, and writes safe results to locale-specific output paths. The diagram shows how these stages connect.
flowchart LR
A[Local source and translation files] --> B[Resolve settings and branch]
B --> C[Upload source files]
C --> D{Command}
D -->|stage| E[Submit for human approval]
D -->|translate| F[Enqueue translation jobs]
F --> G[Poll job status]
E --> H[Approved work]
G --> H
H --> I[Download completed translations]
I --> J[Write locale files and local state]
packages/…/stage.ts coordinates submission and deduplication. packages/…/download.ts coordinates polling, partial success handling, and file download. The service boundary is supplied by the shared General Translation client rather than by the compatibility package. packages/…/stage.ts and packages/…/download.ts define these stages.
References: packages/…/base.ts• L230-289 packages/…/stage.ts• L19-109 packages/…/download.ts• L30-176 packages/…/enqueue.ts• L13-89
Uploads and local edits
The upload command synchronizes source files and existing translations with the service. It does not represent the normal submit-and-wait path. The save-local command serves local authoring instead: it sends detected local changes without enqueueing new translation jobs. packages/…/upload.ts and packages/…/base.ts define these boundaries.
This separation lets a team update source or human-edited translations without starting a new translation run by mistake. It also gives CI and release scripts a direct way to upload prepared files or publish them when project settings enable that path.
References: packages/…/upload.ts• L14-80 packages/…/base.ts• L292-309 packages/…/base.ts• L539-557
Configuration and filesystem model
Configuration resolution
The CLI treats gt.config.json as the project contract for locales, source scope, translation file paths, project behavior, and service settings. It accepts an explicit path and otherwise searches the project root, src, .gt, and the legacy .locadex location. packages/…/resolveConfig.ts defines the search locations.
Each command builds one effective settings object from the config file, command flags, supported environment variables, defaults, and detected project information. It then validates locale values and file rules before the workflow starts. This keeps command actions aligned when users run them from scripts, CI, or different framework projects. packages/…/generateSettings.ts and packages/…/generateSettings.ts define the merge, and packages/…/validateSettings.ts validates locale rules.
References: packages/…/resolveConfig.ts• L5-36 packages/…/generateSettings.ts• L90-115 packages/…/generateSettings.ts• L180-231 packages/…/validateSettings.ts• L7-41
Locale-aware file selection
File configuration maps source files to translated outputs. Include and exclude globs define the files in scope, while [locale] marks the part of an output path that changes for each target locale. The CLI expands these patterns into absolute paths for the current run and keeps placeholder paths so it can resolve each locale later. packages/…/parseFilesConfig.ts and packages/…/parseFilesConfig.ts define this model.
The same file model carries related policy. It can identify files for CDN publishing, mark files that need human review, apply format or path transforms, and provide parsing flags for inline content. The key contract is that a source glob and its locale output pattern describe the same file relationship. A missing [locale] can place translated output in the wrong location.
References: packages/…/parseFilesConfig.ts• L79-200 packages/…/parseFilesConfig.ts• L202-295 packages/…/index.ts• L205-225 packages/…/index.ts• L243-280
Local state and source control
The CLI keeps a lock file named gt-lock.json to connect local outputs with service file versions, locales, branches, and post-processing state. This state lets later runs skip work that is already complete and lets downloads protect local files from an unintended overwrite. packages/…/downloadedVersions.ts defines the read and write boundary.
The git setup command adds merge-driver support for generated translation files. This reduces conflicts when branches change generated outputs. An optional config-ID policy controls whether version identifiers are written into the project config. packages/…/base.ts exposes this source-control workflow.
References: packages/…/downloadedVersions.ts• L6-30 packages/…/downloadedVersions.ts• L131-201 packages/…/downloadedVersions.ts• L249-300 packages/…/base.ts• L311-414
Framework helpers
React and Next.js source wrapping
The React and Next.js helpers reduce the manual work needed to make JSX content translatable. They scan configured source paths, wrap eligible top-level content with translation components, add required imports, and can add a provider at the framework boundary. The helpers change source files, so the CLI asks the developer to confirm or review those changes. packages/…/wrapContent.ts and packages/…/wrapContent.ts define the two source-wrapping roles.
Next.js setup also prepares the application configuration boundary. It can add withGTConfig to the Next config and connect the document language to the active locale when provider setup is requested. React setup supports common React frameworks and can install the matching runtime package before it modifies application files. packages/…/handleInitGT.ts and packages/…/wizard.ts define this guided setup.
References: packages/…/wrapContent.ts• L33-50 packages/…/wrapContent.ts• L82-225 packages/…/wrapContent.ts• L39-52 packages/…/wrapContent.ts• L84-185 packages/…/handleInitGT.ts• L14-21 packages/…/handleInitGT.ts• L132-209
Inline content generation and validation
Inline content means translatable text embedded in application code rather than stored only in standalone locale files. For inline-capable runtimes, translate scans dictionaries and inline content, generate creates a source-locale template for teams that manage translations themselves, and validate checks a whole project or selected files before a translation run. packages/…/inline.ts defines these command roles.
The generated source template uses stable message identifiers and merges with existing locale data. This gives local translation owners a controlled starting point without replacing translations that already exist. The parser choice follows the detected runtime, with a React-compatible fallback for runtimes that share the same inline content shape. packages/…/inline.ts and packages/…/inline.ts define that relationship.
References: packages/…/inline.ts• L20-117 packages/…/inline.ts• L120-200 packages/…/inline.ts• L204-223 packages/…/libraries.ts• L34-48
Developer-facing localization role
Project workflow boundary
GTX sits between source control and the translation platform. Developers use it to declare what should be translated, submit or stage changes, inspect local results, and keep generated files aligned with the active project branch. The service performs translation work, while the CLI owns local file selection, user prompts, state, and safe writes.
The CLI also connects to neighboring developer tools rather than replacing them. init can offer a Locadex setup handoff, generated files can be published to the CDN, and framework helpers prepare runtime packages that consume the resulting translations. See translation operations, translation API client, Locadex operations, and Sanity CMS integration for related operational interfaces.
References: packages/…/base.ts• L604-719 packages/…/base.ts• L489-537 packages/…/setupFlow.ts• L5-18 packages/…/index.ts• L262-280
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to the
gtx-clirelease wrapper, version, orgtdependency must keep the published package version and the delegated CLI version aligned. The changelog records this coupling for each release. - Changes to command adapter selection must preserve the command surface for each supported runtime and the package-detection priority in packages/…/index.ts and packages/…/index.ts.
- Changes to config search or settings merge must keep explicit
--configpaths, environment project IDs, locale validation, and the.gtand legacy.locadexlocations consistent. - Changes to file globs must preserve the
[locale]placeholder contract and the mapping between resolved paths, placeholder paths, publishing policy, review policy, and output transforms. - Changes to staged or downloaded state must preserve branch-aware lock-file reads and compatibility with both lock-file formats.
- Changes to React or Next source wrapping must keep generated imports, provider placement, and the selected runtime package in agreement with the project framework.
- Changes to
stage,translate, ordownloadmust preserve the handoff between uploaded file versions, job data, branch data, and local output paths.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The command runs without a usable project config for a config-dependent command. | The CLI cannot resolve file scope or project settings and exits before translation work starts. | Run from the project root, pass --config, or create the config with gt init. |
| A project ID differs between gt.config.json, a command flag, and the environment. | The run can target different projects depending on the input source. | Settings generation rejects mismatched IDs before the workflow begins. |
A translated output pattern omits [locale]. | Multiple locales can resolve to the same output path or save in the wrong place. | Settings generation warns about the pattern, and URL, import, and copy patterns fail validation when their locale marker is missing. |
A download finds an existing local output and --force-download is not set. | The local file is protected and the translation is not written. | Review the lock state and use the force option only when an overwrite is intended. |
| A translation job times out after some files complete. | The command reports failure even though completed files can still be downloaded. | The download workflow keeps completed results and reports the timeout separately. |
translate is used for a configured Lottie flow that needs asynchronous server work. | The command may try to download the result before it is ready. | Use the staged submission followed by download flow for that file type. |
| The React or Next helper parses an unsupported or malformed source file. | That file is skipped or reported and the source set is only partly updated. | Review the reported warnings and errors, then verify generated changes before committing. |
Key files
| File | Why to read it |
|---|---|
| packages/…/package.json | Shows the published compatibility wrapper, its current 2.25.2 version, its gt dependency, and its normal and binary package entry points. |
| packages/…/CHANGELOG.md | Shows that released gtx-cli versions track corresponding gt versions, including the current 2.25.2 release. |
| packages/…/main.ts | Shows the compatibility wrapper entry point and environment loading. |
| packages/…/index.ts | Shows how the CLI selects a framework adapter. |
| packages/…/base.ts | Shows the shared command groups and the main translation command boundary. |
| packages/…/inline.ts | Shows the commands for inline scanning, generation, validation, and translation. |
| packages/…/flags.ts | Shows the common controls that shape translation runs. |
| packages/…/generateSettings.ts | Shows how config, flags, environment values, and defaults become one run setting. |
| packages/…/parseFilesConfig.ts | Shows how locale-aware file paths and file policies are resolved. |
| packages/…/stage.ts | Shows the source submission and enqueue lifecycle. |
| packages/…/download.ts | Shows job polling, partial completion, and safe download behavior. |
| packages/…/downloadedVersions.ts | Shows the local state contract used to track downloaded and staged work. |
| packages/…/wrapContent.ts | Shows the React source-wrapping helper. |
| packages/…/wrapContent.ts | Shows the Next.js source-wrapping and provider helper. |
| packages/…/wizard.ts | Shows guided framework setup and application changes. |