# General Translation React SDKs (gt-react, gt-next, gt-react-native): tx
URL: https://generaltranslation.com/it/docs/react/nextjs/reference/functions/tx.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: Traduce le stringhe in fase di richiesta nel codice server di Next.js App Router con General Translation. Riferimento API per tx.

La funzione `tx` traduce una stringa in fase di richiesta tramite l&#39;API di General Translation. Usala per il contenuto dinamico che non è noto al build time; usa [`getGT`](/docs/react/nextjs/reference/functions/get-gt) per le stringhe sorgente statiche.

`tx` è disponibile solo lato server e non funziona con il Pages Router.

## Panoramica [#overview]

```tsx
import { tx } from 'gt-next/server';

const translated = await tx('A message loaded at request time');
```

## Parametri [#parameters]

| Parametro | Descrizione                                                                                                  | Tipo     | Facoltativo | Predefinito |
| --------- | ------------------------------------------------------------------------------------------------------------ | -------- | ----------- | ----------- |
| `message` | Stringa da tradurre.                                                                                         | `string` | No          | —           |
| `options` | Impostazione regionale di destinazione, context, formato, limite di lunghezza e variabili di interpolazione. | `object` | Sì          | `{}`        |

`options` accetta `$locale`, `$context`, `$maxChars` e `$format`. Passa le variabili di interpolazione come chiavi di primo livello. `$maxChars` richiede al servizio di traduzione una lunghezza massima intera positiva e, se necessario, tronca la stringa restituita a tale lunghezza.

## Restituisce [#returns]

**Tipo** `Promise<string>`

Una promise che si risolve nella stringa tradotta, oppure nella stringa sorgente quando la traduzione è disabilitata o non necessaria.

## Esempio [#example]

```tsx title="app/notes/[id]/page.tsx"
import { tx } from 'gt-next/server';

export default async function NotePage({ params }) {
  const note = await loadNote((await params).id);
  const translated = await tx(note, {
    $context: 'A user-created note',
  });
  return <p>{translated}</p>;
}
```

## Sitemap

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