enqueueFiles
API Reference for the enqueueFiles method to enqueue file translation jobs
Overview
The enqueueFiles method enqueues translation jobs for previously uploaded files in the General Translation API.
This method takes file references and creates translation jobs for the specified target locales.
const gt = new GT({ projectId: 'your-project-id', apiKey: 'your-api-key' });
const result = await gt.enqueueFiles(fileRefs, {
  sourceLocale: 'en',
  targetLocales: ['es', 'fr', 'de']
});You can only enqueue files for translation after they have been uploaded.
Reference
Parameters
| Name | Type | Description | 
|---|---|---|
| files | FileUploadRef[] | Array of file references from previously uploaded files | 
| options | EnqueueOptions | Configuration options for the translation job | 
EnqueueOptions
| Name | Type | Description | 
|---|---|---|
| sourceLocale? | string | Source locale for translation (defaults to instance sourceLocale) | 
| targetLocales? | string[] | Array of target locales for translation (defaults to instance targetLocale) | 
| publish? | boolean | Whether to automatically publish translations when complete | 
| requireApproval? | boolean | Whether translations require approval before publishing | 
| modelProvider? | string | Specific AI model provider to use for translation | 
| force? | boolean | Force retranslation even if translations already exist | 
| timeout? | number | Request timeout in milliseconds | 
Returns
Promise<EnqueueFilesResult> - Contains job information and processing details.
type EnqueueFilesResult = {
  translations: CompletedFileTranslationData[];
  data: Record<string, { fileName: string; versionId: string }>;
  locales: string[];
  message: string;
}| Property | Type | Description | 
|---|---|---|
| translations | CompletedFileTranslationData[] | Array of translation job data | 
| data | Record<string, { fileName: string; versionId: string }> | Map of file identifiers to file metadata | 
| locales | string[] | List of target locales for the translation jobs | 
| message | string | Status message from the API | 
Example
// (1) Create a GT instance
const targetLocales = ['es', 'fr', 'de'];
const gt = new GT({
  projectId: 'your-project-id',
  apiKey: 'your-api-key',
});
// (2) Upload the file
const fileUpload = {
  content: fileContents,
  fileName: filePath,
  fileFormat: 'JSON',
  locale: 'en',
};
const files = [ { source: fileUpload } ];
const { uploadedFiles } = await gt.uploadSourceFiles(
  files,
  { sourceLocale: 'en' }
);
// (3) Enqueue the file translation job
const enqueueResult = await gt.enqueueFiles(
  uploadedFiles,
  {
  sourceLocale: 'en',
  targetLocales: targetLocales,
});
// (4) Wait for all translations to be completed
let translationIds = [];
const statusQuery = Object.values(enqueueResult.data).flatMap(({fileName, versionId}) => {
  return targetLocales.map((locale) => ({locale, fileName, versionId}));
});
while (true) {
  const status = await gt.checkFileTranslations(statusQuery);
  if (status.translations.length === statusQuery.length) {
    translationIds = status.translations.map(translation => translation.id);
    break;
  }
  await new Promise(resolve => setTimeout(resolve, 1000));
}
// (5) Download the file
const result = await gt.downloadFileBatch(translationIds);Notes
- File content must be uploaded first using uploadSourceFiles
- Translation jobs are asynchronous - use checkFileTranslationsto monitor progress
Next Steps
- See uploadSourceFilesto upload files before enqueueing
- See checkFileTranslationsto monitor translation progress
- See downloadTranslatedFileto retrieve completed translations
How is this guide?

