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 / language-and-framework-extractors

Language and framework extractors

Language and framework extractors locate translation content in application source and convert it into the common extraction update shape. Python and Vue provide dedicated source extractors. React content is found by the CLI, while React Core linting helps authors use patterns that the extractor can understand.

Extraction boundaries

An extraction boundary turns framework source into translation input. Each path applies rules for source ownership and static content, then passes source text, rich content, metadata, and diagnostics to the wider extraction and compilation flow.

AreaRoleMain result
PythonFind supported translation imports and calls in Flask and FastAPI sourceICU string updates with metadata
VueFind gt-vue content in Vue components and project-owned source filesString or rich updates with catalog identity
ReactFind supported React calls and components during CLI scansString and rich JSX updates
React Core lintingKeep translation source static and structurally validDiagnostics and safe source fixes

The extractors do not translate text. They decide which source is translatable and preserve the structure needed by hashing, catalog merge, compilation, and runtime use. The CLI orchestration layer selects the path and combines its result with the rest of the project.

Python extraction

The Python extractor reads Python source for supported Flask and FastAPI translation usage. It uses the translation imports as ownership signals, follows local aliases, and returns valid updates together with errors and warnings.

Python source ownership

Imports from gt_flask and gt_fastapi mark the supported translation functions in a file. Local aliases remain linked to those functions, so renaming a binding does not hide content from extraction. Unrelated imports and functions stay outside the translation boundary.

References: packages/…/extractImports.ts• L7-24 packages/…/constants.ts• L1-13

Python static content

The t and msg calls provide ICU source text when their content is known. Literal strings are the normal case. derive and declare_var describe known static choices and runtime variables so the extractor can include safe variants without treating arbitrary Python values as translatable text.

The extractor carries _id, _context, and _max_chars into update metadata. An unsupported dynamic form produces a source error. Other valid calls in the same file can still be found, and the caller decides whether the diagnostic prevents publication.

References: packages/…/index.ts• L19-79 packages/…/extractCalls.ts• L26-65 packages/…/extractCalls.ts• L214-246 packages/…/extractCalls.ts• L276-327 packages/…/parseStringExpression.ts• L59-113

Python parser runtime

The Python parser uses a shared, lazy parser instance to read Python syntax. The package ships the Python grammar as WebAssembly so an installed package does not need the native tree-sitter-python build step; the same grammar can be resolved in Node and Bun environments.

The published package exports the grammar asset with the extractor. This keeps Python extraction available after installation while keeping the native grammar package in development dependencies. A package check confirms that the published grammar path exists and that the runtime dependency does not install the native package.

References: packages/…/parser.ts• L1-73 packages/…/tsdown.config.mts• L4-24 packages/…/package.json• L27-40 packages/…/package.json• L57-70 packages/…/CHANGELOG.md• L52-57 packages/…/pythonGrammarWasm.test.ts• L11-27

Python static variants

Python derivation expands values that can be known without running the application. It can cover conditional choices, string joins, declared variables, and values from static local or imported collections. Values that cannot be resolved safely remain outside the extracted source.

References: packages/…/parseStringExpression.ts• L250-340 packages/…/parseStringExpression.ts• L387-456 packages/…/parseStringExpression.ts• L463-518 packages/…/parseStringExpression.ts• L694-751

Vue extraction

The Vue extractor supports one-file analysis and project analysis. One-file analysis reads an in-memory Vue single-file component or script. Project analysis determines which packages own Vue content, applies the consuming app's compiler and module rules, and returns a complete update set rather than a partial catalog.

Vue project ownership

Vue ownership defines which source belongs to the Vue extractor. A project is selected when its root directly declares an effective gt-vue dependency, when the caller explicitly selects the gt-vue runtime, or when project-local wrapper packages expose and are used through a public gt-vue API.

Workspace discovery creates Vue scopes for selected packages. A child Vue package does not promote an unrelated workspace root, and a wrapper only propagates ownership when consumer source imports the exact public Vue entry or export. This keeps React-only and ordinary helper code outside the Vue boundary.

The integration planner makes this ownership decision before it loads the full Vue pipeline. For a mixed project, it can keep the primary extractor and Vue extraction in one run. It partitions confirmed Vue SFCs away from the primary scan and merges the two result sets afterward.

