From: Frank Lichtenheld Date: Sat, 17 Nov 2007 10:08:11 +0000 (+0100) Subject: Restore translation support in the Perl modules X-Git-Url: https://git.deb.at/w?a=commitdiff_plain;h=35396b36e9658cb7346fb080531fff92a6d0fd57;p=deb%2Fpackages.git Restore translation support in the Perl modules --- diff --git a/cron.d/500update_mo b/cron.d/500update_mo index 9676466..5855025 100755 --- a/cron.d/500update_mo +++ b/cron.d/500update_mo @@ -49,7 +49,7 @@ podomains="pdo templates sections langs debtags" # Update pot # # Common options for all calls -xgettext_opts="--language=Perl --keyword=N_ --keyword=_g --foreign-user --add-comments" +xgettext_opts="--language=Perl --keyword=N_ --keyword=_g --keyword=g --foreign-user --add-comments" echo gettextfiles=$gettextfiles echo templatefiles=$templatefiles diff --git a/lib/Packages/Dispatcher.pm b/lib/Packages/Dispatcher.pm index b2030aa..ad4c8cb 100755 --- a/lib/Packages/Dispatcher.pm +++ b/lib/Packages/Dispatcher.pm @@ -155,10 +155,10 @@ sub do_dispatch { shift @components; $what_to_do = 'search'; # Done - fatal_error( _g( "search doesn't take any more path elements" ) ) + fatal_error( "search doesn't take any more path elements" ) if @components; } elsif (@components == 0) { - fatal_error( _g( "We're supposed to display the homepage here, instead of getting dispatch.pl" ) ); + fatal_error( "We're supposed to display the homepage here, instead of getting dispatch.pl" ); } elsif (@components == 1) { $what_to_do = 'search'; } else { @@ -181,7 +181,7 @@ sub do_dispatch { my ($cgi, $params_set, $key, $val) = @_; debug("set_param_once key=$key val=$val",4) if DEBUG; if ($params_set->{$key}++) { - fatal_error( sprintf( _g( "%s set more than once in path" ), $key ) ); + fatal_error( "$key set more than once in path" ); } else { $cgi->param( $key, $val ); } @@ -216,7 +216,7 @@ sub do_dispatch { @components = @pkg; if (@components > 1) { - fatal_error( sprintf( _g( "two or more packages specified (%s)" ), "@components" ) ); + fatal_error( "two or more packages specified (@components)" ); } } # else if (@components == 1) @@ -276,6 +276,7 @@ sub do_dispatch { my $charset = "UTF-8"; my $cat = Packages::I18N::Locale->get_handle( $opts{lang} ) or die "get_handle failed"; + $opts{cat} = $cat; $opts{h_suites} = { map { $_ => 1 } @suites }; $opts{h_sections} = { map { $_ => 1 } @sections }; @@ -307,7 +308,7 @@ sub do_dispatch { #FIXME: ugly hack unless (($what_to_do eq 'allpackages' and $opts{format} =~ /^(html|txt\.gz)/) || -e "$TEMPLATEDIR/$opts{format}/${what_to_do}.tmpl") { - fatal_error( _g("requested format not available for this document"), + fatal_error( $cat->g("requested format not available for this document"), "406 requested format not available"); } diff --git a/lib/Packages/DoDownload.pm b/lib/Packages/DoDownload.pm index bc7dbab..566195a 100644 --- a/lib/Packages/DoDownload.pm +++ b/lib/Packages/DoDownload.pm @@ -22,21 +22,24 @@ our @EXPORT = qw( do_download ); sub do_download { my ($params, $opts, $page_content) = @_; + my $cat = $opts->{cat}; if ($params->{errors}{package}) { - fatal_error( _g( "package not valid or not specified" ) ); + fatal_error( $cat->g( "package not valid or not specified" ) ); } if ($params->{errors}{suite}) { - fatal_error( _g( "suite not valid or not specified" ) ); + fatal_error( $cat->g( "suite not valid or not specified" ) ); } if ($params->{errors}{arch}) { - fatal_error( _g( "architecture not valid or not specified" ) ); + fatal_error( $cat->g( "architecture not valid or not specified" ) ); } if (@{$opts->{suite}} > 1) { - fatal_error( sprintf( _g( "more than one suite specified for download (%s)" ), "@{$opts->{suite}}" ) ); + fatal_error( $cat->g( "more than one suite specified for download (%s)", + "@{$opts->{suite}}" ) ); } if (@{$opts->{arch}} > 1) { - fatal_error( sprintf( _g( "more than one architecture specified for download (%s)" ), "@{$opts->{arch}}" ) ); + fatal_error( $cat->g( "more than one architecture specified for download (%s)", + "@{$opts->{arch}}" ) ); } $opts->{h_sections} = { map { $_ => 1 } @SECTIONS }; @@ -88,10 +91,10 @@ sub do_download { my $pkgsize = floor(($data{size}/102.4)+0.5)/10; if ($pkgsize < 1024) { $page_content->{pkgsize} = sprintf( '%.1f', $pkgsize ); - $page_content->{pkgsize_unit} = _g( 'kByte' ); + $page_content->{pkgsize_unit} = $cat->g( 'kByte' ); } else { $page_content->{pkgsize} = sprintf( '%.1f', floor(($data{size}/(102.4*102.4))+0.5)/100 ); - $page_content->{pkgsize_unit} = _g( 'MByte' ); + $page_content->{pkgsize_unit} = $cat->g( 'MByte' ); } $page_content->{architecture} = $arch; foreach (keys %data) { diff --git a/lib/Packages/DoFilelist.pm b/lib/Packages/DoFilelist.pm index 5855042..188cfb8 100644 --- a/lib/Packages/DoFilelist.pm +++ b/lib/Packages/DoFilelist.pm @@ -22,15 +22,16 @@ our @EXPORT = qw( do_filelist ); sub do_filelist { my ($params, $opts, $page_content) = @_; + my $cat = $opts->{cat}; if ($params->{errors}{package}) { - fatal_error( _g( "package not valid or not specified" ) ); + fatal_error( $cat->g( "package not valid or not specified" ) ); } if ($params->{errors}{suite}) { - fatal_error( _g( "suite not valid or not specified" ) ); + fatal_error( $cat->g( "suite not valid or not specified" ) ); } if ($params->{errors}{arch}) { - fatal_error( _g( "architecture not valid or not specified" ) ); + fatal_error( $cat->g( "architecture not valid or not specified" ) ); } my $pkg = $opts->{package}; @@ -45,7 +46,7 @@ sub do_filelist { O_RDONLY, 0666, $DB_BTREE) { unless (exists $contents{$pkg}) { - fatal_error( _g( "No such package in this suite on this architecture." ) ); + fatal_error( $cat->g( "No such package in this suite on this architecture." ) ); } else { my @files = unpack "L/(CC/a)", $contents{$pkg}; my $file = ''; @@ -57,7 +58,7 @@ sub do_filelist { } } } else { - fatal_error( _g( "Invalid suite/architecture combination" ) ); + fatal_error( $cat->g( "Invalid suite/architecture combination" ) ); } } } diff --git a/lib/Packages/DoIndex.pm b/lib/Packages/DoIndex.pm index 416f3db..6d8d4b6 100644 --- a/lib/Packages/DoIndex.pm +++ b/lib/Packages/DoIndex.pm @@ -26,15 +26,18 @@ my %encoding = ( ); sub send_file { my ($file, $params, $opts) = @_; + my $cat = $opts->{cat}; if ($params->{errors}{suite}) { - fatal_error( _g( "suite not valid or not specified" ) ); + fatal_error( $cat->g( "suite not valid or not specified" ) ); } if (@{$opts->{suite}} > 1) { - fatal_error( sprintf( _g( "more than one suite specified for show_static (%s)" ), "@{$opts->{suite}}" ) ); + fatal_error( $cat->g( "more than one suite specified for show_static (%s)", + "@{$opts->{suite}}" ) ); } if (@{$opts->{subsection}} > 1) { - fatal_error( sprintf( _g( "more than one subsection specified for show_static (%s)" ), "@{$opts->{suite}}" ) ); + fatal_error( $cat->g( "more than one subsection specified for show_static (%s)", + "@{$opts->{suite}}" ) ); } my $wwwdir = "$TOPDIR/www"; @@ -70,7 +73,7 @@ sub send_file { close INDEX; exit; } else { - fatal_error( sprintf( _g( "couldn't read index file %s: %s" ), + fatal_error( $cat->g( "couldn't read index file %s: %s", $path, $! ) ); } } diff --git a/lib/Packages/DoNewPkg.pm b/lib/Packages/DoNewPkg.pm index 9be98d5..66a0bfe 100644 --- a/lib/Packages/DoNewPkg.pm +++ b/lib/Packages/DoNewPkg.pm @@ -17,12 +17,14 @@ use Packages::Config qw( $TOPDIR @SECTIONS $ROOT ); sub do_newpkg { my ($params, $opts, $page_content) = @_; + my $cat = $opts->{cat}; if ($params->{errors}{suite}) { - fatal_error( _g( "suite not valid or not specified" ) ); + fatal_error( $cat->g( "suite not valid or not specified" ) ); } if (@{$opts->{suite}} > 1) { - fatal_error( sprintf( _g( "more than one suite specified for newpkg (%s)" ), "@{$opts->{suite}}" ) ); + fatal_error( $cat->g( "more than one suite specified for newpkg (%s)", + "@{$opts->{suite}}" ) ); } my $sort_func = sub { $_[0][0] cmp $_[1][0] }; @@ -39,8 +41,8 @@ sub do_newpkg { open NEWPKG, '<', "$TOPDIR/files/packages/newpkg_info_$suite" or do { warn "can't read newpkg_info_$suite: $!"; - fatal_error( sprintf( _g("no newpkg information found for suite %s"), - $suite) ); + fatal_error( $cat->g("no newpkg information found for suite %s", + $suite) ); return; }; while () { diff --git a/lib/Packages/DoSearch.pm b/lib/Packages/DoSearch.pm index 31e110d..1aa67f1 100644 --- a/lib/Packages/DoSearch.pm +++ b/lib/Packages/DoSearch.pm @@ -18,14 +18,15 @@ use Packages::Config qw( $DBDIR @SUITES @ARCHIVES $ROOT ); sub do_search { my ($params, $opts, $page_content) = @_; + my $cat = $opts->{cat}; $Params::Search::too_many_hits = 0; if ($params->{errors}{keywords}) { - fatal_error( _g( "keyword not valid or missing" ) ); + fatal_error( $cat->g( "keyword not valid or missing" ) ); $opts->{keywords} = []; } elsif (grep { length($_) < 2 } @{$opts->{keywords}}) { - fatal_error( _g( "keyword too short (keywords need to have at least two characters)" ) ); + fatal_error( $cat->g( "keyword too short (keywords need to have at least two characters)" ) ); } my @keywords = @{$opts->{keywords}}; @@ -110,7 +111,8 @@ sub do_search { } else { @pkgs = sort { $sort_by_relevance{$a} <=> $sort_by_relevance{$b} } keys %uniq_pkgs; } - process_packages( $page_content, 'packages', \%pkgs, \@pkgs, $opts, \@keywords, + process_packages( $page_content, 'packages', \%pkgs, \@pkgs, + $opts, \@keywords, \&process_package, \%provided_by, \%archives, \%sect, \%subsect, \%desc ); @@ -141,7 +143,8 @@ sub do_search { } my @pkgs = sort keys %pkgs; - process_packages( $page_content, 'src_packages', \%pkgs, \@pkgs, $opts, \@keywords, + process_packages( $page_content, 'src_packages', \%pkgs, \@pkgs, + $opts, \@keywords, \&process_src_package, \%archives, \%sect, \%subsect, \%binaries ); } # else unless $opts->{source} @@ -160,20 +163,21 @@ sub process_packages { my $have_exact; if ($keyword && grep { $_ eq $keyword } @$pkgs_list) { $have_exact = 1; - $categories[0]{name} = _g( "Exact hits" ); + $categories[0]{name} = $opts->{cat}->g( "Exact hits" ); - $categories[0]{$target} = [ &$print_func( $keyword, $pkgs->{$keyword}||{}, - map { $_->{$keyword}||{} } @func_args ) ]; + $categories[0]{$target} = [ &$print_func( $opts, $keyword, + $pkgs->{$keyword}||{}, + map { $_->{$keyword}||{} } @func_args ) ]; @$pkgs_list = grep { $_ ne $keyword } @$pkgs_list; } if (@$pkgs_list && (($opts->{searchon} ne 'names') || !$opts->{exact})) { my %cat; - $cat{name} = _g( 'Other hits' ) if $have_exact; + $cat{name} = $opts->{cat}->g( 'Other hits' ) if $have_exact; $cat{packages} = []; foreach my $pkg (@$pkgs_list) { - push @{$cat{$target}}, &$print_func( $pkg, $pkgs->{$pkg}||{}, + push @{$cat{$target}}, &$print_func( $opts, $pkg, $pkgs->{$pkg}||{}, map { $_->{$pkg}||{} } @func_args ); } push @categories, \%cat; @@ -185,7 +189,8 @@ sub process_packages { } sub process_package { - my ($pkg, $pkgs, $provided_by, $archives, $sect, $subsect, $desc) = @_; + my ($opts, $pkg, $pkgs, $provided_by, + $archives, $sect, $subsect, $desc) = @_; my %pkg = ( pkg => $pkg, suites => [] ); @@ -227,7 +232,7 @@ sub process_package { $suite{providers} = $p; } } elsif (my $p = $provided_by->{$suite}) { - $suite{desc} = _g('Virtual package'); + $suite{desc} = $opts->{cat}->g('Virtual package'); $suite{providers} = $p; } push @{$pkg{suites}}, \%suite if $suite{versions} || $suite{providers}; @@ -237,7 +242,7 @@ sub process_package { } sub process_src_package { - my ($pkg, $pkgs, $archives, $sect, $subsect, $binaries) = @_; + my ($opts, $pkg, $pkgs, $archives, $sect, $subsect, $binaries) = @_; my %pkg = ( pkg => $pkg, origins => [] ); diff --git a/lib/Packages/DoSearchContents.pm b/lib/Packages/DoSearchContents.pm index 93a2026..272b235 100644 --- a/lib/Packages/DoSearchContents.pm +++ b/lib/Packages/DoSearchContents.pm @@ -18,15 +18,16 @@ use Packages::Config qw( $DBDIR @SUITES @ARCHIVES @ARCHITECTURES $ROOT ); sub do_search_contents { my ($params, $opts, $page_content) = @_; + my $cat = $opts->{cat}; if ($params->{errors}{keywords}) { - fatal_error( _g( "keyword not valid or missing" ) ); + fatal_error( $cat->g( "keyword not valid or missing" ) ); $opts->{keywords} = []; } elsif (grep { length($_) < 2 } @{$opts->{keywords}}) { - fatal_error( _g( "keyword too short (keywords need to have at least two characters)" ) ); + fatal_error( $cat->g( "keyword too short (keywords need to have at least two characters)" ) ); } if ($params->{errors}{suite}) { - fatal_error( _g( "suite not valid or not specified" ) ); + fatal_error( $cat->g( "suite not valid or not specified" ) ); } #FIXME: that's extremely hacky atm @@ -36,7 +37,8 @@ sub do_search_contents { } if (@{$opts->{suite}} > 1) { - fatal_error( sprintf( _g( "more than one suite specified for contents search (%s)" ), "@{$opts->{suite}}" ) ); + fatal_error( $cat->g( "more than one suite specified for contents search (%s)", + "@{$opts->{suite}}" ) ); } my @keywords = @{$opts->{keywords}}; @@ -77,7 +79,7 @@ sub do_search_contents { close FILENAMES or warn "fgrep error: $!\n"; } else { - error(_g("The search mode you selected doesn't support more than one keyword.")) + error($cat->g("The search mode you selected doesn't support more than one keyword.")) if @keywords; my $kw = reverse $first_kw; @@ -102,7 +104,7 @@ sub do_search_contents { my $file = shift @$result; my %pkgs; foreach (@$result) { - my ($pkg, $arch) = split /:/, $_; + my ($pkg, $arch) = split m/:/, $_; next unless $opts->{h_archs}{$arch}; $pkgs{$pkg}{$arch}++; $archs{$arch}++ unless $arch eq 'all'; diff --git a/lib/Packages/DoShow.pm b/lib/Packages/DoShow.pm index 0c65ec1..5d6174c 100644 --- a/lib/Packages/DoShow.pm +++ b/lib/Packages/DoShow.pm @@ -26,15 +26,17 @@ our @EXPORT = qw( do_show ); sub do_show { my ($params, $opts, $page_contents) = @_; + my $cat = $opts->{cat}; if ($params->{errors}{package}) { - fatal_error( _g( "package not valid or not specified" ) ); + fatal_error( $cat->g( "package not valid or not specified" ) ); } if ($params->{errors}{suite}) { - fatal_error( _g( "suite not valid or not specified" ) ); + fatal_error( $cat->g( "suite not valid or not specified" ) ); } if (@{$opts->{suite}} > 1) { - fatal_error( sprintf( _g( "more than one suite specified for show (%s)" ), "@{$opts->{suite}}" ) ); + fatal_error( $cat->g( "more than one suite specified for show (%s)", + "@{$opts->{suite}}" ) ); } my %contents; @@ -69,7 +71,7 @@ sub do_show { } unless (@results || @non_results ) { - fatal_error( _g( "No such package.") ); + fatal_error( $cat->g( "No such package.") ); #sprintf( _g( 'Search for the package' ), make_search_url('','keywords='.uri_escape($pkg)) ) ); } else { my %all_suites; @@ -81,7 +83,7 @@ sub do_show { $contents{suites} = [ suites_sort(keys %all_suites) ]; unless (@results) { - fatal_error( _g( "Package not available in this suite." ) ); + fatal_error( $cat->g( "Package not available in this suite." ) ); } else { $contents{page} = $page; unless ($opts->{source}) { @@ -194,7 +196,7 @@ sub do_show { my $v_str = $version; my $multiple_versions = grep { $_ ne $version } values %$versions; - $v_str .= _g(" and others") if $multiple_versions; + $v_str .= $cat->g(" and others") if $multiple_versions; $contents{versions} = { short => $v_str, multiple => $multiple_versions }; @@ -248,7 +250,7 @@ sub do_show { search => 1 ); } else { # unless $page->is_virtual $contents{is_virtual} = 1; - $contents{desc}{short} = _g( "virtual package" ); + $contents{desc}{short} = $cat->g( "virtual package" ); $contents{subsection} = 'virtual'; my $provided_by = $page->{provided_by}; @@ -406,6 +408,7 @@ sub build_deps { 'suggests' => 'sug', 'build-depends' => 'adep', 'build-depends-indep' => 'idep' ); my $suite = $opts->{suite}[0]; + my $cat = $opts->{cat}; my %out = ( id => $dep_type{$type}, terms => [] ); @@ -424,7 +427,7 @@ sub build_deps { if ($arch_str ||= '') { if ($arch_neg) { - $arch_str = sprintf( _g("not %s"), "$arch_str" ); + $arch_str = $cat->g("not %s", "$arch_str" ); } else { $arch_str = $arch_str; } @@ -474,7 +477,7 @@ sub build_deps { } } elsif ( $rel_out{is_old_pkgs} ) { } else { - $rel_alt_out{desc} = _g( "Package not available" ); + $rel_alt_out{desc} = $cat->g( "Package not available" ); $rel_alt_out{suite} = ''; } push @{$rel_out{alternatives}}, \%rel_alt_out; @@ -512,7 +515,8 @@ sub pkg_list { push @$list, { name => $p, desc => $short_desc, trans_desc => \%sdescs, available => 1 }; } else { - push @$list, { name => $p, desc => _g("Not available") }; + push @$list, { name => $p, + desc => $opts->{cat}->g("Not available") }; } } } diff --git a/lib/Packages/I18N/Locale.pm b/lib/Packages/I18N/Locale.pm index ae64b93..8c27430 100644 --- a/lib/Packages/I18N/Locale.pm +++ b/lib/Packages/I18N/Locale.pm @@ -14,9 +14,8 @@ use Locale::Maketext::Lexicon { use base 'Exporter'; -our @EXPORT = qw( _g N_ ); +our @EXPORT = qw( N_ ); -sub _g { return $_[0]; } sub N_ { return $_[0]; } sub g {