From: Frank Lichtenheld Date: Sun, 17 Jun 2007 16:58:29 +0000 (+0200) Subject: Display translated descriptions X-Git-Url: https://git.deb.at/?p=deb%2Fpackages.git;a=commitdiff_plain;h=1cc237c732b99138c613a79c59db361f75f9dd71;ds=sidebyside Display translated descriptions This only adds support for displaying the description itself on the show page, not the short description in dependencies or in search results. The latter is more complicated now since we store the short description in packages_small exactly because these places are performance critical and to have to access one more database in these places is bad... --- diff --git a/lib/Packages/DoShow.pm b/lib/Packages/DoShow.pm index 3af5e3e..f808f1f 100644 --- a/lib/Packages/DoShow.pm +++ b/lib/Packages/DoShow.pm @@ -12,7 +12,7 @@ use Exporter; use Deb::Versions; use Packages::Config qw( $DBDIR @SUITES @ARCHIVES @SECTIONS - @ARCHITECTURES %FTP_SITES ); + @ARCHITECTURES %FTP_SITES @DDTP_LANGUAGES); use Packages::I18N::Locale; use Packages::CGI qw( :DEFAULT make_url make_search_url note ); use Packages::DB; @@ -121,6 +121,7 @@ sub do_show { debug( "Data search and merging took ".timestr($std) ) if DEBUG; my $did = $page->get_newest( 'description' ); + my $desc_md5 = $page->get_newest( 'description-md5' ); my @complete_tags = split(/, /, $page->get_newest( 'tag' )); my @tags; foreach (@complete_tags) { @@ -153,19 +154,43 @@ sub do_show { # process description # + sub process_description { + my ($desc) = @_; + + my $short_desc = encode_entities( $1, "<>&\"" ) + if $desc =~ s/^(.*)$//m; + my $long_desc = encode_entities( $desc, "<>&\"" ); + + $long_desc =~ s,((ftp|http|https)://[\S~-]+?/?)((\>\;)?[)]?[']?[:.\,]?(\s|$)),$1$3,go; # syntax highlighting -> ']; + $long_desc =~ s/\A //o; + $long_desc =~ s/\n /\n/sgo; + $long_desc =~ s/\n.\n/\n

\n/go; + $long_desc =~ s/(((\n|\A) [^\n]*)+)/\n

$1\n<\/pre>/sgo;
+
+			    return ($short_desc, $long_desc);
+			}
+
 			my $desc = $descriptions{$did};
-			$short_desc = encode_entities( $1, "<>&\"" )
-			    if $desc =~ s/^(.*)$//m;
-			my $long_desc = encode_entities( $desc, "<>&\"" );
-
-			$long_desc =~ s,((ftp|http|https)://[\S~-]+?/?)((\>\;)?[)]?[']?[:.\,]?(\s|$)),$1$3,go; # syntax highlighting -> '];
-			$long_desc =~ s/\A //o;
-			$long_desc =~ s/\n /\n/sgo;
-			$long_desc =~ s/\n.\n/\n

\n/go; - $long_desc =~ s/(((\n|\A) [^\n]*)+)/\n

$1\n<\/pre>/sgo;
-
-			$contents{desc} = { short => $short_desc,
-					    long => $long_desc, };
+			my $long_desc;
+			($short_desc, $long_desc) = process_description($desc);
+
+			$contents{desc}{en} = { short => $short_desc,
+						long => $long_desc, };
+
+			debug( "desc_md5=$desc_md5", 2)
+			    if DEBUG;
+			my $trans_desc = $desctrans{$desc_md5};
+			if ($trans_desc) {
+			    my %trans_desc = split /\000|\001/, $trans_desc;
+			    debug( "TRANSLATIONS: ".join(" ",keys %trans_desc), 2)
+				if DEBUG;
+			    while (my ($l, $d) = each %trans_desc) {
+				my ($short_t, $long_t) = process_description($d);
+
+				$contents{desc}{$l} = { short => $short_t,
+							long => $long_t, };
+			    }
+			}
 
 			my $v_str = $version;
 			my $multiple_versions = grep { $_ ne $version } values %$versions;
diff --git a/templates/html/show.tmpl b/templates/html/show.tmpl
index f2993ed..0ef593e 100644
--- a/templates/html/show.tmpl
+++ b/templates/html/show.tmpl
@@ -4,10 +4,12 @@
     nav_arr.push( { title => 'Source packages', url=>make_url('/'), name=>'Source' } ) IF is_source;
     nav_arr.push( { prefix=>'Section:', title=>'All packages in this section', url=>make_url("$subsection/"), name=>subsection } );
     nav_arr.push( { prefix=>'Package:', name=>pkg } ); -%]
+[% desclang = 'en';
+   SET desclang = lang IF desc.$lang.long %]
 [%- PROCESS 'html/head.tmpl'
    title_tag = ( is_source ? "Details of source package $pkg in $suite"
 	                   : "Details of package $pkg in $suite" )
-   description = desc
+   description = desc.$desclang.short
    keywords = "$suite, $archive, $section, $subsection, $version"
    print_search_field = 'packages'
    search_field_values = { 
@@ -151,9 +153,9 @@ Do not install it on a normal Debian system.

[% UNLESS is_virtual %] - [% IF desc.short %] -

[% desc.short %]

-

[% desc.long %] + [% IF desc.$desclang.short %] +

[% desc.$desclang.short %]

+

[% desc.$desclang.long %] [% END %] [% ELSE %]

This is a virtual package. See the Debian policy for a definition of virtual packages.