Home-made Google Translate plugin Thread poster: Donglai Lou (X)
| Donglai Lou (X) China Local time: 17:35 English to Chinese + ...
Hi everyone, I am excited to share with you a goodie (completely free, except google API) First of all, I would like to thank Jon Olds for writing a déjà vu plugin using autohotkey script. Inspired by GT4T, I altered the script so that the program works everywhere instead of in Deja Vu or MemoQ only. Before using this script you need to have Autohotkey (free) installed on your computer and buy a Google Translate API key. copy and paste the codes at the en... See more Hi everyone, I am excited to share with you a goodie (completely free, except google API) First of all, I would like to thank Jon Olds for writing a déjà vu plugin using autohotkey script. Inspired by GT4T, I altered the script so that the program works everywhere instead of in Deja Vu or MemoQ only. Before using this script you need to have Autohotkey (free) installed on your computer and buy a Google Translate API key. copy and paste the codes at the end of this post to a txt editor like Notepad. then save it with teh extension, ahk. when you run this script for the first time, you need to run it as an administrator. a popup will show prompting you to enter the language pair and google API. since the second time, run the script as a normal user. (to run the script, just right click the ahk file and the popup menu will show the option). when you come across a sentence or a segment you would like to google translate. select it and press ctrl+j, the selected text will be replaced by translation from Google. Instead of sending the whole segment to Google, you can send any part of a sentence and let machine translation work on that part only. Comparing with GT4T, it lacks other features like alternative suggestions and pre-translations using user defined glossary and I am still a fan of GT4T, specially its new pre-translation feature. I am crazily busy this month and might not be able to respond to any inquiry quickly. However if you take some time and look into the code, you might dig out a bit more functions. Good luck. ; ; Language: English ; Author: Jon Olds ; Modified by: Donglai Lou ; ; Requires Autohotkey_L ; Use Ctrl J key combination to translate any highlighted segments ; Use Windows-Shift-G key combination to switch translation engine (Google Translate or Microsoft Translate) #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. RegRead, langfrom, HKEY_LOCAL_MACHINE, SOFTWARE\GBingTrans, sourceLang RegRead, langto, HKEY_LOCAL_MACHINE, SOFTWARE\GBingTrans, targetLang RegRead, apikey, HKEY_LOCAL_MACHINE, SOFTWARE\GBingTrans, apiKey strdeja := % chr(68) . chr(233) . chr(106) . chr(224) ; Choose bing for Microsoft Translate or gtrans for Google Translate as default translation service serv := "bing" if (langfrom="") OR (langto="") OR (apikey="") or (A_IsAdmin) { Gui, Add, Text,, Source Language Gui, Add, Text,, Target Language Gui, Add, Text,, Google Translate Key Gui, Add, Edit, vSource ym ; The ym option starts a new column of controls. Gui, Add, Edit, vTarget Gui, Add, Edit, vAPIKey w300 Gui, Add, Button, default, OK ; The label ButtonOK (if it exists) will be run when the button is pressed. GuiControl,, Source, %langfrom% GuiControl,, Target, %langto% GuiControl,, APIKey, %apikey% Gui, Show,, Settings for G2BingTrans return ; End of auto-execute section. The script is idle until the user does something. } return GuiClose: ButtonOK: Gui, Submit ; Save the input from the user to each control's associated variable. if not A_IsAdmin { Msgbox, You need to run the application as administrator to change the settings (right-click on icon) ExitApp } RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, SOFTWARE\GBingTrans, sourceLang, %Source% RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, SOFTWARE\GBingTrans, targetLang, %Target% RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, SOFTWARE\GBingTrans, apiKey, %APIKey% Msgbox Settings recorded in registry - Please now run the script normally (without running as Administrator) ExitApp ^j:: clipboard = ; Start off empty to allow ClipWait to detect when the text has arrived. ; Collect the highlighted text Send ^c ClipWait ; Wait for the clipboard to contain text. ; copy clipboard text into var var = %clipboard% ; Get rid of codes var:= RegExReplace(var, "\{[\d]+\}", "") ; Sort out ampersand StringReplace, var, var, &, &, All pWHR := ComObjCreate("WinHttp.WinHttpRequest.5.1") ; CreateObject If (serv="bing") { sUrl := "http://api.microsofttranslator.com/v2/Http.svc/Translate?appId=74FE953EB48E1487E94F4BF9C425B6290FF2DA48&from=" . langfrom . "&to=" . langto . "&text=" . var } If (serv="gtrans") { sUrl := "https://www.googleapis.com/language/translate/v2?key=" . apikey . "&q=" . var . "&source=" . langfrom . "&target=" . langto } pWHR.Open("GET", sURL) pWHR.Send() sResponseText := pWHR.ResponseText If (serv="bing") { mk := instr(sResponseText, "/" . chr(34) . ">" ) fg := substr(sResponseText, mk+3) mh := instr(fg, "") ej := substr(fg, 1, mh-1) } If (serv="gtrans") { mk := instr(sResponseText, "translatedText") fg := substr(sResponseText, 18+mk) mh := instr(fg, chr(34)) ej := substr(fg, 1, mh-1) } clipboard = %ej% Send ^v pWHR :="" Return #+g:: if (serv="bing") { serv := "gtrans" Msgbox, Switched to Google Translate } Else { serv := "bing" Msgbox, Switched to Microsoft Translator } Return ▲ Collapse | | | Michael Beijer United Kingdom Local time: 10:35 Member (2009) Dutch to English + ...
Hi Donglai! Thanks for the cool script! I am just trying your script but can't get it to work yet. In what format do the language codes need to be written? for Dutch, e.g.: nl nl-NL NL etc. Michael | | | An intriguing question, | May 10, 2013 |
Michael. I like those problems. I opened the API of my CAT tool, with a lot of problems and unexpected unzipping, and I found out it doesn't contain any languageto/from coding. That makes sense of course, because you set those languages in the CAT tool, and they can vary. So I think you should only enter them in this piece of Donglai's code: sUrl := "https://www.googleapis.com/language/translate/v2?key=" . apikey . "&q=" . var . "&source=" . langfrom . "&target=" . langto ... See more Michael. I like those problems. I opened the API of my CAT tool, with a lot of problems and unexpected unzipping, and I found out it doesn't contain any languageto/from coding. That makes sense of course, because you set those languages in the CAT tool, and they can vary. So I think you should only enter them in this piece of Donglai's code: sUrl := "https://www.googleapis.com/language/translate/v2?key=" . apikey . "&q=" . var . "&source=" . langfrom . "&target=" . langto In your case, I think it should read: sUrl := "https://www.googleapis.com/language/translate/v2?key=" . apikey . "&q=" . var . "&source=" . nl . "&target=" . en I can't try it, as you know. Cheers, Hans
[Edited at 2013-05-10 08:14 GMT] ▲ Collapse | | | Michael Beijer United Kingdom Local time: 10:35 Member (2009) Dutch to English + ...
I tried what you suggested and no luck. I'll keep trying though! Michael | |
|
|
Jeff Whittaker United States Local time: 05:35 Spanish to English + ... Why do we need Google translate????? | May 10, 2013 |
As professional translators, I do not see how anyone would benefit from using Google translate, or am I missing something? | | | Michael Beijer United Kingdom Local time: 10:35 Member (2009) Dutch to English + ... just one more arrow in my quiver | May 10, 2013 |
Hi Jeff, I understand how you feel. I know that many people think it is highly unprofessional to use Google Translate or any other machine translation solution so let me try to explain how I use it myself. I translate in memoQ. I usually start with an empty segment and have Google Translate and Microsoft Translator translations of my source segment to my right in a little window. I might also see a fuzzy hit or two, from (my own) past translations, and a long list of te... See more Hi Jeff, I understand how you feel. I know that many people think it is highly unprofessional to use Google Translate or any other machine translation solution so let me try to explain how I use it myself. I translate in memoQ. I usually start with an empty segment and have Google Translate and Microsoft Translator translations of my source segment to my right in a little window. I might also see a fuzzy hit or two, from (my own) past translations, and a long list of term base hits with single terms and short phrases that I have collected over the years. I either type my translation into the target segment box or speak it in using Dragon Naturally Speaking and a desktop mic. When typing or speaking in my translation, I scan the results from Google Translate and Microsoft Translator and any fuzzy hits and term base hits. Google Translate is therefore only one cog in my complete workflow. That's how I use GT in my own work. Google has managed to design the best MT solution currently available. I think it would be a shame not to make use of that. Michael PS: Please note that I use the (paid) Google Translate API, which is currently built into memoQ and a number of other modern CAT tools. ▲ Collapse | | | BING variant that does offline translation? | Mar 15, 2014 |
Glad to encounter this kind of goodies but I have a question does this work with Bing ? I am interested in lots of translating while disconnected from the web and Bing offers that for a number of languages. Thank you and I appreciate this work. | | | To report site rules violations or get help, contact a site moderator: You can also contact site staff by submitting a support request » Home-made Google Translate plugin TM-Town | Manage your TMs and Terms ... and boost your translation business
Are you ready for something fresh in the industry? TM-Town is a unique new site for you -- the freelance translator -- to store, manage and share translation memories (TMs) and glossaries...and potentially meet new clients on the basis of your prior work.
More info » |
| Trados Business Manager Lite | Create customer quotes and invoices from within Trados Studio
Trados Business Manager Lite helps to simplify and speed up some of the daily tasks, such as invoicing and reporting, associated with running your freelance translation business.
More info » |
|
| | | | X Sign in to your ProZ.com account... | | | | | |