delete $ENV{'LC_MESSAGES'};
bindtextdomain ( 'pdo', $LOCALES );
bindtextdomain ( 'sections', $LOCALES );
+bindtextdomain ( 'templates', $LOCALES );
textdomain( 'pdo' );
my $wwwdir = "$TOPDIR/www";
$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(@_) };
#! /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;
$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;
- 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);;
- 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 =~ 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;
}
. `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"
-podomains="pdo sections langs"
+podomains="pdo templates sections langs"
# 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 templatefiles=$templatefiles
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
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
\@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 ( 'templates', $LOCALES );
textdomain( 'pdo' );
# backwards compatibility stuff
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 };
$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(@_) };
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] }