# General Translation React SDKs (gt-react, gt-next, gt-react-native): Configuration
URL: https://generaltranslation.com/en-US/docs/react/nextjs/config.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: Configure General Translation in a Next.js app with the withGTConfig plugin from gt-next/config, its options, and local versus CDN translations. API reference for withGTConfig.

`withGTConfig` is the `gt-next` config plugin. Wrap your Next.js config with it in `next.config` to enable internationalization at build time. It reads your `gt.config.json` file, merges it with any options you pass and your environment variables, and sets up the compiler, translation loading, and request handling.

This page documents the plugin and its options. For the shared `gt.config.json` locale and file settings, see the [`gt-react` configuration reference](/docs/react/reference/config); for the CLI-side `files` schema, see the [CLI configuration reference](/docs/cli/reference/config).

## Overview [#overview]

Import `withGTConfig` from `gt-next/config` and wrap your Next.js config. Options can be passed as the second argument, but most projects keep locale settings in `gt.config.json` instead.

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

const nextConfig: NextConfig = {
  // your existing Next.js config
};

export default withGTConfig(nextConfig, {
  defaultLocale: 'en',
  locales: ['es', 'fr', 'ja'],
});
```

`withGTConfig` must be used in `next.config` — it is the only place internationalization is wired into the build.

## How it works [#how-it-works]

- **Config resolution.** By default the plugin loads `./gt.config.json` (it also checks `./.gt/gt.config.json` and `./.locadex/gt.config.json`). Values are merged with this precedence: **options you pass > environment variables > `gt.config.json` > defaults.** If a key set in both `gt.config.json` and the options disagrees, the build throws a conflict error, so keep each value in one place.
- **Pages Router locale routing.** When `nextConfig.i18n` is present, its `locales` and `defaultLocale` should match the explicit values in `gt.config.json`. A mismatch emits a build-time warning but does not stop the build. Locale order is ignored, and the General Translation comparison includes `defaultLocale` in its effective locale set. Next.js supplies the active locale to Pages Router data functions.
- **Credentials come from the environment.** You cannot pass `projectId`, `apiKey`, or `devApiKey` as options — set them as environment variables (see [Credentials](#credentials)).
- **Locale standardization.** When General Translation services are enabled, locale codes are standardized to canonical BCP 47 form and invalid locales throw at build time.
- **Translation delivery.** If a [`loadTranslations`](/docs/react/reference/functions/load-translations) file is resolved, translations are loaded from your bundle; otherwise they are fetched from the General Translation CDN. See [Local vs. CDN translations](#translations).

## Credentials [#credentials]

Set your project ID and API key as environment variables, never as plugin options:

| Variable | Description |
| --- | --- |
| `GT_PROJECT_ID` | Project ID. `NEXT_PUBLIC_GT_PROJECT_ID` is still read when this is unset. |
| `GT_API_KEY` | Project API key (prefixed `gtx-api-`) for server runtime translation and, in development, hot reload. |

CLI sessions do not provide runtime SDK credentials. (See [CLI authentication](/docs/cli/guides/configuring#credentials)).

### Development

Put both variables in `.env.local`. [`gt init`](/docs/cli/reference/commands/init) writes these names for Next.js in `gt` 2.27.1 and later. During `next dev`, `GT_API_KEY` is the hot-reload key, and `withGTConfig` passes `GT_PROJECT_ID` and `GT_API_KEY` to client code so client components can translate. Production builds do not include the key.

```bash title=".env.local"
GT_PROJECT_ID="your-project-id"
GT_API_KEY="gtx-api-your-runtime-key"
```

A project set up by an earlier [`gt init`](/docs/cli/reference/commands/init) can keep `NEXT_PUBLIC_GT_PROJECT_ID` and `NEXT_PUBLIC_GT_DEV_API_KEY`. Those names still enable development hot reload when the unprefixed names are unset. `GT_DEV_API_KEY` is not read.

To keep the key out of the browser while you develop, remove `NEXT_PUBLIC_GT_DEV_API_KEY` and set [`runtimeUrl`](#runtime-url) to an empty string. That turns off runtime translation, so `withGTConfig` does not pass `GT_API_KEY` to client code.

<Callout type="info">
  **Changed in v11.4.19:** Development hot reload uses `GT_API_KEY`. `GT_DEV_API_KEY` is no longer read, `GT_PROJECT_ID` takes precedence over `NEXT_PUBLIC_GT_PROJECT_ID`, and a production build no longer fails when `NEXT_PUBLIC_GT_DEV_API_KEY` is set.
</Callout>

### Production

Set the same names in the deployed server's environment:

```bash
GT_PROJECT_ID="your-project-id"
GT_API_KEY="gtx-api-your-production-key"
```

`GT_API_KEY` in `.env.local` is also used by a local `next build` or `next start` for server runtime translation, and it is not added to the client bundle. The key needs **Runtime translation** for server-side [`tx`](/docs/react/nextjs/reference/functions/tx) and [`<Tx>`](/docs/react/nextjs/reference/components/tx). If your deployment build runs [`gt translate`](/docs/cli/reference/commands/translate) with the same key, also grant **Files > Write**, **Translation queue > Enabled**, and **Context > Write**. Do not run `next dev` with that broader key: development passes the key to client code, so use a key limited to **Runtime translation** there. [`<T>`](/docs/react/reference/components/t) and [`useGT`](/docs/react/reference/hooks/use-gt) only look up already-generated translations. Send browser requests that need runtime translation to your authenticated server endpoint instead of exposing the key.

<Callout type="warn">
  **Warning:** Never include any API key in a deployed client bundle, and do not prefix `GT_API_KEY` with `NEXT_PUBLIC_`. We recommend a key with only **Runtime translation** enabled for local development. Next.js can inline `NEXT_PUBLIC_` variables into client code, so remove `NEXT_PUBLIC_GT_DEV_API_KEY` from production environments.
</Callout>

## Options [#options]

All options are optional. Locale options are most commonly set in `gt.config.json` instead of here.

### Locale options [#locale-options]

| Option | Description | Type | Optional | Default |
| --- | --- | --- | --- | --- |
| [`defaultLocale`](#default-locale) | Source locale your app is written in. | `string` | Yes | `en` |
| [`locales`](#locales) | Target locales to translate into. | `string[]` | Yes | `[]` |
| [`ignoreBrowserLocales`](#ignore-browser-locales) | Ignore the browser's preferred locales during detection. | `boolean` | Yes | `false` |
| [`disableInvalidLocaleWarning`](#disable-invalid-locale-warning) | Silence warnings about invalid request locales. | `boolean` | Yes | `false` |
| [`description`](#description) | Natural-language description of your app, used to guide translation. | `string` | Yes | — |

### Translation delivery [#delivery-options]

| Option | Description | Type | Optional | Default |
| --- | --- | --- | --- | --- |
| [`runtimeUrl`](#runtime-url) | Base URL for the General Translation API. Empty string disables runtime translation. | `string \| null` | Yes | `https://api.gtx.dev` |
| [`cacheUrl`](#cache-url) | URL for cached translations. | `string \| null` | Yes | `https://cdn.gtx.dev` |
| [`cacheExpiryTime`](#cache-expiry-time) | Milliseconds before locally cached translations expire. | `number` | Yes | `60000` |
| [`loadTranslationsPath`](#load-translations-path) | Path to a custom [`loadTranslations`](/docs/react/reference/functions/load-translations) file. | `string` | Yes | Auto-resolved |
| [`loadDictionaryPath`](#load-dictionary-path) | Path to a custom [`loadDictionary`](/docs/react/reference/functions/load-dictionary) file. | `string` | Yes | Auto-resolved |
| [`dictionary`](#dictionary) | Path to your dictionary file. | `string` | Yes | Auto-resolved |
| [`config`](#config-path) | Path to the `gt.config.json` file. | `string` | Yes | `./gt.config.json` |

### Rendering [#rendering-options]

| Option | Description | Type | Optional | Default |
| --- | --- | --- | --- | --- |
| [`renderSettings`](#render-settings) | How runtime translations render while loading. | `object` | Yes | See below |

### Performance [#performance-options]

| Option | Description | Type | Optional | Default |
| --- | --- | --- | --- | --- |
| [`maxConcurrentRequests`](#max-concurrent-requests) | Maximum concurrent translation requests. | `number` | Yes | `100` |
| [`maxBatchSize`](#max-batch-size) | Maximum translations per batch. | `number` | Yes | `25` |
| [`batchInterval`](#batch-interval) | Milliseconds between batched requests. | `number` | Yes | `50` |

### Build and integration [#build-options]

| Option | Description | Type | Optional | Default |
| --- | --- | --- | --- | --- |
| [`experimentalCompilerOptions`](#compiler-options) | Compiler plugin settings. | `object` | Yes | See below |
| [`headersAndCookies`](#headers-and-cookies) | Custom locale header and cookie names. | `object` | Yes | See below |
| [`getLocalePath`](#request-function-paths) | Path to a custom [`getLocale`](/docs/react/nextjs/reference/functions/get-locale) function. | `string` | Yes | — |
| [`getRegionPath`](#request-function-paths) | Path to a custom [`getRegion`](/docs/react/nextjs/reference/functions/get-region) function. | `string` | Yes | — |
| [`pathRegex`](#path-regex) | Restrict i18n middleware to matching pathnames. | `string` | Yes | — |
| [`_tagIds`](#tag-ids) | Expose each [`<T>`](/docs/react/reference/components/t) translation hash as a `data-_gt-hash` attribute. | `boolean` | Yes | `false` |
| [`eslint`](#eslint-options) | Generate the General Translation ESLint config. | `boolean` | Yes | `true` |
| [`eslintSeverity`](#eslint-options) | Severity for the generated ESLint rules. | `'error' \| 'warn'` | Yes | `'warn'` |
| [`overwriteESLintConfig`](#eslint-options) | Overwrite an existing `eslint.config.mjs`. | `boolean` | Yes | `false` |

### `defaultLocale` [#default-locale]

**Type** `string` · **Optional** · **Default** `en`

The source locale your app is written in. Used as the fallback when a translation is missing.

### `locales` [#locales]

**Type** `string[]` · **Optional** · **Default** `[]`

The target locales to translate into. Requests for an unsupported locale fall back to the closest match, then to `defaultLocale`. Pick from the [supported locales](/docs/platform/dashboard/reference/supported-locales).

### `ignoreBrowserLocales` [#ignore-browser-locales]

**Type** `boolean` · **Optional** · **Default** `false`

When `true`, the browser's `Accept-Language` preferences are ignored during locale detection.

### `disableInvalidLocaleWarning` [#disable-invalid-locale-warning]

**Type** `boolean` · **Optional** · **Default** `false`

When `true`, warnings about invalid request locales are suppressed.

### `description` [#description]

**Type** `string` · **Optional**

A natural-language description of your app. It is sent as context to improve translation quality.

### Routing options [#routing]

`withGTConfig` also accepts the [`createNextMiddleware`](/docs/react/nextjs/reference/functions/create-next-middleware#options) routing options: [`localeRouting`](/docs/react/nextjs/reference/functions/create-next-middleware#locale-routing), [`prefixDefaultLocale`](/docs/react/nextjs/reference/functions/create-next-middleware#prefix-default-locale), [`enableSmartRouting`](/docs/react/nextjs/reference/functions/create-next-middleware#smart-routing), [`ignoreSourceMaps`](/docs/react/nextjs/reference/functions/create-next-middleware#ignore-source-maps), [`pathConfig`](/docs/react/nextjs/reference/functions/create-next-middleware#path-config), [`routeOverrides`](/docs/react/nextjs/reference/functions/create-next-middleware#route-overrides), and [`localeRoutes`](/docs/react/nextjs/reference/functions/create-next-middleware#locale-routes). Set them here so the middleware and [`<Link>`](/docs/react/nextjs/link) share one configuration. Options passed directly to the middleware take precedence.

[`<Link>`](/docs/react/nextjs/link), [`useLocalizeHref`](/docs/react/nextjs/reference/hooks/use-localize-href), and [`getLocalizeHref`](/docs/react/nextjs/reference/functions/get-localize-href) read `prefixDefaultLocale` and `enableSmartRouting` only from `withGTConfig`. In development, the middleware warns when its values for those two options differ from the ones set here, because links can then trigger an extra redirect.

### `runtimeUrl` [#runtime-url]

**Type** `string | null` · **Optional** · **Default** `https://api.gtx.dev`

Base URL for the General Translation API used for on-demand translation. Set it to an empty string to disable runtime translation entirely.

### `cacheUrl` [#cache-url]

**Type** `string | null` · **Optional** · **Default** `https://cdn.gtx.dev`

URL where cached translations are served from. Point it at a custom cache host, or set it to `null` to disable remote loading.

### `cacheExpiryTime` [#cache-expiry-time]

**Type** `number` · **Optional** · **Default** `60000`

Milliseconds before locally cached translations expire. This default applies to production remote loading without `devApiKey`.

### `loadTranslationsPath` [#load-translations-path]

**Type** `string` · **Optional**

Path to a custom [`loadTranslations`](/docs/react/reference/functions/load-translations) file for [local translations](#translations). By default the plugin auto-resolves a `loadTranslations.[js|ts]` file in your project root or `src/`.

### `loadDictionaryPath` [#load-dictionary-path]

**Type** `string` · **Optional**

Path to a custom [`loadDictionary`](/docs/react/reference/functions/load-dictionary) file. By default the plugin auto-resolves a `loadDictionary.[js|ts]` file in your project root or `src/`.

### `dictionary` [#dictionary]

**Type** `string` · **Optional**

Path to your dictionary file. Files named `dictionary.[js|ts|json]` at the project root or in `src/` are picked up automatically.

### `config` [#config-path]

**Type** `string` · **Optional** · **Default** `./gt.config.json`

Path to the `gt.config.json` file to load.

### `renderSettings` [#render-settings]

**Type** `{ method: 'skeleton' | 'replace' | 'default'; timeout?: number }` · **Optional**

Controls how content renders while a runtime translation loads. This applies only to translations performed on demand; cached translations render immediately.

- `method` — one of:
  - `skeleton` — render nothing (a fragment) while waiting.
  - `replace` — render the default-language content while waiting.
  - `default` — behave like `replace` for same-language locales (such as `en-US` and `en-GB`), and like `skeleton` for different languages.
- `timeout` — milliseconds before the render method times out and falls back to the original content. Defaults to `8000` in development and `12000` in production.

```ts title="next.config.ts"
export default withGTConfig(nextConfig, {
  renderSettings: {
    method: 'skeleton',
    timeout: 10000,
  },
});
```

### `maxConcurrentRequests` [#max-concurrent-requests]

**Type** `number` · **Optional** · **Default** `100`

Maximum number of concurrent translation requests to the General Translation API.

### `maxBatchSize` [#max-batch-size]

**Type** `number` · **Optional** · **Default** `25`

Maximum number of translations grouped into a single batched request.

### `batchInterval` [#batch-interval]

**Type** `number` · **Optional** · **Default** `50`

Milliseconds to wait between batched translation requests, to control request rate.

### `experimentalCompilerOptions` [#compiler-options]

**Type** `object` · **Optional**

Settings for the compiler plugin that analyzes your source at build time. Fields:

| Field | Description | Type | Default |
| --- | --- | --- | --- |
| `type` | Which compiler plugin to use. | `'babel' \| 'swc' \| 'none'` | `'none'` |
| `logLevel` | Log verbosity for the compiler. | `'silent' \| 'error' \| 'warn' \| 'info' \| 'debug'` | `'warn'` |
| `compileTimeHash` | Pre-compute translation hashes at build time. | `boolean` | `true` |
| `disableBuildChecks` | Disable build-time validation checks. | `boolean` | `false` |
| `enableAutoJsxInjection` | Automatically wrap translatable JSX at build time. | `boolean` | `false` |

<Callout type="info">
  **Changed in v11.4.2:** The published `gt-next` package includes the WebAssembly plugin required by `type: 'swc'`. Upgrade to v11.4.2 or later before using the SWC compiler.
</Callout>

Set `enableAutoJsxInjection` here or under `files.gt.parsingFlags` in `gt.config.json`. Prefer `gt.config.json` to keep CLI extraction and compiler transforms in sync; see [Using automatic JSX injection](/docs/cli/guides/using-auto-jsx). In either case, `type: 'babel'` is required so `gt-next` loads the compiler:

```ts title="next.config.ts"
export default withGTConfig(nextConfig, {
  experimentalCompilerOptions: {
    type: 'babel',
    enableAutoJsxInjection: true,
  },
});
```

<Callout type="info">
  **Changed in v11.4.12:** `gt-next` installs `@generaltranslation/compiler` as a dependency. On earlier versions, install it separately before using `type: 'babel'`.
</Callout>

Automatic JSX injection only runs in webpack builds. Run `next dev --webpack` during development and `next build --webpack` for production. Next.js 16 uses Turbopack by default; Turbopack disables the Babel compiler, and `type: 'swc'` or `type: 'none'` does not support injection. In each case, `gt-next` warns that injection was skipped.

### `headersAndCookies` [#headers-and-cookies]

**Type** `object` · **Optional**

Override the header and cookie names `gt-next` uses to carry the locale and related request state. Fields: `localeHeaderName`, `localeCookieName`, `enableI18nCookieName`, `referrerLocaleCookieName`, `localeRoutingEnabledCookieName`, and `resetLocaleCookieName`. Each defaults to the library's standard name.

When Next.js internationalized routing is configured and `localeDetection` is not `false`, `gt-next` uses the standard `NEXT_LOCALE` preference cookie even if `localeCookieName` is customized. Next.js only reads that cookie during automatic locale detection. Setting `nextConfig.i18n.localeDetection` to `false` preserves the configured General Translation cookie name.

<Callout type="info">
  **Changed in v11.1.3:** Pages Router locale detection now follows Next.js `context.locale` and aligns client-side persistence with `NEXT_LOCALE`. Set `localeDetection: false` to retain a custom General Translation locale cookie.
</Callout>

### Request function paths [#request-function-paths]

**Type** `string` · **Optional**

`getLocalePath` and `getRegionPath` point at custom [`getLocale`](/docs/react/nextjs/reference/functions/get-locale) and [`getRegion`](/docs/react/nextjs/reference/functions/get-region) implementations, letting you override how the request locale and region are resolved.

### `pathRegex` [#path-regex]

**Type** `string` · **Optional**

A JavaScript regular expression source string. When set, the i18n middleware and client locale-routing boundary only run on pathnames that match it — for example, `^/(?!uk(?:/|$)).*` to skip everything under `/uk`. An invalid expression throws at build time. This is set here, on `withGTConfig`, not on [`createNextMiddleware`](/docs/react/nextjs/reference/functions/create-next-middleware); the plugin forwards it to the middleware at build time.

Write the expression for paths without the locale prefix. [`<Link>`](/docs/react/nextjs/link), [`useLocalizeHref()`](/docs/react/nextjs/reference/hooks/use-localize-href), and [`getLocalizeHref()`](/docs/react/nextjs/reference/functions/get-localize-href) test the unprefixed path and leave paths that don't match unprefixed, so with `^/(?!api(?:/|$)).*` a link to `/api/export` stays `/api/export` in every locale.

<Callout type="info">
  **Changed in v11.4.14:** Links to paths that don't match `pathRegex` are no longer prefixed. A pattern that only matches locale-prefixed paths, such as `^/(?:en|fr)(?:/|$)`, now produces unprefixed links; rewrite it for paths without the locale prefix.
</Callout>

<Callout type="warn">
  **Handle locale aliases manually:** Filtered paths bypass locale normalization. If your configured locales are `en`, `en-GB`, and `fr`, the path segment `uk` is not recognized as `en-GB`. A custom [`getLocale()`](/docs/react/nextjs/reference/functions/get-locale) function must return `en-GB` for `uk`:

  ```ts title="getLocale.ts"
  import { locale } from 'next/root-params';

  export default async function getLocale() {
    const pathnameLocale = await locale();
    if (pathnameLocale === 'uk') return 'en-GB';
    return pathnameLocale;
  }
  ```

  Apply the same mapping before calling [`registerLocale()`](/docs/react/nextjs/reference/functions/register-locale):

  ```ts
  registerLocale(locale === 'uk' ? 'en-GB' : locale);
  ```

  If [`getLocale()`](/docs/react/nextjs/reference/functions/get-locale) or [`registerLocale()`](/docs/react/nextjs/reference/functions/register-locale) receives an unknown locale, `gt-next` warns and falls back to `defaultLocale`.

  *These examples use* `next/root-params`*, available in Next.js 15.5 and newer. On Next.js 15.2–15.4, use the* `unstable_rootParams` *fallback shown in the [App Router middleware guide](/docs/react/nextjs/app-router-middleware#root-locale).*
</Callout>

### `_tagIds` [#tag-ids]

**Type** `boolean` · **Optional** · **Default** `false`

Enables the shared React runtime's DOM id-tagging. Set it in `gt.config.json` or pass it to `withGTConfig`:

```ts title="next.config.ts"
export default withGTConfig(nextConfig, {
  _tagIds: true,
});
```

(See the shared [`_tagIds` reference](/docs/react/reference/config#tag-ids) for supported frameworks, exact markup behavior, and the React Native exclusion).

### ESLint options [#eslint-options]

- `eslint` (`boolean`, default `true`) — generate the General Translation ESLint config during setup.
- `eslintSeverity` (`'error' | 'warn'`, default `'warn'`) — severity level for the generated rules.
- `overwriteESLintConfig` (`boolean`, default `false`) — allow overwriting an existing `eslint.config.mjs`.

(See [Linting your code](/docs/react/guides/linting-your-code) for the rules themselves).

## Local vs. CDN translations [#translations]

By default, `gt-next` fetches translations from the General Translation CDN at runtime — translated content is uploaded there automatically when you run [`npx gt translate`](/docs/cli/reference/commands/translate). Alternatively, you can bundle translations in your app and load them locally.

Local translations load faster and work offline, at the cost of a larger bundle and a redeploy for every content change. To use them, add a [`loadTranslations`](/docs/react/reference/functions/load-translations) file that returns a locale's translations:

```ts title="src/loadTranslations.ts"
export default async function loadTranslations(locale: string) {
  const translations = await import(`../public/_gt/${locale}.json`);
  return translations.default;
}
```

`withGTConfig` automatically picks up a `loadTranslations.[js|ts]` file in your project root or `src/` directory (or set [`loadTranslationsPath`](#load-translations-path) explicitly). Then point the CLI at the same directory so [`npx gt translate`](/docs/cli/reference/commands/translate) writes files there. See [Storing translations locally](/docs/react/guides/storing-translations) for the full workflow.

<Callout type="info">
  **Changed in v11.1.0:** webpack builds now resolve custom [`loadDictionary`](/docs/react/reference/functions/load-dictionary), [`loadTranslations`](/docs/react/reference/functions/load-translations), and `dictionary` files correctly. Upgrade from v11.0.x if every webpack dictionary lookup reports a missing entry despite the files being present; Turbopack was unaffected.
</Callout>

## Returns [#returns]

`withGTConfig` returns a `NextConfig` object enhanced with the General Translation settings. It throws at build time when the configuration conflicts, when a configured [`loadTranslations`](/docs/react/reference/functions/load-translations) or [`loadDictionary`](/docs/react/reference/functions/load-dictionary) file cannot be found, when Cache Components are enabled without a custom [`loadTranslations`](/docs/react/reference/functions/load-translations), or when an invalid locale is used with General Translation services.

## Sitemap

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