How to use the @google-cloud/translate.v2 function in @google-cloud/translate

To help you get started, we’ve selected a few @google-cloud/translate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleapis / nodejs-translate / samples / quickstart.js View on Github external
function main(
  projectId = 'YOUR_PROJECT_ID' // Your GCP Project Id
) {
  // [START translate_quickstart]
  /**
   * TODO(developer): Uncomment the following line before running the sample.
   */
  // const projectId = 'YOUR_PROJECT_ID';

  // Imports the Google Cloud client library
  const {Translate} = require('@google-cloud/translate').v2;

  // Instantiates a client
  const translate = new Translate({projectId});

  async function quickStart() {
    // The text to translate
    const text = 'Hello, world!';

    // The target language
    const target = 'ru';

    // Translates some text into Russian
    const [translation] = await translate.translate(text, target);
    console.log(`Text: ${text}`);
    console.log(`Translation: ${translation}`);
  }
github googleapis / nodejs-translate / samples / translate.js View on Github external
function translateTextSample(text, target) {
  // [START translate_translate_text]
  // 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];
github CitizensFoundation / active-citizen / models / ac_translation_cache.js View on Github external
"use strict";

const { Translate }= require('@google-cloud/translate').v2;
const farmhash = require('farmhash');
const log = require('../utils/logger');

module.exports = (sequelize, DataTypes) => {
  let AcTranslationCache = sequelize.define("AcTranslationCache", {
    index_key: { type: DataTypes.STRING, allowNull: false },
    content: { type: DataTypes.TEXT, allowNull: false },
  }, {

    indexes: [
      {
        name: 'main_index',
        fields: ['index_key']
      }
    ],