
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
googletrans2
Advanced tools
Free and Unlimited Google translate API for node.js
Using npm
npm i -S googletrans
Using yarn
yarn add googletrans
To gain the TypeScript typings (for intellisense / autocomplete) while using CommonJS imports with require()
use the following approach:
const tr = require("googletrans").default;
const tr = require("googletrans").default;
// Promise
tr("vue")
.then(function (result) {
console.log(result.text); // view
console.log(result.src); // fr
})
.catch(function (error) {
console.log(error);
});
// Want to use async/await?
async function translation() {
try {
const result = await tr("vue");
console.log(result.text); // view
console.log(result.src); // fr
} catch (error) {
console.log(error);
}
}
An array can be used to translate a batch of texts.
// eo => en
tr(["Saluton", "Mondo"])
.then(function (result) {
console.log(result.textArray); // [ 'Hello', 'world' ]
console.log(result.src); // eo
})
.catch(function (error) {
console.log(error);
});
// en => de
tr(["Hello", "world"], "de")
.then(function (result) {
console.log(result.textArray); // [ 'Hallo', 'Welt' ]
console.log(result.src); // en
})
.catch(function (error) {
console.log(error);
});
NOTE: The first element of the text array can not empty string.
If the API suggests a correction text, hasCorrectedText
will equals to true
.
In this case, correction text will have the corrections delimited with brackets ([ ]
), correctedText
is the crrection text.
// en => nl
tr("I spea English", "nl")
.then(function (result) {
console.log(result.text); // ik spreek Engels
console.log(result.hasCorrectedText); // true
console.log(result.correctedText); // I [speak] English
console.log(result.src); // en
})
.catch(function (error) {
console.log(error);
});
from
The source language you want to translate. (Default: auto)to
The language you want to translate into.(Default: en)tld
The google translate domain name. In this case, tld:"co.jp"
it will be uses translate.google.co.jp
// en => ja
tr("Hello", { from: "en", to: "ja", tld: "co.jp" })
.then(function (result) {
console.log(result.text); // こんにちは
console.log(result.src); // en
})
.catch(function (error) {
console.log(error);
});
If the source language is not right, hasCorrectedLang
will equal to true
.
tr("Hero", { from: "pt", to: "nl" })
.then(function (res) {
console.log(res.hasCorrectedLang); // true
console.log(res.src); // en
})
.catch(function (err) {
console.log(err);
});
The support languages. You can use the short name or the full name.
// short name
tr("koa", "en")
.then(function (result) {
console.log(result.text); // also
console.log(result.src); // mg
})
.catch(function (error) {
console.log(error);
});
// full name
tr("koa", "English")
.then(function (result) {
console.log(result.text); // also
console.log(result.src); // mg
})
.catch(function (error) {
console.log(error);
});
googletrans includes TypeScript definitions.
import tr from "googletrans";
const tr = require("googletrans").default;
tr(text, options)
// string
"en";
// object
{
// The language you want to translate into.(Default: en)
to: "en";
// The source language you want to translate. (Default: auto)
from: "fr";
// The google translate domain name
tld: "co.jp";
}
The result of a request contains the following information.
Result {
// the translated text.
text: string;
// array of the translated text.
textArray: string[];
// pronunciation
pronunciation: string;
// has correct source language?
hasCorrectedLang: boolean;
// source language
src: string;
// has correct source text?
hasCorrectedText: boolean;
// correct source text
correctedText: string;
// multiple translations
translations: [];
// the raw response from Google Translate servers.
raw: [];
}
DISCLAIMER: this is an unofficial library using the web API of Google Translate and also is not associated with Google.
Copyright (c) 2020-present, Darin Lo
FAQs
Free and Unlimited Google translate API for node.js
We found that googletrans2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.