Friends, i have api from google translator and you need to throw post requests.
I want to send them using ajax.
I have already learned how to throw requests to find out the ip address, network data, currencies, etc.
The other day I found an api from Google for translating words, but I don’t know how to correctly formulate the request and throw
Here is the request for js
// Imports the Google Cloud client library
const {Translate} = require('@google-cloud/translate').v2;
// Creates a client
const translate = new Translate();
/**
* TODO(developer): Uncomment the following lines before running the sample.
*/
// const text = 'The text to translate, e.g. Hello, world!';
// const target = 'The target language, e.g. ru';
async function translateText() {
// Translates the text into the target language. "text" can be a string for
// translating a single piece of text, or an array of strings for translating
// multiple texts.
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}`);
});
}
translateText();