References: packages/…/integration.ts• L75-118 packages/…/inspectVueProject.ts• L25-100 packages/…/scopes.ts• L52-131 packages/…/consumerUsage.ts• L93-141 packages/…/wrapperProvenance.ts• L46-93 packages/…/consumerUsage.test.ts• L27-75 packages/…/integrationPlanner.test.ts• L24-144

Vue source boundaries

Project extraction searches the selected Vue scopes for Vue single-file components and supported JavaScript or TypeScript modules. A file with a .vue name is not enough to establish a Vue boundary because legacy JSX modules can use that suffix. The extractor classifies the source before it assigns the file to Vue or to the primary framework scan.

Default project patterns cover the source locations owned by each selected package. Explicit patterns replace those defaults, but files outside a discovered Vue scope remain outside project extraction. This lets a mixed repository select source without making every framework parser inspect the same file.

References: packages/…/extractFromVueProject.ts• L69-113 packages/…/inspectVueProject.ts• L103-190 packages/…/vueSourceClassification.ts• L18-67 packages/…/projectExtraction.test.ts• L17-41 packages/…/projectExtraction.test.ts• L116-130

Vue source provenance

Vue extraction follows statically known translation identities through local aliases, namespace values, barrel files, package exports, and supported TypeScript or CommonJS forms. Provenance means that the extractor can show that a call or component came from gt-vue, rather than only matching a name such as T or msg.

When identity is ambiguous, mutable, unresolved, or dynamic, the extractor fails closed. It does not publish content that may belong to another runtime. The same rule keeps mixed React-family imports and ordinary helpers silent when they have no gt-vue origin.

References: packages/…/extractFromVueSource.ts• L135-188 packages/…/consumerUsage.ts• L194-229 packages/…/wrapperProvenance.ts• L61-93 packages/…/localModuleResolution.test.ts• L17-61 packages/…/localModuleResolution.test.ts• L304-374 packages/…/mixedRuntimeIsolation.test.ts• L39-125

Vue template content

Vue extraction recognizes gt-vue components and string translation calls in both template and script content. A <T> component becomes rich source content that preserves meaningful elements, variables, branches, and plural forms. Direct string calls become string updates when their source and context are static.

Runtime values inside rich content use recognized variable components such as Var, Num, DateTime, or Currency. The default slot supplies the main source, while branch and plural slots remain explicit alternatives. The result keeps rich values, branch data, and supported metadata available to later catalog steps.

Vue and React share the semantic rich-content contract. The Vue extractor checks the same source and hash meaning for portable cases, while still applying Vue slot and whitespace behavior. Unsupported dynamic content produces a diagnostic instead of incomplete translation text.

References: packages/…/extractFromVueSource.ts• L64-132 packages/…/template.ts• L171-185 packages/…/template.ts• L321-397 packages/…/stringCalls.ts• L20-94 packages/…/extractFromVueSource.test.ts• L11-94 packages/…/reactParity.test.ts• L12-60 packages/…/templateExtraction.test.ts• L19-78

Vue project identity

Project extraction applies the Vue compiler behavior that belongs to each consuming app. It resolves the app's Vue compiler and matching compiler-dom version, reads static Vite or Nuxt options, and uses project aliases and package export rules to resolve local translation identities.

Each extracted result receives a stable catalog hash. Results with the same hash are combined, while their source paths and source context remain available as metadata. Discovery, configuration, file access, or extraction errors make the project result empty so downstream systems cannot mistake an incomplete scan for a complete catalog.

The integration boundary preserves this identity when Vue results join another extractor. A matching hash becomes one update, and the primary update remains authoritative while Vue locations and source context are added.

References: packages/…/extractFromVueProject.ts• L117-147 packages/…/extractFromVueProject.ts• L208-271 packages/…/mergeVueProjectExtraction.ts• L14-67 packages/…/vueCompiler.ts• L47-110 packages/…/resolveVueCompilerOptions.ts• L86-145 packages/…/projectExtraction.test.ts• L334-367 packages/…/vueCompiler.test.ts• L57-196

React extraction support

