implement import of translations into pofiles

This commit is contained in:
Yann Dirson 2004-07-01 10:07:08 +00:00
parent d2ac52ebc3
commit 63298a647e

View file

@ -1,12 +1,27 @@
#! /usr/bin/perl -w
# WARNING:
# DO NOT commit po-files convverted with this script yet. There is
# still some work to do !
# TODO:
# - tag as UTF-8
# - tag converted entries as fuzzy
# - how to permanently get rid of this supurious c-format keyword ?
use strict;
require "utils/wmltrans.pm";
our ($wmlfile, $pofile) = @ARGV;
our %english = readwml ('data/translations/english.cfg');
#our %lang = readwml ($wmlfile);
our %revenglish;
foreach my $key (keys %english) {
$revenglish{$english{$key}} = $key;
}
our %lang = readwml ($wmlfile);
open (POFILE, $pofile) or die "cannot open $pofile";
@ -46,7 +61,47 @@ sub processentry {
# lookup
print "msgid $curid";
print "msgstr $curmsg";
print "msgstr ";
if ($curmsg eq "\"\"\n") {
my $id = $revenglish{po2rawstring($curid)};
if (defined $id) {
my $trans = $lang{$id};
if (defined $trans) {
print raw2postring($trans);
} else {
# printf STDERR "WARNING: no translation found for $id - setting to empty\n";
printf raw2postring("");
}
} else {
printf STDERR "WARNING: no id found (setting translation to empty) for $curid\n";
printf raw2postring("");
}
} else {
print $curmsg;
}
$curid = undef; $curmsg = undef;
}
sub raw2postring {
my $str = shift;
$str =~ s/^(.*)$/"$1\\n"/mg;
$str =~ s/\\n\"$/\"\n/g;
return $str;
}
sub po2rawstring {
my $str = shift;
my @lines = split (/\n/, $str);
$str = "";
foreach my $line (@lines) {
$line =~ m/"(.*)"/;
$str .= $1;
}
return $str;
}