Get and insert synonyms from Microsoft Word

Hi everyone!

It has been already discussed here:  synonyms - like in MS Word
Now based on the post of Jack Dunning mentioned on the link above, the following AutoHotkey script grabs synonyms from Microsoft Word application. Then it’ll show a pop-up menu with the available meaning-synonyms and then insert the selected synonym (right submenu) in Trados (see figure below). Only synonyms (right submenu) are clickable.

Screenshot of Trados Studio showing a pop-up menu with Spanish synonyms for a selected word. The right submenu with synonyms is clickable.

Synonyms will be picked based on the top language set on File > Options > Language > Office authoring languages and proofing (Spanish [Spain] in my particular case. The proofing package must be installed in order to use it):

Screenshot of Microsoft Word Options dialog box highlighting the 'Office authoring languages and proofing' section with Spanish (Spain) set as preferred.

This is the AutoHotkey script:

;-------------------------------------------------
; Search for synonyms in Trados Studio using Microsoft Word app.
; Ensure Microsoft Word is running (otherwise, the script will run it for you).
; Select the word in Trados Studio Editor.
; Use the shortcut is SHIFT+F7 (the same as in Word)
; In the pop-up menu first select the meaning and then the synonym.
; The synonym selected will be inserted on the Target segment.
; learn.microsoft.com/.../word.application.synonyminfo
; learn.microsoft.com/.../word.synonyminfo.synonymlist
;------------------------------------------------
#IfWinActive ahk_exe SDLTradosStudio.exe
+F7::
    Send ^c
    if StrLen(A_Clipboard)
        SynonymsWord()
return
#IfWinActive
    
    
SynonymsWord(sel := "")
{
Global leadingSpace
Global trailingSpace
    Try
        oWord := ComObjActive("Word.Application")
    catch
    {
        Run, WinWord, , Min
        Loop
        {
            Sleep 200
            try
                oWord := ComObjActive("Word.Application")
            if (A_index > 60)
            {
                ME("Microsoft Word is not installed and no synonyms can be retrieved from Word.")
                return
            }
        } Until oWord!=""
    }
    
    if (sel = "")
        sel := A_Clipboard
    if (RegexMatch(sel, "^\s"))
        leadingSpace := SubStr(sel, 1, 1)
    else
        leadingSpace := ""
    if (RegexMatch(sel, "\s$"))
        trailingSpace := SubStr(sel, 0)
    else
        trailingSpace := ""
    sel := RegExReplace(sel, "^\s+") ; Remove leading spaces
    sel := RegExReplace(sel, "\s+$") ; Remove trailing spaces
    
    nMeanings := oWord.SynonymInfo(sel).MeaningCount
    meanings := oWord.SynonymInfo(sel).MeaningList
    StringUpper, selUpper, sel
    
    Menu, MenuSynonyms, add, %selUpper%, Nothing, +Radio
    Menu, MenuSynonyms, check, %selUpper%
    Menu, MenuSynonyms, default, %selUpper%
    Loop % nMeanings
    {
        try
            meaning := meanings[A_Index]
        catch
            continue
        
        nMeaning := A_Index
        mySubmenu := "MenuMeanings" nMeaning
        
        synonyms := oWord.SynonymInfo(sel).SynonymList(A_Index)
        max := synonyms.MaxIndex()
        Loop % max
        {
            synonym := synonyms[A_Index]
            Menu, %mySubmenu%, add, %synonym%, SynonymAction
        }
        Menu, MenuSynonyms, add, %meaning%, :%mySubmenu%
    }
    
    if (!nMeanings)
        Menu, MenuSynonyms, add, No synonyms from Word!, Nothing
    Menu, MenuSynonyms, Show
    
    Menu, MenuSynonyms, DeleteAll
    Loop
    {
        mySubmenu := "Meanings" A_Index
        try
            Menu, %mySubmenu%, Delete
        catch
            Break
    }
}

SynonymAction()
{
Global leadingSpace
Global trailingSpace
    SendRaw % leadingSpace A_ThisMenuItem trailingSpace
}


Nothing()
{
    
}

  • The script works not only in Trados Studio Editor, but also in Translation Memories, etc…
  • The out-of-the-box script works only in Trados Studio, but it can work also in other applications. Don’t hesitate to edit the script to suit your needs.
  • In case you are wondering if it’s possible to select the proofing language automatically based on the target language of the Studio project, yes, I think it is, but I leave to RWS to publish an app with this feature.

Enjoy!



Generated Image Alt-Text
[edited by: Trados AI at 4:32 AM (GMT 0) on 5 Mar 2024]
emoji
Parents Reply Children
No Data