James Briggs

NAME

Gettext - Perl extension for emulating gettext-related API.

SYNOPSIS

  use Gettext;

DESCRIPTION

Gettext.pm emulates the gettext library routines in Perl, although it calls the external utility program gettext to actually read .mo files.

man gettext on Solaris has pretty good documentation.

The steps to use this module are:

  • install the gnu gettext package if necessary (not needed on Solaris or Red Hat)

  • set TEXTDOMAINDIR, LANGUAGE, LANG, and LC_* if needed in your env.

  • use xgettext on your script that contains gettext calles to make the .po (portable message object) file, run msgfmt to make the .mo (message object) file, and move the .mo file to where you want it, normally $TEXTDOMAINDIR/lang/LC_MESSAGES.

  • call setlocale before calling these functions.

use Gettext;

my $gt = new Gettext;

$gt->textdomain('domainname');

$gt->bindtextdomain('domainname', 'dirname');

$gt->gettext('msgid');

$gt->dgettext('domainname', 'msgid');

$gt->dcgettext('domainname', 'msgid', 'category (locale)');

SAMPLE

use strict;

use diagnostics;

use POSIX 'locale_h';

use locale;

use Gettext;

   setlocale(LC_CTYPE, 'es_ES');

   my $gt = new Gettext();

   $gt->bindtextdomain("messages", "/root/work");

   print $gt->gettext("flower"),"\n";
   print $gt->gettext("yellow"),"\n";

   print $gt->dgettext("messages", "flower"),"\n";
   print $gt->dgettext("messages", "yellow"),"\n";

   print $gt->dcgettext("messages", "flower", "fr_FR"),"\n";
   print $gt->dcgettext("messages", "yellow", "fr_FR"),"\n";

   print $gt->textdomain(),"\n";
   print $gt->textdomain(''),"\n";

Tested on Solaris 2.6 and Red Hat Linux 6.0

AUTHOR

James Briggs, james@rf.net

SEE ALSO

perldoc perllocale

TO DO

Gettext.pm calls the external gettext utility program, but someday should have an internal routine to directory read .mo files.