; Released under the GNU General Public License version 3+ by J2897.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
;#Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
FileEncoding UTF-8 ; Converts text from files into Unicode format.
; Typing "{gt" will launch Google Translate.
; Typing "{np" will launch Naver Papago.
; Anything you type between curly braces will be automatically translated.
; The closing curly brace is what triggers the action.
; You need a username and password to use this service...
; https://console.bluemix.net/docs/services/language-translator/getting-started.html
; Other requirements...
; 1. curl: https://curl.haxx.se/download.html
; 2. JQ: https://stedolan.github.io/jq/download/
; 3. AutoHotkey v1.1.30.00: https://autohotkey.com/download/
; Note that, if a Spell Checker changes your words, those changes will not be recorded.
LANGUAGES := "en-ko" ; Translate from and to: https://console.bluemix.net/docs/services/language-translator/identifiable-languages.html
USERNAME := "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
PASSWORD := "XXXXXXXXXXXX"
API := "https://gateway.watsonplatform.net/language-translator/api/v3/translate?version=2018-05-01"
IBM_TRANSLATION_JSON := A_Temp "\IBM_Watson.json"
IBM_TRANSLATION_TXT := A_Temp "\IBM_Watson.txt"
CURL_EXE := "C:\Users\" A_UserName "\Programs\curl\bin\curl.exe"
JQ_EXE := "C:\Users\" A_UserName "\Programs\jq\jq-win32.exe"
MsgBox IBM Watson Language Translator AutoHotkey interface loaded.
~{::
Input, UserInput, V T60 L400 C, {}}, np,gt
if (ErrorLevel = "Max") {
MsgBox, You entered "%UserInput%", which is the maximum length of text.
return
}
if (ErrorLevel = "Timeout") {
MsgBox, You entered "%UserInput%" at which time the input timed out.
return
}
if (ErrorLevel = "NewInput")
return
If InStr(ErrorLevel, "EndKey:") {
RunWait, cmd /c "%CURL_EXE% --user %USERNAME%:%PASSWORD% --request POST --header "Content-Type: application/json" --data "{\"text\": [\"%UserInput%\"]`, \"model_id\":\"%LANGUAGES%\"}" %API% >%IBM_TRANSLATION_JSON%"
RunWait, cmd /c "type %IBM_TRANSLATION_JSON% | %JQ_EXE% -j .translations[].translation >%IBM_TRANSLATION_TXT%"
FileReadLine, FF, %IBM_TRANSLATION_TXT%, 1
UILengh := StrLen(UserInput) + 2
Send, {backspace %UILengh%}{Text}%FF%
clipboard = %FF%
return
}
if (UserInput = "np") {
Send, {backspace 3}
Run, https://papago.naver.com
}
else if (UserInput = "gt") {
Send, {backspace 3}
Run, http://translate.google.com
}
return
; Reload after saving (CTRL+S).
#ifwinactive, *C:\Users\John\Code\AHK\TranslatorIBM.ahk - Notepad++
~^s::
Send, ^s
Reload
return
Comments
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