# General Translation Platform: downloadFileBatch URL: https://generaltranslation.com/ja/docs/platform/core/reference/gt-class-methods/translation/download-file-batch.mdx --- title: downloadFileBatch description: 1 回のリクエストで複数の翻訳済みファイルをダウンロードします。downloadFileBatch の API リファレンス。 --- General Translation で、複数のソースファイルまたは翻訳ファイルを 1 回のバッチリクエストでダウンロードします。ネットワークのオーバーヘッドを減らすには、多数の個別の [`downloadFile`](/docs/platform/core/reference/gt-class-methods/translation/download-file) 呼び出しの代わりにこれを使用してください。 ## 概要 [#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 ``` *注: `downloadFileBatch` を使用するには、GT インスタンスに `apiKey` (または `devApiKey`) と `projectId` の設定が必要です。複数のファイルを 1 回の API 呼び出しでダウンロードできるため、`downloadFile` を繰り返し呼び出すよりも効率的です。* ## 仕組み [#how-it-works] * **順序。** 可能な場合、ファイルはリクエストした項目と同じ順序で返されます。 * **部分的な成功。** バッチ 内の個別のダウンロードが失敗しても、バッチ 全体が失敗することはありません。 * **準備状況。** ダウンロードする前に、[`queryFileData`](/docs/platform/core/reference/gt-class-methods/translation/query-file-data) を使用してファイルの準備ができていることを確認してください。 ## パラメータ [#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` を返します: ```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文字列としてのファイルの内容 metadata: JsonObject; fileFormat: FileFormat; }; ``` | プロパティ | 説明 | 型 | | -------------------- | --------------------------- | ------------------- | | `files` | ダウンロードされたファイルオブジェクトの配列。 | `DownloadedFile[]` | | `count` | 正常にダウンロードされたファイルの数。 | `number` | | `files[].id` | ダウンロードされたファイルレコードの一意の識別子。 | `string` | | `files[].branchId` | Branch ID。 | `string` | | `files[].fileId` | File ID。 | `string` | | `files[].versionId` | Version ID。 | `string` | | `files[].locale` | ファイルのロケール。翻訳ファイルの場合に含まれます。 | `string` (optional) | | `files[].fileName` | 元のファイル名。ソースファイルの場合に含まれます。 | `string` (optional) | | `files[].data` | UTF-8文字列としてのファイル内容。 | `string` | | `files[].metadata` | ファイルのフォーマット固有のメタデータ。 | `JsonObject` | | `files[].fileFormat` | ファイルの形式 (`JSON`、`MDX` など) 。 | `FileFormat` | ## 例 [#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 文字列として返されます。 * まず [`queryFileData`](/docs/platform/core/reference/gt-class-methods/translation/query-file-data) を使って、ファイルをダウンロード可能な状態かどうかを確認してください。 * ファイルは、可能であれば要求した項目と同じ順序で返されます。 * バッチ 内の個々のファイルのダウンロードに失敗しても、バッチ 全体が失敗することはありません。