Using Google Translate to automate text translation

Post your working scripts, libraries and tools for AHK v1.1 and older
RussF
Posts: 1292
Joined: 05 Aug 2021, 06:36

Re: Using Google Translate to automate text translation

Post by RussF » 12 Oct 2023, 09:09

I have read posts on this forum where some have had the Google API block their IP after a certain number of hits, although I don't know the particulars of the algorithm that does that. It seems to vary between users.

I have not had that issue. My wife is a teacher who occasionally has bilingual students with non-English speaking parents. She puts out a weekly newsletter (created in MS Publisher) that then must be translated for them. It's usually a couple of pages with a couple dozen paragraphs.

Using @teadrinker's phenomenal function (thank you @teadrinker!), I wrote a script to do an in-place translation for her. After creating the English version and saving it, she goes back through to translate it. Highlighting a paragraph or section, she presses a hotkey (^t in this case) and the script copies the highlighted text to the clipboard. It then pumps it through the translator, putting the translated text back into the clipboard. Since the text in the document is still highlighted, the script simply needs to send a ^v to paste it, which replaces the highlighted text. Simply put: highlight, ^t, done. In over two years of using it, she has never mentioned a problem.

Unfortunately, your mileage may vary and I don't have a definitive answer for you.

Russ
User avatar
kunkel321
Posts: 1133
Joined: 30 Nov 2015, 21:19

Re: Using Google Translate to automate text translation

Post by kunkel321 » 12 Oct 2023, 10:37

RussF wrote:
12 Oct 2023, 09:09
[...] My wife is a teacher who occasionally has bilingual students with non-English speaking parents. [...]
I use my version (discussed here)
viewtopic.php?f=6&t=63835&start=160#p442360
for the same purpose. I'm not a teacher, but a school psychologist in a public school district. I got the idea from an app called 'Translator Boomerang' that was made by Mouser over at Donation Coder a long time ago. It was actually made as a novelty "toy" rather than a utility. It translated some text from English, to another language, then took the result and translated it back to English. I immediately saw the potential to use it as a tool to error-check translations. Basically, if the message gets lost in translation, then I re-word it and try again.

Mouser's tool also utilized Google translate, but it stopped working years ago. So when I saw Teadrinker's function a long time ago I remade the boomerang effect. Teadrinker helped me setup my adaptation. (Thanks Teadrinker! :ugeek: ) My setup uses a MsgBox to preview the versions of the prose though, so if you used it for multiple pages of text, it probably wouldn't fit on the MsgBox.

For what it's worth, I've never had problems with Google blocking me, but I only ever use it for a small number of translations.
ste(phen|ve) kunkel
teadrinker
Posts: 4366
Joined: 29 Mar 2015, 09:41
Contact:

Re: Using Google Translate to automate text translation

Post by teadrinker » 12 Oct 2023, 11:44

Guys, it's really nice to know that my script is being put to good use! I'm going to keep it up. :)
RussF
Posts: 1292
Joined: 05 Aug 2021, 06:36

Re: Using Google Translate to automate text translation

Post by RussF » 12 Oct 2023, 12:51

That's because your code rocks, @teadrinker!

We're not worthy!
We're not worthy!

:lol:

Russ
User avatar
Tykvesh
Posts: 7
Joined: 12 Jul 2023, 04:03

Re: Using Google Translate to automate text translation

Post by Tykvesh » 12 Oct 2023, 12:52

Thank you Teadrinker! It's a real life saver for live communications.

Do you know if the fetched package contains the detected source language (when it is set to automatic)?
teadrinker
Posts: 4366
Joined: 29 Mar 2015, 09:41
Contact:

Re: Using Google Translate to automate text translation

Post by teadrinker » 12 Oct 2023, 15:10

Tykvesh wrote: Do you know if the fetched package contains the detected source language (when it is set to automatic)?
Sorry, I missed your message.
Yes, the from variable in line 30
from := oJSON[2]
contains the determined source language.
User avatar
Tykvesh
Posts: 7
Joined: 12 Jul 2023, 04:03

Re: Using Google Translate to automate text translation

Post by Tykvesh » 12 Oct 2023, 16:51

You didn't miss it, I have someone reviewing my baby posts. :mrgreen:

I realized that I can just use this without any changes to your script!

Code: Select all

Locale := "auto"
GoogleTranslate(A_Clipboard, &Locale)
Post Reply

Return to “Scripts and Functions (v1)”