React extraction runs in the CLI's inline update path. It scans configured source files, identifies supported General Translation imports, and sends string calls and translation components to the matching parser. The path then hashes and deduplicates the updates before handing them to the CLI.

React source discovery

The React parser follows translation callbacks through local aliases and helper functions. This lets it find content when a callback from useGT or getGT crosses a local or imported helper while keeping the search tied to the original source binding.

References: packages/…/createInlineUpdates.ts• L36-123 packages/…/createInlineUpdates.ts• L195-205 packages/…/parseStringFunction.ts• L69-304

React rich content

React <T> content is read as a rich JSX tree. Static text and known static expressions remain source content. Recognized variable components mark runtime values, while branch and plural content become explicit alternatives. An unsupported unwrapped expression produces an extraction error instead of incomplete translation text.

The CLI can add internal wrappers around extractable JSX before a second extraction pass when auto-injection is enabled. This keeps the source shaping step separate from later transforms described in the compiler transform pipeline.

References: packages/…/parseJsx.ts• L200-333 packages/…/parseJsx.ts• L357-488 packages/…/parseJsx.ts• L661-815 packages/…/createInlineUpdates.ts• L126-191

React Core linting support

React Core linting is an author-time guard for the same source contracts used by React extraction. The ESLint plugin is separate from extraction. It reports invalid patterns early and can apply safe fixes for some dynamic forms.

ESLint rule set

@generaltranslation/react-core-linter enables rules for static string registration, static rich JSX content, and valid branch attributes in its recommended configuration. The plugin checks import bindings and configured General Translation libraries, so an unrelated component named T or function named msg is not treated as translation code.

References: packages/…/index.ts• L9-47 packages/…/constants.ts• L3-14 packages/…/STYLEGUIDE.md• L20-39

Static string rule

The static-string rule keeps gt and msg registration content known at analysis time. It accepts static strings and checks ICU syntax when needed. A fixable interpolation can become an ICU variable with an options object, while translation metadata must remain static.

References: packages/…/index.ts• L1-8 packages/…/index.ts• L93-217

Static JSX rule

The static-jsx rule keeps <T> children understandable to the extractor. It permits literal content and known translation structure. It reports dynamic expressions unless they use a recognized variable component. A known conditional or logical expression can be wrapped as Branch content by an auto-fix.

References: packages/…/index.ts• L30-195

Branch attribute rule

The no-data-attrs-on-branch rule prevents data-* attributes on Branch from becoming a false source contract. The runtime ignores these attributes, so the rule reports them before they can mislead authors or tooling.

References: packages/…/index.ts• L7-67

Extraction flow

The flow below shows how source ownership selects an extractor, how extracted content becomes updates, and where React linting acts before extraction.

flowchart LR
  A[Application source] --> B{Source family}
  B -->|Python| C[Python extractor]
  B -->|Vue| D[Vue project extractor]
  B -->|React| E[CLI React parser]
  A --> F[React Core ESLint plugin]
  F -->|diagnostics or fixes| A
  C --> G[Translation updates]
  D --> G
  E --> G
  G --> H[Hash, merge, compile]

The linter does not replace extraction. The extractors locate content and report diagnostics. Downstream stages decide how updates enter catalogs and compiled output. See React integration for the runtime side of React translation use.

References: packages/…/index.ts• L19-79 packages/…/integration.ts• L165-245 packages/…/createInlineUpdates.ts• L36-205 packages/…/index.ts• L1-7

Change checklist

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

  • Keep Python import ownership, parser grammar packaging, and the published WASM export aligned. A package can build while runtime parsing still fails if the grammar path changes alone.
  • Keep Vue ownership detection, wrapper provenance, consumer usage, and workspace scope selection aligned. A mismatch can activate Vue for the wrong package or omit a real consumer.
  • Keep Vue source classification and mixed-framework pattern partitioning aligned. A change can scan one source twice or hide a legacy JSX module from the primary extractor.
  • Keep Vue compiler selection, compiler options, aliases, and module resolution aligned with the consuming app. A hash can change when extraction uses different build rules.
  • Keep Vue rich-source types aligned with the format package, React parity contract, and hash input. A new child or branch shape can change catalog identity.
  • Keep project atomic-error behavior aligned with the caller's publication contract. Returning partial updates can silently replace a complete catalog with an incomplete one.
  • Keep React parser rules and React Core linter rules aligned. A lint fix must produce a structure that extraction can read.
  • Keep the configured React library list aligned across CLI import tracking and linter import detection. A missing library can remove source from one path.
  • Keep metadata names and formats aligned across Python keyword arguments, Vue props, React variables, and update normalization.
  • Keep public exports, generated declarations, and shared dependency versions aligned for the Python and Vue packages. Package boundary changes can hide an extractor or create incompatible update types.

