# General Translation Platform: downloadFileBatch
URL: https://generaltranslation.com/ja/docs/platform/core/reference/gt-class-methods/translation/download-file-batch.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 1 回のリクエストで複数の翻訳済みファイルをダウンロードします。downloadFileBatch の API リファレンス。

多数の個別の [`downloadFile`](/docs/platform/core/reference/gt-class-methods/translation/download-file) 呼び出しを行う代わりに、1 回のリクエストで複数のソースファイルまたは翻訳ファイルを取得でき、ネットワークのオーバーヘッドを減らせます。

## 概要 [#overview]

ファイルリクエストの配列を渡して `downloadFileBatch` を呼び出します。各リクエストでは、翻訳 (`locale` あり) またはソースファイル (`locale` なし) を対象として指定できます。

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

const result = await gt.downloadFileBatch([
  { fileId: 'file-123', branchId: 'branch-456', locale: 'es' },
  { fileId: 'file-123', branchId: 'branch-456', locale: 'fr' },
  { fileId: 'file-123', branchId: 'branch-456', locale: 'de' },
]);
```

シグネチャ:

```typescript
downloadFileBatch(
  requests: DownloadFileBatchRequest,
  options?: DownloadFileBatchOptions
): Promise<DownloadFileBatchResult>
```

*注: `downloadFileBatch` を使用するには、GT インスタンスに `apiKey` (または `devApiKey`) と `projectId` の設定が必要です。複数のファイルを 1 回の API 呼び出しでダウンロードできるため、[`downloadFile`](/docs/platform/core/reference/gt-class-methods/translation/download-file) を繰り返し呼び出すよりも効率的です。*

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

* **順序。** レスポンス内の位置ではなく、`fileId`、`branchId`、`versionId`、`locale` を使用して、各結果を対応するリクエストに関連付けます。
* **ロケール解決。** リクエストした各ロケールは、保存に使用されるサポート対象ロケールに解決されます。同等のコードは1つの保存済み翻訳に解決される場合があります。`ja` と `ja-JP` の両方をリクエストした場合、各リクエストの結果には渡したロケールが付与されます。
* **部分的な成功。** バッチ 内の個別のダウンロードが失敗しても、バッチ 全体が失敗することはありません。
* **準備状況。** ダウンロードする前に、[`queryFileData`](/docs/platform/core/reference/gt-class-methods/translation/query-file-data) を使用してファイルの準備ができていることを確認してください。
* **バイナリ形式。** テキスト形式ではデコード済みの UTF-8 データが返されます。呼び出し元がバイトを破損させずにバイナリ `.lottie` ファイルを再構築できるよう、`LOTTIE` はBase64エンコードされたままです。

## パラメータ [#parameters]

| パラメータ                   | 説明                  | 型                          | 任意  | デフォルト |
| ----------------------- | ------------------- | -------------------------- | --- | ----- |
| [`requests`](#requests) | ファイルリクエストオブジェクトの配列。 | `DownloadFileBatchRequest` | いいえ | —     |
| [`options`](#options)   | ダウンロードリクエストの構成。     | `DownloadFileBatchOptions` | はい  | —     |

### `requests` [#requests]

**型** `DownloadFileBatchRequest` · **必須**

ファイルリクエストの配列です:

```typescript
type DownloadFileBatchRequest = {
  fileId: string;
  branchId?: string;
  locale?: string;
  versionId?: string;
  useLatestAvailableVersion?: boolean;
}[];
```

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

### `options` [#options]

**Type** `DownloadFileBatchOptions` · **任意**

| Field     | Description            | Type     | Optional |
| --------- | ---------------------- | -------- | -------- |
| `timeout` | リクエストのタイムアウト時間 (ミリ秒) 。 | `number` | はい       |

## 戻り値 [#returns]

**型** `Promise<DownloadFileBatchResult>`

ダウンロードされたファイルと件数を含む `DownloadFileBatchResult` を返します:

```typescript
type DownloadFileBatchResult = {
  files: DownloadedFile[];
  count: number;
};

type DownloadedFile = {
  id: string;
  branchId: string;
  fileId: string;
  versionId: string;
  locale?: string; // ファイルが翻訳の場合に存在する
  fileName?: string; // ソースファイルの場合に存在する（ロケールが存在しない場合）
  data: string; // UTF-8テキスト、バイナリ形式の場合はbase64
  metadata: JsonObject;
  fileFormat: FileFormat;
};
```

| プロパティ                | 説明                                                       | 型                                                               |
| -------------------- | -------------------------------------------------------- | --------------------------------------------------------------- |
| `files`              | ダウンロードされたファイルオブジェクトの配列。                                  | `DownloadedFile[]`                                              |
| `count`              | 正常にダウンロードされたファイルの数。                                      | `number`                                                        |
| `files[].id`         | ダウンロードされたファイルレコードの一意の識別子。                                | `string`                                                        |
| `files[].branchId`   | ブランチ ID。                                               | `string`                                                        |
| `files[].fileId`     | File ID。                                                 | `string`                                                        |
| `files[].versionId`  | バージョン ID。                                              | `string`                                                        |
| `files[].locale`     | ファイルのロケール。翻訳ファイルの場合に含まれます。                               | `string` (optional)                                             |
| `files[].fileName`   | 元のファイル名。ソースファイルの場合に含まれます。                                | `string` (optional)                                             |
| `files[].data`       | テキスト形式の場合はUTF-8ファイル内容、`LOTTIE` の場合はBase64エンコードされたバイナリ内容。 | `string`                                                        |
| `files[].metadata`   | ファイルのフォーマット固有のメタデータ。                                     | `JsonObject`                                                    |
| `files[].fileFormat` | ファイルの形式 (`JSON`、`MDX` など) 。                              | [`FileFormat`](/docs/platform/core/reference/types/file-format) |

## 例 [#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 downloadResult = await gt.downloadFileBatch(
  targetLocales.map((locale) => ({
    fileId,
    branchId,
    locale,
  }))
);

downloadResult.files.forEach((file) => {
  console.log(`Downloaded ${file.locale}: ${file.fileName}`);
});
```

## メモ [#notes]

* テキストファイルは UTF-8 文字列として返されます。バイナリ `.lottie` ファイルを書き込むには、`LOTTIE` データを base64 からデコードしてください。
* まず [`queryFileData`](/docs/platform/core/reference/gt-class-methods/translation/query-file-data) を使って、ファイルをダウンロード可能な状態かどうかを確認してください。
* 結果は位置ではなく、ファイル、バージョン、ブランチ、ロケールの識別子 でリクエストと照合してください。
* バッチ 内の個々のファイルのダウンロードに失敗しても、バッチ 全体が失敗することはありません。

## Sitemap

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