X-Git-Url: https://git.deb.at/?a=blobdiff_plain;f=lib%2FPackages%2FDoSearch.pm;h=64160c13b52183081957b38f45749242adb636ad;hb=3bb6c9d9922b0487901c02962b1d64c525f1bdd7;hp=1b85714d524963af9f75f6de8a1d56da46785277;hpb=53004bf39f89fca7abc8dc72e7b4571d419a4d9d;p=deb%2Fpackages.git diff --git a/lib/Packages/DoSearch.pm b/lib/Packages/DoSearch.pm index 1b85714..64160c1 100644 --- a/lib/Packages/DoSearch.pm +++ b/lib/Packages/DoSearch.pm @@ -3,7 +3,7 @@ package Packages::DoSearch; use strict; use warnings; -use Benchmark; +use Benchmark ':hireswallclock'; use DB_File; use URI::Escape; use HTML::Entities; @@ -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§ion=$sections_param&keywords=$keyword_esc&searchon=$searchon&arch=$archs_param"; # for output my $keyword_enc = encode_entities $keyword || ''; @@ -96,43 +102,43 @@ sub do_search { } if ($Packages::Search::too_many_hits) { - error( "Your search was too wide so we will only display exact matches. At least $Packages::Search::too_many_hits 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 %s 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. ". - "". - ($#non_results+1)."". + hint( _g( "Can't find that package." )." ". + sprintf( _g( '%s'. " 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 allowing subword matching." ); + hint( sprintf( _g( 'You have searched only for words exactly matching your keywords. You can try to search allowing subword matching.' ), + encode_entities("$SEARCH_URL?exact=0&$opts->{common_params}") ) ); } } - hint( ( $printed ? "Or you" : "You" )." can try a different search on the Packages search page." ); + hint( sprintf( _g( 'You can try a different search on the Packages search page.' ), "$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 => { @@ -219,20 +225,22 @@ sub print_packages { my ($pkgs, $pkgs_list, $opts, $keyword, $print_func, @func_args) = @_; #my ($start, $end) = multipageheader( $input, scalar @pkgs, \%opts ); - my $str .= "

Found ".(scalar @$pkgs_list)." matching packages."; + my $str = '

'; + $str .= "

".sprintf( _g( "Found %s matching packages." ), + scalar @$pkgs_list )."

"; #my $count = 0; my $have_exact; if (grep { $_ eq $keyword } @$pkgs_list) { $have_exact = 1; - $str .= '

Exact hits

'; + $str .= '

'._g( "Exact hits" ).'

'; $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 .= '

Other hits

' + $str .= '

'._g( 'Other hits' ).'

' if $have_exact; foreach my $pkg (@$pkgs_list) { @@ -242,9 +250,11 @@ sub print_packages { map { $_->{$pkg}||{} } @func_args ); } } elsif (@$pkgs_list) { - $str .= "

". - ($#{$pkgs_list}+1)." results have not been displayed because you requested only exact matches.

"; + $str .= "

".sprintf( _g( '%s results have not been displayed because you requested only exact matches.' ), + encode_entities("$SEARCH_URL?exact=0&$opts->{common_params}"), + scalar @$pkgs_list )."

"; } + $str .= '
'; return $str; } @@ -252,8 +262,8 @@ sub print_packages { sub print_package { my ($pkg, $pkgs, $provided_by, $archives, $sect, $subsect, $desc) = @_; - my $str = sprintf "

Package %s

\n", $pkg; - $str .= "