# General Translation Knowledge Base: How do I translate Next.js Server Components?
URL: https://generaltranslation.com/en-GB/kb/translate-nextjs-server-components.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: Load translations on the server for the request's locale and render translated text there, so Server Components send finished HTML and no translation code to the browser. With gt-next, wrap JSX in T and call useGT in synchronous components, await getGT in async ones, and let GTProvider pass translations to Client Components.
Category: Internationalisation
Last updated: 2026-11-23
Authors: Kevin Wu
Published: 2026-11-23

A Server Component runs once per request (or once at build time) and sends HTML, not JavaScript, to the browser. Translating it means three things: knowing the request&#39;s locale on the server, loading that locale&#39;s translations there, and rendering the translated text before the HTML leaves. Client-side i18n libraries that keep translations in React context don&#39;t work here, because Server Components can&#39;t read context and can&#39;t call hooks that depend on browser state.

## Where translation runs in the App Router

The App Router mixes three kinds of components, and each translates differently:

| Component                         | Runs on              | Can use hooks?                                                 | How it gets translations                         |
| --------------------------------- | -------------------- | -------------------------------------------------------------- | ------------------------------------------------ |
| Synchronous Server Component      | Server only          | No browser hooks; server-aware hooks from an i18n library only | Reads them on the server for the request         |
| Async Server Component            | Server only          | No                                                             | Awaits a server function                         |
| Client Component (`'use client'`) | Server, then browser | Yes                                                            | Receives them from a provider rendered higher up |

The main benefit of translating on the server is that translated text arrives in the HTML. Search engines index each language version without running JavaScript, the browser downloads no translation files for server-rendered parts of the page, and there is no flash of the source language while translations load.

## Step 1: resolve the locale on the server

A Server Component can&#39;t read `navigator.language`. It learns the locale from the request: a URL segment such as `/es/pricing`, a cookie saved by a language switcher, or the `Accept-Language` header on a first visit. For public pages, put the locale in the URL so each language has its own address for search engines. (See [How do I set up SEO for a multilingual Next.js app?](/kb/multilingual-nextjs-seo)).

With `gt-next`, [`createNextMiddleware`](/docs/react/nextjs/reference/functions/create-next-middleware) handles this: it detects the locale from the URL, a saved cookie, or the `Accept-Language` header, stores it in a cookie, and, with locale routing enabled, redirects or rewrites to the localised path. In a Server Component, [`getLocale`](/docs/react/nextjs/reference/functions/get-locale) from `gt-next/server` returns it.

## Step 2: translate JSX in Server Components

In `gt-next`, the same [`<T>`](/docs/react/reference/components/t) import works in Server and Client Components; the package resolves a server implementation when it is imported into a Server Component. Wrap the JSX and it renders in the request&#39;s language:

```tsx title="app/[locale]/page.tsx"
import { T, Var } from 'gt-next';

export default function Page({ user }) {
  return (
    <T>
      <h1>Welcome back</h1>
      <p>
        {/* Dynamic values stay variables and are not translated */}
        You have new messages, <Var>{user.name}</Var>.
      </p>
    </T>
  );
}
```

This component is still a Server Component. Nothing about it ships to the browser except the translated HTML.

## Step 3: translate strings in sync and async components

Some text isn&#39;t JSX: an `aria-label`, a placeholder, an `alt` attribute, or a string passed to another function. Use a translation function. Which one depends on whether the component is `async`:

* **Synchronous Server Component:** call [`useGT`](/docs/react/reference/hooks/use-gt) from `gt-next`. In a Server Component it is a server-aware function, not a browser hook, so it works without `'use client'`.
* **Async Server Component:** await [`getGT`](/docs/react/nextjs/reference/functions/get-gt) from `gt-next/server`.

```tsx title="app/[locale]/search/page.tsx"
import { getGT } from 'gt-next/server';

export default async function SearchPage() {
  const gt = await getGT();
  const results = await fetchResults();

  return (
    <>
      <input aria-label={gt('Search the docs')} placeholder={gt('Search…')} />
      <p>{gt('{count} results', { count: results.length })}</p>
    </>
  );
}
```

`gt()` takes source strings written in the code and accepts [ICU message format](/kb/icu-message-format) placeholders, so `{count}` is filled in after translation and plural forms can be expressed in the message.

## Step 4: translate page metadata

`<title>`, meta descriptions, and Open Graph text come from `generateMetadata`, which is an async server function. Use [`getGT`](/docs/react/nextjs/reference/functions/get-gt) there too:

```tsx title="app/[locale]/pricing/page.tsx"
import type { Metadata } from 'next';
import { getGT } from 'gt-next/server';

export async function generateMetadata(): Promise<Metadata> {
  const gt = await getGT();
  return {
    title: gt('Pricing'),
    description: gt('Usage-based pricing with no seat fees.'),
  };
}
```

Search results show these strings, so translating them matters as much as translating the page. Add `alternates.canonical` and `alternates.languages` in the same function for `hreflang`.

## Step 5: pass translations to Client Components

Client Components still need translations for the parts that render in the browser, such as a drop-down or a form with validation messages. Render [`<GTProvider>`](/docs/react/reference/components/gt-provider) once in the root layout. In the App Router it is itself a Server Component: it loads the request&#39;s translations on the server and hands them to Client Components below it, so you don&#39;t pass `locale` or `translations` props.

