30 lines
705 B
Bash
Executable file
30 lines
705 B
Bash
Executable file
#!/bin/bash
|
||
|
||
tmpfile="$(mktemp)"
|
||
if [ -t 0 ]; then
|
||
[ "$#" = 0 ] && exit 1
|
||
echo "$@" > "$tmpfile"
|
||
else
|
||
cat > "$tmpfile"
|
||
case "$1" in
|
||
r*) dir=en-ru;;
|
||
e*) dir=ru-en;;
|
||
esac
|
||
fi
|
||
|
||
[ -z "$dir" ] &&
|
||
if (( $(grep -oP '\p{Latin}' < "$tmpfile" | wc -l) > $(grep -oP '\p{Cyrillic}' < "$tmpfile" | wc -l) )); then
|
||
dir='en-ru'
|
||
else
|
||
dir='ru-en'
|
||
fi
|
||
|
||
curl -s \
|
||
http://ядро.орг:9000/translate \
|
||
-H 'Content-Type: text/html' \
|
||
-H "X-Translation-Direction: $dir" \
|
||
--data-binary @- -o- < "$tmpfile" | \
|
||
tail -n +2 | \
|
||
perl -pe 's,<SPAN CLASS=UNKNOWN_WORD>(.*?)</SPAN>,\1,g' |
|
||
sed -e 's/>/>/g' -e 's/</</g' -e 's/"/"/g'
|
||
echo
|