www.multilingual.ch - English translations & proofreading - WWW Search Interfaces for Translators
Machine translation macros for translators

 


The macros below work in Word 97

 

Machine translation macro no. 1
Machine translation macro no. 2

 

Once you have installed these macros, you will need to add a macro button in your toolbar or in your right-click menu to run the macro.

 

 

Machine translation macro no. 1

What the macro does

This macro automatically searches and replaces terms in your source document. It works in conjunction with a previously compiled list of bilingual terminology and is especially useful for ensuring consistency in technical translations.

NOTE:
- This macro is case sensitive.

- To prevent problems with accents, save your .txt file with Unicode encoding.
- I recommend that you create a different word list for each client or at least for each subject area.
- Place phrases before single words. Why? Imagine your list contained the word "acqua" (to be replaced with with "water") followed by "acqua potabile" (to be replaced with "drinking water"). Since the search-and-replace macro works from the top of your word list down, all occurrences of "water" will be replaced first, but then the phrase "acqua potabile" will no longer be found! Before adding a phrase to your terminology list, always make sure that you place it before any occurrences of the individual workds that compose it.
- Place plurals before singulars ("compressors" before "compressor") (same reason as above), or, more precisely, any similar terms with extra letters: e.g. "necessario" must come before "necessari".
- You could create a separate list for general (everyday) words (the, is, of etc.), which your could use for all clients. Again, remember: phrases before single words. If necessary, place one space before and one after the word (e.g. " la ") to prevent it being replaced elsewhere (e.g. in "ballare")
- If you would like to use this macro in combination with a Translation Memory programme, you will first need to open translation units (TUs) for all sentences in your text (so that the text in the source language part of the TU is the same as the text in the target language part of the TU), then hide all hidden text (Tools/Options/...deselect "Hidden text"), and then run the macro...

NOTE: This macro is best used with Translation Memory programmes that update the TM database when you make changes to a TU, rather than with those programmes that create an additional TU each time.

 

How to prepare your list of terminology

To use this macro you will need to have created a text file containing a list of bilingual terminology in the following format:

     pressure, pressione
     electrical systems, sistemi elettrici
     electrical system, sistema elettrico
     measure the voltage, misurare la tensione
     voltage, tensione
     make sure that, controllare attentamente che

(i.e. source language term, target language term)

NOTE:
- Each line must end with a carriage return (press the ENTER key);
- One space after the comma;

- Phrases before single words;
- Plurals before singulars etc.
- Leave only one carriage return at the very end of your text file.

Once you have created your list of terminology, save it under C:/TERMINOLOGY/ and give it the ending ".dic". (If you wish to save it somewhere else, you will need to make the necessary changes in the code below: search for "C:"...)

Examples of names for lists:
en-it_technical_phrases.dic
en-it_technical_words.dic
en-it_general_phrases.dic
en-it_general_words.dic

 

How to set up the macro

1. Select and copy the text of the macro shown below: Copy only the material that appears between the lines of asterisks; DO NOT copy extra blank lines or the asterisks themselves.

**********cut here (do not include this line) **********
Dim FileName As String
Dim SetCase, SetWhole, SetWild As Boolean
Dim allwords, dword, eword As String
SetCase = True
SetWhole = True
SetWild = False
ChangeFileOpenDirectory "C:\TERMINOLOGY\"
With Dialogs(wdDialogFileOpen)
.Name = "*.dic"
If .Display = -1 Then
FileName = .Name
Call DoTrans(FileName, SetCase, SetWhole, SetWild)
End If
End With
End Sub
Sub DoTrans(fname, mcase, mwhole, mwild)
Dim Pos1 As Long
If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdNormalView
Else
ActiveWindow.View.Type = wdNormalView
End If
Open fname For Input As #10 Len = 32767
Do While Not EOF(10)
Line Input #10, allwords
Pos1 = InStr(allwords, ", ")
dword = Left(allwords, Pos1 - 1)
eword = Right(allwords, Len(allwords) - Pos1 - 1)
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = dword
.Replacement.Text = eword
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = mcase
.MatchWholeWord = mwhole
.MatchWildcards = mwild
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Loop
Close #10

**********cut here (do not include this line) **********

2. In the menu bar at the top of your window in Word, click on the Tools menu. Click on Macro, then on Macros in the sub-menu.

3. The Macros dialog box will open. Type the name "TranslateTerms" for the macro in the "Macro name:" field.

4. Click the Create button.

5. A window titled "Microsoft Visual Basic – Normal – [New Macros (Code)]" will open. In the window that appears, find the line of text that reads: Macro created [Today’s Date] by [Your Name]

6. Paste the macro lines that you copied in Step 1 into the Visual Basic window, at the spot where the input cursor is blinking.

7. Save your macro by clicking the Save button (diskette icon) on the toolbar.

8. Close the whole Visual Basic window. Your macro is now installed.

9. Add a macro button in your toolbar or in your right-click menu to run the macro.

 

How to run the macro

Open the Word document that you have to translate, click on the macro button. When prompted, open the list of terminology that you wish to use.

 

Machine translation macro no. 2 (in French)

What the macro does

Same procedure as above but different code:

**********cut here (do not include this line) **********

ReDim Liste1__$(WordBasic.CountWindows() - 1) ' Liste des documents disponibles
ReDim Liste2__$(WordBasic.CountWindows() - 1) ' Liste des documents disponibles
Dim ChoixDoc1$ ' Document source
Dim ChoixDoc2$ ' Document cible
Dim TrouvePhrase ' La phrase cherchée est trouvé
Dim A$ ' Phrase du document source
Dim b$ ' Phrase du document cible
Dim i ' Compteur
Dim x ' Valeur de retour boîte de dialogue

