]> git.sesse.net Git - ttk-gettext/blob - process-template.pl
Add a note about what to do when changing/adding strings.
[ttk-gettext] / process-template.pl
1 #! /usr/bin/perl
2 use strict;
3 use warnings;
4 use POSIX;
5 use Locale::gettext;
6 use Template;
7 require 'Sesse::GettextizeTemplates.pm';
8
9 # Common short macro to get non-templatized gettext stuff working
10 *_ = sub {
11         return Locale::gettext::gettext(@_);
12 };
13
14 # set the locale
15 POSIX::setlocale(&POSIX::LC_CTYPE, "");
16 POSIX::setlocale(&POSIX::LC_MESSAGES, "");
17 Locale::gettext::bindtextdomain("myproject", ".");
18 Locale::gettext::textdomain("myproject");
19
20 # Do a test message with no templates
21 print _("Test message from outside a template.\n");
22
23 # Process the test template and print it to stdout
24 my $template = Template->new({ FACTORY => 'Sesse::GettextizeTemplates' });
25 my $output = '';
26 $template->process('test.tmpl', { foo => int(rand 2) }, \$output)
27         or die $template->error();
28
29 print $output;