Here's a version that actually works: --- /usr/bin/translate.orig 2005-04-15 00:28:24.041456448 +0100 +++ /usr/bin/translate 2005-04-15 00:30:09.072489304 +0100 @@ -26,7 +26,7 @@ GLOBDIR=/usr/share/trans GLOBALCONF=/etc/translate.conf LOCALCONF=$LOCDIR/translate.conf -LANG=de-en +LANGUAGE=de-en WHOLEWORD=false DONT_ASK=false INVERS=false @@ -76,6 +76,18 @@ fi } +display () +{ + if [ "$2" = "-n" ]; then + OPT="-n" + fi + if [ $UTF8 ]; then + echo $OPT "$1" | iconv -f ISO-8859-1 -t UTF-8 + else + echo $OPT "$1" + fi +} + # If there is no $LOCDIR we should create one if [ ! -d $LOCDIR ] then @@ -104,7 +116,7 @@ -h) usage; exit 0 ;; -n) DONT_ASK=true; shift;; -i) invert_lang; shift;; - -l) LANG=$2; shift; shift;; + -l) LANGUAGE=$2; shift; shift;; --) shift; break;; esac done @@ -115,8 +127,8 @@ fi # Finally we should know what language to use -GLOBDIC=$GLOBDIR/$LANG -LOCDIC=$LOCDIR/$LANG +GLOBDIC=$GLOBDIR/$LANGUAGE +LOCDIC=$LOCDIR/$LANGUAGE # Is there already a global dictionary for these languages # or should we rely on our own, private one? @@ -139,39 +151,46 @@ fi fi +if locale 2>&1 | grep -E -q "UTF-8?$"; then + UTF8=1 +fi +SEARCH=$* +[ $UTF8 ] && SEARCH=$(echo "$SEARCH" | iconv -f UTF-8 -t ISO-8859-1) +LANG=en_US # now get the real work done -if - +if [ 1 ] ; then if [ $WHOLEWORD = false ] then if [ $INVERS = false ] then - egrep -ihs "$*".*' :: ' $DIC + result=$(egrep -ihs "$SEARCH".*' :: ' $DIC) else - egrep -ihs ' :: '.*"$*" $DIC + result=$(egrep -ihs ' :: '.*"$SEARCH" $DIC) fi else if [ $INVERS = false ] then - egrep -ihs '\b'"$*"'\b'.*' :: ' $DIC + result=$(egrep -ihs '\b'"$SEARCH"'\b'.*' :: ' $DIC) else - egrep -ihs ' :: '.*'\b'"$*"'\b' $DIC + result=$(egrep -ihs ' :: '.*'\b'"$SEARCH"'\b' $DIC) fi fi +fi -then # Done +if [ "$result" ]; then + display "$result" exit 0 else # Fallback to human intelligence (unless "-n" is present) if [ $DONT_ASK = true ] then - echo "Sorry \"$*\" not found" + display "Sorry \"$SEARCH\" not found" else echo "No matches. Teach me or press Return." - echo -n "$* :: " + display "$SEARCH :: " -n read NEW_ENTRY if [ -z "$NEW_ENTRY" ] then # User is lazy @@ -179,10 +198,11 @@ else # We've got a new entry if [ $INVERS = false ] + # FIXME: handle UTF-8 (?) then - echo "$* :: $NEW_ENTRY" >> $LOCDIC + echo "$SEARCH :: $NEW_ENTRY" >> $LOCDIC else - echo "$NEW_ENTRY :: $*" >> $LOCDIC + echo "$NEW_ENTRY :: $SEARCH" >> $LOCDIC fi exit 0 fi
The "if [ 1 ]" clause should obviously be removed and the code re-intended, but I just put in the "1" to make the diff rasier to read. -- Martin Michlmayr http://www.cyrius.com/ -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]