# General Translation Platform: downloadFile
URL: https://generaltranslation.com/ja/docs/platform/core/reference/gt-class-methods/translation/download-file.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 翻訳完了後、翻訳済みファイルを 1 つダウンロードします。downloadFile の API リファレンス。

General Translation を使用して、1 つのファイルの内容を UTF-8 文字列としてダウンロードします。ロケールを渡すかどうかに応じて、ソースファイルまたは対応する翻訳ファイルを返します。

## 概要 [#overview]

ファイル記述子を指定して `downloadFile` を呼び出します。翻訳をダウンロードするには `locale` を指定し、ソースファイルをダウンロードするには省略します。

```typescript
const gt = new GT({ projectId: 'your-project-id', apiKey: 'your-api-key' });

// 翻訳をダウンロードする
const translatedContent = await gt.downloadFile({
  fileId: 'file-123',
  branchId: 'branch-456',
  locale: 'es',
  versionId: 'version-789',
});

// ソースファイルをダウンロードする（ロケール未指定）
const sourceContent = await gt.downloadFile({
  fileId: 'file-123',
  branchId: 'branch-456',
});
```

シグネチャ:

```typescript
downloadFile(
  file: {
    fileId: string;
    branchId?: string;
    locale?: string;
    versionId?: string;
    useLatestAvailableVersion?: boolean;
  },
  options?: DownloadFileOptions
): Promise<string>
```

*注: `downloadFile` を使用するには、GT インスタンスに `apiKey` (または `devApiKey`) と `projectId` が必要です。翻訳をダウンロードする場合は、完了済みの翻訳でのみ機能します。まず [`queryFileData`](/docs/platform/core/reference/gt-class-methods/translation/query-file-data) で status を確認してください。*

## 仕組み [#how-it-works]

* **ソースと翻訳。** `locale` が指定されている場合、解決された対応ロケールの翻訳が完了している必要があります。`locale` が指定されていない場合は、ソースファイルが返されます。
* **ロケールの解決。** リクエストされたロケールは、保存に使用される対応ロケールに解決されます。たとえば、`ja-JP` は `ja` に解決されます。`en-GB` のような個別の対応ロケールは変更されません。
* **形式は保持されます。** 返される文字列は元のソースファイルと同じ形式で、翻訳の場合は、翻訳可能なすべてのテキストが対象ロケールに変換されます。
* **失敗。** ファイルが見つからない場合、この呼び出しは失敗します。

## パラメータ [#parameters]

| パラメータ                 | 説明                          | 型                     | 省略可 | デフォルト |
| --------------------- | --------------------------- | --------------------- | --- | ----- |
| [`file`](#file)       | ダウンロードするファイルを指定するためのファイル情報。 | `object`              | いいえ | —     |
| [`options`](#options) | ダウンロードリクエストの設定。             | `DownloadFileOptions` | はい  | —     |

### `file` [#file]

**型** `object` · **必須**

ダウンロードするファイルを指定します。

| フィールド                       | 説明                                                                     | 型         | 任意  | デフォルト     |
| --------------------------- | ---------------------------------------------------------------------- | --------- | --- | --------- |
| `fileId`                    | ダウンロードするファイルの一意の識別子。                                                   | `string`  | いいえ | —         |
| `branchId`                  | ダウンロード元のブランチ。                                                          | `string`  | はい  | デフォルトブランチ |
| `locale`                    | ダウンロードする翻訳の対象ロケール。省略すると、ソースファイルをダウンロードします。                             | `string`  | はい  | —         |
| `versionId`                 | ファイルのバージョン ID。                                                         | `string`  | はい  | 最新バージョン   |
| `useLatestAvailableVersion` | `true` の場合、指定した `versionId` が見つからなくても失敗せず、代わりに利用可能な最新バージョンにフォールバックします。 | `boolean` | はい  | `false`   |

### `options` [#options]

**型** `DownloadFileOptions` · **任意**

| フィールド     | 説明                   | 型        | 任意 |
| --------- | -------------------- | -------- | -- |
| `timeout` | リクエストのタイムアウト (ミリ秒) 。 | `number` | はい |

## 戻り値 [#returns]

**型** `Promise<string>`

元のソースファイルと同じ形式のUTF-8文字列として、ファイルの内容を返します。翻訳の場合、翻訳可能なすべてのテキストは対象ロケールに変換されます。

## 例 [#examples]

```typescript title="index.ts"
// (1) GTインスタンスを作成する
const targetLocales = ['es', 'fr', 'de'];
const gt = new GT({
  projectId: 'your-project-id',
  apiKey: 'your-api-key',
});

// (2) ファイルをアップロードする
const fileUpload = {
  content: fileContents,
  fileName: filePath,
  fileFormat: 'JSON',
  locale: 'en',
};
const files = [{ source: fileUpload }];
const { uploadedFiles } = await gt.uploadSourceFiles(files, { sourceLocale: 'en' });

// (3) ファイルの翻訳ジョブをキューに追加する
const enqueueResult = await gt.enqueueFiles(uploadedFiles, {
  sourceLocale: 'en',
  targetLocales: targetLocales,
});

// (4) すべての翻訳が完了するまで待機する
const { fileId, versionId, branchId } = uploadedFiles[0];
const result = await gt.awaitJobs(enqueueResult);

if (!result.complete) {
  console.error('Some jobs did not finish in time');
}

// (5) 単一ファイルをダウンロードする
const spanishContent = await gt.downloadFile({
  fileId,
  branchId,
  locale: 'es',
});

console.log('Spanish translation:', spanishContent);
```

## メモ [#notes]

* ダウンロードしたファイルを UTF-8 文字列として取得します。
* ロケールが指定されている場合、そのファイルでは解決された対応ロケールの翻訳が完了している必要があります。
* ロケールが指定されていない場合は、ソースファイルが返されます。
* ファイルが見つからない場合、この呼び出しは失敗します。

## Sitemap

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