AHK Fast Translator

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
balawi28
Posts: 27
Joined: 09 Mar 2021, 13:53
Contact:

AHK Fast Translator

Post by balawi28 » 13 Jul 2023, 13:17

AHKFastTranslator is an AutoHotkey script that provides a fast and convenient way to translate text using Google Translate API.
It allows you to assign a hotkey that triggers the translation process, and the translated text can be displayed in a tooltip or a message box.

- No need to use a web browser to translate anymore!
- Translate text quickly without leaving your current application.
- Assign a custom hotkey to trigger the translation.
- Display the translated text in a tooltip or a message box.
- The application remembers its position on the screen as well as your settings.
- Copy the translation to the clipboard (optional).
- Run the script at startup (optional).
image.png
image.png (15.17 KiB) Viewed 3241 times
Source code and live demo:
https://github.com/balawi28/AHKFastTranslator

User avatar
V0RT3X
Posts: 241
Joined: 20 May 2023, 21:59
Contact:

Re: AHK Fast Translator

Post by V0RT3X » 13 Jul 2023, 20:13

WOW... Very Impressive!!
Works as advertised and love the customizing options.
Thank you much for this!!!
:clap:

User avatar
balawi28
Posts: 27
Joined: 09 Mar 2021, 13:53
Contact:

Re: AHK Fast Translator

Post by balawi28 » 15 Jul 2023, 05:46

@V0RT3X Thanks buddy, please keep me posted if you face any bugs.

User avatar
V0RT3X
Posts: 241
Joined: 20 May 2023, 21:59
Contact:

Re: AHK Fast Translator

Post by V0RT3X » 15 Jul 2023, 07:02

So far still loving this. Only wish I could come up with is for it to have a 'Detect language" option.
That is literally the only thing I'm finding that isn't included in the 133 languages. I didn't even realize we had that many...lol.

ozzii
Posts: 482
Joined: 30 Oct 2013, 06:04

Re: AHK Fast Translator

Post by ozzii » 16 Jul 2023, 04:06

Great script can be useful.
I like the ini in the stream of the file :clap:

For me, for exemple, a line under the language selection with 3 favorite languages will be easier for use when I need to switch between my most 3 used langages.
And like said V0RT3X a 'detect language' can be also useful.

But great script even without these.

User avatar
balawi28
Posts: 27
Joined: 09 Mar 2021, 13:53
Contact:

Re: AHK Fast Translator

Post by balawi28 » 17 Jul 2023, 14:02

@V0RT3X Check Git Hub, I have updated the script to include auto-language detection.

@ozzii Thank you, it is a good idea but a little bit hard to implement.

User avatar
V0RT3X
Posts: 241
Joined: 20 May 2023, 21:59
Contact:

Re: AHK Fast Translator

Post by V0RT3X » 18 Jul 2023, 20:10

Thank you! This will become part of my portables "toolbox"
I'll get to try it out this week at work. Should be fun.

User avatar
V0RT3X
Posts: 241
Joined: 20 May 2023, 21:59
Contact:

Re: AHK Fast Translator

Post by V0RT3X » 12 Aug 2023, 09:27

Hello @balawi28, just thought I'd drop you a note informing that this thing is still working great. I have yet to run into any 'bugs' or anything of the sort.
Hope you don't mind, but I've edited your script (for personal aesthetics) changing the drag method and added a couple small gLabel/ToolTip items.
Hover your mouse over and check out 'Knowledge' and also the header. Header is Google colors. Hope you approve!!
image.png
image.png (2.34 KiB) Viewed 2863 times
The 'Clipboard Only' radio button is just so I have the option of not using a message box or tooltip, but just what hits the clipboard for pasting.

image.png
image.png (18.31 KiB) Viewed 2863 times
Spoiler

User avatar
balawi28
Posts: 27
Joined: 09 Mar 2021, 13:53
Contact:

Re: AHK Fast Translator

Post by balawi28 » 14 Aug 2023, 05:49

Thanks for the update @V0RT3X, I don't mind at all, you can change the script and use it as you wish, I liked The UI changes (except the background color, lol), when I tested the new script on my computer (WIndows 10) I noticed some issues in the text/icons:
image.png
image.png (21.74 KiB) Viewed 2817 times
The new characters appear from special Unicode characters that you have used for spacing instead of regular space, also AHK replaced the emojis/icons with random text, you don't need to edit that if it works on your machine, just wanted to tell you about the issue in case you want to share the script
image.png
image.png (30.92 KiB) Viewed 2817 times
I liked the new dragging method and knowledge section also.

User avatar
V0RT3X
Posts: 241
Joined: 20 May 2023, 21:59
Contact:

Re: AHK Fast Translator

Post by V0RT3X » 14 Aug 2023, 06:49

Interesting, thank you for the reply. It appears that the white space characters I use for alignments don't always come out as white space. I am also using Windows 10 64-bit so I'm surprised we are seeing things differently. Lesson learned, I'll have to rethink my use of those characters. I need to redo some stuff anyhow since my attempt to add in the 'Clipboard' radio button broke that section. I know it is something simple with the line "GuiControl,, % outputMethod...", but I don't fully understand that one yet so I'll be putting it back the way you have it. Glad you liked the Knowledge section, a small tribute to your awesome script. And I agree on the coloring. LOL. I'll be changing that eventually too. This was just easier on my aging eyes than white while figuring out how I was wanting to arrange everything.
Thank you once again for this great script!!!

