#!/bin/bash

browser="lynx -dump -nolist -useragent=lynx "
#dicios italiano
dicios="http://it.dicios.com/"
# wordreference: inglés, portugués y francés
wordref="http://www.wordreference.com/"

ayuda()
{
echo "Uso : $0 Idioma Palabra"
echo
echo "Ejecutar el script con los siguientes parámetros: idioma y palabra a busca"
echo
echo "Idiomas: "
echo "esen  Español-English<--->enes  English-Español "
echo "esit  Español-Italiano<-->ites  Italiano-Español"
echo "esfr  Español-Francés<--->fres  Francés-Español"
echo "esde  Español-Alemán<---->dees  Alemán-Espoañol"
echo "espt  Español-Portugués ptes  Portugués-Español"
echo "esal  Español-Albanés<--->ales  Albanés-Español"
echo "eslat Español-Latín<----->lates Latín-Español"
echo "escal Español-Caló"
echo "esru  Español-Ruso"	
echo "esca  Español-Catalán<--->caes  Catalán-Español"
echo ""              
echo "Ejemplo: $0 ites urlo "
echo "(busca urlo en un diccionario Español-Italiano)"
}	


if [ $# -lt 2 ];
 then
 ayuda
 exit 1
 fi
 
 
 if [ $1 = "fres" ] || [ $1 = "esfr" ]|| [ $1 = "espt" ]|| [ $1 = "ptes" ] || [ $1 = "esen" ] || [ $1 = "enes" ];
 then
 $browser $wordref$1/$2 | less
 exit 1
 fi
 
 if [ $1 = "esit" ] || [ $1 = "ites" ]
then
$browser $dicios$1/$2 | less
exit 1
fi

if [ $1 = "esde" ];
then
$browser "http://diccionario.reverso.net/espanol-aleman/$2" | tac | sed '1, 50 d' | tac | sed '1, 18 d'
exit 1
fi

if [ $1 = "dees" ];
then
$browser "http://diccionario.reverso.net/aleman-espanol/$2"| tac | sed '1, 50 d' | tac | sed '1, 18 d'
exit 1
fi

if [ $1 = "esal" ];
then
$browser "http://www.foreignword.com/cgi-bin/albesp.pl?lengua=espalb&termbox=$2" | sed '1, 12 d'| tac | sed ' 1, 5 d' | tac
exit 1
fi

if [ $1 = "ales" ];
then
$browser "http://www.foreignword.com/cgi-bin/albesp.pl?lengua=albesp&termbox=$2" | sed '1, 12 d'| tac | sed ' 1, 5 d' | ta
exit 1
fi

if [ $1 = "caes" ] || [ $1 = "esca" ]
then
$browser "http://dicts.info/2/catalan-spanish.php?word=$2&begin=Search"
exit 1
fi

if [ $1 = "lates" ];
then
$browser "http://dictionaries.travlang.com/LatinSpanish/dict.cgi?query=$2&max=50" | sed '1, 27 d' | tac | sed '1, 53 d' |t
exit 1
fi

if [ $1 = "eslat" ];
then
$browser "http://dictionaries.travlang.com/SpanishLatin/dict.cgi?query=$2&max=50" | sed '1, 27 d' | tac | sed '1, 53 d' |t
exit 1
fi

if [ $1 = "esru" ];
then
$browser "http://www.diccionario.ru/cgi-bin/dic.cgi?p=$2&page=search&vkb=0&base=general&newinput=1&l=es&prefbase=general" |more
exit 1
fi

if [ $1 = "esbu" ];
then
$browser "http://www.dicts.info/ud.php?k1=87&k2=164&w=$2" | more
exit 1
fi
if [ $1 = "escz" ];
then
$browser "http://www.dicts.info/ud.php?k1=87&k2=21&w=$2" | more
exit 1
fi
if [ $1 = "esfi" ];
then
$browser "http://www.dicts.info/ud.php?k1=87&k2=31&w=$2" | more
exit 1
fi
if [ $1 = "fies" ];
then
$browser "http://www.dicts.info/ud.php?k1=31&k2=87&w=$2" | more
exit 1
fi

 exit 0