```tsx title="app/[locale]/layout.tsx"
import { GTProvider, useLocale } from 'gt-next';

export default function RootLayout({ children }: { children: React.ReactNode }) {
  const locale = useLocale();
  return (
    <html lang={locale}>
      <body>
        <GTProvider>{children}</GTProvider>
      </body>
    </html>
  );
}
```

Inside a `'use client'` file, [`<T>`](/docs/react/reference/components/t) and [`useGT`](/docs/react/reference/hooks/use-gt) import from `gt-next` the same way and resolve to their client implementations.

## Rules that trip people up

* **Server-only functions can&#39;t cross into Client Components.** Importing [`getGT`](/docs/react/nextjs/reference/functions/get-gt), [`getLocale`](/docs/react/nextjs/reference/functions/get-locale), or anything from `gt-next/server` into a `'use client'` file throws. Use [`useGT`](/docs/react/reference/hooks/use-gt) in Client Components.
* **Pass translated strings, not translation functions, as props.** Functions can&#39;t be serialised from a Server Component to a Client Component. Translate on the server and pass the resulting string, or translate inside the Client Component.
* **Keep source strings static.** Build-time translation works by finding the strings in your code, so `gt(someVariable)` can&#39;t be translated ahead of time. Put changing values in placeholders. The `static-string` rule in General Translation&#39;s [ESLint plugin](/docs/react/reference/lint-rules) flags this.
* **Format dates and numbers with a fixed locale and zone.** A Server Component formats in the server&#39;s time zone. (See [Why do dates cause a React hydration mismatch?](/kb/date-hydration-mismatch)).

## Content that isn&#39;t in your code

[`<T>`](/docs/react/reference/components/t) and [`getGT`](/docs/react/nextjs/reference/functions/get-gt) translate text written in the codebase, which is translated before deployment and loaded for each request. Text that only exists at request time, such as a user&#39;s post or a CMS field, needs translation as the request runs. In `gt-next` that is the server-only [`<Tx>`](/docs/react/nextjs/reference/components/tx) component and [`tx`](/docs/react/nextjs/reference/functions/tx) function, which call the translation API on the server and are slower than build-time translation. (See [Build time, run time, or translation proxy: how should you deliver translations?](/kb/build-time-vs-runtime-translation)).

## Key takeaways

* Server Components need the locale and translations on the server, from the request, not from React context.
* In `gt-next`, [`<T>`](/docs/react/reference/components/t) and [`useGT`](/docs/react/reference/hooks/use-gt) work in synchronous Server Components; async components and `generateMetadata` use [`getGT`](/docs/react/nextjs/reference/functions/get-gt).
* [`<GTProvider>`](/docs/react/reference/components/gt-provider) in the root layout passes translations to Client Components.
* Don&#39;t import `gt-next/server` into Client Components, and pass translated strings rather than functions across the boundary.
* Translated text in server HTML is what search engines index, so translate metadata as well as the page.

To set up a new project end to end, follow [How do I add i18n to a Next.js App Router app?](/kb/add-i18n-to-nextjs) or the [`gt-next` Quickstart](/docs/react/nextjs-quickstart).

## Related questions

- [How do I add i18n to a Next.js App Router app?](https://generaltranslation.com/en-GB/kb/add-i18n-to-nextjs.mdx): Start with gt init to configure General Translation in a supported App Router project, then mark source content, generate translations and verify language switching. gt-next keeps copy in JSX with translation context; the CLI, Dashboard editor and Locadex handle generation, review and ongoing updates. This guide also shows the explicit local-file set-up.
- [How do I set up SEO for a multilingual Next.js app?](https://generaltranslation.com/en-GB/kb/multilingual-nextjs-seo.mdx): Give each language its own prefixed URL, such as /en/about and /es/about, then publish html lang, a self-referencing canonical, hreflang alternates with x-default, a translated title and description, and a sitemap entry for each published language. Mark unpublished versions noindex. General Translation's gt-next routes each language to its own URL and translates titles with getGT.
- [Why do dates cause a React hydration mismatch?](https://generaltranslation.com/en-GB/kb/date-hydration-mismatch.mdx): The server and the browser format the same date differently when they run in different time zones or default locales, so the HTML React hydrates doesn't match the client render. Pass an explicit locale and timeZone to every date format, or render the date only on the server.
- [Build time, run time, or translation proxy: how should you deliver translations?](https://generaltranslation.com/en-GB/kb/build-time-vs-runtime-translation.mdx): Use General Translation to generate known app translations before release, then bundle them with your code or load them from its CDN. Bundles keep wording tied to a release; published CDN edits can reach new renders without a code deploy. Use request-time translation for content a visitor needs immediately, and a proxy when you can't change the site's code.
- [next-intl alternatives: gt-next vs. next-intl](https://generaltranslation.com/en-GB/kb/next-intl-vs-gt-next.mdx): next-intl renders translations you supply in a message catalogue for each language. gt-next renders translations too, and General Translation also generates them from copy written inline in your JSX. Both are MIT-licensed and support the App Router and Server Components. If your next-intl catalogues already work, you can keep them and use General Translation to translate them without migrating.

## Previous and next questions

- Previous question: [How do I translate gendered text in an app?](https://generaltranslation.com/en-GB/kb/translate-gendered-text.mdx)
- Next question: [Which languages should I translate my app into first?](https://generaltranslation.com/en-GB/kb/which-languages-first.mdx)

## Sitemap

See the [Knowledge Base sitemap](https://generaltranslation.com/en-GB/kb/sitemap.md) for every article.
