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;
37 use Lingua::Stem v0.82;
39 use Packages::Config qw( $TOPDIR $DBDIR @DDTP_LANGUAGES );
40 &Packages::Config::init( './' );
41 my %descriptions = ();
45 -d $DBDIR || mkpath( $DBDIR );
47 my $fixja = Text::Iconv->new("EUC-JP", "UTF-8");
49 foreach my $lang (@DDTP_LANGUAGES) {
50 print "Reading Translations for $lang...";
51 open PKG, "zcat $TOPDIR/archive/*/*/*/i18n/Translation-$lang.gz|";
59 while (/^(\S+):\s*(.*)\s*$/mg) {
60 my ($key, $value) = ($1, $2);
61 $value =~ s/\377/\n /g;
62 $key =~ tr [A-Z] [a-z];
65 # Skip double descriptions
66 next if exists($descriptions{$data{"description-md5"}}{$lang});
67 # some weirdnesses in the files
68 next unless defined $data{"description-".lc($lang)};
70 my $fixed = $fixja->convert($data{"description-ja"});
71 $data{"description-ja"} = $fixed if $fixed;
73 $descriptions{$data{"description-md5"}}{$lang} = $data{"description-".lc($lang)};
80 print "Writing database (".scalar(keys %descriptions)." unique descriptions)...\n";
82 tie %descriptions_db, "DB_File", "$DBDIR/descriptions_translated.db.new",
83 O_RDWR|O_CREAT, 0666, $DB_BTREE
84 or die "Error creating DB: $!";
85 while (my ($md5, $v) = each(%descriptions)) {
87 while (my ($lang, $desc) = each %$v) {
88 unless ($lang && $desc) {
89 warn "MD5: $md5 LANG: $lang DESC: $desc\n";
92 $str .= "$lang\001$desc\000";
95 $descriptions_db{$md5} = $str;
97 untie %descriptions_db;
99 rename("$DBDIR/descriptions_translated.db.new",
100 "$DBDIR/descriptions_translated.db");