GT ClassMethodsTranslation

enqueueFiles

API reference for the enqueueFiles method to enqueue file translation jobs

Overview

The enqueueFiles method enqueues translation jobs for previously uploaded source files. 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
filesFileReference[]Array of file references from previously uploaded files
optionsEnqueueOptionsConfiguration options for the translation job

FileReference Structure

type FileReference = {
  fileId: string;
  versionId: string;
  branchId: string;
  fileName: string;
  fileFormat?: FileFormat;
  dataFormat?: DataFormat;
}
NameTypeDescription
fileIdstringUnique file identifier
versionIdstringVersion identifier
branchIdstringBranch identifier
fileNamestringFile name
fileFormat?FileFormatFile format (JSON, MD, etc.)
dataFormat?DataFormatData format within file (ICU, I18NEXT, JSX)

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 = {
  jobId: string;
  locales: string[];
  message: string;
}
PropertyTypeDescription
jobIdstringThe translation job ID for status checking
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,
  }
);

console.log(`Translation job created: ${enqueueResult.jobId}`);

// (4) Wait for all translations to be completed
const { fileId, versionId, branchId } = uploadedFiles[0];
const translatedFileQueries = targetLocales.map((locale) => ({
  fileId,
  versionId,
  branchId,
  locale
}));

while (true) {
  const result = await gt.queryFileData({
    translatedFiles: translatedFileQueries
  });

  const allCompleted = result.translatedFiles?.every(
    (file) => file.status === 'completed'
  );

  if (allCompleted) {
    break;
  }

  await new Promise(resolve => setTimeout(resolve, 1000));
}

// (5) Download the files
const downloadResult = await gt.downloadFileBatch(
  targetLocales.map((locale) => ({
    fileId,
    branchId,
    locale
  }))
);

Notes

  • File content must be uploaded first using uploadSourceFiles
  • Translation jobs are asynchronous - use queryFileData to monitor progress
  • File references include branchId for proper versioning with branching support

Next steps

How is this guide?