Unable to get translated word using google translate and HTTP Request

getuxagig

New member
Hi! As an example, I'm trying to translate the word milch from german to english, which in english it means milk, by using this (imgur) setup for HTTP Request. The URL used, as also seen in the pictures, is https://translate.google.com/?sl=de&tl=en&text=milch

The answer I get in the string variable gt is an HTML document, but nowhere in the HTML document I am able to find the word milk. I am only able to find the word milch within the HTML document.

Does anyone know how can I get the translated word? Or does anyone know any alternative to google translate, in case there's no solution for this?

Thank you!
 

Jacob L

Moderator (Lawsonator)
Not sure why but it doesn't seem to save the result. I've also tried another translator. We might need an API for this
 

Josué García

MacroDroid Support
Staff member
Hi! As an example, I'm trying to translate the word milch from german to english, which in english it means milk, by using this (imgur) setup for HTTP Request. The URL used, as also seen in the pictures, is https://translate.google.com/?sl=de&tl=en&text=milch

The answer I get in the string variable gt is an HTML document, but nowhere in the HTML document I am able to find the word milk. I am only able to find the word milch within the HTML document.

Does anyone know how can I get the translated word? Or does anyone know any alternative to google translate, in case there's no solution for this?

Thank you!
I think it is because the web you are loading has not yet processed the translation (that is why it only finds the translation in the code) and by the way Google does have an API for translation and it is not free I think I vaguely remember
 

getuxagig

New member
@Jacob L
Thanks for trying to help! :)

I forgot to mention that I tried bing, but that doesn't even get an URL with parameters for translation. In the meantime, I got a couple more ideas, and I think I found something I'll post below, after answering @JosueG28.

@JosueG28
I was trying the same with on google translate site, while having a look in Chrome Dev Tools, in the Network tab, and the response I got for:
https://translate.google.com/?sl=de&tl=en&text=milch
would also not contain the word milk, but the webpage would display the word milk in the translation.
Indeed, Google has a translation api, and as you have already mentioned it is paid. Although it has some free part, they give you 300$ and you're supposed to spend them in the first 90 days of activation.

Thanks for chiming in!

What I found out just few minutes ago is that yandex has an api and it seems free, but what I need to do is try to figure out how they generate the ID, as it seems to be the most important parameter. Here you can see the ID is c968715c.6482136d.a7465121.74722d74657874-0-0.
To find this related info to yandex I used Fiddler and then I monitored:
https://translate.yandex.com/en/?source_lang=de&target_lang=en&text=milch

The monitoring lead up to this link:
https://translate.yandex.net/api/v1...ng=de&target_lang=en&reason=paste&format=text
for which I got this result:
1686247666089.png
You can see milk in the JSON structure, as the response.

I tried issuing the same request using the Fiddler Composer, by only changing mich to gut (gut means good in german), and guess what, I got the translation for it as well:
1686247876263.png
, and this is the answer:
1686247832607.png
Now you can see good showing up in the JSON structure.

I'm gonna try first to use this ID to see for how long it will hold before denying requests.

In case I won't figure out how the ID gets generated, and if also the requests will break after some time, I'll try having a look at other translators. I think baidu and naver have also translators as I'm avoiding paid APIs.
 

FrameXX

Well-known member
@JosueG28 is right. This way it would be far too easy for web scrapers to get translations for free. The translation is handled by script after the side loads which means it is not part of the GET response. The website never really loads if you use the MacroDroid HTTP GET action as only the source code is returned.
 

Qarboz

Well-known member
Could it be an obstacle that Google asks for consent to cookies before showing the translation on the web page? (I say this only for "intuition", I don't know anything about web languages...)
 

Endercraft

Moderator (& bug finder :D)
It may be too, but I believe the main cause is what @FrameXX said. It is true that there is loading when translating with Google translate.
 

Dimlos

Well-known member
DeepL API also has a free plan.
It requires registration and an AuthKey, but I will upload a sample macro.
 

Attachments

  • Macro.jpg
    Macro.jpg
    541.8 KB · Views: 12
  • DeepL_Translation.macro
    3.2 KB · Views: 6

getuxagig

New member
@Qarboz @Endercraft
Hmm, I see.

@Dimlos
Since It asks for a credit card and since I'm making this script work for other users mostly I'm pretty confident most of them wouldn't sign up to it using a credit card. But thanks for letting me know about it! Also thank you for the macro!

Thanks guys for tuning in!

It seems yandex translator API is the way to go for now, as I managed to get a more simplified request, using the minimal parameters:
1686391909417.png
and the reply was trimmed down to:
1686391945832.png

After more than 24 hours the id still works, although, issuing a new request from a new webpage, a different id is assigned. I've noticed a pattern in the id, so in the future, if the request gets denied, I'll try to randomly generate a new id based on the pattern.

One drawback of yandex is it doesn't autodetect what language is used as a source, or perhaps I'll have yet to figure out that too.

This is the setup used for Macrodroid to make the request work. Where the URL used is this one:
https://translate.yandex.net/api/v1...0-0&srv=tr-text&source_lang=de&target_lang=en

In case there's no way to use auto language detection, I'll make a prompt to pick the right source language. Or try to find other APIs. Or in case I won't find any translation APIs that work, I'll try to use a github repo like these ones:
https://github.com/731MY/google-translator
https://github.com/matheuss/google-translate-api/tree/master
, and use a service like replit.com to host any of the repos, then use replit's API to interact with the app using Macrodroid, as I don't want to host a server on my machine. Although, I think replit is not free for API access, so I might need to find something similar.

I know of this app hosted on replit that sorts youtube videos based on the oldest date:
https://replit.com/@rufifkfk/Youtube-sort-by-oldest

Where the source code can be found here:
https://replit.com/@rufifkfk/Youtube-sort-by-oldest#main.py

After more digging, I found out these sites have APIs in fact:
https://www.bing.com/translator
https://fanyi.baidu.com/
https://papago.naver.com/
, but they seem very difficult to use.

After more thinking, as an alternative to yandex API, I'll make use of the google translate app. I guess I'll switch to the google translate app based on the output of yandex.
 

Dimlos

Well-known member
I found a way to use google translate without api key using termux and python module.
I will upload the script and macros when I have time if requested.
 
Top