I18N Shell Scripts (gettext)
- From: Wayne <nospam@xxxxxxxxxxxxxx>
- Date: Thu, 01 Nov 2007 14:58:18 -0400
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
.
- Follow-Ups:
- Re: I18N Shell Scripts (gettext)
- From: Stephane CHAZELAS
- Re: I18N Shell Scripts (gettext)
- From: Stephane CHAZELAS
- Re: I18N Shell Scripts (gettext)
- Prev by Date: Re: Can you do the following
- Next by Date: Re: I18N Shell Scripts (gettext)
- Previous by thread: wget for downloading scientific papers
- Next by thread: Re: I18N Shell Scripts (gettext)
- Index(es):
Relevant Pages
|