GT ClassMethodsTranslation

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

NameTypeDescription
filesFileUploadRef[]Array of file references from previously uploaded files
optionsEnqueueOptionsConfiguration options for the translation job

EnqueueOptions

NameTypeDescription
sourceLocale?stringSource locale for translation (defaults to instance sourceLocale)
targetLocales?string[]Array of target locales for translation (defaults to instance targetLocale)
publish?booleanWhether to automatically publish translations when complete
requireApproval?booleanWhether translations require approval before publishing
modelProvider?stringSpecific AI model provider to use for translation
force?booleanForce retranslation even if translations already exist
timeout?numberRequest 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;
}
PropertyTypeDescription
translationsCompletedFileTranslationData[]Array of translation job data
dataRecord<string, { fileName: string; versionId: string }>Map of file identifiers to file metadata
localesstring[]List of target locales for the translation jobs
messagestringStatus message from the API

Example

index.ts
// (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

Next Steps

How is this guide?

enqueueFiles