# General Translation React SDKs (gt-react, gt-next, gt-react-native): gtMiddleware
URL: https://generaltranslation.com/en-GB/docs/react/tanstack-start/reference/functions/gt-middleware.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: Create request-scoped locale state for TanStack Start server functions. API reference for gtMiddleware.

The `gtMiddleware` export is the global request middleware for TanStack Start. Import it from `gt-tanstack-start` and register it before calling runtime helpers on the server.

## Overview [#overview]

```ts title="src/start.ts"
import { createCsrfMiddleware, createStart } from '@tanstack/react-start';
import { gtMiddleware } from 'gt-tanstack-start';

const csrfMiddleware = createCsrfMiddleware({
  filter: ({ handlerType }) => handlerType === 'serverFn',
});

export const startInstance = createStart(() => ({
  requestMiddleware: [csrfMiddleware, gtMiddleware],
}));
```

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

* Resolves the locale, region, and internationalisation setting from the incoming request and your General Translation configuration.
* When `localeRouting` is enabled, prioritises the first supported path segment over the locale cookie and `Accept-Language` header. The default locale remains unprefixed.
* Respects TanStack Router&#39;s base path through `TSS_ROUTER_BASEPATH`.
* Stores those values in request-local state for server-side rendering, server routes, and server functions.
* Keeps request state isolated during concurrent server requests.
* Persists the resolved locale in the General Translation locale cookie.

Call [`initializeGT`](/docs/react/reference/config#initialize) from `gt-tanstack-start` before the middleware handles a request. The middleware throws if initialisation has not created its condition store.

## Server helpers [#server-helpers]

The middleware provides request state to:

* [`getLocale`](/docs/react/tanstack-start/reference/functions/get-locale)
* [`getEnableI18n`](/docs/react/tanstack-start/reference/functions/get-enable-i18n)
* [`getGT`](/docs/react/tanstack-start/reference/functions/get-gt)
* [`getMessages`](/docs/react/tanstack-start/reference/functions/get-messages)
* [`getTranslations`](/docs/react/tanstack-start/reference/functions/get-translations)

These helpers are isomorphic. Their server branches throw when called outside the active middleware request scope; their client branches read the browser condition store initialised by [`initializeGT`](/docs/react/reference/config#initialize).

## Version history [#version-history]

| Version  | Changes                                                                                                                |
| -------- | ---------------------------------------------------------------------------------------------------------------------- |
| `11.1.5` | Exported `gtMiddleware` from the root browser condition, allowing setup files to use the root import in client builds. |

## Sitemap

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