-
Notifications
You must be signed in to change notification settings - Fork 729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Found a Google Translate endpoint that doesn't require an API key. #268
Comments
This seems like a great discovery! I'll take a look at this shortly. Thank you so much! |
@ssut No problem! |
@theonefoster Glad to be of use! |
Stopped working for me (403) |
@shatteringlass Mentioned that in the initial post:
That's why I want this endpoint to be seamlessly integrated into |
I found another endpoint within the source code of one of the google translate extensions on VSCode too. "https://translate.googleapis.com/translate_a/single?client=gtx&dt=t + params"
// where the params are:
{
"sl": source language,
"tl": destination language,
"q": the text to translate
} The results looks something like this: [[["こんにちは、今日はお元気ですか?","Hello, how are you today?",null,null,3,null,null,[[]
]
,[[["9588ca5d94759e1e85ee26c1b641b1e3","kgmt_en_ja_2020q3.md"]
]
]
]
]
,null,"en",null,null,null,null,[]
]
And something like this: [[["Bonjour","Hello",null,null,1]
]
,null,"en",null,null,null,null,[]
]
When using it only to translate things, I would use it like so: from json import loads
from requests import get
request_result = get("https://translate.googleapis.com/translate_a/single?client=gtx&dt=t&sl=en&tl=fr&q=Hello")
translated_text = loads(request_result.text)[0][0][0]
print(translated_text) |
@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? |
What am I doing wrong? word = 'لماذا تفعل هذا'
try:
request_result = requests.post("https://clients5.google.com/translate_a/t?client=dict-chrome-ex&sl=auto&tl=en&q="+ word).json()
print(request_result)
print('[In English]: '+ request_result['alternative_translations'][0]['alternative'][0]['word_postproc'])
print('[Language Dectected]: ' + request_result['src'])
except:
traceback.print_exc() Output:
why is it outputting it like that? |
@NawtJ0sh Why are you making a POST request? It's a GET request you should be making. How does that even return a response? |
No idea, it does the exact same thing with requests.get() |
If you try to open it in a browser it seems to work fine: {"sentences":[{"trans":"Why are you doing this","orig":"لماذا تفعل هذا","backend":1},{"src_translit":"limadha tafeal hdha"}],"src":"ar","alternative_translations":[{"src_phrase":"لماذا تفعل هذا","alternative":[{"word_postproc":"Why are you doing this","score":1000,"has_preceding_space":true,"attach_to_next_token":false}],"srcunicodeoffsets":[{"begin":0,"end":14}],"raw_src_segment":"لماذا تفعل هذا","start_pos":0,"end_pos":0}],"confidence":1,"ld_result":{"srclangs":["ar"],"srclangs_confidences":[1],"extended_srclangs":["ar"]}} Might be a problem with the decoding, try to use the It might be because your terminal doesn't support arabic or something like that Also maybe try to url encode the text before sending it (and use GET as it should not work with POST) |
After some testing with the request headers, I found the solution for the garbled text. Example: import requests
word = 'لماذا تفعل هذا'
url = "https://clients5.google.com/translate_a/t?client=dict-chrome-ex&sl=auto&tl=en&q=" + word
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36'
}
try:
request_result = requests.get(url, headers=headers).json()
print(request_result)
print('[In English]: ' + request_result['alternative_translations'][0]['alternative'][0]['word_postproc'])
print('[Language Dectected]: ' + request_result['src'])
except:
pass Response:
|
@d4n3436 How interesting. It's almost like a form of copy protection. |
Maybe that they are retrieving the User-Agent to process some analytics in the bg and that without it it breaks something. But, I mean, still weird that it gives a gibberish response and that it accepted the |
It's weird... If you don't use User-Agent, the response will have an incorrect encoding (ASCII). About the |
if anyone wants to try and get this Bing translator to work that'd be awesome import requests
url = 'https://www.bing.com/ttranslatev3'
post_header = {}
post_header['Host'] = 'www.bing.com'
post_header['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0'
post_header['Accept'] = '*/*'
post_header['Accept-Language'] = 'en-US,en;q=0.5'
post_header['Accept-Encoding'] = 'gzip, deflate'
post_header['Referer'] = 'https://www.bing.com/'
post_header['Content-Type'] = 'application/x-www-form-urlencoded'
post_header['Connection'] = 'keep-alive'
parameters_payload = {'IG' : '839D27F8277F4AA3B0EDB83C255D0D70', 'IID' : 'translator.5033.3'}
data_payload = {'text':'Platypus', 'from':'en', 'to':'es'}
resp = requests.post(url, headers=post_header, params=parameters_payload, data=data_payload)
print(resp.json()) |
@NawtJ0sh Microsoft might have changed their API since I get back: {'statusCode': 400} # if this was a http status code, means bad request --> might be because the params don't work anymore (which is weird since the HTTP status code is 200) |
@NawtJ0sh I made a simple API wrapper for Bing Translator in C# some months ago. You can use it and port it. |
Nice! if you could try it with the Yandex translator, that'd be cool! |
All that was changed was the 'from' to 'fromLang' haha |
I actually made one, but unfortunately Yandex has a captcha protection that is triggered after a few uses of their API. |
Lmao, yea I just checked and it worked! [{'detectedLanguage': {'language': 'en', 'score': 1.0}, 'translations': [{'text': 'Ornitorrinco', 'to': 'es', 'sentLen': {'srcSentLen': [8], 'transSentLen': [12]}}]}] |
Well here you go: from json import loads
from requests import post
HEADERS = {
"Host": "www.bing.com",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0",
"Accept": "*/*",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate",
"Referer": "https://www.bing.com/",
"Content-Type": "application/x-www-form-urlencoded",
"Connection": "keep-alive"
}
PARAMS = {'IG' : '839D27F8277F4AA3B0EDB83C255D0D70', 'IID' : 'translator.5033.3'}
def translate(text, to, fromLang="auto-detect"):
"""
Translates the given text to the given language using Microsoft's Bing Translation API (ttranslatev3)
"""
request = post("https://www.bing.com/ttranslatev3", headers=HEADERS, params=PARAMS, data={'text': str(text), 'fromLang': str(fromLang), 'to': str(to)})
if request.status_code < 400:
try:
return loads(request.text)[0]["translations"][0]["text"]
except:
return None
else:
return None
def language(text):
"""
Gives you back the ISO 639-1 Alpha-2 language code the text has been written in using Microsoft's Bing Translation API (ttranslatev3)
> The output is a tuple with the language code and the score (confidence)
"""
request = post("https://www.bing.com/ttranslatev3", headers=HEADERS, params=PARAMS, data={'text': str(text), 'fromLang': "auto-detect", 'to': "en"})
if request.status_code < 400:
try:
detectedLanguage = loads(request.text)[0]["detectedLanguage"]
return detectedLanguage["language"], detectedLanguage["score"]
except:
return None
else:
return None Just call translate("<your text>", "<the ISO 639-1 Alpha-2 language codes (I guess) of the output language>") Or if you want to know the language of a given text: language("<your text>") And it gives you back the result or
>>> translate("Hello", "ja")
'こんにちは'
>>> translate("Hello", "fr")
'Bonjour'
>>> translate("Hello", "fr", "en")
'Bonjour'
>>> language("Hello")
('en', 1.0)
>>> language("Hola")
('es', 1.0) |
Here is the yandex translate, I worked on last night its just like the bing.com one i posted. import requests
url = 'https://translate.yandex.net/api/v1/tr.json/translate?id=1308a84a.6016deed.0c4881a2.74722d74657874-3-0&srv=tr-text&lang=en&reason=auto&format=text'
post_header = {}
post_header['Accept'] = '*/*'
post_header['Accept-Encoding'] = 'gzip, deflate'
post_header['Accept-Language'] = 'en-US,en;q=0.9'
post_header['Cache-Control'] = 'no-cache'
post_header['Connection'] = 'keep-alive'
post_header['Content-Type'] = 'application/x-www-form-urlencoded'
post_header['Host'] = 'translate.yandex.com'
post_header['Referer'] = 'https://translate.yandex.com/'
post_header['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36'
data_payload = {'text': search_str, 'options': '4'}
resp = requests.get(url, headers=post_header, data=data_payload).json()
print(str(resp) + '\n') |
I just made a repository which groups all of the APIs if you want (called
|
Nice you fixed it!! Thank you. |
|
Error from server : Too many request :'( |
Closing this issue as our research was never implemented in this repo. I think it's best to assume that Please stop using this issue as a support thread; tired of getting everyone's emails. Maintainers, I'd recommend you lock this thread. |
Why you confusing people with broken package? Update the readme and unpublish from the pip. Thats it |
It seems that now the two "free endpoints" of Google Translate API don't respond in a nice way anymore. For single words translations, they used to respond with a detailed list of possible translations. Now they only give you back a single one (the most common one) and I can't find a way to change this. Have a look for "body" translated from EN to IT ("corpo", "organismo", "organo", "carrozzeria", ...) Free endpoint 1: https://clients5.google.com/translate_a/t?client=dict-chrome-ex&sl=en&tl=it&q=body Free endpoint 2: https://translate.googleapis.com/translate_a/single?client=gtx&dt=t&sl=en&tl=it&q=body Any ideas? |
I don't believe it would be possible to get detailed lists without using a different endpoint, because in the applications these endpoints are in, they don't need all the possible translations. |
I've found this alternative endpoint for google: |
@lokinmodar The only caveat is that it's the mobile version of Google Translate which tends to yield worse translations |
@lokinmodar The only caveat is that it's the mobile version of Google Translate which tends to yield worse translations (based on previous observations, this might have changed and this page is slightly different than the normal Google Translate mobile page) |
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 |
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.
In conclusion, the second endpoint is currently the best free Google Translate API endpoint, unless someone manages to decipher the |
this is what the url is like now (on the Google Dictionary Extension) |
https://translate.google.com/_/TranslateWebserverUi/data/batchexecu seems no longer to work, 404 now. |
https://translate.google.com/_/TranslateWebserverUi/data/batchexecute still OK. https://translate.google.cn/_/TranslateWebserverUi/data/batchexecute no longer works because translate.google.cn is dead (redirected to translate.google.com.hk in fact). |
Hello,everyone |
I know this is an older thread but just wanted to warn people that
|
I have found that The only drawback is that it splits the translation into multiple parts if the query is too long, which requires us to join them back together. It also provides far better translations compared to |
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
dict-chrome-ex
dict-chrome-ex
or else you'll get a 403 error.auto
Example Response
The text was updated successfully, but these errors were encountered: