A free and unlimited API for Google Translate 💵🚫 for Node.js.
- Auto language detection
- Spelling correction
- Language correction
- Fast and reliable – it uses the same servers that translate.google.com uses
Why this fork?
This fork of original matheuss/google-translate-api contains several improvements:
- New option
client="gtx"seems to work even with outdated token, see this discussion for details
- Fixed extraction of TKK ceed from current
https://translate.google.comsources (via @vitalets/google-translate-token)
- Removed unsecure
unsafe-evaldependency (See #2)
- Added daily CI tests to get notified if Google API changes
- Added support for custom
tld(especially to support
translate.google.cn, see #7)
- Added support for outputting pronunciation (see #17)
- Added support for custom got options. It allows to use proxy and bypass request limits (see #25)
- Added support for language extensions from outside of the API (See #18)
npm install @vitalets/google-translate-api
From automatic language detection to English:
const translate = ;;
From English to Dutch with a typo:
Sometimes, the API will not use the auto corrected text in the translation:
You can also add languages in the code and use them in the translation:
translate = ;translatelanguages'sr-Latn' = 'Serbian Latin';;
Too many requests
Google Translate has request limits. If too many requests are made, you can either end up with a 429 or a 503 error. You can use proxy to bypass them:
const tunnel = ;;
Does it work from web page context?
https://translate.google.com does not provide CORS http headers allowing access from other domains.
translate(text, [options], [gotOptions])
The text to be translated
text language. Must be
auto or one of the codes/names (not case sensitive) contained in languages.js
The language in which the text should be translated. Must be one of the codes/names (case sensitive!) contained in languages.js.
true, the returned object will have a
raw property with the raw response (
string) from Google Translate.
client used in API calls. Can be
TLD for Google translate host to be used in API calls:
The got options: https://github.com/sindresorhus/got#options
text(string) – The translated text.
trueif the API suggest a correction in the source language
iso(string) - The code of the language that the API has recognized in the
trueif the API has auto corrected the
value(string) – The auto corrected
textwith suggested corrections
trueif the API has suggested corrections to the
raw(string) - If
options.rawis true, the raw response from Google Translate servers. Otherwise,
res.from.text will only be returned if
from.text.didYouMean equals to
true. In this case, it will have the corrections delimited with brackets (
Otherwise, it will be an empty
vertaler– CLI for this module