]> git.deb.at Git - deb/packages.git/commitdiff
Add L10N support for Template Toolkit output
authorFrank Lichtenheld <frank@lichtenheld.de>
Sat, 13 Oct 2007 21:58:55 +0000 (23:58 +0200)
committerFrank Lichtenheld <frank@lichtenheld.de>
Sat, 13 Oct 2007 21:58:55 +0000 (23:58 +0200)
These go to a new templates domain, to not have to mix
xgettext and ttxgettext input for the same .pot file.

bin/create_index_pages
bin/ttxgettext
cron.d/500update_mo
lib/Packages/Dispatcher.pm
lib/Packages/I18N/Locale.pm

index 72498e9299669f6a931171b84f441433340773d4..9beac92d98d3b6fcb6c95f8090929f6aba670561 100755 (executable)
@@ -28,6 +28,7 @@ delete $ENV{'LC_ALL'};
 delete $ENV{'LC_MESSAGES'};
 bindtextdomain ( 'pdo', $LOCALES );
 bindtextdomain ( 'sections', $LOCALES );
 delete $ENV{'LC_MESSAGES'};
 bindtextdomain ( 'pdo', $LOCALES );
 bindtextdomain ( 'sections', $LOCALES );
+bindtextdomain ( 'templates', $LOCALES );
 textdomain( 'pdo' );
 
 my $wwwdir = "$TOPDIR/www";
 textdomain( 'pdo' );
 
 my $wwwdir = "$TOPDIR/www";
@@ -53,6 +54,7 @@ my (%pages, %tt_vars);
 
 $tt_vars{make_search_url} = sub { return &Packages::CGI::make_search_url(@_) };
 $tt_vars{make_url} = sub { return &Packages::CGI::make_url(@_) };
 
 $tt_vars{make_search_url} = sub { return &Packages::CGI::make_search_url(@_) };
 $tt_vars{make_url} = sub { return &Packages::CGI::make_url(@_) };
+$tt_vars{g} = sub { return &Packages::I18N::Locale::tt_gettext(@_) };
 # needed to work around the limitations of the the FILTER syntax
 $tt_vars{html_encode} = sub { return HTML::Entities::encode_entities(@_,'<>&"') };
 $tt_vars{uri_escape} = sub { return URI::Escape::uri_escape(@_) };
 # needed to work around the limitations of the the FILTER syntax
 $tt_vars{html_encode} = sub { return HTML::Entities::encode_entities(@_,'<>&"') };
 $tt_vars{uri_escape} = sub { return URI::Escape::uri_escape(@_) };
index 7464f60f2837147cd23ea221c5cecb15c923fa92..5e3aced61652e4bba97e67e18549c5012aa629fd 100755 (executable)
@@ -1,5 +1,14 @@
 #! /usr/bin/perl -w
 
 #! /usr/bin/perl -w
 
+# copied from webwml/english/po/wmlxgettext.pl and
+# adapted for Template Toolkit
+#  Copyright © 2002-2003  Denis Barbier <barbier@debian.org>
+#  Copyright © 2007 Frank Lichtenheld <frank@lichtenheld.de>
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
 use strict;
 use Getopt::Std;
 
 use strict;
 use Getopt::Std;
 
@@ -41,18 +50,23 @@ sub processFile {
                 $repl = $1;
         }
         $file =~ s{^$prefix}{$repl}o unless $prefix eq '__';
                 $repl = $1;
         }
         $file =~ s{^$prefix}{$repl}o unless $prefix eq '__';
-        #  Remove comments if they contain <gettext> or </gettext>
-        $text =~ s/^[ \t]*#.*<\/?gettext\b//mg;
+#        #  Remove comments if they contain <gettext> or </gettext>
+#        $text =~ s/^[ \t]*#.*<\/?gettext\b//mg;
         $lineno = 1;
         $lineno = 1;
