views:

41

answers:

1

I've been following a tutorial from a recent edition of the Linux Journal which teaches how to internationalize Bash scripts. However, I'm having trouble getting it to work on my system (Ubuntu 10.04.) When I get to the part where I'm supposed to call "gettext," after setting the environment variable TEXTDOMAINDIR, I get:

toby@toby-laptop:~/Desktop/i18n$ gettext -s "Greeting"
Greeting

But it should be printing a message that says "Hello, I can generate a random number between 2 numbers that you provide" instead of just "Greeting." Can anybody replicate this problem? Any ideas what I'm doing wrong? Thanks!

+1  A: 

The author of that tutorial forgot the following step:

export TEXTDOMAIN=rand.sh

which should be performed when step shown as export TEXTDOMAINDIR=/home/lji/locale is done (substituting the appropriate directory name).

You can use $"" instead of gettext:

$ cat rand.sh
#!/bin/bash
TEXTDOMAINDIR=$HOME/locale   # probably not the best place for these files, but OK for testing
TEXTDOMAIN=rand.sh
gettext -s "Greeting"
echo $"Greeting"
$ ./rand.sh
Hello, I can generate a random number between 2 numbers that you provide
Hello, I can generate a random number between 2 numbers that you provide

Note that the Bash manual says that some systems may make use of the variables $LC_MESSAGES, $TEXTDOMAIN and $TEXTDOMAINDIR in different ways.

Dennis Williamson
what would be the best places for those files?
Corey Jeffco
I would consider paralleling similar system-defined directories, so possible choices might be `/usr/local/locale`, `/usr/local/lib/locale` or `/usr/local/share/locale` or similar.
Dennis Williamson