# General Translation Integrations: データの翻訳
URL: https://generaltranslation.com/ja/docs/integrations/databricks/guides/translating-data.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: gt-node を使用して、Databricks App のクエリ結果やモデルの回答を翻訳する方法。

クエリ結果やモデルの回答など、Databricks App 内のデータはランタイムにしか存在しません。ブラウザに届く前に、サーバー側で `gt-node` を使って翻訳しましょう。

## 始める前に [#before-start]

まず[クイックスタート](/docs/integrations/databricks/quickstart)を完了してください。以下の例はすべて `/api` 配下のルート内で実行されます。これらのルートでは、クイックスタートで設定したミドルウェアが [`withGT`](/docs/node/reference/functions/with-gt) によってリクエストのロケールをすでにバインドしています。

## クエリ結果を翻訳する [#query-results]

ユーザーに表示するテキスト列ごとに [`tx`](/docs/node/reference/functions/tx) を呼び出します。識別子、数値、日付は翻訳せず、そのまま残します。

```ts title="server/server.ts"
app.get('/api/products', async (_req, res) => {
  const rows = await getProducts(); // 任意のクエリ
  const translated = await Promise.all(
    rows.map(async (row) => ({
      ...row,
      description: await tx(row.description, {
        $context: 'Product description from the catalog table',
      }),
    }))
  );
  res.json(translated);
});
```

* `$context` は、テキストがどこに表示されるかを翻訳モデルに伝えます。文言そのものではなく、「売上ダッシュボードの列ヘッダー」のように、翻訳元テキストの出どころを説明してください。
* `gt-node` は翻訳をキャッシュするため、複数の行やリクエストで繰り返し出現するテキストは、キャッシュエントリが有効な間は一度だけ翻訳されます。エントリはデフォルトの有効期間が過ぎると失効します。この期間は [`cacheExpiryTime`](/docs/node/reference/config#cache-expiry) で変更できます。
* リクエストのロケールが `defaultLocale` の場合、[`tx`](/docs/node/reference/functions/tx) はテキストをそのまま返します。

## モデルの回答を翻訳する [#model-answers]

モデルの回答を訪問者の言語で表示するには、モデルの応答後にサーバー側で翻訳します。

```ts title="server/server.ts"
app.get('/api/summary', async (_req, res) => {
  const answer = await summarizeSales(); // 利用するサービングエンドポイントまたはエージェント
  res.json({ answer: await tx(answer, { $context: 'Answer from a data assistant' }) });
});
```

モデル自身が訪問者の言語で回答を生成する場合は、代わりにロケールをモデルに渡します。ロケールは [`getLocale`](/docs/node/reference/functions/get-locale) で取得できます。

## 使い分け [#when]

* **`client/` 内の [`<T>`](/docs/react/reference/components/t):** UI テキスト向けで、ビルド時に翻訳されます。ユーザーが読むメッセージはクライアント側に置くことで、CLI が事前に翻訳できます。
* **サーバー上の [`tx`](/docs/node/reference/functions/tx):** クエリ結果やモデルの回答など、ランタイムになるまで内容がわからないデータ向けです。

## Next steps

- /docs/integrations/databricks/guides/deploying

## Sitemap

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