Search PowerShellers and other PowerShell-related sites

Monday, July 2, 2007

Translate with Google Dictionary Translation and PowerShell

Google Translate has added a nifty new feature: dictionary translation. Dictionary translation is currently available between English and French, Italian, German, Spanish, and Korean. You can get it right from the command line with a little help from PowerShell.



# Usage:
# Get-Translation -word power -dictionary ef
# Get-Translation shell ei
# gt "ab und zu" de

Function Get-Translation {
param([string]$word="",[string]$dictionary="")

switch($dictionary) {
ef {$langpair = "en%7Cfr"} # English-French
fe {$langpair = "fr%7Cen"} # French-English
ed {$langpair = "en%7Cde"} # English-German BETA
de {$langpair = "de%7Cen"} # German-English BETA
ei {$langpair = "en%7Cit"} # English-Italian
ie {$langpair = "it%7Cen"} # Italian-English
ek {$langpair = "en%7Cko"} # English-Korean
ke {$langpair = "ko%7Cen"} # Korean-English
es {$langpair = "en%7Ces"} # English-Spanish
se {$langpair = "es%7Cen"} # Spanish-English
}

$objIE = New-Object -Com Internetexplorer.Application
$url = "http://translate.google.com/translate_dict?q=" + $word + "&sa=N&hl=en&langpair=" + $langpair
$objIE.Navigate($url)
$objIE.Visible=$true
}

Set-Alias gt Get-Translation




A dictionary translation of your word or short phrase will be displayed in Internet Explorer.