Re: Kernel messages...

Riley Williams (rhw@bigfoot.com)
Fri, 11 Dec 1998 18:40:43 +0000 (GMT)


Hi Bruce.

On Thu, 10 Dec 1998, Bruce Korb wrote:

>> identification. A script could be provided to convert messages
>> back into English for this list, the maintainer, etc.

> Translations of a formatted string is a very hard problem. You
> really cannot tell which parts came from the format string and
> which were formatted values. One of the reasons I advocate a binary
> log *in addition to* the traditional text one.

That's one reason why I see the adoptation of a series of text files
of messages, one per language, as important - the conversion routine
then becomes trivial enough to do in a bash script...

Q> #!/bin/bash
Q> if [ $# -lt 4 ]; then
Q> echo "Usage: `basename $0` oldlang newlang key message" >&2
Q> exit 255
Q> fi
Q> function ml() { tr -s ' ' '\n' ; }
Q> function sl() { tr '\n' ' ' ; }
Q> export OLDLANG=$1
Q> export NEWLANG=$2
Q> export KEY=$3
Q> shift
Q> shift
Q> shift
Q> export OLDMSG="$*"
Q> export OLDFMT="`grep ^$KEY < $OLDLANG | head -1`"
Q> export OLDSIZE=`echo -n $OLDFMT | wc -w`
Q> declare -i N=1
Q> export FIELDS=''
Q> while [ $N -le $OLDSIZE ]; do
Q> FMT=`echo "$OLDFMT" | cut -d ' ' -f $N`
Q> WORD=`echo "$OLDMSG" | cut -d ' ' -f $N`
Q> if [ "`echo \"$FMT\" | cut -b 1`" = "%" ]; then
Q> ID=`echo "$FMT" | cut -b 2-`
Q> export FIELDS="$FIELDS $ID:$WORD"
Q> fi
Q> done
Q> export NEWFMT="`grep ^$KEY < $NEWLANG | tail -1`"
Q> export NEWSIZE=`echo -n $NEWFMT | wc -w`
Q> echo -n "$KEY"
Q> for WORD in `echo $NEWFMT | cut -d ' ' -f 2-` ; do
Q> if [ "`echo \"$WORD\" | cut -b 1`" = "%" ]; then
Q> ID=`echo "$WORD" | cut -b 2-`
Q> TERM=`echo $FIELDS | tr ' ' '\n' | grep "^$ID:" | tail -1`
Q> echo -n " `echo $TERM | cut -d : -f 2-`"
Q> else
Q> echo -n " $WORD"
Q> fi
Q> done
Q> echo

Given the above script and the following two files...

Q> % grep ^SAMPLE01 Deutsch English
Q> Deutsch:SAMPLE01 Kaffee nicht gefundep: %USER gehaltet.
Q> English:SAMPLE01 No coffee: %USER halted.
Q> %

...then the following...

Q> % kernxlate Deutsch English \
Q> SAMPLE01 Kaffee nicht gefundep: Tobi gehaltet.

...should produce...

Q> SAMPLE01 No coffee: Tobi halted.

Note that it doesn't even need to be a kernel facility, but it DOES
require that the relevant language data files are accurate...

Before anybody complains, my German is rather less than fluent...

Best wishes from Riley.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/