I am paying to use the Google api to translate document and google is adding Machine Translated by Google
on each page.
I know this is part of the attribution requirements but if I specify it on my website it should not be required on the generated document.
const crypto = require('crypto')
const { TranslationServiceClient } = require('@google-cloud/translate').v3
const { Storage } = require('@google-cloud/storage');
const fetch = require('node-fetch');
const fs = require('fs')
const translationClient = new TranslationServiceClient();
const parent = translationClient.locationPath('***', 'global');
const storage = new Storage();
async function translateFile({ uri, from, to }) {
process.env.GOOGLE_APPLICATION_CREDENTIALS = './***.json'
const pdfResponse = await fetch(uri);
if (!pdfResponse.ok) {
throw new Error(`Failed to download the PDF: ${response.statusText}`);
}
const buffer = await pdfResponse.buffer();
const bucket = storage.bucket('***');
const file = bucket.file(`${crypto.randomUUID()}.pdf`)
await file.save(buffer)
const inputUri = `gs://${bucket.name}/${file.name}`
const documentInputConfig = { gcsSource: { inputUri } };
const request = {
parent,
documentInputConfig: documentInputConfig,
sourceLanguageCode: from,
targetLanguageCode: to,
//customizedAttribution: 'Test'
};
const [response] = await translationClient.translateDocument(request);
await file.delete()
fs.writeFileSync(`data/${crypto.randomUUID()}.pdf`, response.documentTranslation.byteStreamOutputs[0])
}
Seems like I can change it with customizedAttribution
but each time I have an error Error: 3 INVALID_ARGUMENT: Invalid customized attribution: Test
The other solution as I let my user know it is translated by google will be a post process but remove text keeping background is not that simple with nodejs the only solution I have is to set a white rectangle on Machine Translated by Google
there is no way to keep remove the background