Switch to Target Language After Adding Files to a Project

I wrote the script below to automatically switch to the target language (first in the Dropdown list, so it works great for bilingual projects) after preparing files newly added to an existing project.

After loading the script, you don't need to do anything else, the script will be triggered when you click OK in the Batch Processing window after completing your file preparation, switching to the target language.

Tip: I've noticed that the name of the control (WindowsForms10.COMBOBOX.app.0.29531c8_r9_ad14) is different between my desktop and laptop computers, so you may want to check yours and make the appropriate changes if the script doesn't work on your system.

;–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-

;Automatically switch to target language after preparing files

;–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-

 

#IfWinActive ahk_exe SDLTradosStudio.exe


~LButton::
IfWinExist, Batch Processing

{

WinWaitClose, Batch Processing

Sleep, 1000
Control, Choose, 2, WindowsForms10.COMBOBOX.app.0.29531c8_r9_ad14, ahk_class WindowsForms10.Window.8.app.0.29531c8_r9_ad1 ; Selects option 2
}

Return

  • An old thread, but anyway I wanted to show how I change languages in the FILE View.

    #IfWinActive ahk_exe SDLTradosStudio.exe
    ; ----------------------------------
    ; Change language in FILE View
    ; ----------------------------------
    XButton1::
    XButton2::
        DetectHiddenText, Off
        WinGetText, ALLTEXT, A
        MouseGetPos, x, y ; Starting position of the mouse    
        ; Mouse in File View
        if (InStr(ALLTEXT,"Carpetas de proyecto") or InStr(ALLTEXT,"Project folders"))
        {
            ChangeLanguage()
            MouseMove, x, y    ; mouse pointer to starting coordinates
        }
    return

    ChangeLanguage()
    {
        static UpDown
        
        CoordMode, Mouse, Client
        Click, 92, 202 ; Language Listbox coordinates
        Sleep, 200
        
        UpDown := !UpDown
        if UpDown
            SendInput {Down}{Enter} ; Language down
        else
            SendInput {Up}{Enter} ; Language up
    }

    #IfWinActive

     

    Notes:

    • The script works in any version of Trados Studio, but only in English and Spanish user interfaces. If you work with another UI, just edit the line with InStr function to your convenience.
    • For simplicity, this script uses the 4th and 5th mouse buttons (back and forth wheel buttons), but you can also add the following hotkeys:
      ^WheelDown:: ; CTRL + WheelDown
      ^WheelUp:: ; CTRL + WheelUp
      PGUP:: ; Page up
      PGDN:: ; Page Down
      To the shown hotkeys:
      XButton1::
      XButton2::
  • Hi Nora,

    The script does not seem to be working for me. When I try and reload the script, I get an error :
    Line Text: ~LButton
    Error: Duplicate hotkey.
    Any idea why this is happening.
    Cheers,
    Olivier Den Hartigh
  • Hi Olivier,
    I guess that you are adding Nora’ script to yours, right? In this case, the reason of the error is that you already had one script with the same hotkey (LButton) and that’s not possible in AutoHotkey.
  • Thank you for your help, Jesus. My file does contains several scripts, with one "!LButton::" instruction. Can "LButton" be replaced in Nora's script?
  • Hi Olivier,

    Yes, you can change it to any other hotkey, however, the way the script works is that you don't really need to do anything different from the way you usually prepare your files, as the last step in the file preparation process, a left click (LButton) on the OK button of the last window also triggers the script to switch to the target language. Using a different hotkey might require a different script.

    Is there a way of limiting the operation of this hotkey to an instance when the Batch Processing window is active to prevent conflicts with other uses of the same hotkey? Maybe by placing an "IfWinExist" line right before the hotkey?
  • Jesus Prieto said:

    An old thread, but anyway I wanted to show how I change languages in the FILE View.

     

    Hi Jesús,

    I finally had a chance to have a play with this, and just wanted to come back and say that it's brilliant! Thank you for this, I hope more users discover and use it.

  • Yes, Nora:

    I use smae hotkeys in several places inside Trados Studio, but as you said, there must be a mechanism to split the scripts. I don't know if there are more, but I use the following 3 ways:

    • WinGetTitle (to grab de name of the active window title)
    WinGetTitle, title, A
    If title="Batch Processing
    {
       ; your code here
    }
    • MouseGetPos (to grab de name of the control where the mouse is on). I use the Window Spy tool to know the name of the needed control.
    MouseGetPos, , , , myControl

    I only use it in a couple of places inside Trados Studio, as control names keep changing ramdomly). Anyway, I hope I have time and post some scripts I use everyday.

    • WinGetText (to grab the visible/all text in the window). Useful to know if I'm in a particular view and the language of the user interface (I keep swapping Spanish and English UI).
    DetectHiddenText, On ; ON = WHOLE text — OFF = visible text
    WinGetText, textALLTEXT, A
    if InStr(textALLTEXT,"Incluir subcarpetas") ; Spanish
            Language := "ES"
    if InStr(textALLTEXT,"Include subfolders") ; English
            Language := "EN"
  • That's excellent, thank you for sharing, Jesús!