2 # Convert Translation.gz files into Sleepycat db files for efficient usage of
5 # Copyright (C) 2006 Jeroen van Wolffelaar <jeroen@wolffelaar.nl>
6 # Copyright (C) 2007 Frank Lichtenheld <frank@lichtenheld.de>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 # max. distinct results for a given package postfix
28 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 my $fixja = Text::Iconv->new("EUC-JP", "UTF-8");
48 foreach my $lang (@DDTP_LANGUAGES) {
49 (my $locale = $lang) =~ s/^([a-z]{2})-([a-z]{2})$/"$1_".uc($2)/e;
50 print "Reading Translations for $lang ($locale)...";
51 open PKG, "zcat $TOPDIR/archive/*/*/*/i18n/Translation-$locale.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($locale)};
70 my $fixed = $fixja->convert($data{"description-ja"});
71 $data{"description-ja"} = $fixed if $fixed;
73 $descriptions{$data{"description-md5"}}{$lang} =
74 $data{"description-".lc($locale)};
81 print "Writing database (".scalar(keys %descriptions)." unique descriptions)...\n";
83 tie %descriptions_db, "DB_File", "$DBDIR/descriptions_translated.db.new",
84 O_RDWR|O_CREAT, 0666, $DB_BTREE
85 or die "Error creating DB: $!";
86 while (my ($md5, $v) = each(%descriptions)) {
88 while (my ($lang, $desc) = each %$v) {
89 unless ($lang && $desc) {
90 warn "MD5: $md5 LANG: $lang DESC: $desc\n";
93 $str .= "$lang\001$desc\000";
96 $descriptions_db{$md5} = $str;
98 untie %descriptions_db;
100 rename("$DBDIR/descriptions_translated.db.new",
101 "$DBDIR/descriptions_translated.db");