I18N Shell Scripts (gettext)



I don't have a need for this, but I can't
get it to work and it's frustrating! Please
tell me what I'm doing wrong! I am using
Fedora Linux with Bash and gettext:
$ gettext --version
gettext (GNU gettext-runtime) 0.16.1

Suppose I have this script as i18n_greet.sh:

#!/bin/sh
printf "Enter your name: "
read NAME
printf "Hello, $NAME!\n"
# End of Script

To internationalize it, say to support French as well
as English, I have transformed it to this:

#!/bin/sh
export TEXTDOMAINDIR=~/locale # normally /usr/share/locale is used
export TEXTDOMAIN=i18n_greet
.. gettext.sh
printf "$(gettext -n 'Enter your name: ')"
read NAME
printf "$(eval_gettext 'Hello, $NAME!')"
# End of Script

That works for English. To make it work for French as well,
I generate a French PO file (i18n_greet.fr.po) with:
$ umask 022
$ xgettext -d i18n_greet.fr -L Shell i18n_greet.sh

And this template PO file is edited to produce:

# French .po file for i18n_greet.sh script.
# Copyright (C) 2007
# This file is distributed under the same license as the i18n_greet.sh package.
# Author: Wayne <nospam@xxxxxxxxxxxxxxx>, 2007
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: i18n_greet.sh-1.0\n"
"Report-Msgid-Bugs-To: Wayne <nospam@xxxxxxxxxxxxxxx>\n"
"POT-Creation-Date: 2007-11-01 11:02-0400\n"
"PO-Revision-Date: 2007-11-01 11:02-0400\n"
"Last-Translator: Wayne <nospam@xxxxxxxxxxxxxxx>\n"
"Language-Team: French <LL@xxxxxx>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: i18n_greet.sh:10
msgid "Enter your name: "
msgstr "Entrez votre nom"

#: i18n_greet.sh:11
#, sh-format
msgid "Hello, $NAME!"
msgstr "Salut, $NAME!"


Now compile this PO file to an MO file:

$ umask 022
$ msgfmt -o i18n_greet.mo i18n_greet.fr.po
$ mkdir ~/fr/LC_MESSAGES/
$ mv i18n_greet.mo ~/fr/LC_MESSAGES/

(Note that the directories and the files have
the proper permissions, so the file can be found
and read.)

That should be it. But, even if I set (and export)
LANG and/or LC_ALL to 'fr', it comes out in English.

I read someplace there is a POSIX alternative to the
Gnu gettext / PO / MO system "gencat"?). If I need
To use that, can anyone point out an example
"hello, world" script?

Thanks!

-Wayne
.



Relevant Pages

  • Re: Tips, Tricks and favorites
    ... So I decided to create a little script that would ... of "ispell" command call, because the script has ... For checking french spelling of a single word, ...
    (comp.os.linux.misc)
  • Script fails when MUI configured French
    ... Is there a settings that will allow a script to create a file in English, ... while maintaining the French MUI settings menus. ...
    (microsoft.public.win2000.active_directory)
  • Login script fails when French MUI selected
    ... Is there a settings that will allow a script to create a file in English, ... while maintaining the French MUI settings menus. ...
    (microsoft.public.windows.server.general)
  • Moving to a modified URL
    ... I would like to create a link on a web page that will call a script and jump ... user is on my web site, if he clicks on the FRENCH button at the top, he ... On this French version of the web page, if he clicks on the ENGLISH button, ...
    (comp.lang.php)
  • Re: [KCONFIG] Cant compile 2.6.12 without Gettext
    ... My gettext implementation is not exactly complete. ... > script shouldn't failed at this step. ... > the kernel by modifying a bit the lkc.h and mconf.c files. ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)