So you might be sitting around asking yourself,
“Do I really need a web browser or collection of clunky travel dictionaries to translate to and from different languages of the world? Isn’t there a command line tool that can do the same thing and make my life easier, while making me even more awesome at the same time?”
The answer is YES!
The Translate Word and Graphical TW project is your gateway to having superior translation capabilities right in your CONSOLE!
Download tw from http://savannah.nongnu.org/files/?group=twandgtw.
I’m using tw-0.1.3.tar.bz2.
Major Dependencies
elinks
http://elinks.or.cz/download
I’m using elinks-0.11.5.tar.bz2.
I’m using Cygwin and I was missing the following:
curl
libiconv
util-linux random utils (For the getopt() function)
The above Cygwin packages can easily be obtained through the Cygwin setup program.
1. Extract elinks. Build it starting with “sh configure”. Then type “make”. After it finishes, type “make install”.
2. Repeat step 1 with tw.
3. Type “tw -h” to test that everything is installed correctly.
4. If everything went well, try typing “tw en-es hello” and you should get the following output:
hello : hola
You’re all set! Now you can quickly translate between many languages straight from your bash shell. Type “tw -l” to see a list of “all” the languages.
Customized Script for Google Translate
Google’s translate service is one of the most comprehensive language translators available. A major benefit of using Google’s translation service is that you can pass in as much text as you want; simply surround the text with quotes. Even though tw does not list all of the languages that Google supports, it is still a bash script that parses input parameters, and it does not do any validation. You can append anything you want to the argument “translate.google.com”. For instance, Croatian is not listed as one of the languages (“hr”). However, all you need to do is append the appropriate language pair to the end of the argument string, like so:
$ tw translate.google.com.en-hr hello
zdravo
To make this a bit more user-friendly, I have created a simple wrapper script (twg) for tw that only uses Google’s translate service. It works just like tw, except you do not have to type “translate.google.com”. You only need to put in the language pair. For example:
$ twg en-es “Hello World”
Hola Mundo
Type “twg -l” to get a complete list of supported languages. You can find more details about featured languages at http://www.google.com/help/faq_translation.html#langpairs.
#!/bin/bash # author: eokuwwy # http://reverttoconsole.com # description: customized tw wrapper script that uses google translate</code> if [ "$1" = "-l" ]; then echo "Arabic=ar"; echo "Bulgarian=bg"; echo "Catalan=ca"; echo "Chinese=zh-cn"; echo "Chinese=zh-tw"; echo "Croation=hr"; echo "Czech=cs"; echo "Danish=da"; echo "Dutch=nl"; echo "English=en"; echo "Filipino=tl"; echo "Finnish=fi"; echo "French=fr"; echo "German=de"; echo "Greek=el"; echo "Hebrew=iw"; echo "Hindi=hi"; echo "Indonesian=id"; echo "Italian=it"; echo "Japanese=ja"; echo "Korean=ko"; echo "Latvian=lv"; echo "Lithuanian=lt"; echo "Norwegian=no"; echo "Polish=pl"; echo "Portuguese=pt-BR"; echo "Romanian=ro"; echo "Russian=ru"; echo "Serbian=sr"; echo "Slovak=sk"; echo "Slovenian=sl"; echo "Spanish=es"; echo "Swedish=sv"; echo "Ukranian=uk"; echo "Vietnamese=vi"; elif [ "$1" = "-h" -o -z "$1" ]; then echo "Usage: twg [sourcelang-destlang (i.e. en-es)] [term]"; echo "twg -h (shows help)"; echo "twg -l (shows language list)"; else tw translate.google.com.$1 "$2"; fi
Happy command line translation! Now jailbreak (at your own risk) your iPhone/Blackberry/PDA and put tw on there!
$ twg en-es “peace out”
a la paz
-eokuwwy
Post a Comment