How do you make a vocabulary list that can be used for all projects?
How do you make a vocabulary list that can be used for all projects?
Hi Mao Okawa
There is not out of the box import/export function, although that would be desirable. As we are re-organizing our glossary, the word list function is getting quite important for us, so I wrote a little AHK script to import word pairs from an Excel sheet into Studio's word list.
This is far from perfect and I am not a proper programmer either - it's a crutch, but it works for me. I consider this as a band-aid until there is a proper import/export function.
It works like this: You have to have the project settings -> Word list window open and active, and you must have Excel running and the sheet with the word list open:
Field A1 must contain "Wrong Form" and field B1 must contain "Correct Form" - this is to prevent the macro from blindly copying values from whatever Excel sheet might be open by accident.
So you would organize your Word lists in Excel and copy them either into the general or into the language pair specific word list of your Studio project.
Daniel
PS: Here's the script (hey, it's my first proper AHK script):
#SingleInstance Force
#IfWinActive ahk_exe SDLTradosStudio.exe
#F7:: ;Windows Key + F7
ClipboardStore := ClipboardAll ;Store clipboard content, so that it can be used after the script termninated
WordPair := [] ;Array to store the wrong and correct word forms
if StudioCheck() { ;checks whether the Word List window of Studio's Project Settings is open and active
} else Exit
if ExcelCheck() { ;checks whether there is an open Excel sheet with correct column headings
} else Exit
if WordlistActivate() { ;activates the "Check word list" option
} else {
MsgBox, Failed to determine check box value
Exit
}
Sleep, 500
RowCounter := 2 ;set row 2 as starting point for word pairs - row 1 are the headings
Loop { ;reads word pairs from Excel and writes them into Studio's word list
WordPair := ReadValues(RowCounter) ;Read values from Excel sheet
WordPairCheck := CheckValues(WordPair[1], WordPair[2], WordPair[3])
if (WordPairCheck = 1) {
if WriteValues(WordPair[1], WordPair[2]) {
} else break
} else break
RowCounter := RowCounter + 1
}
SetTitleMatchMode, 3
WinActivate, ahk_exe SDLTradosStudio.exe ;Switch the focus back to Studio
MsgBox, WordlistCopy complete
Clipboard := ClipboardStore
return
/*
************* END OF MAIN CODE *********************
*/
StudioCheck() {
SetTitleMatchMode, RegEx
if WinActive("Project Settings.+") { ;is the project settings window open?
WinGetText, WordListOpenCheck ;grab text from open window
if InStr(WordListOpenCheck, "Word List") { ;Does this text contain "Word List"?
return 1
} else {
MsgBox, 16,, Word List Window not open.
return 0
}
}
}
ExcelCheck() {
SetTitleMatchMode, 3
if WinExist("ahk_exe EXCEL.EXE") { ;Checks whether Excel is running and a Word list is on the active sheet
CellA1Check := GetExcelCell("a",1)
if InStr(CellA1Check, "Wrong Form"){
}
else {
MsgBox, 16,, Content of cell A1 of the active Excel sheet is %CellA1Check%`nIt is expected to contain "Wrong Form".
return 0
}
CellB1Check := GetExcelCell("b",1)
if InStr(CellB1Check, "Correct Form"){
} else {
MsgBox, 16,, Content of cell B1 of the active Excel sheet is %CellB1Check%`nIt is expected to contain "Correct Form".
return 0
}
}
else {
MsgBox, 16,, No open Excel window found.
return 0
}
return 1
}
GetExcelCell(Col, Row) { ;returns the content of the specified Excel cell
SetTitleMatchMode, 3
WinActivate, ahk_exe EXCEL.EXE
Sleep, 100
Send, ^g
Sleep, 50
Send, %Col%
Sleep, 50
Send, %Row%
Sleep, 50
Send, {Enter}
Sleep, 50
Send, ^c
Sleep, 200
return Clipboard
}
WordlistActivate() { ;Checks whether the Word list is active and activates it if not.
SetTitleMatchMode, 3
WinActivate, ahk_exe SDLTradosStudio.exe
; ControlGet did not seem to find the "Check word list" checkbox, so I had to do this in a trial and error way...
Sleep, 500
Send, !w
Sleep, 100
Send, a
Sleep, 100
Send, ^a
Sleep, 100
Send, ^x
Sleep, 100
if InStr(Clipboard, "a") {
return 1
} else {
Send, !c
Sleep, 500
return 1
}
}
ReadValues(RowCounter) { ;returns an array with both word forms
SetTitleMatchMode, 3
WinActivate, ahk_exe EXCEL.EXE
Sleep, 100
Send, ^g
Sleep, 100
Send, a
Sleep, 100
Send, %RowCounter%
Sleep, 100
Send, {Enter}
Sleep, 100
Send, ^c
Sleep, 100
WrongWord:= StrReplace(Clipboard, "`r`n")
Send, {TAB}
Sleep, 300
Send, ^c
Sleep, 100
CorrectWord := StrReplace(Clipboard, "`r`n")
return [WrongWord, CorrectWord, RowCounter]
}
CheckValues(Wrong, Correct, Row) { ;return values 0= one field empty, 1=both fields have content, 2=both fields empty
If StrLen(Wrong) {
} else if StrLen(Correct) {
MsgBox, 16,,"Wrong Form" field empty in row %Row% of Excel sheet.
return 0
} else return 2
If StrLen(Correct) {
} else if StrLen(Wrong) {
MsgBox, 16,,"Correct Form" field empty in row %Row% of Excel sheet.
return 0
} else return 2
return 1
}
WriteValues(WrongForm, CorrectForm) {
SetTitleMatchMode, 3
WinActivate, ahk_exe SDLTradosStudio.exe ;Switch to Studio and enter Words into list
if StudioCheck() {
} else {
MsgBox, 16,,Could not activate Studio window to write Word list.
return 0
}
Sleep, 100
Send, !w
Sleep, 100
Send, %WrongForm%
Sleep, 100
Send, !o
Sleep, 100
Send, %CorrectForm%
Sleep, 100
Send, {Tab}
Sleep, 100
Send, {AppsKey}
Sleep, 100
Send, {Down}
Sleep, 50
Send, {Enter}
Sleep, 100
if WinActive("ahk_class #32770", "This item already exists.") { ;If there is a double value, click okay and proceed
Send, {Enter}
Sleep, 100
Send, !w
Sleep, 100
Send, ^a
Sleep, 100
Send, {DEL}
Sleep, 100
Send, !o
Sleep, 100
Send, ^a
Sleep, 100
Send, {DEL}
} else if WinActive("ahk_class #32770", "Fill all required values first.") { ;If there is a double value, click okay and proceed
Send, {Enter}
MsgBox, 16,, Sorry. Something went wrong.
return 0
}
return 1
}
Hi Mao Okawa
There is not out of the box import/export function, although that would be desirable. As we are re-organizing our glossary, the word list function is getting quite important for us, so I wrote a little AHK script to import word pairs from an Excel sheet into Studio's word list.
This is far from perfect and I am not a proper programmer either - it's a crutch, but it works for me. I consider this as a band-aid until there is a proper import/export function.
It works like this: You have to have the project settings -> Word list window open and active, and you must have Excel running and the sheet with the word list open:
Field A1 must contain "Wrong Form" and field B1 must contain "Correct Form" - this is to prevent the macro from blindly copying values from whatever Excel sheet might be open by accident.
So you would organize your Word lists in Excel and copy them either into the general or into the language pair specific word list of your Studio project.
Daniel
PS: Here's the script (hey, it's my first proper AHK script):
#SingleInstance Force
#IfWinActive ahk_exe SDLTradosStudio.exe
#F7:: ;Windows Key + F7
ClipboardStore := ClipboardAll ;Store clipboard content, so that it can be used after the script termninated
WordPair := [] ;Array to store the wrong and correct word forms
if StudioCheck() { ;checks whether the Word List window of Studio's Project Settings is open and active
} else Exit
if ExcelCheck() { ;checks whether there is an open Excel sheet with correct column headings
} else Exit
if WordlistActivate() { ;activates the "Check word list" option
} else {
MsgBox, Failed to determine check box value
Exit
}
Sleep, 500
RowCounter := 2 ;set row 2 as starting point for word pairs - row 1 are the headings
Loop { ;reads word pairs from Excel and writes them into Studio's word list
WordPair := ReadValues(RowCounter) ;Read values from Excel sheet
WordPairCheck := CheckValues(WordPair[1], WordPair[2], WordPair[3])
if (WordPairCheck = 1) {
if WriteValues(WordPair[1], WordPair[2]) {
} else break
} else break
RowCounter := RowCounter + 1
}
SetTitleMatchMode, 3
WinActivate, ahk_exe SDLTradosStudio.exe ;Switch the focus back to Studio
MsgBox, WordlistCopy complete
Clipboard := ClipboardStore
return
/*
************* END OF MAIN CODE *********************
*/
StudioCheck() {
SetTitleMatchMode, RegEx
if WinActive("Project Settings.+") { ;is the project settings window open?
WinGetText, WordListOpenCheck ;grab text from open window
if InStr(WordListOpenCheck, "Word List") { ;Does this text contain "Word List"?
return 1
} else {
MsgBox, 16,, Word List Window not open.
return 0
}
}
}
ExcelCheck() {
SetTitleMatchMode, 3
if WinExist("ahk_exe EXCEL.EXE") { ;Checks whether Excel is running and a Word list is on the active sheet
CellA1Check := GetExcelCell("a",1)
if InStr(CellA1Check, "Wrong Form"){
}
else {
MsgBox, 16,, Content of cell A1 of the active Excel sheet is %CellA1Check%`nIt is expected to contain "Wrong Form".
return 0
}
CellB1Check := GetExcelCell("b",1)
if InStr(CellB1Check, "Correct Form"){
} else {
MsgBox, 16,, Content of cell B1 of the active Excel sheet is %CellB1Check%`nIt is expected to contain "Correct Form".
return 0
}
}
else {
MsgBox, 16,, No open Excel window found.
return 0
}
return 1
}
GetExcelCell(Col, Row) { ;returns the content of the specified Excel cell
SetTitleMatchMode, 3
WinActivate, ahk_exe EXCEL.EXE
Sleep, 100
Send, ^g
Sleep, 50
Send, %Col%
Sleep, 50
Send, %Row%
Sleep, 50
Send, {Enter}
Sleep, 50
Send, ^c
Sleep, 200
return Clipboard
}
WordlistActivate() { ;Checks whether the Word list is active and activates it if not.
SetTitleMatchMode, 3
WinActivate, ahk_exe SDLTradosStudio.exe
; ControlGet did not seem to find the "Check word list" checkbox, so I had to do this in a trial and error way...
Sleep, 500
Send, !w
Sleep, 100
Send, a
Sleep, 100
Send, ^a
Sleep, 100
Send, ^x
Sleep, 100
if InStr(Clipboard, "a") {
return 1
} else {
Send, !c
Sleep, 500
return 1
}
}
ReadValues(RowCounter) { ;returns an array with both word forms
SetTitleMatchMode, 3
WinActivate, ahk_exe EXCEL.EXE
Sleep, 100
Send, ^g
Sleep, 100
Send, a
Sleep, 100
Send, %RowCounter%
Sleep, 100
Send, {Enter}
Sleep, 100
Send, ^c
Sleep, 100
WrongWord:= StrReplace(Clipboard, "`r`n")
Send, {TAB}
Sleep, 300
Send, ^c
Sleep, 100
CorrectWord := StrReplace(Clipboard, "`r`n")
return [WrongWord, CorrectWord, RowCounter]
}
CheckValues(Wrong, Correct, Row) { ;return values 0= one field empty, 1=both fields have content, 2=both fields empty
If StrLen(Wrong) {
} else if StrLen(Correct) {
MsgBox, 16,,"Wrong Form" field empty in row %Row% of Excel sheet.
return 0
} else return 2
If StrLen(Correct) {
} else if StrLen(Wrong) {
MsgBox, 16,,"Correct Form" field empty in row %Row% of Excel sheet.
return 0
} else return 2
return 1
}
WriteValues(WrongForm, CorrectForm) {
SetTitleMatchMode, 3
WinActivate, ahk_exe SDLTradosStudio.exe ;Switch to Studio and enter Words into list
if StudioCheck() {
} else {
MsgBox, 16,,Could not activate Studio window to write Word list.
return 0
}
Sleep, 100
Send, !w
Sleep, 100
Send, %WrongForm%
Sleep, 100
Send, !o
Sleep, 100
Send, %CorrectForm%
Sleep, 100
Send, {Tab}
Sleep, 100
Send, {AppsKey}
Sleep, 100
Send, {Down}
Sleep, 50
Send, {Enter}
Sleep, 100
if WinActive("ahk_class #32770", "This item already exists.") { ;If there is a double value, click okay and proceed
Send, {Enter}
Sleep, 100
Send, !w
Sleep, 100
Send, ^a
Sleep, 100
Send, {DEL}
Sleep, 100
Send, !o
Sleep, 100
Send, ^a
Sleep, 100
Send, {DEL}
} else if WinActive("ahk_class #32770", "Fill all required values first.") { ;If there is a double value, click okay and proceed
Send, {Enter}
MsgBox, 16,, Sorry. Something went wrong.
return 0
}
return 1
}