#! /bin/sh
# usage: dic WORD [LANG]
# where LANG may be one of en, fr, es, it, ch, ru, pt, pl
# multiple WORDs may be seperated by + like this: multiple+words
set -euf
main() {
case $# in
1|2) :;; # ok
*) usage; exit 23;;
esac
# all three are used by GET
search="$1"
langlang="${2-en}de"
lang="de"
GET | simplify | tac
}
GET() {
curl -sS -b 'LEOABTEST=T; browser=webkit%3B5%3Bajax' \
"https://dict.leo.org/dictQuery/m-vocab/$langlang/query.xml?tolerMode=nof&lp=$langlang&lang=$lang&rmWords=off&rmSearch=on&search=$search&searchLoc=0&resultOrder=basic&multiwordShowSingle=on"
}
simplify() {
sed '
s||\nREPR: |g
s||\n|g
' | grep ^REPR |
sed '
s/^REPR: //
1~2{s/$//}
2~2{s/$//}
' |
tr -d \\n |
sed '
s// [;30m-[m /g
s//\n/g
#q
s/⇔/⇔/g
s/ / /g; #
s/ */ /g
#
s/ *//g
s| *|/|g
s| *|/|g
s:1:¹:g; s:2:²:g; s:3:³:g;
s::^(:g
s::):g
s:0:₀:g;
s:1:₁:g; s:2:₂:g; s:3:₃:g;
s:4:₄:g; s:5:₅:g; s:6:₆:g;
s:7:₇:g; s:8:₈:g; s:9:₉:g;
s::_(:g
s::):g
s: *:[;4m:g
s: *:[m:g
s| *|[;30;1m|g
s| *|[m|g
'
}
usage() {
sed -rn '/^# usage:/,/^[^#]/{/^#/{s/# //;p}}' "$0" >&2
}
main "$@"