Important failure modes

TriggerConsequenceGuard
The Python package cannot resolve its bundled grammar WASMPython parsing cannot start after installationKeep the WASM export, copied build asset, and runtime resolver aligned
A Python call uses an unsupported dynamic valueThe call is rejected and its content is absent from the resultUse a literal or supported derive and declare_var form
A root has no direct Vue ownership and only an unused or non-public wrapper dependencyVue extraction stays inactive and the project receives no Vue updatesDeclare gt-vue, select the gt-vue runtime, or use a public wrapper API in project source
A wrapper exposes both Vue and another framework but source imports the wrong public entryThe package is not promoted to a Vue scopeImport the exact public Vue subpath and export
A Vue alias is unresolved, ambiguous, mutable, or dynamically loadedThe possible translation is not publishedUse a statically resolvable ESM or supported CommonJS identity
A Vue project has an invalid compiler, alias, discovery, or file-read resultThe project returns no updates instead of a partial catalogUse the consuming app's supported Vue compiler and readable static project settings
Vue and vue/compiler-sfc or compiler-dom versions do not matchSFC extraction is rejected because source meaning may differInstall matching compiler packages beside the consuming app
A Vue rich translation contains an unrecognized runtime value or source-shaping directiveThe rich update is rejected instead of producing incomplete textUse a recognized variable component and static translation structure
A React <T> contains an unwrapped runtime expressionThe CLI reports an extraction error and skips the rich updateMake the value static or wrap it in a recognized variable component
A React registration call uses a dynamic non-ICU stringLint reports an error and cannot apply the ICU fixUse a static string or matching ICU variables
A Branch contains a data-* attributeThe runtime ignores the attribute and authors may assume it is preservedRemove the attribute and follow the linter diagnostic

Key files

FileWhy to read it
packages/…/index.tsPublic Python extraction boundary and diagnostic result shape
packages/…/extractImports.tsPython translation ownership and alias handling
packages/…/extractCalls.tsPython call recognition and metadata handling
packages/…/parseStringExpression.tsPython static value and variant model
packages/…/parser.tsPython parser lifecycle and grammar loading boundary
packages/…/package.jsonPublished Python entry points and grammar asset boundary
packages/python-extractor/tsdown.config.mtsPublished Python grammar asset contract
packages/…/integration.tsVue activation, mixed-project planning, source partitioning, and result merge boundary
packages/…/inspectVueProject.tsVue scope discovery and explicit mixed-framework partitioning
packages/…/scopes.tsWorkspace ownership and selected Vue source scopes
packages/…/consumerUsage.tsPublic wrapper use and consumer ownership evidence
packages/…/extractFromVueProject.tsVue discovery, compiler/config resolution, hashing, deduplication, and atomic diagnostics
packages/…/extractFromVueSource.tsOne-file provenance and extraction boundary
packages/…/template.tsVue rich content, slots, variables, and static template rules
packages/…/vueCompiler.tsConsuming-app compiler selection and compatibility boundary
packages/…/mergeVueProjectExtraction.tsCross-framework update merge and metadata preservation
packages/…/package.jsonPublic Vue analysis boundaries and package exports
packages/…/createInlineUpdates.tsReact scan lifecycle and update handoff
packages/…/parseStringFunction.tsReact string-call and callback tracing
packages/…/parseJsx.tsReact rich JSX extraction and dynamic-content diagnostics
packages/…/index.tsESLint plugin exports and recommended rules
packages/…/index.tsStatic string and ICU contract
packages/…/index.tsStatic rich JSX contract and safe wrapper fixes
packages/…/index.tsBranch attribute contract