blob: 4a27f6a322dbfb6f4b47ac70b88aa338965b1e00 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#!/bin/sh
# Translate words using http://context.reverso.net and scraping the answers
for dependency in pup curl fzf
do
if ! command -v "$dependency" > /dev/null
then
>&2 printf '"%s" (dependency) could not be found.\n' "$dependency"
exit 1
fi
done
# returns available languages
languages () {
printf 'arabic\nchinese\nczech\ndanish\ndutch\nenglish\nfrench\ngerman\ngreek\nhebrew\nhindi\nhungarian\nitalian\njapanese\nkorean\npersian\npolish\nportuguese\nromanian\nslovak\nspanish\nswedish\nthai\nturkish\nukrainian\n'
}
if [ -z "${word:=$1}" ]
then
>&2 printf '>'
word="$(head -n1)"
fi
[ "$word" ] || exit 1
primary="$(languages | fzf --prompt="from:")"
[ "$primary" ] || exit 1
secondary="$(languages | fzf --prompt="to:")"
[ "$secondary" ] || exit 1
# url="https://www.reverso.net/text-translation#sl=$primary&tl=$secondary&text=$word"
url="https://context.reverso.net/translation/$primary-$secondary/$word"
curl -s "$url" \
--compressed \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' \
-H 'Accept-Encoding: gzip, deflate, br' |
pup 'a.link_highlighted em text{}' |
sed 's/.*/\L&/' |
sort | uniq | sed 's/.*/ &/'
|