# General Translation React SDKs (gt-react, gt-next, gt-react-native): tx
URL: https://generaltranslation.com/ja/docs/react/nextjs/reference/functions/tx.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: General Translation を使用して、Next.js App Router のサーバーコードでリクエスト時の文字列を翻訳します。tx の API リファレンス。

`tx` 関数は、General Translation API を介してリクエスト時に文字列を翻訳します。build time では不明な動的コンテンツに使用し、静的な ソース文字列 には [`getGT`](/docs/react/nextjs/reference/functions/get-gt) を使用してください。

`tx` はサーバー専用で、Pages Router では動作しません。

## 概要 [#overview]

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

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

## パラメータ [#parameters]

| パラメータ     | 説明                           | 型        | 任意  | デフォルト |
| --------- | ---------------------------- | -------- | --- | ----- |
| `message` | 翻訳する文字列。                     | `string` | いいえ | —     |
| `options` | 対象ロケール、コンテキスト、形式、文字数上限、補間変数。 | `object` | はい  | `{}`  |

`options` には `$locale`、`$context`、`$maxChars`、`$format` を指定できます。補間変数はトップレベルのキーとして渡してください。`$maxChars` は翻訳サービスに正の整数の最大文字数を指定し、必要に応じて返された文字列をその長さに切り詰めます。

## 戻り値 [#returns]

**型** `Promise<string>`

翻訳後の文字列を返す Promise です。翻訳が無効、または不要な場合は、ソース文字列を返します。

## 例 [#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.
