py-googletrans: Found a Google Translate endpoint that doesn't require an API key.
This isn’t a bug report, just a sharing of some findings while looking through minified source code.
While digging through the source code of Google’s Google Dictionary Chrome extension, which has support for translating via Google Translate, I found the endpoint they use in order to do just that. Since googletrans frequently runs into 5xx errors, it might be useful to switch off to another endpoint, although this one is also annoyingly touchy with 403s.
Breakdown
Endpoint: https://clients5.google.com/translate_a/t
Query Parameters
| Query Parameter | Default | Notes |
|---|---|---|
| client | dict-chrome-ex |
Needs to be dict-chrome-ex or else you’ll get a 403 error. |
| sl | auto |
Designates the source language of the text to translate. |
| tl | (none) | Designates the destination language of the text to translate. |
| q | (none) | Text to translate |
Example Response
URL:
https://clients5.google.com/translate_a/t?client=dict-chrome-ex&sl=auto&tl=en&q=bonjour
{
"sentences": [
{
"trans": "Hello",
"orig": "bonjour",
"backend": 1
}
],
"dict": [
{
"pos": "interjection",
"terms": [
"Hello!",
"Hi!",
"Good morning!",
"Good afternoon!",
"How do you do?",
"Hallo!",
"Hullo!",
"Welcome!"
],
"entry": [
{
"word": "Hello!",
"reverse_translation": [
"Bonjour!",
"Salut!",
"Tiens!",
"Allô!"
],
"score": 0.7316156
},
{
"word": "Hi!",
"reverse_translation": [
"Salut!",
"Bonjour!",
"Hé!"
],
"score": 0.084690653
},
{
"word": "Good morning!",
"reverse_translation": [
"Bonjour!"
],
"score": 0.065957151
},
{
"word": "Good afternoon!",
"reverse_translation": [
"Bonjour!"
],
"score": 0.02749503
},
{
"word": "How do you do?",
"reverse_translation": [
"Bonjour!",
"Salut!",
"Ça marche?"
]
},
{
"word": "Hallo!",
"reverse_translation": [
"Bonjour!",
"Tiens!",
"Salut!",
"Allô!"
]
},
{
"word": "Hullo!",
"reverse_translation": [
"Tiens!",
"Allô!",
"Salut!",
"Bonjour!"
]
},
{
"word": "Welcome!",
"reverse_translation": [
"Salut!",
"Bonjour!",
"Soyez le bienvenu!"
]
}
],
"base_form": "Bonjour!",
"pos_enum": 9
}
],
"src": "fr",
"alternative_translations": [
{
"src_phrase": "bonjour",
"alternative": [
{
"word_postproc": "Hello",
"score": 1000,
"has_preceding_space": true,
"attach_to_next_token": false
}
],
"srcunicodeoffsets": [
{
"begin": 0,
"end": 7
}
],
"raw_src_segment": "bonjour",
"start_pos": 0,
"end_pos": 0
}
],
"confidence": 0.96875,
"ld_result": {
"srclangs": [
"fr"
],
"srclangs_confidences": [
0.96875
],
"extended_srclangs": [
"fr"
]
},
"query_inflections": [
{
"written_form": "bonjour",
"features": {
"gender": 1,
"number": 2
}
},
{
"written_form": "bonjours",
"features": {
"gender": 1,
"number": 1
}
},
{
"written_form": "bonjour",
"features": {
"number": 2
}
},
{
"written_form": "bonjours",
"features": {
"number": 1
}
}
]
}
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 62
- Comments: 61 (1 by maintainers)
Links to this issue
Commits related to this issue
- [fix] Fixing Google Translate following ssut/py-googletrans#268 — committed to Animenosekai/translate by Animenosekai 3 years ago
After some testing with the request headers, I found the solution for the garbled text. Simply set the User-Agent header to the one that Google Chrome uses.
Example:
Response:
I found another endpoint within the source code of one of the google translate extensions on VSCode too.
The results looks something like this:
And something like this:
When using it only to translate things, I would use it like so:
@NawtJ0sh
I just made a repository which groups all of the APIs if you want (called
translate)I made a comparison of all (known) Google Translate API endpoints based on my findings while making my translation library, this may be useful if you don’t know which API endpoint to use.
https://clients5.google.com/translate_ano longer seems to return faithful translations; only returns the translated text.https://translate.googleapis.com/translate_a/singlestill returns faithful translations and some info about the translation (source language, translation confidence and transliteration if available).https://translate.google.com/_/TranslateWebserverUi/data/batchexecuteonly returns a faithful translation with theX-Goog-BatchExecute-Bgr, the algorithm that creates this header doesn’t seem to be deciphered yet. This is the endpoint that returns the most info (source language, translation confidence, transliteration, alternative translations, definitions, examples, etc.).https://translate.google.com/mreturns a faithful translation, but no extra info. Returns HTML instead of JSON so parsing is required.In conclusion, the second endpoint is currently the best free Google Translate API endpoint, unless someone manages to decipher the
X-Goog-BatchExecute-Bgrheader.https://clients5.google.com/translate_a/single?dj=1&dt=t&dt=sp&dt=ld&dt=bd&client=dict-chrome-ex&sl=auto&tl=en&q=kanker
this is what the url is like now (on the Google Dictionary Extension)
@Animenosekai Awesome, another endpoint to add. We should probably create a way to house all of these endpoints through one API, perhaps an interface that all of the endpoints implement?
Seems like a few hours ago @SuperSonicHub1’s Google Translate endpoint has started to return the more detailed response structure.
I’ve found this alternative endpoint for google: Free endpoint: https://translate.google.com/m?hl=en&sl=en&tl=pt&ie=UTF-8&prev=_m&q=Text The caveat? the response is an HTML page. It is easily parseable though and the translation is much better than the ones they are spitting through the simple json endpoints above
The endpoint now returns a simpler response (translation and detected language).
Url: https://clients5.google.com/translate_a/t?client=dict-chrome-ex&sl=auto&tl=es&q=Hello World
Response:
[[[[["Hola Mundo"]],null,"en"]]]Formatted response:
Here is the yandex translate, I worked on last night its just like the bing.com one i posted.
I know this is an older thread but just wanted to warn people that
https://translate.googleapis.com/translate_a/singlehas issues with punctuation and will just halt translations (like if it encounters an ‘!’).https://clients5.google.com/translate_a/tworks great though! Thank you @SuperSonicHub1 !i noticed this is much more faithful to the translations I used to get with the https://clients5.google.com/translate_a/t?client=dict-chrome-ex&sl=en&tl=it&q=body endpoint before they screwed it up
Lmao that’s exactly what I did on Animenosekai/translate d5f0357 (flipped their position though)
Edit: the new version is up on PyPI, update the module with
pip install --upgrade translatepy(might want to run it twice to force pip checking for the new version)@d4n3436 It seems our little operation has been busted by Google. This heavily reminds me of their other obfuscated JSON responses, where arrays are used instead of objects, which makes it hell for us stragglers to trivially parse. Try making more translations in a variety of languages and then share the results with us, as the lengths of the inner arrays may vary.
Nice you fixed it!! Thank you.