google-translate-client
v0.0.6
Published
![npm](https://img.shields.io/npm/dm/google-translate-client) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/[email protected]) ![GitHub stars](https://img.shields.io/github/stars/nickfoden/google-translate-client?style=social)
Downloads
6
Maintainers
Readme
Translating all the words
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!