]> git.deb.at Git - deb/packages.git/commitdiff
Display translated descriptions
authorFrank Lichtenheld <frank@lichtenheld.de>
Sun, 17 Jun 2007 16:58:29 +0000 (18:58 +0200)
committerFrank Lichtenheld <frank@lichtenheld.de>
Sun, 17 Jun 2007 16:58:29 +0000 (18:58 +0200)
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...

lib/Packages/DoShow.pm
templates/html/show.tmpl

index 3af5e3e7c83056a118a40dcd6ac587677903752b..f808f1f7e547b57ea5ac56e1837eafe55c77728f 100644 (file)
@@ -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~-]+?/?)((\&gt\;)?[)]?[']?[:.\,]?(\s|$)),<a href=\"$1\">$1</a>$3,go; # syntax highlighting -> '];
+                           $long_desc =~ s/\A //o;
+                           $long_desc =~ s/\n /\n/sgo;
+                           $long_desc =~ s/\n.\n/\n<p>\n/go;
+                           $long_desc =~ s/(((\n|\A) [^\n]*)+)/\n<pre>$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~-]+?/?)((\&gt\;)?[)]?[']?[:.\,]?(\s|$)),<a href=\"$1\">$1</a>$3,go; # syntax highlighting -> '];
-                       $long_desc =~ s/\A //o;
-                       $long_desc =~ s/\n /\n/sgo;
-                       $long_desc =~ s/\n.\n/\n<p>\n/go;
-                       $long_desc =~ s/(((\n|\A) [^\n]*)+)/\n<pre>$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;
index f2993ed1b2ea47d178477dac80a2bb297205edfc..0ef593e7bafd9bc51598bbe2d90ee15d9b4bb78f 100644 (file)
@@ -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.</p>
 <div id="pdesctab">
 <div id="pdesc">
 [% UNLESS is_virtual %]
-       [% IF desc.short %]
-       <h2>[% desc.short %]</h2>
-       <p>[% desc.long %]
+       [% IF desc.$desclang.short %]
+       <h2>[% desc.$desclang.short %]</h2>
+       <p>[% desc.$desclang.long %]
        [% END %]
 [% ELSE %]
        <p>This is a <em>virtual package</em>. See the <a href="[% policy_url %]">Debian policy</a> for a <a href="[% policy_url %]ch-binary.html#s-virtual_pkg">definition of virtual packages</a>.</p>