]> git.deb.at Git - deb/packages.git/blobdiff - lib/Packages/DoSearch.pm
Change _small.db layout a bit, to include virtual packages consisely at the
[deb/packages.git] / lib / Packages / DoSearch.pm
index 630411f5de9e76db68997d25bd6bce62947c24b1..275cb9bebc73d4a3846f4645b6b1779be1af0e3e 100644 (file)
@@ -12,19 +12,24 @@ our @ISA = qw( Exporter );
 our @EXPORT = qw( do_search );
 
 use Deb::Versions;
+use Packages::I18N::Locale;
 use Packages::Search qw( :all );
 use Packages::CGI;
 use Packages::DB;
-use Packages::Config qw( $DBDIR $SEARCH_URL $SEARCH_CGI $SEARCH_PAGE
+use Packages::HTML qw(marker);
+use Packages::Config qw( $DBDIR $SEARCH_URL $SEARCH_PAGE
                         @SUITES @ARCHIVES $ROOT );
+use Packages::HTML;
 
 sub do_search {
     my ($params, $opts, $html_header, $menu, $page_content) = @_;
 
+    $Params::Search::too_many_hits = 0;
+
     if ($params->{errors}{keywords}) {
-       fatal_error( "keyword not valid or missing" );
+       fatal_error( _g( "keyword not valid or missing" ) );
     } elsif (length($opts->{keywords}) < 2) {
-       fatal_error( "keyword too short (keywords need to have at least two characters)" );
+       fatal_error( _g( "keyword too short (keywords need to have at least two characters)" ) );
     }
 
     $$menu = "";
@@ -37,6 +42,7 @@ sub do_search {
     my $suites_param = join ',', @{$params->{values}{suite}{no_replace}};
     my $sections_param = join ',', @{$params->{values}{section}{no_replace}};
     my $archs_param = join ',', @{$params->{values}{arch}{no_replace}};
+    $opts->{common_params} = "suite=$suites_param&section=$sections_param&keywords=$keyword_esc&searchon=$searchon&arch=$archs_param";
 
     # for output
     my $keyword_enc = encode_entities $keyword || '';
@@ -75,64 +81,69 @@ sub do_search {
     }
     
 #    use Data::Dumper;
-#    debug( join( "", Dumper( \@results, \@non_results )) );
+#    debug( join( "", Dumper( \@results, \@non_results )) ) if DEBUG;
     my $st1 = new Benchmark;
     my $std = timediff($st1, $st0);
-    debug( "Search took ".timestr($std) );
+    debug( "Search took ".timestr($std) ) if DEBUG;
     
-    my $suite_wording = $suites_enc eq "all" ? "all suites"
-       : "suite(s) <em>$suites_enc</em>";
-    my $section_wording = $sections_enc eq 'all' ? "all sections"
-       : "section(s) <em>$sections_enc</em>";
-    my $arch_wording = $archs_enc eq 'any' ? "all architectures"
-       : "architecture(s) <em>$archs_enc</em>";
+    my $suite_wording = $suites_enc eq "all" ? _g("all suites")
+       : sprintf(_g("suite(s) <em>%s</em>", $suites_enc) );
+    my $section_wording = $sections_enc eq 'all' ? _g("all sections")
+       : sprintf(_g("section(s) <em>%s</em>", $sections_enc) );
+    my $arch_wording = $archs_enc eq 'any' ? _g("all architectures")
+       : sprintf(_g("architecture(s) <em>%s</em>", $archs_enc) );
     if ($searchon eq "names") {
-       my $source_wording = $opts->{source} ? "source " : "";
-       my $exact_wording = $opts->{exact} ? "named" : "that names contain";
-       msg( "You have searched for ${source_wording}packages $exact_wording <em>$keyword_enc</em> in $suite_wording, $section_wording, and $arch_wording." );
+       my $source_wording = $opts->{source} ? _g("source packages") : _g("packages");
+       # sorry to all translators for that one... (patches welcome)
+       msg( sprintf( _g( "You have searched for %s that names contain <em>%s</em> in %s, %s, and %s." ),
+                     $source_wording, $keyword_enc,
+                     $suite_wording, $section_wording, $arch_wording ) );
     } else {
-       my $exact_wording = $opts->{exact} ? "" : " (including subword matching)";
-       msg( "You have searched for <em>$keyword_enc</em> in packages names and descriptions in $suite_wording, $section_wording, and $arch_wording$exact_wording." );
+       my $exact_wording = $opts->{exact} ? "" : _g(" (including subword matching)");
+       msg( sprintf( _g( "You have searched for <em>%s</em> in packages names and descriptions in %s, %s, and %s%s." ),
+                     $keyword_enc,
+                     $suite_wording, $section_wording, $arch_wording,
+                     $exact_wording ) );
     }
 
     if ($Packages::Search::too_many_hits) {
-       error( "Your search was too wide so we will only display exact matches. At least <em>$Packages::Search::too_many_hits</em> results have been omitted and will not be displayed. Please consider using a longer keyword or more keywords." );
+       error( sprintf( _g( "Your search was too wide so we will only display exact matches. At least <em>%s</em> results have been omitted and will not be displayed. Please consider using a longer keyword or more keywords." ), $Packages::Search::too_many_hits ) );
     }
     
     if (!@Packages::CGI::fatal_errors && !@results) {
-       my $printed = 0;
        if ($searchon eq "names") {
            unless (@non_results) {
-               error( "Can't find that package." );
+               error( _g( "Can't find that package." ) );
            } else {
-               hint( "Can't find that package. ".
-                     "<a href=\"$SEARCH_URL/$keyword_esc\">".
-                     ($#non_results+1)."</a>".
+               hint( _g( "Can't find that package." )." ".
+                     sprintf( _g( '<a href="%s">%s</a>'.
                      " results have not been displayed due to the".
-                     " search parameters." );
+                     " search parameters." ), "$SEARCH_URL/$keyword_esc" ,
+                     $#non_results+1 ) );
            }
            
        } else {
            if (($suites_enc eq 'all')
                && ($archs_enc eq 'any')
                && ($sections_enc eq 'all')) {
-               error( "Can't find that string." );
+               error( _g( "Can't find that string." ) );
            } else {
-               error( "Can't find that string, at least not in that suite ($suites_enc, section $sections_enc) and on that architecture ($archs_enc)." );
+               error( sprintf( _g( "Can't find that string, at least not in that suite (%s, section %s) and on that architecture (%s)." ),
+                               $suites_enc, $sections_enc, $archs_enc ) );
            }
            
            if ($opts->{exact}) {
-               $printed++;
-               hint( "You have searched only for words exactly matching your keywords. You can try to search <a href=\"$SEARCH_CGI?exact=0;searchon=$searchon;suite=$suites_param;section=$sections_param;keywords=$keyword_esc;arch=$archs_param\">allowing subword matching</a>." );
+               hint( sprintf( _g( 'You have searched only for words exactly matching your keywords. You can try to search <a href="%s">allowing subword matching</a>.' ),
+                              encode_entities("$SEARCH_URL?exact=0&$opts->{common_params}") ) );
            }
        }
-       hint( ( $printed ? "Or you" : "You" )." can try a different search on the <a href=\"$SEARCH_PAGE#search_packages\">Packages search page</a>." );
+       hint( sprintf( _g( 'You can try a different search on the <a href="%s">Packages search page</a>.' ), "$SEARCH_PAGE#search_packages" ) );
        
     }
 
-    %$html_header = ( title => 'Package Search Results' ,
-                     lang => 'en',
-                     title_tag => 'Debian Package Search Results',
+    %$html_header = ( title => _g( 'Package Search Results' ) ,
+                     lang => $opts->{lang},
+                     title_tag => _g( 'Debian Package Search Results' ),
                      print_title => 1,
                      print_search_field => 'packages',
                      search_field_values => { 
@@ -172,7 +183,7 @@ sub do_search {
                    
                    $desc{$pkg}{$suite}{$archive}{$version} = $desc;
                } else {
-                   $provided_by{$pkg}{$suite}{$archive} = [ split /\s+/, $desc ];
+                   $provided_by{$pkg}{$suite} = [ split /\s+/, $desc ];
                }
            }
 
@@ -219,20 +230,22 @@ sub print_packages {
     my ($pkgs, $pkgs_list, $opts, $keyword, $print_func, @func_args) = @_;
 
     #my ($start, $end) = multipageheader( $input, scalar @pkgs, \%opts );
-    my $str .= "<p>Found <em>".(scalar @$pkgs_list)."</em> matching packages.";
+    my $str = '<div id="psearchres">';
+    $str .= "<p>".sprintf( _g( "Found <em>%s</em> matching packages." ),
+                          scalar @$pkgs_list )."</p>";
     #my $count = 0;
            
     my $have_exact;
     if (grep { $_ eq $keyword } @$pkgs_list) {
        $have_exact = 1;
-       $str .= '<h2 style="padding:.3em;border-top:solid grey thin;border-bottom:solid grey thin;background-color:#bdf">Exact hits</h2>';
+       $str .= '<h2>'._g( "Exact hits" ).'</h2>';
        $str .= &$print_func( $keyword, $pkgs->{$keyword}||{},
                              map { $_->{$keyword}||{} } @func_args );
        @$pkgs_list = grep { $_ ne $keyword } @$pkgs_list;
     }
            
     if (@$pkgs_list && (($opts->{searchon} ne 'names') || !$opts->{exact})) {
-       $str .= '<h2 style="padding:.3em;border-top:solid grey thin;border-bottom:solid grey thin;background-color:#bdf">Other hits</h2>'
+       $str .= '<h2>'._g( 'Other hits' ).'</h2>'
            if $have_exact;
        
        foreach my $pkg (@$pkgs_list) {
@@ -242,9 +255,11 @@ sub print_packages {
                                  map { $_->{$pkg}||{} } @func_args );
        }
     } elsif (@$pkgs_list) {
-       $str .= "<p><a href=\"$SEARCH_URL/FIXME\">".
-           ($#{$pkgs_list}+1)."</a> results have not been displayed because you requested only exact matches.</p>";
+       $str .= "<p>".sprintf( _g( '<a href="%s">%s</a> results have not been displayed because you requested only exact matches.' ),
+                              encode_entities("$SEARCH_URL?exact=0&$opts->{common_params}"),
+                              scalar @$pkgs_list )."</p>";
     }
+    $str .= '</div>';
 
     return $str;
 }
@@ -252,8 +267,8 @@ sub print_packages {
 sub print_package {
     my ($pkg, $pkgs, $provided_by, $archives, $sect, $subsect, $desc) = @_;
 
-    my $str = sprintf "<h3>Package %s</h3>\n", $pkg;
-    $str .= "<ul>\n";
+    my $str = '<h3>'.sprintf( _g( 'Package %s' ), $pkg ).'</h3>';
+    $str .= '<ul>';
     foreach my $suite (@SUITES) {
        foreach my $archive (@ARCHIVES) {
            next if $archive eq 'security';
@@ -264,7 +279,7 @@ sub print_package {
                my @versions = version_sort keys %{$pkgs->{$suite}{$archive}};
                my $origin_str = "";
                if ($sect->{$suite}{$archive}{$versions[0]}) {
-                   $origin_str .= " [<span style=\"color:red\">$sect->{$suite}{$archive}{$versions[0]}</span>]";
+                   $origin_str .= " ".marker($sect->{$suite}{$archive}{$versions[0]});
                }
                $str .= sprintf( "<li><a href=\"$ROOT/%s/%s\">%s</a> (%s): %s   %s\n",
                                 $path, $pkg, $path, $subsect->{$suite}{$archive}{$versions[0]},
@@ -273,7 +288,7 @@ sub print_package {
                foreach my $v (@versions) {
                    my $archive_str = "";
                    if ($archives->{$suite}{$archive}{$v}) {
-                       $archive_str .= " [<span style=\"color:red\">$archives->{$suite}{$archive}{$v}</span>]";
+                       $archive_str .= " ".marker($archives->{$suite}{$archive}{$v});
                    }
                    
                    my @archs_to_print = grep { !$archs_printed{$_} } sort keys %{$pkgs->{$suite}{$archive}{$v}};
@@ -282,15 +297,15 @@ sub print_package {
                        if @archs_to_print;
                    $archs_printed{$_}++ foreach @archs_to_print;
                }
-               if (my $p =  $provided_by->{$suite}{$archive}) {
-                   $str .= '<br>also provided by: '.
+               if (my $p =  $provided_by->{$suite}) {
+                   $str .= '<br>'._g( 'also provided by: ' ).
                        join( ', ', map { "<a href=\"$ROOT/$path/$_\">$_</a>"  } @$p);
                }
                $str .= "</li>\n";
-           } elsif (my $p =  $provided_by->{$suite}{$archive}) {
+           } elsif (my $p =  $provided_by->{$suite}) {
                $str .= sprintf( "<li><a href=\"$ROOT/%s/%s\">%s</a>: Virtual package<br>",
                                 $path, $pkg, $path );
-               $str .= 'provided by: '.
+               $str .= _g( 'provided by: ' ).
                    join( ', ', map { "<a href=\"$ROOT/$path/$_\">$_</a>"  } @$p);
            }
        }
@@ -302,23 +317,23 @@ sub print_package {
 sub print_src_package {
     my ($pkg, $pkgs, $archives, $sect, $subsect, $binaries) = @_;
 
-    my $str = sprintf "<h3>Source package %s</h3>\n", $pkg;
+    my $str = '<h3>'.sprintf( _g( 'Source package %s' ), $pkg ).'</h3>';
     $str .= "<ul>\n";
     foreach my $suite (@SUITES) {
        foreach my $archive (@ARCHIVES) {
            if (exists $pkgs->{$suite}{$archive}) {
                my $origin_str = "";
                if ($sect->{$suite}{$archive}{source}) {
-                   $origin_str .= " [<span style=\"color:red\">$sect->{$suite}{$archive}{source}</span>]";
+                   $origin_str .= " ".marker($sect->{$suite}{$archive}{source});
                }
                if ($archives->{$suite}{$archive}{source}) {
-                   $origin_str .= " [<span style=\"color:red\">$archives->{$suite}{$archive}{source}</span>]";
+                   $origin_str .= " ".marker($archives->{$suite}{$archive}{source});
                }
                $str .= sprintf( "<li><a href=\"$ROOT/%s/source/%s\">%s</a> (%s): %s   %s",
                                 $suite.(($archive ne 'us')?"/$archive":''), $pkg, $suite.(($archive ne 'us')?"/$archive":''), $subsect->{$suite}{$archive}{source},
                                 $pkgs->{$suite}{$archive}, $origin_str );
                
-               $str .= "<br>Binary packages: ";
+               $str .= "<br>"._g( 'Binary packages: ' );
                my @bp_links;
                foreach my $bp (@{$binaries->{$suite}{$archive}}) {
                    my $bp_link = sprintf( "<a href=\"$ROOT/%s/%s\">%s</a>",