Donglai Lou (X) China Local time: 23: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 | | |