From: Frank Lichtenheld Date: Sat, 13 Oct 2007 23:30:17 +0000 (+0200) Subject: Make all index pages translatable X-Git-Url: https://git.deb.at/w?a=commitdiff_plain;h=1bae1b743532d7d100015b751fe1f7be52198b8b;p=deb%2Fpackages.git Make all index pages translatable --- diff --git a/bin/create_index_pages b/bin/create_index_pages index 9beac92..7f35b31 100755 --- a/bin/create_index_pages +++ b/bin/create_index_pages @@ -61,6 +61,7 @@ $tt_vars{uri_escape} = sub { return URI::Escape::uri_escape(@_) }; $tt_vars{quotemeta} = sub { return quotemeta($_[0]) }; my $template = new Packages::Template( "$TOPDIR/templates", 'html', \%tt_vars ); +my $txt_template = new Packages::Template( "$TOPDIR/templates", 'txt', \%tt_vars ); print "write suite index files ...\n"; foreach my $s (@SUITES) { @@ -90,20 +91,14 @@ foreach my $s (@SUITES) { } } - open $pages{$key}{$lang}{index}{fh}, '>', "$wwwdir/$key/index.$lang.html.new" - or die "can't open index file for output: $!"; - print {$pages{$key}{$lang}{index}{fh}} $template->page( 'suite_index', \%content ); - close $pages{$key}{$lang}{index}{fh} or - warn "can't close index file $wwwdir/$key/index.$lang.html.new: $!"; + $template->page( 'suite_index', \%content, + "$wwwdir/$key/index.$lang.html.new"); rename( "$wwwdir/$key/index.$lang.html.new", "$wwwdir/$key/index.$lang.html" ); $content{source} = 'source'; - open $pages{$key}{$lang}{source_index}{fh}, '>', "$wwwdir/source/$key/index.$lang.html.new" - or die "can't open index file for output: $!"; - print {$pages{$key}{$lang}{source_index}{fh}} $template->page( 'suite_index', \%content ); - close $pages{$key}{$lang}{source_index}{fh} or - warn "can't close index file $wwwdir/source/$key/index.$lang.html.new: $!"; + $template->page( 'suite_index', \%content, + "$wwwdir/source/$key/index.$lang.html.new"); rename( "$wwwdir/source/$key/index.$lang.html.new", "$wwwdir/source/$key/index.$lang.html" ); @@ -206,64 +201,72 @@ sub write_files { foreach my $s (@SUITES) { my $key = $s; mkpath ( "$wwwdir/$source$key" ); - print "writing $source$s/allpackages...\n"; - $template->process( 'html/index.tmpl', { packages => $pkgs->{$key}, suite => $s, lang => 'en', is_source => $source }, - "$wwwdir/$source$key/allpackages.en.html.new" ) - or die "error writing allpackages for $key: ".$template->error(); - print "writing $source$s/allpackages (txt)...\n"; - my $gzfh = gzopen("$wwwdir/$source$key/allpackages.en.txt.gz.new", - 'wb9') - or die "can't open text index file for output: $!"; - my $gztxt; - $template->process( 'txt/index.tmpl', { packages => $pkgs->{$key}, suite => $s, lang => 'en', is_source => $source }, - \$gztxt ) - or die "error writing allpackages txt for $key: ".$template->error(); - $gzfh->gzwrite($gztxt); - ($gzfh->gzclose == Z_OK) or - warn "can't close text index file $wwwdir/$source$key/allpackages.en.txt.gz.new: ".$gzfh->gzerror; - - rename( "$wwwdir/$source$key/allpackages.en.html.new", - "$wwwdir/$source$key/allpackages.en.html" ); - rename( "$wwwdir/$source$key/allpackages.en.txt.gz.new", - "$wwwdir/$source$key/allpackages.en.txt.gz" ); - - foreach my $sec (keys %{$sections->{$s}}) { - mkpath ( "$wwwdir/$source$key/$sec" ); - - print "writing $source$s/$sec/index...\n"; - $template->process( 'html/index.tmpl', { packages => [ grep { $_->{section} eq $sec } @{$pkgs->{$key}} ], - suite => $s, lang => 'en', is_source => $source, - category => { id => 'section', name => $sec } }, - "$wwwdir/$source$key/$sec/index.en.html.new" ) - or die "error writing section index for $key/$sec: ".$template->error(); - rename( "$wwwdir/$source$key/$sec/index.en.html.new", - "$wwwdir/$source$key/$sec/index.en.html" ); - } - foreach my $ssec ((keys %{$subsections->{$s}}, 'virtual')) { - next if $ssec eq '-'; - mkpath ( "$wwwdir/$source$key/$ssec" ); - - print "writing $source$s/$ssec/index...\n"; - $template->process( 'html/index.tmpl', { packages => [ grep { $_->{subsection} eq $ssec } @{$pkgs->{$key}} ], - suite => $s, lang => 'en', is_source => $source, - category => { id => 'subsection', name => $ssec } }, - "$wwwdir/$source$key/$ssec/index.en.html.new" ) - or die "error writing subsection index for $key/$ssec: ".$template->error(); - rename( "$wwwdir/$source$key/$ssec/index.en.html.new", - "$wwwdir/$source$key/$ssec/index.en.html" ); - } - foreach my $prio (keys %{$priorities->{$s}}) { - next if $prio eq '-'; - mkpath ( "$wwwdir/$source$key/$prio" ); - - print "writing $source$s/$prio/index...\n"; - $template->process( 'html/index.tmpl', { packages => [ grep { $_->{priority} eq $prio } @{$pkgs->{$key}} ], - suite => $s, lang => 'en', is_source => $source, - category => { id => 'priority', name => $prio } }, - "$wwwdir/$source$key/$prio/index.en.html.new" ) - or die "error writing priority index for $key/$prio: ".$template->error(); - rename( "$wwwdir/$source$key/$prio/index.en.html.new", - "$wwwdir/$source$key/$prio/index.en.html" ); + foreach my $lang (@LANGUAGES) { + my $locale = get_locale( $lang ); + my $charset = get_charset( $lang ); + setlocale ( LC_ALL, $locale ) or do { + warn "couldn't set locale ($lang/$locale)\n"; + next; + }; + + my %lang_vars = ( lang => $lang, charset => $charset, + used_langs => \@LANGUAGES ); + print "writing $source$s/allpackages (lang=$lang)...\n"; + $template->page( 'index', { %lang_vars, packages => $pkgs->{$key}, + suite => $s, is_source => $source }, + "$wwwdir/$source$key/allpackages.$lang.html.new" ); + print "writing $source$s/allpackages (txt,lang=$lang)...\n"; + my $gzfh = gzopen("$wwwdir/$source$key/allpackages.$lang.txt.gz.new", + 'wb9') + or die "can't open text index file for output: $!"; + my $gztxt; + $gztxt = $txt_template->page( 'index', { %lang_vars, packages => $pkgs->{$key}, + suite => $s, is_source => $source }, + ); + $gzfh->gzwrite($gztxt); + ($gzfh->gzclose == Z_OK) or + warn "can't close text index file $wwwdir/$source$key/allpackages.$lang.txt.gz.new: ".$gzfh->gzerror; + + rename( "$wwwdir/$source$key/allpackages.$lang.html.new", + "$wwwdir/$source$key/allpackages.$lang.html" ); + rename( "$wwwdir/$source$key/allpackages.$lang.txt.gz.new", + "$wwwdir/$source$key/allpackages.$lang.txt.gz" ); + + foreach my $sec (keys %{$sections->{$s}}) { + mkpath ( "$wwwdir/$source$key/$sec" ); + + print "writing $source$s/$sec/index (lang=$lang)...\n"; + $template->page( 'index', { packages => [ grep { $_->{section} eq $sec } @{$pkgs->{$key}} ], + %lang_vars, suite => $s, is_source => $source, + category => { id => _g('Section'), name => $sec } }, + "$wwwdir/$source$key/$sec/index.$lang.html.new" ); + rename( "$wwwdir/$source$key/$sec/index.$lang.html.new", + "$wwwdir/$source$key/$sec/index.$lang.html" ); + } + foreach my $ssec ((keys %{$subsections->{$s}}, 'virtual')) { + next if $ssec eq '-'; + mkpath ( "$wwwdir/$source$key/$ssec" ); + + print "writing $source$s/$ssec/index (lang=$lang)...\n"; + $template->page( 'index', { packages => [ grep { $_->{subsection} eq $ssec } @{$pkgs->{$key}} ], + %lang_vars, suite => $s, is_source => $source, + category => { id => _g('Subsection'), name => $ssec } }, + "$wwwdir/$source$key/$ssec/index.$lang.html.new" ); + rename( "$wwwdir/$source$key/$ssec/index.$lang.html.new", + "$wwwdir/$source$key/$ssec/index.$lang.html" ); + } + foreach my $prio (keys %{$priorities->{$s}}) { + next if $prio eq '-'; + mkpath ( "$wwwdir/$source$key/$prio" ); + + print "writing $source$s/$prio/index (lang=$lang)...\n"; + $template->page( 'index', { packages => [ grep { $_->{priority} eq $prio } @{$pkgs->{$key}} ], + %lang_vars, suite => $s, is_source => $source, + category => { id => _g('Priority'), name => $prio } }, + "$wwwdir/$source$key/$prio/index.$lang.html.new" ); + rename( "$wwwdir/$source$key/$prio/index.$lang.html.new", + "$wwwdir/$source$key/$prio/index.$lang.html" ); + } } } } diff --git a/lib/Packages/DoIndex.pm b/lib/Packages/DoIndex.pm index 45a5b49..1c8f52a 100644 --- a/lib/Packages/DoIndex.pm +++ b/lib/Packages/DoIndex.pm @@ -44,14 +44,12 @@ sub send_file { $path .= "$opts->{archive}[0]/" if @{$opts->{archive}} == 1; $path .= "$opts->{subsection}[0]/" if @{$opts->{subsection}}; $path .= "$opts->{priority}[0]/" if @{$opts->{priority}}; - # we don't have translated index pages for subsections yet - $opts->{lang} = 'en' if @{$opts->{subsection}} or $file eq 'allpackages'; #FIXME: ugly hack if ($opts->{lang} ne 'en' and !-f "$wwwdir/$path$file.$opts->{lang}.$opts->{format}") { - $opts->{lang} = 'en'; + $opts->{lang} = 'en'; } - $path .= "$file.$opts->{lang}.$opts->{format}"; + $path .= "$file.$opts->{lang}.$opts->{format}"; unless (@Packages::CGI::fatal_errors) { my $buffer; diff --git a/templates/html/index.tmpl b/templates/html/index.tmpl index 74a30b0..a5139b5 100644 --- a/templates/html/index.tmpl +++ b/templates/html/index.tmpl @@ -1,15 +1,19 @@ [% PROCESS 'config/archive_layout.tmpl' %] -[% pkg_type = is_source ? 'Source' : 'Software'; - title_common = category ? "$pkg_type Packages in \"$suite\", $category.id $category.name" - : "$pkg_type Packages in \"$suite\""; +[% IF is_source; + title_common = category ? g('Source Packages in "%s", %s %s', suite, category.id, category.name) + : g('Source Packages in "%s"', suite); + ELSE; + title_common = category ? g('Software Packages in "%s", %s %s', suite, category.id, category.name) + : g('Software Packages in "%s"', suite); + END; - nav_arr = [ { prefix=>'Distribution:', title=>'Overview over this suite', url=>make_url('/','','suite',suite), name=>suite } ]; + nav_arr = [ { prefix=>g('Distribution:'), title=>g('Overview over this suite'), url=>make_url('/','','suite',suite), name=>suite } ]; IF category; nav_last = { prefix=>"$category.id:", name=>category.name }; ELSE; - nav_last = { name=>'All Packages' }; + nav_last = { name=>g('All Packages') }; END; - nav_arr.push( { name=>'Source', + nav_arr.push( { name=>g('Source'), url=>make_url('/','','suite',suite,'source','source') } ) IF is_source; nav_arr.push( nav_last ); @@ -31,7 +35,7 @@ [% END %] [% IF providers.size %]
[% name %]
-
virtual package provided by +
[% g('virtual package provided by') %] [% FOREACH provider IN providers %][% provider %] [%- ', ' UNLESS loop.last %][% END %]
[% IF versions.length %] diff --git a/templates/html/suite_index.tmpl b/templates/html/suite_index.tmpl index 465c693..baf70e4 100644 --- a/templates/html/suite_index.tmpl +++ b/templates/html/suite_index.tmpl @@ -1,8 +1,8 @@ [% nav_arr = [ { name=> suite, url=>make_url('/','','suite',suite) } ]; - nav_arr.push( { name => 'Source' } ) IF source; - nav_arr.push( { name => 'Index' } ); + nav_arr.push( { name => g('Source') } ) IF source; + nav_arr.push( { name => g('Index') } ); PROCESS 'html/head.tmpl' - title_tag = "List of sections in \"$suite\"" + title_tag = g('List of sections in "%s"', suite) keywords = suite navigation = nav_arr %] @@ -17,7 +17,7 @@ [%- '' IF loop.last -%] [% END %] -

