Any ideas?
This is what my code looks like. I followed the basic project setup guide for Node.
Init
const {Translate} = require('@google-cloud/translate').v2;
const translate = new Translate({projectId, credentials});
const text = 'The text to translate, e.g. Hello, world!';
const target = 'es';
The function to translate.
async function translateText() {
let [translations] = await translate.translate(text, target);
translations = Array.isArray(translations) ? translations : [translations];
console.log('Translations:');
translations.forEach((translation, i) => {
console.log(`${text[i]} => (${target}) ${translation}`);
});
}
It's pretty frustrating that every API doc mentions that the source language gets automatically "detected", without any information about how to stop Google from guessing at it. Seems like something Google would benefit from also... Less work for them.