' Rempli les deux listes avec les documents disponibles
For i = 1 To WordBasic.CountWindows()
Liste1__$(i - 1) = WordBasic.[WindowName$](i)
Liste2__$(i - 1) = WordBasic.[WindowName$](i)
Next

' Déclaration de la première boîte de dialogue
WordBasic.BeginDialog 644, 126, "Choix des documents"
WordBasic.Text 16, 14, 65, 13, "Source :", "Texte1"
WordBasic.Text 16, 49, 49, 13, "Cible :", "Texte2"
WordBasic.DropListBox 165, 16, 452, 30, Liste1__$(), "ListeDéroul1"
WordBasic.DropListBox 165, 51, 452, 30, Liste2__$(), "ListeDéroul2"
WordBasic.OKButton 217, 90, 88, 21
WordBasic.CancelButton 339, 90, 88, 21
WordBasic.EndDialog
Dim dlg As Object: Set dlg = WordBasic.CurValues.UserDialog

ChoixDoc:

' Affichage de la boîte de dialogue
x = WordBasic.Dialog.UserDialog(dlg, -1)

' Récuperation des erreurs
' On Error Goto Erreur

' Si l'utilisateur a cliquer sur le boutton OK alors
If x = -1 Then
' Affectation du document source
ChoixDoc1$ = Liste1__$(dlg.ListeDéroul1)

' Affectation du document cible
ChoixDoc2$ = Liste2__$(dlg.ListeDéroul2)

' Si le document source est différant du document cible alors
If ChoixDoc1$ <> ChoixDoc2$ Then
WordBasic.WindowArrangeAll

' Déclaration de la boîte de dialogue de confirmation
WordBasic.BeginDialog 153, 123, 411, 119, "Confirmation"
WordBasic.Text 10, 6, 382, 73, "Remplacer les phrases du document : <" + ChoixDoc1$ + "> dans le document : <" + ChoixDoc2$ + ">", "Texte1"
WordBasic.OKButton 88, 89, 88, 21
WordBasic.CancelButton 233, 89, 88, 21
WordBasic.EndDialog
Set dlg = WordBasic.CurValues.UserDialog
Set dlg = WordBasic.CurValues.UserDialog

' Affichage de la boîte de dialogue de confirmation
x = WordBasic.Dialog.UserDialog(dlg, -1)

' Si l'utilisateur clique su le boutton OK alors
If x = -1 Then
' Activer document source
WordBasic.Activate ChoixDoc1$
' Positionner au début du document source
WordBasic.StartOfColumn 0
WordBasic.StartOfRow 0
' Tant que la fin du document n'est pas atteinte faire...
' Enlever toute sélection préalable
If WordBasic.SelType() = 2 Then WordBasic.SelType 1
WordBasic.StartOfRow
' Sélectionner la phrase courante
WordBasic.SelectCurSentence
' Affectation de la phrase courante dans a$
A$ = WordBasic.[Selection$]()
While WordBasic.AtEndOfDocument() = 0 And WordBasic.[RTrim$](A$) <> ""
' Phrase suivante
WordBasic.NextCell
WordBasic.SelectCurSentence
b$ = WordBasic.[Selection$]()
' Activer document cible
WordBasic.Activate ChoixDoc2$
' Positionner au début du document cible
WordBasic.StartOfDocument
' Enlever toute sélection préalable
If WordBasic.SelType() = 2 Then WordBasic.SelType 1
WordBasic.EditReplace Find:=A$, Replace:=b$, MatchCase:=0, WholeWord:=1, ReplaceAll:=1, Format:=1
' Activer document source
WordBasic.Activate ChoixDoc1$
WordBasic.NextCell
' Enlever toute sélection préalable
If WordBasic.SelType() = 2 Then WordBasic.SelType 1
WordBasic.StartOfRow
' Sélectionner la phrase courante
WordBasic.SelectCurSentence
' Affectation de la phrase courante dans a$
A$ = WordBasic.[Selection$]()
Wend
' Activer document cible
WordBasic.Activate ChoixDoc2$
' Positionnement au début du document cible
WordBasic.StartOfDocument
' Affichage du message de fin de traitement
WordBasic.MsgBox "Fin du traitement..."
End If
Else
' Affichage du message
WordBasic.MsgBox "Attention le document source et le document cible ne peuvent pas être les mêmes..."
' Retour à la boîte de dialogue de sélection du document source
' et du document cible
GoTo ChoixDoc
End If
End If
' Fin sans erreurs
GoTo Fin

' Traitement de l'erreur par l'affichage d'un message
Erreur:
WordBasic.MsgBox "Attention mauvais paramètres..."

Fin:

**********cut here (do not include this line) **********

Add a macro button in your toolbar or in your right-click menu to run the macro.

 

NOTE:
- Source and target documents are Word files (.doc);
- Format of source document: a list of terminology in a table with two columns (source language terms in column 1, target language terms in column 2);
- Format of target document: any format (text, list, table etc.);
- Each cell in the table may contain a word or phrase;
- No carriage return at the end of each word/phrase;
- No text outside the table;
- This macro is case sensitive ("Open" is not considered the same as "open") and form sensitive (will not replace specially formatted text).

 

How to run the macro

1. Open your source document (list of terms) and your target document (the document you need to translate);

2. Activate the source document window and press Ctrl+Home to place the cursor at the top of the table in first cell, top left);

4. Click on macro button in toolbar;

5. In Fenêtre Choix des documents, select:

    Source field: Select your source document.

    Cible field: Select your target document.

6. Click on OK

7. Final check: In the Confirmation window: check the source/target selection made earlier, then click on OK.

 

 

Print this page!

 

Back / Tools for Translators / Home / Site Map

http://www.multilingual.ch
Web design by Tanya Harvey Ciampi