checkFileTranslations
API reference for the checkFileTranslations method to check translation status without downloading files
Overview
The checkFileTranslations method checks the translation status of files without downloading their contents.
This is useful for monitoring translation progress, checking completion status, and determining which translations are available.
const gt = new GT({ projectId: 'your-project-id', apiKey: 'your-api-key' });
const status = await gt.checkFileTranslations([
{
versionId: 'version-123',
fileName: 'app.json',
locale: 'es'
}
]);Reference
Parameters
| Name | Type | Description |
|---|---|---|
data | FileTranslationQuery[] | Array of file translation queries to validate |
options? | CheckFileTranslationsOptions | Optional configuration for the request |
FileTranslationQuery
| Name | Type | Description |
|---|---|---|
versionId | string | Version ID of the file to check |
fileName? | string | File name identifier (required if fileId isn’t provided) |
fileId? | string | File ID identifier (required if fileName isn’t provided) |
locale | string | Target locale for which to check translation status |
CheckFileTranslationsOptions
| Name | Type | Description |
|---|---|---|
timeout? | number | Request timeout in milliseconds |
Returns
Promise<CheckFileTranslationsResult> – Contains information about the translation status.
type CheckFileTranslationsResult = {
translations: CompletedFileTranslationData[];
}| Property | Type | Description |
|---|---|---|
translations | CompletedFileTranslationData[] | Array of translation status data |
CompletedFileTranslationData structure
type CompletedFileTranslationData = {
id: string;
fileId: string;
versionId: string;
fileName: string;
locale: string;
status: 'completed' | 'pending' | 'failed';
completedAt: string | null;
approvedAt: string | null;
publishedAt: string | null;
createdAt: string;
updatedAt: string;
}Examples
Basic Usage
Check translation status for specific files and locales:
// (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));
}Notes
- Translation status includes
pending,completed, andfailedstates - Completed translations may still require approval before being published
- Use this method for efficient status checks when monitoring multiple translation jobs
Next steps
- Check the Quickstart for a complete example of how to use this method.
- See
downloadTranslatedFileto download completed translations. - See
enqueueFilesto create translation jobs. - See
querySourceFileto get source file and translation information.
How is this guide?