Gettext - Perl extension for emulating gettext-related API.
use Gettext;
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.
my $gt = new Gettext;
$gt->textdomain('domainname');
$gt->bindtextdomain('domainname', 'dirname');
$gt->gettext('msgid');
$gt->dgettext('domainname', 'msgid');
$gt->dcgettext('domainname', 'msgid', 'category (locale)');
use strict;
use diagnostics;
use POSIX 'locale_h';
use locale;
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
James Briggs, james@rf.net
perldoc perllocale
Gettext.pm calls the external gettext utility program, but someday should have an internal routine to directory read .mo files.
To install Gettext, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Gettext
CPAN shell
perl -MCPAN -e shell install Gettext
For more information on module installation, please visit the detailed CPAN module installation guide.