Monday, December 24, 2007

Translating text in text boxes

Text contained in text boxes in Word can be estimated and translated easily by first extracting the text to a separate file. Note that the Word Count feature in Word (Alt + T + W) does not count text in text boxes. When you receive a Word file with lots of text boxes, click on the text boxes one by one and find out whether they are grouped or not. If grouped, ungroup them one by one. Then save the original file with a different name and run the macro given below (this is to make sure that your original file remains intact). It dumps all the text in the text boxes to a different file, which you may with a "tb" suffix to indicate that the text in this file is from the text. Now take the w count (Ctrl + Alt + W) of the original file and add it to that of the file with the text from the text boxes to arrive at the total Word count.

The "Extract from Textbox" macro was written by Yves Champollion (Wordfast author) when I made a request to him through the Wordfast mailing list to write one about 5 years ago. It still works fine in Word 2003; I have not tried it in later versions. Here it is:

Sub ExtractFromTextBox()

'

' Macro ExtractFromTextBoxesVersion3recorded

' by Yves

'

Dim i As Integer, Boite As Shape, ThisDoc As Document

Set ThisDoc = ActiveDocument

Documents.Add

For Each Boite In ThisDoc.Shapes

If Boite.Type = msoGroup Then

For i = 1 To Boite.GroupItems.Count

With Boite.GroupItems(i).TextFrame

If .HasText Then

Selection.InsertAfter .TextRange

Selection.InsertParagraphAfter

Selection.Start = Selection.End

End If

End With

Next

Else

With Boite.TextFrame

If .HasText Then

Selection.InsertAfter .TextRange

Selection.InsertParagraphAfter

Selection.Start = Selection.End

End If

End With

End If

Next

End Sub

6 comments:

Harvey said...

Thanks for the great blog! Do you read any other similar blogs with translator tips? Or perhaps do you have any websites with resources that you frequently visit? It would be great if you could share those with us in a post!

Keep up the good work!

Gururaj Rao said...

Thank you, Harvey. Rather than visiting websites, I subscribe to various mailing lists such as Nihongo Computing, Wordfast, Deja Vu, Trados, Help, and so on, several newsletters, and also read newsgroups occasionally. Maybe others reading this blog can chime in and suggest some useful websites to Harvey?

Jon said...

Thank you for sharing this macro! I still use Office 2003 and am looking forward to saving time on word counts.

While not related to counting words in text boxes, I have found the program Adwords to be extremely helpful in saving time for a varity of tasks. While it is hard to quickly describe all of its uses, it allows a user to create shortcuts, scripts or macros in any Windows program.

Gururaj Rao said...

Jon,
Could you share with us the details of Adwords? This isn't a Google application, is it? I'll be writing about a similar tool that I use in the near future, and I'd like to try Adwords before I write. Thanks.

Gururaj Rao

honyaku said...

Hi,

Apart from this macro, you can use Werecat, which also works for shapes and powerpoint files. http://www.volny.cz/ddaduc/werecat.html

Thanks for this great blog.

Gururaj Rao said...

Thanks, honyaku (wish I could address you by your real name :( ). Yes, I have used Werecat for translating Powerpoint files. I'll cover accessories to CAT tools in the near future.