^!r::Reload ; Assign Alt-Ctr-R as a hotkey to restart the script.
#x:: ; Windows+X - Translate segment MemoQ, Across, Trados Studio with Google Translate
FileEncoding, utf-8
WinGetActiveTitle, Title
IfInString, Title, memoQ
{
Send ^+s
Sleep, 200
SendInput ^{F8}
Sleep, 300
SendInput ^a
Sleep, 300
SendInput ^c
Clipwait
Send ^c
Sleep, 300
Clipwait
Sleep, 200
}
IfInString, Title, Across
{
Send !{PgDn}
Sleep, 200
SendInput ^a
Sleep, 300
}
IfInString, Title, Trados Studio
{
Sleep, 300
Send ^{Ins}
Sleep, 200
SendInput ^a
Sleep, 300
}
SendInput ^c
Clipwait
Send ^c
Sleep, 300
Clipwait
Sleep, 300
Clipwait
Sleep, 300
searchtext := clipboard
;StringReplace, searchtext, searchtext, .%A_SPACE%, ._, All ;StringReplace, searchtext, searchtext, %A_SPACE%., _., All
;StringReplace, searchtext, searchtext, `;%A_SPACE%, `;_, All, ; `%5F - for underscore
;StringReplace, searchtext, searchtext, `.%A_SPACE%, `._, All ;Msgbox %searchtexturlencoded%
searchtexturlencoded := UriEncode(searchtext)
;searchtexturlencoded := URLEncoding(searchtext)
; StringReplace, searchtext, searchtext, %A_SPACE%&%A_SPACE%, `%26, All
; StringReplace, searchtext, searchtext, %A_SPACE%, +, All
Sleep, 300
RunWait, wget.exe -U "Mozilla/5.0 Chrome/62.0.3202.94" "http://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=de&dt=t&q=%searchtexturlencoded%" -O source.out.txt,, Hide
FileRead, targettext, source.out.txt ;Msgbox %targettext%
StringTrimLeft, targettext, targettext, 4
StringTrimRight, targettext, targettext, 73
quotes := ""","""
Loop, 4 ;MsgBox, Iteration number is %A_Index%.
{
addedvalue := (A_Index - 1)
textbreak = "`,null`,null`,%addedvalue%`]`,`[" ;MsgBox Textbreak %textbreak%
IfInString, targettext, %textbreak%
{
StringReplace, targettext, targettext, %textbreak%, ‡, All ;Msgbox targettext . %targettext%
}
}
occurences =
Loop, Parse, targettext, ‡
{
loopingtext = %A_LoopField% ;Msgbox Loopfield: %loopingtext%
StringLen, targetlength, loopingtext
StringGetPos, posghilimele, loopingtext, %quotes% ;MsgBox Poziţie glilimele %posghilimele% Msgbox Target length %targetlength%
StringLen, targetlength, loopingtext
StringTrimRight, occurence, loopingtext, (targetlength - posghilimele)
occurences .= occurence ;Msgbox occurence after add %occurences% ;occurences := occurences . occurence
}
StringReplace, occurences, occurences, ș, ş, All
StringReplace, occurences, occurences, Ș, Ş, All
StringReplace, occurences, occurences, ț, ţ, All
StringReplace, occurences, occurences, Ț, Ţ, All
StringReplace, occurences, occurences, %A_SPACE%._%A_SPACE%, .%A_SPACE%, All
StringReplace, occurences, occurences, `;%A_SPACE%_, `;%A_SPACE%, All
StringReplace, occurences, occurences, `;%A_SPACE%%A_SPACE%, `;%A_SPACE%, All
StringReplace, occurences, occurences, `._, `.%A_SPACE%, All
occurences := UnSlashUnicode(occurences)
Clipboard = %occurences% ;googleout := Clipboard
Send ^v
Reload
; IfInString, Title, memoQ {Send ^{Enter} ;Send ^+{Enter}Send !{Up}}
return
uriDecode(str) {
Loop
If RegExMatch(str, "i)(?<=%)[\da-f]{1,2}", hex)
StringReplace, str, str, `%%hex%, % Chr("0x" . hex), All
Else Break
return
, str
}
UriEncode(Uri, RE="[0-9A-Za-z]"){
VarSetCapacity(Var,StrPut(Uri,"UTF-8"),0),StrPut(Uri,&Var,"UTF-8")
While Code:=NumGet(Var,A_Index-1,"UChar")
Res.=(Chr:=Chr(Code))~=RE?Chr:Format("%{:02X}",Code)
return, Res
}
UnSlashUnicode(s) ; unslash unicode sequences like \u0026
{
rx = \\u([0-9a-fA-F]{4})
pos = 0
loop
{
pos := RegExMatch(s,rx,m,pos+1)
if (pos = 0)
break
StringReplace, s, s, %m%, % Chr("0x" . SubStr(m,3,4))
}
return, s
}
Showing posts with label AHK. Show all posts
Showing posts with label AHK. Show all posts
Sunday, February 16, 2020
Thursday, November 1, 2018
Toggle Keyboard Layout in Windows with AutoHotkey
Run AHK script and press Super+1 to switch keyboard layouts.
#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.
; This should be replaced by whatever your native language is. See
; http://msdn.microsoft.com/en-us/library/dd318693%28v=vs.85%29.aspx
; for the language identifiers list.
de := DllCall("LoadKeyboardLayout", "Str", "00010407", "Int", 1)
en := DllCall("LoadKeyboardLayout", "Str", "00010409", "Int", 1)
ro := DllCall("LoadKeyboardLayout", "Str", "00010418", "Int", 1)
#1::
w := DllCall("GetForegroundWindow")
pid := DllCall("GetWindowThreadProcessId", "UInt", w, "Ptr", 0)
l := DllCall("GetKeyboardLayout", "UInt", pid)
if (l = en)
{
PostMessage 0x50, 0, %ro%,, A
}
else if (l = de)
{
PostMessage 0x50, 0, %en%,, A
}
else
{
PostMessage 0x50, 0, %de%,, A
}
#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.
; This should be replaced by whatever your native language is. See
; http://msdn.microsoft.com/en-us/library/dd318693%28v=vs.85%29.aspx
; for the language identifiers list.
de := DllCall("LoadKeyboardLayout", "Str", "00010407", "Int", 1)
en := DllCall("LoadKeyboardLayout", "Str", "00010409", "Int", 1)
ro := DllCall("LoadKeyboardLayout", "Str", "00010418", "Int", 1)
#1::
w := DllCall("GetForegroundWindow")
pid := DllCall("GetWindowThreadProcessId", "UInt", w, "Ptr", 0)
l := DllCall("GetKeyboardLayout", "UInt", pid)
if (l = en)
{
PostMessage 0x50, 0, %ro%,, A
}
else if (l = de)
{
PostMessage 0x50, 0, %en%,, A
}
else
{
PostMessage 0x50, 0, %de%,, A
}
Labels:
AHK,
AutoHotKey,
English,
german,
Programming,
Romanian,
Tips / Tricks
Sunday, August 5, 2018
Autohotkey and Google Translate
Run Translation Program.ahk. A Messagebox will appear on every initial start. Just click ok to get rid of it. Now everytime you copy something a new Messagebox will apear with the translated text.
To close the program: First close all Messageboxes then press Control+j. This can be changed to whatever if you know your way around Autohotkey. Check Translate Program.ahk
Changing the language: Open Translate.ahk with any text edito of your choice and change "LangIn" and "LangOut" correspondingly. "LangIn" is the language of the original text and "LangOut" the language it is meant to be translated to.
You need to know the language codes. The Text is translated with Google Translator so expect some bad grammar and broken sentences, but for getting a basic understading of what is being said. Source: https://github.com/Pjer4/Translation-Program
Translation Program.ahk
| OnClipBoardChange: | |
| Loop |
| { |
| Run Translate.ahk |
| return |
| } |
| Numpad1:: |
|
Labels:
AHK,
AutoHotKey,
Machine Translation,
MT,
Neural Machine Translation
Saturday, July 28, 2018
Add tags in Trados with a single keystroke
This AHK script allows you to insert tags sequentially by pressing a single
key while ignoring placeables. This script uses the Left
Windows key.
The script assumes that the default Ctrl+Enter shortcut is used to
confirm segments. If a different shortcut is used, it needs to be
replaced accordingly on the last line of the script.
;Add tags with LWin key
n:=1
return
Lwin::
if (n = 1)
Send, ^!{Right}{Esc}{Right}
else
{
Send, {Ctrl Down}{Alt Down}{Right %n%}
Sleep 200
Send, {Ctrl Up}{Alt Up}{Esc}{Right}
}
n++ ; increment n
return
~^Enter::n := 1 ;script is reset with Confirm and Move to Next Segment shortcut, tilde is needed to pass through the original action for Ctrl+Enter
Source: https://community.sdl.com
;Add tags with LWin key
n:=1
return
Lwin::
if (n = 1)
Send, ^!{Right}{Esc}{Right}
else
{
Send, {Ctrl Down}{Alt Down}{Right %n%}
Sleep 200
Send, {Ctrl Up}{Alt Up}{Esc}{Right}
}
n++ ; increment n
return
~^Enter::n := 1 ;script is reset with Confirm and Move to Next Segment shortcut, tilde is needed to pass through the original action for Ctrl+Enter
Source: https://community.sdl.com
Labels:
AHK,
AutoHotKey,
Language,
Machine Translation,
macro,
Trados,
Traduceri,
Translation
Thursday, January 11, 2018
AHK Script to translate segment with Google Translate in Across
#NoEnv
SendMode Input
^!I::
Send ^a
Sleep, 500
Send ^c
ClipWait, 2
google_url:="http://translate.google.com/#de/ro/" clipboard
Run %google_url%
Sleep, 2000
MouseMove 966, 297 ; replace with default mouse position for the window
Send ^c
Sleep, 500
Send ^w ; close tab in Firefox
Sleep, 500
StringCaseSense On
StringReplace, clipboard, clipboard, ș, ş, All ; replace new with old diacritics, if needed
StringReplace, clipboard, clipboard, Ș, Ş, All
StringReplace, clipboard, clipboard, ț, ţ, All
StringReplace, clipboard, clipboard, Ț, Ţ, All
WinActivate Across Translator Premium Edition v6.3 7557_en ; replace with current Across version
Sleep, 500
Send ^v
return
SendMode Input
^!I::
Send ^a
Sleep, 500
Send ^c
ClipWait, 2
google_url:="http://translate.google.com/#de/ro/" clipboard
Run %google_url%
Sleep, 2000
MouseMove 966, 297 ; replace with default mouse position for the window
Send ^c
Sleep, 500
Send ^w ; close tab in Firefox
Sleep, 500
StringCaseSense On
StringReplace, clipboard, clipboard, ș, ş, All ; replace new with old diacritics, if needed
StringReplace, clipboard, clipboard, Ș, Ş, All
StringReplace, clipboard, clipboard, ț, ţ, All
StringReplace, clipboard, clipboard, Ț, Ţ, All
WinActivate Across Translator Premium Edition v6.3 7557_en ; replace with current Across version
Sleep, 500
Send ^v
return
Labels:
Across,
AHK,
AutoHotKey,
Tips / Tricks,
Translation
Subscribe to:
Posts (Atom)

