Skip to content

NickFoden/google-translate-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Translating all the words

npm npm bundle size GitHub stars

Will need api key from google cloud

https://cloud.google.com/docs/authentication/api-keys#creating_an_api_key

Getting started:

npm i google-translate-client

Initialize the client

"../myfiles/api/gcloud.js";

const googleTranslate = require("google-translate-client");

const translateClient = googleTranslate.createClient({
  apiKey: "googleApiKey",
});

Use the client

import { translateClient } from "../myfiles/api/gcloud.js";

Takes 2 arguments - the text and the language you wish to translate to

translateClient("ozark or stranger things ?", "es")
  .then((result) => console.dir(result))
  //result will be an object with a key data with the translated text and the detected source language
  .catch((err) => console.dir(err));
//err is an object and has a code and a message and few other keys google sends back

result

// {data: {
//   translatedText: "¿Ozark o cosas más extrañas?",
//   detectedSourceLanguage: "en",
// }}

err

// { code: 403,
//  message: "The request is missing a valid API key.",
//  errors: [{…}],
//  status: "PERMISSION_DENIED",
// }

Sweet now more people can interpret your content!