This is a simple and easy to use package for translating text using Google Translate for Free
. It is a TypeScript package and can be used in both TypeScript and JavaScript projects.
npm install google-translator-ts
import { translator } from "google-translator-ts";
const source = "en"; // "" or "auto" for auto-detection
const target = "es";
const text = "Hello, how are you?";
translator(source, target, text)
.then((translation) => {
console.log("translation:", translation);
})
.catch((error) => {
console.error("error:", error);
});