RussF
Posts: 1285
Joined: 05 Aug 2021, 06:36

Re: AHK Fast Translator

Post by RussF » 14 Aug 2023, 08:54

Nice implementation and great ad-hoc translator. I particularly like the easy way to switch languages. Well done!

A couple of years ago, I adapted @teadrinker's code found here to make a utility for my wife. She teaches kindergarten and often has students with non-english-speaking parents, so she must translate her weekly newsletters for them. Since she is usually translating entire paragraphs at once, I wrote it so that wherever she is editing, she just highlights the text she wants translated. The hotkey then copies the text to the clipboard, pumps it through the translator and then replaces the text with the translated version. Since the text was still highlighted, a simple ^v paste in the code is all that's required. She can usually translate an entire two page newsletter in a couple of minutes.

I only mention this because you may want to incorporate a feature to do an in-place translation like that without having to copy the text, activate the gui, paste the text into the edit box, translate, close the msgbox, go back to the application and finally paste the translated text where you want it. Instead - highlight, hotkey, done. The gui is nice to select languages and could be activated with a separate hotkey.

Just my thoughts to possibly enhance an already great script.

Russ

User avatar
V0RT3X
Posts: 241
Joined: 20 May 2023, 21:59
Contact:

Re: AHK Fast Translator

Post by V0RT3X » 01 Sep 2023, 09:02

Finally was able to get this working correctly after changing the aesthetics to personal preferences and it still works awesomely. Once again, many thanks @balawi28!!
I am attempting the idea by @RussF to allow for inline translation of highlighted editable text also. I had an old script copy that does this on its own quite well, at least for my needs.
I am having trouble meshing the two scripts together however and am hoping someone can spot my 'URI Encode issue'. The 1st script is the quick inline version that swaps editable highlighted text. Wish I could find the original posting.
Spoiler

And my edited version of this AHK-Fast-Translator with the Inline version added in. I currently have it commented out and made easy to find with big blockish type arrows (๐Ÿกฐ)...
All I have done after recreating the Fast Translator is add a gLabel button, Insert the Inline code, and then had to add the Google Translate Function I found from @teadrinker found at...
viewtopic.php?f=6&t=63835#p273621. And now I have the issue of...
"Line Text: URIEncode(str, encoding := "UTF-8")"
"Error: Duplicate function definition."
Unfortunately I am only finding that mention once in the script.
Spoiler

image.png
image.png (247 KiB) Viewed 2488 times

And just for kicks, here is my working updated aesthetics version...

gregster
Posts: 9073
Joined: 30 Sep 2013, 06:48

Re: AHK Fast Translator

Post by gregster » 01 Sep 2023, 11:09

V0RT3X wrote: โ†‘
01 Sep 2023, 09:02
viewtopic.php?f=6&t=63835#p273621. And now I have the issue of...
"Line Text: URIEncode(str, encoding := "UTF-8")"
"Error: Duplicate function definition."
Unfortunately I am only finding that mention once in the script.
In line 512, a function named URIEncode already gets defined. Parameters are different than in the second instance - haven't looked closer. Nevertheless, the second one would be a duplicate function definition. If they are different and you need both, you could rename one to URIEncode2 - but obviously you would need also to change the calls to that function...

User avatar
V0RT3X
Posts: 241
Joined: 20 May 2023, 21:59
Contact:

Re: AHK Fast Translator

Post by V0RT3X » 02 Sep 2023, 08:51

Thank you @gregster, the renaming did the trick.
Original idea was to click a button to allow for translating editable highlighted text, but realized a button would be pointless versus just simply hitting a hotkey when this script is active.
Other than some rearrangement, a couple add-ons, and color changes, no actual real changes have been done to @balawi28's original as it works perfect as is.

Original in English..............So unless this is translating incorrectly, I believe this is a wrap for me.
Translated to German..........Wenn dies also nicht falsch รผbersetzt wird, glaube ich, dass dies ein Wrap fรผr mich ist.
Translated back to English.....So unless this is mistranslated, I believe this is a wrap for me. <-- Slight alteration of original...

I would love for someone to test this and see if I broke anything this time and for those fluent in both English and German, if the translations are at least close to accurate.

Spoiler

image.png
image.png (57.64 KiB) Viewed 2372 times

BritScar
Posts: 1
Joined: 11 Sep 2023, 09:41

Re: AHK Fast Translator

Post by BritScar » 11 Sep 2023, 09:48

Hi this seems like a wonderful tool.
However, it is written in AHK v1.x
It does not work in the latest version of AHK v 2.x
I was wondering if you have 2.x version?
If not I will try and update myself! :)
Thanks

User avatar
ArkuS
Posts: 14
Joined: 29 Nov 2019, 22:54

Re: AHK Fast Translator

Post by ArkuS » 28 Apr 2024, 20:53

@V0RT3X How does this gui script work to bypass translation limits? When I only use the function itself
MsgBox, % GoogleTranslate("Hello, World", "en", "pl")
After a while, the translation is blocked, and the gui version still works. Do you know how to do it without GUI?

Post Reply

Return to โ€œScripts and Functions (v1)โ€