From 0b660761b65e55027eec44870c649a55f2f6f487 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Mon, 7 Oct 2013 00:09:15 +0200 Subject: [PATCH] translate: alternate translations support --- .gitignore | 1 + .scripts/translate | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 7dd11b7e..0068413b 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ personal temp todo.org +projects diff --git a/.scripts/translate b/.scripts/translate index 4c6705ca..10bbdc55 100755 --- a/.scripts/translate +++ b/.scripts/translate @@ -20,12 +20,14 @@ Synopsis. -h: Show this help. -i: input language (optional). + -l: show alternate translations. EOF } +FILTER='s/\[\[\["\([^"]*\).*/\1/' unset SL -while getopts ":hi:" opt; do +while getopts ":hi:l" opt; do case $opt in h) _printhelp "$0" @@ -33,6 +35,8 @@ while getopts ":hi:" opt; do ;; i) SL="$OPTARG" ;; + l) + FILTER='s/\[\[\[[^[]*\[\[[^[]*\[\([^[]*\)\].*/\1/' ;; ?) _printhelp "$0" exit 1 @@ -63,7 +67,7 @@ _translate() curl -A "Mozilla/5.0" 'http://translate.google.com/translate_a/t?client=t&text='$TEXT'&tl='$TL'&ie=UTF-8&oe=UTF-8' else curl -A "Mozilla/5.0" 'http://translate.google.com/translate_a/t?client=t&text='$TEXT'&sl='$SL'&tl='$TL'&ie=UTF-8&oe=UTF-8' - fi 2>/dev/null | sed 's/\[\[\["\([^"]*\).*/\1/' + fi 2>/dev/null | sed -e $FILTER -e 's/"//g' echo }