Has anybody been able to get the google-cloud/translate nom to work?
I get this error “TranslationServiceClient is not a constructor” when using this code:
const projectId = ‘XXXXXXXXX’;
const location = ‘global’;
const text = ‘something’;
// Imports the Google Cloud Translation library const {TranslationServiceClient} = require(‘@google-cloud/translate’);
// Instantiates a client const translationClient = new TranslationServiceClient();
async function translateText() {
// Construct request
const request = {
parent: projects/${projectId}/locations/${location}
,
contents: [text], mimeType: ‘text/plain’, // mime types: text/plain, text/html sourceLanguageCode: ‘en’,
targetLanguageCode: ‘sr-Latn’, };
try { // Run request
const [response] = await translationClient.translateText(request);
for (const translation of response.translations)
{ console.log(Translation: ${translation.translatedText}
); } }
catch (error) { console.error(error.details); } } translateText();