Add gettext support to the template frontend!
authorSteinar H. Gunderson <sesse@samfundet.no>
Sat, 16 Jul 2005 23:55:13 +0000 (23:55 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Sat, 16 Jul 2005 23:55:13 +0000 (23:55 +0000)
html/ccbs.pm
intl/Sesse::GettextizeTemplates.pm [new file with mode: 0644]

index d4bc6bc4518d46ab7224ad05e2120ff4b265efc7..c1406ce1b259e15e6ddc85a1ef1df3f207b7f1b4 100755 (executable)
@@ -4,8 +4,11 @@ use CGI;
 use DBI;
 use HTML::Entities;
 use Time::HiRes;
+use Locale::gettext;
+use POSIX;
 use strict;
 use warnings;
+require '../intl/Sesse::GettextizeTemplates.pm';
 
 our $start_time;
 
@@ -73,11 +76,16 @@ sub process_template {
        $vars->{'public'} = $ccbs_noadmin;
        $vars->{'timetogenerate'} = sprintf "%.3f", Time::HiRes::tv_interval($start_time);
        
+       POSIX::setlocale( &POSIX::LC_MESSAGES , "en_DK.UTF-8");
+       Locale::gettext::bindtextdomain("ccbs", "po");
+       Locale::gettext::textdomain("ccbs");
+       
        my $config = {
                INCLUDE_PATH => 'templates/',
                INTERPOLATE  => 1,
                POST_CHOMP   => 1,
                EVAL_PERL    => 1,
+               FACTORY      => 'Sesse::GettextizeTemplates'
        };
        my $template = Template->new($config);
 
diff --git a/intl/Sesse::GettextizeTemplates.pm b/intl/Sesse::GettextizeTemplates.pm
new file mode 100644 (file)
index 0000000..ec734e0
--- /dev/null
@@ -0,0 +1,19 @@
+
+package Sesse::GettextizeTemplates;
+use strict;
+use warnings;
+use Locale::gettext qw(gettext);
+use Template::Directive;
+
+our @ISA = qw(Template::Directive);
+
+sub textblock {
+       my ($self, $text) = @_;
+
+       $text =~ s/(<(h[1-6]|p|td|th|title|input|span|li|_)[^>]*>)(.*?)(<\/\2>)/$1.gettext($3).$4/seg;
+
+       return $self->SUPER::textblock($text);
+}
+
+
+