# gt: General Translation CLI tool: Using automatic JSX injection
URL: https://generaltranslation.com/en-US/docs/cli/guides/using-auto-jsx.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: How to wrap translatable JSX text in General Translation components at build time with automatic JSX injection.

Automatic JSX injection makes the compiler wrap translatable JSX text in [`<T>`](/docs/react/reference/components/t) components at build time, so you do not have to add them by hand.

Automatic JSX injection is disabled by default. It works in React single-page apps (SPAs), server-rendered React apps, and Next.js webpack builds.

## Enable automatic JSX injection [#enable]

Install the compiler:

<Tabs items={['npm', 'yarn', 'bun', 'pnpm']}>
  <Tab value="npm">
    ```bash
    npm install @generaltranslation/compiler
    ```
  </Tab>

  <Tab value="yarn">
    ```bash
    yarn add @generaltranslation/compiler
    ```
  </Tab>

  <Tab value="bun">
    ```bash
    bun add @generaltranslation/compiler
    ```
  </Tab>

  <Tab value="pnpm">
    ```bash
    pnpm add @generaltranslation/compiler
    ```
  </Tab>
</Tabs>

Set `enableAutoJsxInjection` under `files.gt.parsingFlags` in `gt.config.json`. This keeps CLI extraction and compiler transforms in sync.

```json title="gt.config.json"
{
  "files": {
    "gt": {
      "parsingFlags": {
        "enableAutoJsxInjection": true
      }
    }
  }
}
```

## Configure the build [#configure-build]

The `gt.config.json` flag takes effect when the General Translation compiler runs.

### React SPAs

Add `@generaltranslation/compiler` to your Vite, webpack, Rollup, Rspack, or esbuild configuration. See [Developing with SPA translations](/docs/react/guides/developing-spa-translations#setup) for adapter examples.

### React apps (non-SPA) [#react-apps]

For server-rendered React apps that use Vite, add the compiler plugin to your Vite configuration:

```ts title="vite.config.ts"
import react from '@vitejs/plugin-react';
import { vite as gtCompiler } from '@generaltranslation/compiler';
import { defineConfig } from 'vite';
import gtConfig from './gt.config.json';

export default defineConfig({
  plugins: [react(), gtCompiler(gtConfig)],
});
```

### Next.js

Configure `gt-next` to use the Babel-based webpack compiler:

```ts title="next.config.ts"
import { withGTConfig } from 'gt-next/config';

const nextConfig = {};

export default withGTConfig(nextConfig, {
  experimentalCompilerOptions: {
    type: 'babel',
    enableAutoJsxInjection: true,
  },
});
```

Run both the development server and production build with webpack:

```json title="package.json"
{
  "scripts": {
    "dev": "next dev --webpack",
    "build": "next build --webpack"
  }
}
```

Next.js 16 uses Turbopack by default. Turbopack disables the Babel compiler, warns that automatic injection will be skipped, and leaves JSX unwrapped. See [Next.js compiler options](/docs/react/nextjs/config#compiler-options).

## How it works [#how]

Without injection, you wrap translatable text yourself.

```jsx
import { T } from 'gt-react';

function Welcome() {
  return (
    <T>
      <h1>Welcome to our app</h1>
    </T>
  );
}
```

Next.js projects import [`<T>`](/docs/react/reference/components/t) from `gt-next` instead.

With injection enabled, the compiler detects the translatable text and wraps it automatically at build time.

```jsx
function Welcome() {
  return <h1>Welcome to our app</h1>;
}
```

Text you have already wrapped in [`<T>`](/docs/react/reference/components/t), along with other General Translation components such as [`<Var>`](/docs/react/reference/components/var), [`<Branch>`](/docs/react/reference/components/branch), [`<Plural>`](/docs/react/reference/components/plural), and [`<Derive>`](/docs/react/reference/components/derive), is left untouched.

## Next steps

- /docs/cli/guides/using-autoderive
- /docs/cli/guides/generating-translations
- /docs/cli/guides/configuring
- /docs/cli/guides/managing-translations

## Sitemap

See the full [sitemap](https://generaltranslation.com/sitemap.md) for all pages.
