]> git.deb.at Git - deb/packages.git/blobdiff - bin/parse-debtags-voc
Merge branch 'master' of ssh://git.debian.org/git/webwml/packages
[deb/packages.git] / bin / parse-debtags-voc
index 4caf0b0444089302c5567f93b6c6d6cf22fde7ec..be251781a89616dafd66b880f84473a15675ca88 100755 (executable)
@@ -1,8 +1,6 @@
 #!/usr/bin/perl -w
 # Convert Debtags vocabulary.gz files into Sleepycat db files
 #
-# $Id: parse-packages 227 2006-11-12 20:24:48Z djpig $
-#
 # Copyright (C) 2006  Frank Lichtenheld <djpig@debian.org>
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -16,7 +14,7 @@
 
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 use strict;
 use warnings;
@@ -24,6 +22,7 @@ use lib './lib';
 
 $| = 1;
 
+use POSIX;
 use DB_File;
 use File::Path;
 use Data::Dumper;
@@ -32,9 +31,10 @@ use URI::Escape;
 
 use Deb::Versions;
 use Packages::Template;
-use Packages::Config qw( $TOPDIR );
-use Packages::CGI;
+use Packages::Config qw( $TOPDIR @LANGUAGES );
+use Packages::I18N::Locale;
 &Packages::Config::init( './' );
+&Packages::I18N::Locale::load( "$TOPDIR/po" );
 my $debtagsdir = "$TOPDIR/files/debtags";
 my $wwwdir = "$TOPDIR/www/about";
 my $voc_file = "$debtagsdir/vocabulary";
@@ -42,10 +42,20 @@ my (%voc, %voc_db);
 
 $/ = "";
 
-delete $ENV{'LANGUAGE'};
-delete $ENV{'LANG'};
-delete $ENV{'LC_ALL'};
-delete $ENV{'LC_MESSAGES'};
+sub process_desc {
+    my ($desc) = @_;
+
+    if ($desc) {
+       $desc = encode_entities($desc);
+
+       $desc =~ s,((ftp|http|https)://[\S~-]+?/?)((\&gt\;)?[)]?[']?[:.\,]?(\s|$)),<a href=\"$1\">$1</a>$3,go; # syntax highlighting -> '];
+       $desc =~ s/\A //o;
+       $desc =~ s/\n /\n/sgo;
+       $desc =~ s/\n.\n/\n<p>\n/go;
+       $desc =~ s/(((\n|\A) [^\n]*)+)/\n<pre>$1\n<\/pre>/sgo;
+    }
+    return $desc;
+}
 
 print "Parsing Vocabulary...\n";
 tie %voc_db, "DB_File", "$debtagsdir/vocabulary.db.new",
@@ -74,18 +84,22 @@ while (<VOC>) {
        warn "Duplicated key found: $voc_key\n";
        next;
     }
-    my ($sdesc,$ldesc) = split /\n/, encode_entities($data{description}), 2;
-
-    if ($ldesc) {
-       $ldesc =~ s,((ftp|http|https)://[\S~-]+?/?)((\&gt\;)?[)]?[']?[:.\,]?(\s|$)),<a href=\"$1\">$1</a>$3,go; # syntax highlighting -> '];
-       $ldesc =~ s/\A //o;
-       $ldesc =~ s/\n /\n/sgo;
-       $ldesc =~ s/\n.\n/\n<p>\n/go;
-       $ldesc =~ s/(((\n|\A) [^\n]*)+)/\n<pre>$1\n<\/pre>/sgo;
-    }
-    $data{html_description} = [ $sdesc, $ldesc||"" ];
+    my ($sdesc,$ldesc) = split /\n/, $data{description}, 2;
 
+    $data{html_description} = [ encode_entities($sdesc), process_desc($ldesc)||"" ];
     $voc_db{$voc_key} = $sdesc || "";
+
+    foreach my $lang (@LANGUAGES) {
+       next if $lang eq 'en';
+
+       my $cat = Packages::I18N::Locale->get_handle($lang)
+           or die "get_handle failed for $lang";
+
+       my $sdesc_trans = $cat->maketext($sdesc);
+       $voc_db{"$voc_key-$lang"} = $sdesc_trans
+           if $sdesc_trans and $sdesc_trans ne $sdesc;
+    }
+
     $voc{$voc_key} = \%data;
 }
 
@@ -104,7 +118,7 @@ my @facets = sort( grep { exists $voc{$_}{facet} } keys %voc );
 my @tags = sort( grep { exists $voc{$_}{tag} } keys %voc );
 my %tags_by_facet;
 foreach (@tags) {
-    my ($facet, $tag) = split /::/, $_, 2;
+    my ($facet, $tag) = split m/::/, $_, 2;
     warn "No facet data available for $facet\n"
        unless exists $voc{$facet};
     $tags_by_facet{$facet} ||= [];
@@ -113,12 +127,6 @@ foreach (@tags) {
 my %content = ( vocabulary => \%voc,
                facets => \@facets, tags => \@tags,
                tags_by_facet => \%tags_by_facet );
-# needed to work around the limitations of the the FILTER syntax
-$content{html_encode} = sub { return HTML::Entities::encode_entities(@_,'<>&"') };
-$content{uri_escape} = sub { return URI::Escape::uri_escape(@_) };
-$content{quotemeta} = sub { return quotemeta($_[0]) };
-$content{string2id} = sub { return &Packages::CGI::string2id(@_) };
-
 print TAGLST $template->page( 'tag_index', \%content );
 close TAGLST or warn "Couldn't close tag list: $!";