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

In Linux, for English to Gujarati dictionary we open up a browser for an online database, but here we achieved it in just one tiny shell script.

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

All you need to do is download the engtoguj.sh script 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 below and save it as /usr/local/bin/engtoguj.sh and make it executable.

#!/bin/sh
# Purpose: English to Gujarati dictionary for Linux Desktop

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,/<tbody>/d;/<\/tbody>/,$d' | sed -e '/<td>\(.*\)<\/td>/s//\1/')"

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

rm -f ${TMPFILE}

A simple tool to improve your desktop productivity.

Originally published April 15, 2012 on jaymspatel.blogspot.com