iamtraction / Google Translate
Licence: mit
🈯 A Node.JS library to consume Google Translate API for free.
Stars: ✭ 152
Programming Languages
javascript
184084 projects - #8 most used programming language
js
455 projects
Projects that are alternatives of or similar to Google Translate
Trino
Trino: Master your translations with command line!
Stars: ✭ 118 (-22.37%)
Mutual labels: api, google, translate
Php Google Translate Free
PHP class to use the Google Translator API for free.
Stars: ✭ 182 (+19.74%)
Mutual labels: api, google, translate
Google Translate Api
A free and unlimited API for Google Translate 💵🚫
Stars: ✭ 1,996 (+1213.16%)
Mutual labels: api, google, translate
Node Google Dfp
A service for integrating with Google DFP over NodeJS
Stars: ✭ 84 (-44.74%)
Mutual labels: api, google
Google Translate Api Browser
A free and unlimited API for Google Translate
Stars: ✭ 96 (-36.84%)
Mutual labels: api, translate
Parse Google Docs Json
Authenticates with Google API and parse Google Docs to JSON or Markdown
Stars: ✭ 100 (-34.21%)
Mutual labels: api, google
Esp V2
A service proxy that provides API management capabilities using Google Service Infrastructure.
Stars: ✭ 120 (-21.05%)
Mutual labels: api, google
Gsheets Db Api
A Python DB-API and SQLAlchemy dialect to Google Spreasheets
Stars: ✭ 122 (-19.74%)
Mutual labels: api, google
Google Translator
Free Google Translator for Dart
Stars: ✭ 68 (-55.26%)
Mutual labels: google, translate
Searchconsoler
R interface with Google Search Console API v3, including Search Analytics.
Stars: ✭ 99 (-34.87%)
Mutual labels: api, google
Google Analytics Api Symfony
Google Analytics API Symfony Bundle
Stars: ✭ 43 (-71.71%)
Mutual labels: api, google
Dynamictranslator
Instant translation application for windows in .NET 🎪
Stars: ✭ 131 (-13.82%)
Mutual labels: google, translate
Alfred Polyglot
🈚️ Translate text using Google Translate in Alfred
Stars: ✭ 142 (-6.58%)
Mutual labels: google, translate
Yunmai Data Extract
Extract your data from the Yunmai weighing scales cloud API so you can use it elsewhere
Stars: ✭ 21 (-86.18%)
Mutual labels: api, google
Google Translate API
A Node.JS library to consume Google Translate for free.
Feature Highlights
- Automatically detect source language
- Automatic spelling corrections
- Automatic language correction
- Fast and reliable
Table of Contents
Installation
# Stable version, from npm repository
npm install --save @iamtraction/google-translate
# Latest version, from GitHub repository
npm install --save iamtraction/google-translate
Usage
// If you've installed from npm, do:
const translate = require('@iamtraction/google-translate');
// If you've installed from GitHub, do:
const translate = require('google-translate');
translate(text, options)
Method: translate(text, options).then(console.log).catch(console.error);
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
text |
String |
No | - | The text you want to translate. |
options |
Object |
- | - | The options for translating. |
options.from |
String |
Yes | 'auto' |
The language name/ISO 639-1 code to translate from. If none is given, it will auto detect the source language. |
options.to |
String |
Yes | 'en' |
The language name/ISO 639-1 code to translate to. If none is given, it will translate to English. |
options.raw |
Boolean |
Yes | false |
If true , it will return the raw output that was received from Google Translate. |
Promise<Object>
Returns: Response Object:
Key | Type | Description |
---|---|---|
text |
String |
The translated text. |
from |
Object |
- |
from.language |
Object |
- |
from.language.didYouMean |
Boolean |
Whether or not the API suggest a correction in the source language. |
from.language.iso |
String |
The ISO 639-1 code of the language that the API has recognized in the text. |
from.text |
Object |
- |
from.text.autoCorrected |
Boolean |
Whether or not the API has auto corrected the original text. |
from.text.value |
String |
The auto corrected text or the text with suggested corrections. Only returned if from.text.autoCorrected or from.text.didYouMean is true . |
from.text.didYouMean |
Boolean |
Wherether or not the API has suggested corrections to the text |
raw |
String |
The raw response from Google Translate servers. Only returned if options.raw is true in the request options. |
Examples
From automatic language detection to English:
translate('Tu es incroyable!', { to: 'en' }).then(res => {
console.log(res.text); // OUTPUT: You are amazing!
}).catch(err => {
console.error(err);
});
From English to French, with a typo:
translate('Thank you', { from: 'en', to: 'fr' }).then(res => {
console.log(res.text); // OUTPUT: Je vous remercie
console.log(res.from.autoCorrected); // OUTPUT: true
console.log(res.from.text.value); // OUTPUT: [Thank] you
console.log(res.from.text.didYouMean); // OUTPUT: false
}).catch(err => {
console.error(err);
});
Sometimes Google Translate won't auto correct:
translate('Thank you', { from: 'en', to: 'fr' }).then(res => {
console.log(res.text); // OUTPUT: ''
console.log(res.from.autoCorrected); // OUTPUT: false
console.log(res.from.text.value); // OUTPUT: [Thank] you
console.log(res.from.text.didYouMean); // OUTPUT: true
}).catch(err => {
console.error(err);
});
Extras
If you liked this project, please give it a ⭐ in GitHub.
Credits to matheuss for writing the original version of this library. I rewrote this, with improvements and without using many external libraries, as his library was not actively developed and had vulnerabilities.
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].