List of sections in "[% suite %]"

+

[% g('List of sections in "%s"', suite) %]

[% FOREACH subsections %] [% '
' IF loop.first %] @@ -35,9 +35,14 @@ [% '
' IF loop.last %] [% END %] +[% link_title = is_source ? g('List of all source packages') + : g('List of all packages'); + link_text = is_source ? g('All source packages') + : g('All packages'); +-%]

- All [% "source " IF source %]packages
- (compact compressed textlist) + [% link_text %]
+ ([% g('compact compressed textlist') %])

[%- PROCESS 'html/foot.tmpl' -%] diff --git a/templates/txt/index.tmpl b/templates/txt/index.tmpl index 12e249c..dca0910 100644 --- a/templates/txt/index.tmpl +++ b/templates/txt/index.tmpl @@ -1,9 +1,9 @@ [%- PROCESS 'config/archive_layout.tmpl' -%] -All Debian Packages in "[% suite %]" +[% g('All %s Packages in "%s"', organisation, suite) %] -Last Modified: [% timestamp.string %] -Copyright (C) [% copyright.years %] [% copyright.name %]; -See for the license terms. +[% g('Generated:') _ ' ' _ timestamp.string %] +[% g('Copyright (C)') _ ' ' _ copyright.years _ ' ' _ copyright.name %]; +[% g('See for the license terms.', license.url) %] [% FOREACH packages -%] [%- BLOCK marker %] [[% text %]][% END -%] @@ -12,7 +12,7 @@ See for the license terms. [%- PROCESS marker text=archive IF archive != main_archive -%] [%- END -%] [%- IF providers.size %] -[% name %] virtual package provided by [% providers.join(', ') %] +[% name %] [% g('virtual package provided by') _ ' ' _ providers.join(', ') %] [%- END -%] [%- IF versions %] [% name %] ([% versions %])[% PROCESS markers %] [% desc %]