Simple JS library for talking to Google's Translate API for free.
Eliminates IP request limitations
https://cloud.google.com/translate/docs/languages
Install package
npm i @kreisler/js-google-translate-free
import JsGoogleTranslateFree from "@kreisler/js-google-translate-free";
or
const JsGoogleTranslateFree = require("@kreisler/js-google-translate-free");
(async () => {
try {
const from = "es";
const to = "en";
const text = "buenos días";
const translation = await JsGoogleTranslateFree.translate({ from, to, text });
console.log(translation); // Good morning
} catch (error) {
console.error(error);
}
})();
(async () => {
try {
// const from = "en"; optional default is "auto"
const to = "es";
const text = "Good morning";
const translation = await JsGoogleTranslateFree.translate({ to, text });
console.log(translation); // Buenos días
} catch (error) {
console.error(error);
}
})();