-        while ($text =~ m{\G(.*?)(<gettext\b(?:\s+domain="([^"]+)")?[^>]*>)(.*?)</gettext>}gs) { # " -- to fix vim syntax hilighting :)
+        while ($text =~ m{\G(.*?) # begin at end of previous match, $1=prefix
+                             (\bg\(\s* # "g(" , $2=whole match
+                              (["']) # " quoting, $3=quotes
+                                (.*?)\3 # string, $4=string
+                              )}gxs) {
                 $msgid = escape($4);
                 $lineno += countNewline ($1.$2);
                 $nextlineno = countNewline ($4);;
                 $msgid = escape($4);
                 $lineno += countNewline ($1.$2);
                 $nextlineno = countNewline ($4);;
-                my $dom = ($3) ? $3 : 'templates';
-                if ($domain ne $dom) {
-                   $lineno += $nextlineno;
-                   next;  # wrong domain
-                }
+               my $dom = $domain;
+#                my $dom = ($3) ? $3 : 'templates';
+#                if ($domain ne $dom) {
+#                   $lineno += $nextlineno;
+#                   next;  # wrong domain
+#                }
                 $comment = '';
                 if ($1 =~ m/(((^|\n)[ \t]*#.*)+)\n?[^\n]*$/) {
                         $comment = $1;
                 $comment = '';
                 if ($1 =~ m/(((^|\n)[ \t]*#.*)+)\n?[^\n]*$/) {
                         $comment = $1;
@@ -60,12 +74,12 @@ sub processFile {
                         $comment =~ s/\n[ \t]*#\s*/\n/g;
                 }
                 push (@msgids, $msgid);
                         $comment =~ s/\n[ \t]*#\s*/\n/g;
                 }
                 push (@msgids, $msgid);
-                if (defined ($messages->{$msgid})) {
-                        print STDERR "wmlxgettext: Warning: msgid multiple defined:\n\t".
-                                $msgid."\n";
-                } else {
-                        $messages->{$msgid} = [];
-                }
+#                if (defined ($messages->{$msgid})) {
+#                        print STDERR "ttxgettext: Warning: msgid multiple defined:\n\t".
+#                                $msgid."\n";
+#                } else {
+#                        $messages->{$msgid} = [];
+#                }
                 push (@{$messages->{$msgid}}, $comment, $file, $lineno);
                 $lineno += $nextlineno;
         }
                 push (@{$messages->{$msgid}}, $comment, $file, $lineno);
                 $lineno += $nextlineno;
         }
index ec37c4fd0b0e699c6a661e109655deab72b6bb40..168a2fec669b63a3e1058ef7a8104373fbed4e9a 100755 (executable)
@@ -2,17 +2,21 @@
 
 . `dirname $0`/../config.sh
 
 
 . `dirname $0`/../config.sh
 
-gettextfiles=$(find cgi-bin lib -not -name 'LanguageNames.pm' -a -not -name 'Sections.pm' -a \( -name '*.pl' -o -name '*.pm' \));
+cd "$topdir"
+gettextfiles=$(find cgi-bin lib -not -name 'LanguageNames.pm' -a -not -name 'Sections.pm' -a \( -name '*.pl' -o -name '*.pm' \))
+templatefiles=$(find templates -name '*.tmpl' -o -name '*.inc')
 gettextfiles="$gettextfiles bin/create_index_pages"
 gettextfiles="$gettextfiles bin/create_index_pages"
-podomains="pdo sections langs"
+podomains="pdo templates sections langs"
 
 # Update pot
 #
 # Common options for all calls
 
 # Update pot
 #
 # Common options for all calls
-xgettext_opts="--language=Perl --keyword=_ --keyword=N_ --keyword=_g --foreign-user --add-comments"
+xgettext_opts="--language=Perl --keyword=N_ --keyword=_g --foreign-user --add-comments"
 
 echo gettextfiles=$gettextfiles
 
 echo gettextfiles=$gettextfiles
+echo templatefiles=$templatefiles
 xgettext $xgettext_opts -d pdo -o ${podir}/pdo.pot ${gettextfiles}
 xgettext $xgettext_opts -d pdo -o ${podir}/pdo.pot ${gettextfiles}
+$topdir/bin/ttxgettext templates ${templatefiles} >${podir}/templates.pot
 xgettext $xgettext_opts -d sections -o ${podir}/sections.pot ${libdir}/Packages/Sections.pm
 xgettext $xgettext_opts -d langs -o ${podir}/langs.pot ${libdir}/Packages/I18N/LanguageNames.pm
 
 xgettext $xgettext_opts -d sections -o ${podir}/sections.pot ${libdir}/Packages/Sections.pm
 xgettext $xgettext_opts -d langs -o ${podir}/langs.pot ${libdir}/Packages/I18N/LanguageNames.pm
 
@@ -40,8 +44,8 @@ for lang in ${polangs}
 do
   for domain in ${podomains}
   do
 do
   for domain in ${podomains}
   do
-    mv ${domain}.${lang}.po ${domain}.${lang}.po.tmp
-    msgmerge -q -F -o ${domain}.${lang}.po ${domain}.${lang}.po.tmp ${domain}.pot
+    cp ${domain}.${lang}.po ${domain}.${lang}.po.tmp
+    msgmerge --previous --quiet --sort-by-file -o ${domain}.${lang}.po ${domain}.${lang}.po.tmp ${domain}.pot
     rm ${domain}.${lang}.po.tmp
     # normalize paths in .po files
     perl -p -i -e "s,^#:\s*\Q${topdir}\E,#: .,go" ${domain}.${lang}.po
     rm ${domain}.${lang}.po.tmp
     # normalize paths in .po files
     perl -p -i -e "s,^#:\s*\Q${topdir}\E,#: .,go" ${domain}.${lang}.po
index 221bfbec8234eccc5790b6579c18464e1a1f0bf9..3ae8004ee7a577c15ce9750652acb37b0b68de6e 100755 (executable)
@@ -102,8 +102,9 @@ sub do_dispatch {
                                   \@all_langs ) || 'en';
     debug( "LANGUAGES=@all_langs header=".
           ($input->http("Accept-Language")||'').
                                   \@all_langs ) || 'en';
     debug( "LANGUAGES=@all_langs header=".
           ($input->http("Accept-Language")||'').
-          " http_lang=$http_lang", 2 ) if DEBUG;
+          " http_lang=$http_lang", 1 ) if DEBUG;
     bindtextdomain ( 'pdo', $LOCALES );
     bindtextdomain ( 'pdo', $LOCALES );
+    bindtextdomain ( 'templates', $LOCALES );
     textdomain( 'pdo' );
 
     # backwards compatibility stuff
     textdomain( 'pdo' );
 
     # backwards compatibility stuff
@@ -287,7 +288,7 @@ sub do_dispatch {
                        setlocale( LC_ALL, "C" );
                    };
            };
                        setlocale( LC_ALL, "C" );
                    };
            };
-    debug( "locale=$locale charset=$charset", 2 ) if DEBUG;
+    debug( "locale=$locale charset=$charset", 1 ) if DEBUG;
 
     $opts{h_suites} = { map { $_ => 1 } @suites };
     $opts{h_sections} = { map { $_ => 1 } @sections };
 
     $opts{h_suites} = { map { $_ => 1 } @suites };
     $opts{h_sections} = { map { $_ => 1 } @sections };
@@ -338,6 +339,7 @@ sub do_dispatch {
                                        $host .= ':'.$uri->port if $uri->port != $uri->default_port;
                                        return $host;
                                    };
                                        $host .= ':'.$uri->port if $uri->port != $uri->default_port;
                                        return $host;
                                    };
+    $page_content{g} = sub { return &Packages::I18N::Locale::tt_gettext(@_) };
     # needed to work around the limitations of the the FILTER syntax
     $page_content{html_encode} = sub { return HTML::Entities::encode_entities(@_,'<>&"') };
     $page_content{uri_escape} = sub { return URI::Escape::uri_escape(@_) };
     # needed to work around the limitations of the the FILTER syntax
     $page_content{html_encode} = sub { return HTML::Entities::encode_entities(@_,'<>&"') };
     $page_content{uri_escape} = sub { return URI::Escape::uri_escape(@_) };
index 623bfc7f9ce1f53e4eed09bfef5bf0183f28fa7a..fd987586020433cdf80680c4262f9950774d3f71 100644 (file)
@@ -49,6 +49,11 @@ sub get_charset {
     return $lang2charset{$lang} || $lang2charset{default};
 }
 
     return $lang2charset{$lang} || $lang2charset{default};
 }
 
+sub tt_gettext {
+    my ($str, @args) = @_;
+    return dgettext( 'templates', $str ) unless @args;
+    return sprintf(dgettext( 'templates', $str ), @args);
+}
 sub _g { return gettext( $_[0] ) }
 sub N_ { return $_[0] }
 
 sub _g { return gettext( $_[0] ) }
 sub N_ { return $_[0] }