April 15, 2012

English to Gujarati Dictionary in Linux

This post is to all Linux Desktop users from Gujarat who are looking for a English to Gujarati dictionary in Linux Desktop.

In Linux, for English to gujarati dictionary we are opening up browser for online database but here we achieved it in just one tiny shell script.

The constraint is that it required internet connection as it uses online database but good thing about this tool is that It would have updated dictionary database and second it supports clipboard capture so we don't have to type a word each time.

All you need to do is just download a engtoguj.sh dictionary and create a launcher on your desktop panel.

$ sudo wget -O /usr/local/bin/engtoguj.sh https://raw.github.com/technostab/shellscripts/master/engtoguj.sh
$ chmod 755 /usr/local/bin/engtoguj.sh

Or, copy the script contents from here and save it as /usr/local/bin/engtoguj.sh and make it executable.

#!/bin/sh

# Purpose  : This shell script it for Linux Desktop users who wants English to Gujarati dictionary. Just add this program to you Desktop panel as an application launcher and it would work great
# Date/Time  : Sun Apr  1 12:33:25 IST 2012
# Modification Date :

ZENITY=`which zenity`
XCLIP=`which xclip`

if [ -z "${ZENITY}" ]; then
 echo "zenity not found!"
 exit 1
fi

if [ -z "${XCLIP}" ]; then
 echo "xclip not found!"
 exit 1
fi

CLIPBOARD="$(${XCLIP} -o)"

if [ -n "${CLIPBOARD}" ]; then
 ENGWORD=$(${ZENITY} --entry --text "Insert Word" --entry-text "${CLIPBOARD}")
else
 ENGWORD=$(${ZENITY} --entry --text "Insert Word")
fi

TMPFILE=`mktemp`

if [ -n "${ENGWORD}" ]; then
 wget -O ${TMPFILE} "http://gujaratilexicon.com/dictionary/EG/${ENGWORD}*/" 2> /dev/null
else
 exit 1
fi

ANS="$(cat ${TMPFILE} | sed '1,//d;/<\/tbody>/,$d' | sed -e '/\)\(.*\)\(<.*$\)/\2/')"

if [ -n "${ANS}" ]; then
 ${ZENITY} --info --text "${ENGWORD}:\n${ANS}"
else
 ${ZENITY} --error --text "${ENGWORD}:\nNo such word in dictionary"
fi

rm -f ${TMPFILE}

Look at the demonstration, it show how you can configure and make it work in few seconds under Linux.


It's a pretty simple tool to use to improve your desktop productivity.