Re: L10n in Gtk2-perl with Locale::Maketext::Lexicon



I just wrote the following example of how to do localization of a
Gtk2-perl program and thought it might be useful for others. Perhaps
we should put it somewhere in the wiki:

Although Locale::Maketest is a nice system, and much easier to use in
Perl, l in my experience it's better to use GNU gettext for l10n. Using
gettext means that auto-generated strings like those from Glade get
automagically generated.

e.g.:

        use POSIX qw(setlocale);
        use Locale::gettext;
        
        # name of your program:
        my $APP_NAME = 'foobar';
        
        # get language from environment:
        my $LANGUAGE = $ENV{LANG} || 'en_US';
        
        # put your .mo files in /usr/share/locale/$APP_NAME/LC_MESSAGES:
        my $DIRECTORY = '/usr/share/locale';
        
        setlocale(LC_ALL, $LANGUAGE);
        bindtextdomain($APP_NAME, $DIRECTORY);
        textdomain($APP_NAME);

        print gettext('Hello World!');

Gavin.

-- 
Gavin Brown
e: gavin brown uk com
w: http://jodrell.net/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]