I guess this section is outdate, because nowadays there's a way to translate PDF documents using several languages through REST requests. But there's a Node example in this page using NodeJs https://cloud.google.com/translate/docs/advanced/translate-documents#translate_batch_translate_document-nodejs
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const location = 'us-central1';
// const inputUri = 'path_to_your_files';
// const outputUri = 'path_to_your_output_bucket';
// Imports the Google Cloud Translation library
const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1;
// Instantiates a client
const translationClient = new TranslationServiceClient();
const documentInputConfig = {
gcsSource: {
inputUri: inputUri,
},
};
async function batchTranslateDocument() {
// Construct request
const request = {
parent: translationClient.locationPath(projectId, location),
documentInputConfig: documentInputConfig,
sourceLanguageCode: 'en-US',
targetLanguageCodes: ['sr-Latn'],
inputConfigs: [
{
gcsSource: {
inputUri: inputUri,
},
},
],
outputConfig: {
gcsDestination: {
outputUriPrefix: outputUri,
},
},
};
// Batch translate documents using a long-running operation.
// You can wait for now, or get results later.
const [operation] = await translationClient.batchTranslateDocument(request);
// Wait for operation to complete.
const [response] = await operation.promise();
console.log(`Total Pages: ${response.totalPages}`);
}
batchTranslateDocument();