Extraction and compilation pipeline
The extraction and compilation pipeline turns application source into localization records and build output that use the same message identities. The CLI finds source content and creates files or catalogs. Compiler and framework tools prepare source for runtime lookup and preserve the context needed by translation workflows.
Pipeline boundary
Extraction and compilation are two views of one localization contract. Extraction creates source entries for upload or local catalogs. Compilation prepares application code to find those entries at runtime. Both paths must agree on message content, rich-content structure, metadata, and identity rules.
The pipeline produces two kinds of output:
- Localization artifacts: source records, catalogs, translated files, metadata, and locale-specific paths.
- Instrumented or generated code: application modules and generated runtime files that use the same message identities.
This diagram shows how a command or build turns project input into localization artifacts or changed source.
flowchart LR
A[CLI command or build] --> B[Resolve project settings]
B --> C[Discover source content]
C --> D{Source kind}
D -->|Configured files| E[Read and normalize files]
D -->|Inline code| F[Use language or framework extractor]
D -->|Paraglide project| G[Follow imports and message targets]
A --> H[Parse application module]
H --> I[Run ordered compiler passes]
E --> J[Create source records]
F --> K[Create shared updates]
G --> L[Create usage metadata]
I --> M[Emit changed module]
J --> N[Upload or write locale output]
K --> N
L --> O[Write metadata files]
References: packages/…/base.ts• L301-325 packages/…/index.ts• L13-48 packages/…/generateSettings.ts• L92-169 packages/…/index.ts• L215-305 packages/…/context.ts• L23-43
Package boundaries
The CLI is the command and artifact boundary. The compiler is the bundler boundary. Language and framework extractors provide syntax-aware readers for source models. Paraglide JS provides a separate context collector that follows project imports and writes source-code metadata for existing Paraglide message files. These tools can be used alone or together.
References: packages/…/package.json• L1-12 packages/…/package.json• L1-8 packages/…/package.json• L1-7 packages/…/package.json• L1-8 packages/…/package.json• L1-22 packages/…/compiler.ts• L1-96
Command orchestration
The CLI turns a user command into one settings object and then sends source content through extraction, upload, translation, download, or local-edit workflows. The command choice controls which part of the lifecycle runs. It does not create a second extraction model.
Command invocation
The root command selects a framework-aware CLI before it registers project commands. The selected CLI provides setup, upload, staging, translation, download, validation, generation, and local-edit actions. Shared settings define the source scope, locales, file formats, credentials, review policy, and output rules.
Startup keeps diagnostics separate from command data. Interactive terminals use normal display output. CI and machine-readable commands use plain or structured output while keeping diagnostics off stdout. The Paraglide context command follows the same boundary: summaries use stdout while usage errors and warnings use stderr.
The paraglide-context command scans the working directory or a given project root. It can install the language tools required by selected extractors as project dev dependencies. Installation uses the detected package manager and skips packages that the project can already load. When includeSourceCodeContext is enabled, gt translate, gt stage, gt upload, and gt setup can collect this context as part of their own source scan before they read files for the workflow.
References: packages/…/index.ts• L13-48 packages/…/base.ts• L252-325 packages/…/generateSettings.ts• L92-169 packages/…/logger.ts• L17-40 packages/…/logging.ts• L63-78 packages/…/index.ts• L11-117 packages/…/install.ts• L24-105 packages/…/print.ts• L1-10 packages/…/diagnostics.ts• L1-27 packages/…/CHANGELOG.md• L37-45
Command lifecycle
The main command roles form one source-to-output lifecycle:
generatescans inline content and writes a source-locale catalog for local work.setupanduploadsend source artifacts to the translation service.stagesubmits source content for work that needs review.translatecombines staging and download when the project is not already staged.downloadfetches completed work and applies the same final file processing astranslate.save-localresolves the active branch, compares local locale content with the matching downloaded version, and sends only local changes without starting new translation work.
The paraglide-context command is a related analysis path. It accepts include and exclude scopes, resolves project aliases, scans source files, and writes metadata beside known message files. Its install subcommand prepares missing language tools before a later scan.
Setup prepares the runtime path that consumes emitted translations. It validates the full plan before it changes application files or configuration. Unsupported targets and unsafe layouts stop at a manual action or failure instead of receiving an unverified source edit.
References: packages/…/base.ts• L406-425 packages/…/base.ts• L926-1045 packages/…/base.ts• L1164-1537 packages/…/stage.ts• L27-112 packages/…/download.ts• L47-230 packages/…/index.ts• L11-117 packages/…/install.ts• L35-105
Pipeline state
The CLI persists the project and translation state that later commands need to continue a run. Project configuration records identifiers and staging choices. Staged-version data records submitted file and version identities. gt-lock.json records downloaded translations by branch, output paths, and post-processing state. Commands that compare or reuse downloaded content select the branch resolved for the current run instead of relying on the first branch listed in an older lockfile.
The lockfile reader presents old and new on-disk formats through one working model. This keeps download and post-processing decisions stable across CLI upgrades.
References: packages/…/updateConfig.ts• L7-75 packages/…/updateVersions.ts• L7-45 packages/…/downloadedVersions.ts• L132-205 packages/…/downloadedVersions.ts• L250-301
Artifact submission
The CLI combines configured files with inline updates before submission. Configured files retain source paths and target mappings. Inline updates become a source template keyed by stable identities. File and version identities let the service recognize unchanged content and moved files without losing existing translations.
Large source files and requests with large format metadata use direct storage references instead of the inline upload route. Staging resolves the branch, uploads sources, saves local edits when requested, applies optional review data, and enqueues only work that needs translation. The local-edit path first uses the resolved branch to find the last downloaded baseline, compares each locale slice with that baseline, and submits only real text diffs. It reports skipped locales when a baseline is unavailable or unsafe to read, and it does not create or resolve a remote branch when there is no content to inspect.
References: packages/…/upload.ts• L55-228 packages/…/upload.ts• L20-85 packages/…/UploadSourcesStep.ts• L38-70 packages/…/stage.ts• L27-112 packages/…/saveLocalEdits.ts• L16-91 packages/…/collectUserEditDiffs.ts• L203-524
Source discovery
Discovery defines which project content belongs in a run and which reader can process it. A matching file is only a candidate. The selected extractor must also find supported translation calls, components, or source structures before the file becomes localization content.
File scopes and ownership
The CLI applies configured or conventional source patterns, then uses project ownership to select the correct framework extractor. Vue projects require proven ownership before Vue extraction runs. Mixed projects can combine Vue results with the primary extractor without treating the same source as two unrelated applications.
Paraglide context collection applies include and exclude scopes from the project root. It follows imports like the project bundler, ignores dependencies and generated output during source analysis, and can add configured or detected auto-imports to the module graph. An unresolved alias can therefore cause a usage to be missed even when the source file itself was selected.
Framework detection also protects setup boundaries. Native targets such as React Native and Expo are not treated as plain web projects. Framework detection alone does not make a file translatable.
References: packages/…/extractInline.ts• L19-53 packages/…/integration.ts• L93-220 packages/…/detectFramework.ts• L24-101 packages/…/index.ts• L18-82 packages/…/index.ts• L11-35 packages/…/collector.ts• L137-164 packages/…/project-resolver.ts• L32-89 packages/…/unresolved-imports.ts• L17-44
Project resolution
Project resolution gives context collection the same import view that the application bundler uses without starting the bundler. It reads aliases from project settings and supported bundler configuration, then falls back to normal package and file resolution.
When a possible alias cannot be resolved, the collector reports the missed usages and points to a project alias declaration or an explicit --alias option. Relative paths and known virtual modules are not treated as aliases. This keeps warnings focused on imports that can change the source graph.
References: packages/…/project-resolver.ts• L42-155 packages/…/unresolved-imports.ts• L5-44 packages/…/index.ts• L98-137
Content normalization
Normalization converts different authoring forms into one entry model. Static text stays text. Rich UI content becomes a serialized value with variables and component boundaries. Dynamic content is accepted only when a supported static or derive form can produce stable variants.
Entry identity
An entry hash is its catalog identity. The hash uses source content, data format, and identity-affecting metadata such as context, character limits, and review requirements. Post-processing removes duplicates and links related derive variants so one catalog entry can represent several source locations.
The compiler and CLI must calculate equivalent identities. JSX child numbering follows the runtime model across Branch and Plural children. This keeps variable keys, extracted records, and emitted runtime lookups aligned.
References: packages/…/postProcess.ts• L5-89 packages/…/createDictionaryUpdates.ts• L65-115 packages/…/processCallExpression.ts• L263-292 packages/…/constructJsxChildren.ts• L340-391
Diagnostics and partial results
Extractors return entries together with warnings and errors. Syntax problems, missing parser support, incomplete ownership, and unsupported dynamic values can make a scan unsafe. The CLI reports these diagnostics and fails closed when a partial scan could remove valid entries from a later catalog version.
Paraglide context collection keeps skipped files and missing language tools visible. It groups repeated tool failures by language or file part and gives a package-manager command when a required package is not installed. A warning does not turn an incomplete module into a complete usage record.
Continuing after a non-fatal warning does not make an invalid entry extractable. It only keeps the rest of the run visible.
References: packages/…/stage.ts• L27-84 packages/…/validate.ts• L156-206 packages/…/extractFromVueProject.ts• L79-94 packages/…/index.ts• L19-79 packages/…/language.ts• L197-275 packages/…/missing-tools.ts• L29-142
Compiler transformation
The compiler is a universal build plugin for bundlers such as Vite, webpack, Rollup, Rspack, and esbuild. It reads supported JavaScript and TypeScript modules, records translation use, checks the source, and emits changed code only when a configured pass must modify the module.
Ordered compiler passes
The compiler passes form one ordered transformation. Each later pass can use the normalized form created by an earlier pass:
- JSX insertion adds internal translation and variable boundaries when automatic JSX extraction is enabled.
- Macro expansion turns supported tagged templates and string expressions into normal translation calls.
- Collection validates calls and components and records source data.
- Injection adds identities and runtime metadata when compile-time hashing is enabled.
- Development runtime translation can add hot-reload calls after collection.
The transform keeps settings, scope information, collected strings, and diagnostics in one state. Scope tracking prevents unrelated functions with the same local name from being treated as translation calls.
References: packages/…/index.ts• L185-305 packages/…/initializeState.ts• L14-93 packages/…/jsxInsertionPass.ts• L11-43 packages/…/macroExpansionPass.ts• L7-31
Build output
The compiler changes the module passed to the bundler. It does not replace the translation service or write the project catalog. The emitted module carries identities or runtime parameters that point to catalog entries. If no configured pass changes a module, the original module stays unchanged.
Invalid translation use can stop compilation. A disabled-check setting can return the original code with a diagnostic, but it does not make the use safe or extractable.
References: packages/…/index.ts• L226-305 packages/…/handleErrors.ts• L13-37 packages/…/injectTComponentParameters.ts• L9-56 packages/…/package.json• L40-47
Language and framework extraction
Each supported source model has a syntax-aware extractor that returns the shared entry shape. The CLI then applies common identity, validation, deduplication, and upload rules. This gives different languages one catalog model.
JavaScript and React extraction
The JavaScript-family extractor reads parsed JavaScript and TypeScript modules. It finds translation imports and aliases, standalone calls, user-written translation components, and optional automatic JSX boundaries. Dictionary sources are loaded separately and merged with inline entries before identity calculation.
References: packages/…/createInlineUpdates.ts• L36-205 packages/…/createDictionaryUpdates.ts• L20-115 packages/…/createESBuildConfig.ts• L12-29 packages/…/postProcess.ts• L31-89
Vue extraction
The Vue extractor treats a single-file component as one source unit with script and template content. It resolves project scope and visible template bindings, then serializes supported translation components and rich children. The CLI activates it only for an explicitly selected or directly declared Vue runtime.
References: packages/…/extractInline.ts• L19-53 packages/…/integration.ts• L93-119 packages/…/extractFromVueProject.ts• L61-70 packages/…/extractFromVueSource.ts• L56-132
Paraglide source languages
Paraglide context collection presents each supported language as a source-language adapter. The adapter turns framework syntax into a mapped JavaScript or TypeScript module so one analyzer can trace message calls and component use back to the original file.
Vue and VitePress Markdown use Vue language tooling. Svelte uses the project's Svelte compiler and source map. If a file part needs a missing tool, the rest of the file can still be analyzed and the skipped part is reported. Markdown without a script is ignored when Vue tools are unavailable, which avoids treating ordinary documentation as an unreadable application module.
References: packages/…/language.ts• L42-121 packages/…/language.ts• L162-235 packages/…/markdown.ts• L18-34 packages/…/svelte.ts• L14-53 packages/…/generate.ts• L58-117
Python extraction
The Python extractor parses source without running application code. It accepts recognized imports and calls whose values resolve to supported strings or variants. Unsupported dynamic forms become diagnostics instead of guessed catalog entries. Successful results map into the same updates model used by the JavaScript and Vue paths.
References: packages/…/parser.ts• L4-72 packages/…/index.ts• L19-79 packages/…/mapToUpdates.ts• L7-24
Paraglide JS compilation
Paraglide JS context collection records where generated Paraglide messages are used. It complements message compilation by producing metadata that the translation service and CLI can use without changing Paraglide-generated code.
Public context interface
The public Paraglide compiler API exposes context collection, target definitions, source-language definitions, bundler configuration, and resolver and collector types. The paraglide-context command is the user-facing path for writing metadata. Both paths use the same project analysis model.
References: packages/…/compiler.ts• L1-96 packages/…/index.ts• L1-9 packages/…/package.json• L1-22
Project context collection
The paraglide-context command and library resolve a project root, select supported source files, follow imports as the project bundler would, and analyze the loaded module graph. The collector identifies Paraglide targets and generated output directories before it records message usage. It can also account for configured or detected auto-imports.
The scan loads all selected source modules before analysis. This lets values and calls that cross module boundaries be understood as one project graph. Unresolved imports, missing parser tools, and files that do not parse become warnings or skipped inputs rather than invented usage records.
References: packages/…/context.ts• L23-43 packages/…/create.ts• L29-69 packages/…/collector.ts• L137-164 packages/…/collector.ts• L187-227 packages/…/project-resolver.ts• L32-89 packages/…/packages.ts• L7-65
Message catalogs and metadata
The collector reads message identities from generated messages.js files and their re-exports. It compares each discovered usage with the catalog for its output directory, pairs that directory with an inlang project, and writes metadata beside the message files.
Static message names must exist in the catalog. Dynamic names are checked against known catalog identities and can report matching identities. A use that cannot be tied to a known message remains visible as a warning, but it receives no generated metadata.
Metadata keeps hand-written message fields and adds source-code snippets around each use. The collector writes only changed metadata and uses an atomic replacement so readers do not see a partial file. A missing metadata file is created only for a project with message files. An unreadable or invalid existing file is left in place and reported rather than overwritten.
References: packages/…/catalog.ts• L13-37 packages/…/catalog-check.ts• L5-45 packages/…/collector.ts• L323-363 packages/…/collector.ts• L397-409 packages/…/metadata-files.ts• L26-145 packages/…/source-code.ts• L33-52 packages/…/metadata.ts• L10-46
Localization artifacts
After extraction, the CLI preserves source identity and target-file mapping while it creates artifacts. Inline content becomes a source template. Configured content becomes source records that the service can translate and later write to locale-specific paths.
File formats and source aggregation
The file boundary supports structured, document, resource, Apple, Android, subtitle, binary, and code-adjacent localization formats. Each accepted record keeps source format and requested output format distinct so later processing uses the right rules.
Aggregation validates each configured source before upload. It parses structured files, slices multi-locale catalogs, carries binary content through a safe representation, and reports unreadable or unsafe files. The same boundary serves upload, staging, translation, and local-edit flows.
References: packages/…/supportedFiles.ts• L1-50 packages/…/transformFormat.ts• L20-38 packages/…/aggregateFiles.ts• L91-111 packages/…/aggregateFiles.ts• L321-604
Source templates
The source template stores each extracted value under its identity and stores review metadata beside the upload. Its version identity depends on source keys and effective review policy. The generate command writes a source-locale view and can remove target keys that no longer exist in the current source set.
References: packages/…/aggregateFiles.ts• L181-196 packages/…/index.ts• L243-277 packages/…/reviewSetupWarning.ts• L27-63
Locale output mapping
The CLI resolves translated paths from source paths, locale placeholders, path transforms, and format transforms. This mapping is shared by upload, download, local-edit comparison, and publishing. Platform-specific paths follow the target platform's locale rules.
References: packages/…/fileMapping.ts• L18-173 packages/…/localePath.ts• L1-24 packages/…/androidLocale.ts• L6-48 packages/…/transformFormat.ts• L154-170
Download and post-processing
Download creates work for each source file and target locale, tracks each job, and polls work that is not complete. It downloads confirmed completed translations even when another job fails or polling times out. The workflow reports an incomplete result instead of hiding the missing work.
translate and download share the same final file processing. These passes localize document links, imports, frontmatter URLs, relative assets, OpenAPI references, redirects, and configured shared assets. They leave dynamic, external, unsafe, or unresolved paths unchanged.
The passes process files in bounded batches and one locale at a time. This limits open files during large documentation runs while preserving input order.
References: packages/…/download.ts• L47-230 packages/…/PollJobsStep.ts• L38-205 packages/…/keepUntranslatedPagePaths.ts• L33-175 packages/…/localizeMintlifyRedirects.ts• L29-145 packages/…/batchProcess.ts• L1-40
Related systems
- CLI orchestration and repository workflows explains command lifecycle, configuration, filesystem state, Git integration, and translation workflows.
- Compiler transform pipeline explains compiler settings, state, ordered passes, and source transforms.
- Language and framework extractors explains Vue and Python extraction plus React support.
- Paraglide JS compilation explains project analysis, message targets, source context, and metadata output.
Change checklist
When these files or sections are changed, remember to consider these:
- Keep compiler and CLI rich-content serialization, JSX numbering, and hash inputs in parity. A mismatch makes runtime lookup keys miss catalog keys.
- When adding a file format or source language, update recognition, normalization, output mapping, and format processing as one contract.
- Keep configured locale identities separate from canonical service locales. File mapping and lockfile lookups use configured spelling.
- When changing translation polling, preserve separate completed, failed, skipped, and in-progress states. Download only confirmed completed work.
- When changing download or post-processing order, preserve the same finalization in
translateanddownload. - When changing static links, imports, redirects, OpenAPI references, or assets, preserve translated-page checks and the distinction between documents and shared assets.
- When changing framework ownership, keep direct dependency checks and mixed-project boundaries aligned with the selected extractor.
- When changing Paraglide source selection or target resolution, keep import resolution, generated outdir detection, catalog pairing, and metadata paths aligned.
- When changing Paraglide metadata, preserve hand-written message fields and keep source snippets tied to the same message identities.
- When changing language tooling requirements, keep the parser's skipped-part behavior, missing-tool warnings, and
installpackage mapping aligned. - When changing alias discovery, preserve the order between explicit aliases and bundler-config aliases and keep unresolved-alias warnings off normal command data.
- When changing logging or command output, preserve stdout and stderr separation for machine-readable output and keep warnings visible under quiet mode.
- When changing branch resolution or lockfile reads, use the branch resolved for the current invocation for both locale baselines and source-template versions. Do not let an earlier persisted branch override it.
- When changing local-edit collection, preserve locale-level comparison, the distinction between a missing baseline and an empty baseline, and the partial-save count shown by
save-local.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Compiler and CLI serialize the same rich content differently | Runtime identities do not match catalog keys | Keep compiler passes and CLI extraction rules in parity |
JSX numbering differs after Branch or Plural children | Variable keys point to the wrong localization data | Follow the runtime child-numbering contract |
| A source pattern includes files outside the intended framework scope | The catalog contains content from another application | Require proven ownership and fail closed on incomplete discovery |
| A translation call uses unsupported dynamic content | No safe stable entry is created | Report a diagnostic and require supported static or derive content |
| A configured source cannot be parsed | The accepted source set becomes incomplete | Validate at aggregation and surface file-specific warnings |
| A required language tool is missing or cannot load | A file or part of a file is skipped and its usages are absent | Report the skipped scope and install the required project dev dependency |
| A source request exceeds the inline upload limit | Staging or translation fails before work starts | Use direct storage references for large content and format metadata |
| A job fails while another locale completes | Usable translations are lost or an incomplete result is hidden | Track per-file status and download confirmed completions |
| A localized page links to a source page with no translation | The locale page links to a missing target | Keep the source path when translated output is absent |
| A shared asset is treated as a localized document | Locale-prefixed links point to missing files | Keep asset mirroring separate from text URL localization |
| A bundler alias cannot be read or resolved | Usages through that alias are missed | Declare the alias in project settings or pass it with --alias |
| A Paraglide outdir or message module cannot be resolved | Message usage or catalog checks are incomplete | Warn on unresolved imports and write metadata only for known projects |
| A dynamic message name matches no catalog identity | The usage receives no metadata | Check dynamic names against the known catalog and show a bounded warning |
| Paraglide metadata replaces hand-written fields | Translator context or message rules are lost | Preserve existing metadata fields and replace only generated source context |
| An existing metadata file is unreadable or invalid | The file cannot be safely refreshed | Leave it unchanged and report the required repair |
| A v1 lockfile is read without the branch resolved for the current run | Local edits or the GT template use a stale branch version | Scope lockfile reads to the file branch or current branch result |
| A local edit has no retrievable server baseline | The edit cannot be compared and is not submitted | Warn for the affected locale and report it as skipped |
| A save run has no configured files or template | Branch resolution can create remote state for no useful work | Return before branch resolution and diff collection |
| Diagnostics are written to stdout with machine-readable data | Pipelines cannot parse command output | Route diagnostics to stderr |
Key files
| File | Why to read it |
|---|---|
| packages/…/index.ts | Shows startup framework selection and CLI dispatch. |
| packages/…/base.ts | Shows command registration, settings resolution, and shared translation finalization. |
| packages/…/generateSettings.ts | Shows how configuration and command flags become one settings object. |
| packages/…/download.ts | Shows branch-aware download and partial translation handling. |
| packages/…/downloadedVersions.ts | Shows the persistent link between branches, service versions, downloaded locales, and post-processing state. |
| packages/…/saveLocalEdits.ts | Shows branch resolution and the local-edit save flow before translation work is enqueued. |
| packages/…/collectUserEditDiffs.ts | Shows locale-level comparison against downloaded baselines and submission of user edit diffs. |
| packages/…/aggregateFiles.ts | Shows the boundary from configured files to accepted source records. |
| packages/…/fileMapping.ts | Shows how source files map to locale output paths. |
| packages/…/index.ts | Shows the compiler plugin boundary and pass order. |
| packages/…/constructJsxChildren.ts | Shows runtime-aligned rich JSX identity construction. |
| packages/…/createInlineUpdates.ts | Shows the JavaScript and React extraction boundary. |
| packages/…/integration.ts | Shows Vue activation and extractor integration. |
| packages/…/index.ts | Shows the Python source-to-results boundary. |
| packages/…/compiler.ts | Shows the public Paraglide context, language, target, and resolver API. |
| packages/…/index.ts | Shows context command options, project roots, aliases, and output streams. |
| packages/…/install.ts | Shows how missing language tools are mapped to project package-manager commands. |
| packages/…/context.ts | Shows the public context-collection flow. |
| packages/…/collector.ts | Shows source selection, module analysis, catalog checks, and metadata writes. |
| packages/…/metadata-files.ts | Shows metadata preservation and atomic output. |
| packages/…/catalog.ts | Shows how generated message identities are read without running generated code. |
| packages/…/language.ts | Shows the common source-language contract and skipped-part behavior. |
| packages/…/generate.ts | Shows the Vue and VitePress source boundary. |
| packages/…/svelte.ts | Shows the Svelte source boundary. |
| packages/…/project-resolver.ts | Shows bundler-aligned import resolution and alias warnings. |
| packages/…/packages.ts | Shows how project language tools are found and loaded. |