API translator from google. Requests

0 favourites
  • 1 posts
From the Asset Store
Google Analytics 4 Plugin for Construct 3 enables metrics and analytics for your games easily.
  • 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();
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)