Tuesday, June 21, 2011

Google Dictionary for Word

GD4Word (Google Dictionary for Word) does one simple thing: Select a word, and press CTRL+ALT+D, a Google Dictionary window will open displaying the definition, translation and examples of that word.
GD4Word is a Word Macro and it only works inside Microsoft Word.
In Word 2003 and under,
Go to Tools–>Macros—>Visual Basic
Right click on “Normal”, and choose “Insert”—>”Module”
Paste the following code to the newly inserted module.

'code start

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
 
Sub Gdictionary()
 
Dim SLan As String
Dim TLan As String
Dim SText As String
Dim Gurl As String
 
SLan = "en"
TLan = "zh-CN"
SText = VBA.Trim(VBA.Replace(Selection.Text, Chr(13), ""))
 
Gurl = "http://www.google.com/dictionary?langpair=" + SLan + "|" + TLan + "&q=" + SText + "&hl=en&aq=f"
 
Debug.Print Gurl
 
ShellExecute 0&, vbNullString, Gurl, vbNullString, vbNullString, vbNormalFocus
 
End Sub
 
'code end
 
Then you can assign a keyboard shortcut to the macro: Gdictionary().
This code works when the source language uses ASCII characters only. If you want to make it work with pairs like Chinese to English, you will need to utf-8 encode your source text string.
“en”, “zh-CN” are shortcodes for the source language and the target language. You need to change them to your pair.
Google language short codes:
auto=Auto Detect,af=Afrikaans,sq=Albanian,ar=Arabic,be=Belarusian,bg=Bulgarian,ca=Catalan,zh-CN=Chinese (Simplified),zh-TW=Chinese (Traditional),hr=Croatian,cs=Czech,da=Danish,nl=Dutch,en=English,et=Estonian,tl=Filipino,fi=Finnis h,fr=French,gl=Galician,de=German,el=Greek,iw=Hebrew,hi=Hindi,hu=Hungarian,is=Icelandic,id=Indonesia n,ga=Irish,it=Italian,ja=Japanese,ko=Korean,lv=Latvian,lt=Lithuanian,mk=Macedonian,ms=Malay,mt=Malte se,no=Norwegian,fa=Persian,pl=Polish,pt=Portuguese,ro=Romanian,ru=Russian,sr=Serbian,sk=Slovak,sl=Sl ovenian,es=Spanish,sw=Swahili,sv=Swedish,th=Thai,tr=Turkish,uk=Ukrainian,vi=Vietnamese,cy=Welsh,yi=Y iddish
When translating with TRADOS Translator’s Workbench to Chinese, font of English letters in the target language is changed to Chinese font too. English letters usually look ugly in Chinese font. To avoid this, go to Translator’s Workbench window, click on File->Setup->Fonts->and deselect the “all fonts will be converted to the default target language font.”  Source: http://dallascao.com