package-translations/translate_packages.pl

111 lines
2.7 KiB
Perl
Raw Normal View History

#!/usr/bin/perl
# Copyright (c) 2007, 2008, SUSE Linux Products GmbH
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
use Locale::gettext;
use POSIX; # Needed for setlocale()
$ENV{'LC_ALL'} = 'en_US.UTF-8';
setlocale(LC_MESSAGES, "en_US.UTF-8");
setlocale(LC_ALL, "en_US.UTF-8");
my $lang = $ARGV[0];
textdomain("package-translations-$lang");
my $indesc = 0;
my $ineula = 0;
my $descr = '';
my $pkg = '';
while ( <STDIN> ) {
if ($_ =~ m/^=Ver:/ || $_ =~ m/^#/) {
print $_;
next;
}
if ($_ =~ m/^=Pkg:\s*(\S*)\s/) {
$pkg = $1;
print $_;
next;
}
if ($_ =~ m/^=Sum:\s*(.*)\s*$/) {
my $sum = $1;
print "=Sum: " . gettext($sum) . "\n";
next;
}
if ($_ =~ m/^\+Eul:/) {
$ineula = 1;
next;
}
if ($_ =~ m/^\-Eul:/) {
$ineula = 0;
$descr = '';
next;
}
if ($_ =~ m/^\+Des:/) {
print $_;
$indesc = 1;
next;
}
if ($_ =~ m/^-Des:/) {
$indesc = 0;
$descr =~ s,\s*Authors:\n--------[.\s\n]*,\@AUTHORS\@,g;
$descr =~ s,\@AUTHORS\@[\S\s\n]*,\@AUTHORS\@,g;
$descr =~ s,\@AUTHORS\@,,g;
print gettext($descr) . "\n";
$descr = '';
print $_;
if (-f "/usr/share/doc/packages/eulas/$pkg.$lang") {
print "+Eul:\n";
open(EULA, "/usr/share/doc/packages/eulas/$pkg.$lang");
while ( <EULA> ) {
print $_;
}
close(EULA);
print "-Eul:\n";
}
next;
}
if ($indesc == 1) {
my $line = $_;
chomp $line;
if ($descr) {
$descr = $descr . "\n" . $line;
} else {
$descr = $line;
}
next;
}
if ($ineula == 1) {
my $line = $_;
chomp $line;
if ($descr) {
$descr = $descr . "\n" . $line;
} else {
$descr = $line;
}
next;
}
die "DIE " . $_;
}