2 # Convert Translation.gz files into Sleepycat db files for efficient usage of
7 # Copyright (C) 2006 Jeroen van Wolffelaar <jeroen@wolffelaar.nl>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 # max. distinct results for a given package postfix
29 my $MAX_PACKAGE_POSTFIXES = 100;
36 use Lingua::Stem v0.82;
38 use Packages::Config qw( $TOPDIR $DBDIR @DDTP_LANGUAGES );
39 &Packages::Config::init( './' );
40 my %descriptions = ();
44 -d $DBDIR || mkpath( $DBDIR );
46 foreach my $lang (@DDTP_LANGUAGES) {
47 print "Reading Translations for $lang...";
48 open PKG, "zcat $TOPDIR/archive/*/*/*/i18n/Translation-$lang.gz|";
56 while (/^(\S+):\s*(.*)\s*$/mg) {
57 my ($key, $value) = ($1, $2);
58 $value =~ s/\377/\n /g;
59 $key =~ tr [A-Z] [a-z];
62 # Skip double descriptions
63 next if exists($descriptions{$data{"description-md5"}}{$lang});
64 # some weirdnesses in the files
65 next unless defined $data{"description-".lc($lang)};
66 $descriptions{$data{"description-md5"}}{$lang} = $data{"description-".lc($lang)};
73 print "Writing database (".scalar(keys %descriptions)." unique descriptions)...\n";
75 tie %descriptions_db, "DB_File", "$DBDIR/descriptions_translated.db.new",
76 O_RDWR|O_CREAT, 0666, $DB_BTREE
77 or die "Error creating DB: $!";
78 while (my ($md5, $v) = each(%descriptions)) {
80 while (my ($lang, $desc) = each %$v) {
81 unless ($lang && $desc) {
82 warn "MD5: $md5 LANG: $lang DESC: $desc\n";
85 $str .= "$lang\001$desc\000";
88 $descriptions_db{$md5} = $str;
90 untie %descriptions_db;
92 rename("$DBDIR/descriptions_translated.db.new",
93 "$DBDIR/descriptions_translated.db");