Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@vitalets/google-translate-api
Advanced tools
A free and unlimited API for Google Translate for Node.js.
In version 9+ library was fully rewritten. For legacy documentation please see legacy branch.
npm install @vitalets/google-translate-api
import { translate } from '@vitalets/google-translate-api';
const { text } = await translate('Привет, мир! Как дела?', { to: 'en' });
console.log(text) // => 'Hello World! How are you?'
Since react-native has full support of fetch API translation works the same way as in Node.js.
This library does not work inside web pages because translate.google.com
does not provide CORS headers allowing access from other domains.
Although library does not work in regular web pages it can be used in browser extensions. Extensions background and popup pages are not limited with same origin policy. To use translation API you should do the following:
Add host permissions to manifest.json
:
+ "host_permissions": [
+ "https://translate.google.com/"
+ ]
Import translate
as usual in background or popup script:
// background.js
import { translate } from '@vitalets/google-translate-api';
const { text } = await translate('Привет мир');
console.log(text);
Bundle code (for example with webpack
):
// webpack.config.js
module.exports = {
mode: 'development',
entry: './background.js',
output: {
filename: 'bundle.js',
},
};
Google Translate has request limits. If too many requests are made, you can get a TooManyRequestsError (code 429). You can use proxy to bypass it:
import { translate } from '@vitalets/google-translate-api';
import createHttpProxyAgent from 'http-proxy-agent';
const agent = createHttpProxyAgent('http://103.152.112.162:80');
const { text } = await translate('Привет, мир!', {
to: 'en',
fetchOptions: { agent },
});
Available proxy list you can find here.
Common pattern for selecting proxy is following:
try {
const { text } = await translate('Привет, мир!', {
to: 'en',
fetchOptions: { agent },
});
} catch (e) {
if (e.name === 'TooManyRequestsError') {
// retry with another proxy agent
}
}
tbd
MIT © Matheus Fernandes, forked and maintained by Vitaliy Potapov.
FAQs
A free and unlimited API for Google Translate
The npm package @vitalets/google-translate-api receives a total of 49,288 weekly downloads. As such, @vitalets/google-translate-api popularity was classified as popular.
We found that @vitalets/google-translate-api 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
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.