implement import of translations into pofiles
This commit is contained in:
parent
d2ac52ebc3
commit
63298a647e
1 changed files with 57 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue