3 # Import translations from LK8000.
9 use vars
qw($lk_language);
11 # XXX hard-coded path, sorry!
12 $lk_language = '/usr/src/git/LK8000/Common/Data/Language';
14 # hard-coded list of LK8000 languages
42 print STDERR "loading $path\n";
45 open FILE, "<:encoding($encoding)", $path or die $!;
48 if /^_\@M(\d+)_\s+"(.*)"/;
56 # load the English message file
57 my @english = load_msg('UTF-8', "$lk_language/ENG_MSG.TXT");
59 # now iterate over all languages of LK8000
60 foreach my $lng (keys %languages) {
61 my $iso = $languages{$lng};
63 # read the LK8000 translation file
64 my @translated = load_msg('UTF-8',
65 "$lk_language/Translations/${lng}_MSG.TXT");
67 for (my $i = 0; $i <= $#translated; $i++) {
68 my $english = $english[$i];
69 next unless defined $english;
70 my $translated = $translated[$i];
71 next unless defined $translated;
72 next unless length $translated;
73 next if $english eq $translated;
75 $english = fold_english($english);
78 $table{$english} = $translated;
80 # see if we can merge it with the prefix number stripped
81 if ($english =~ /^(\d+)\s+(.*)$/s) {
82 my ($e_number, $english2) = ($1, $2);
83 if ($translated =~ /^(\d+)\s+(.*)$/s) {
84 my ($t_number, $translated2) = ($1, $2);
85 $table{$english2} = $translated2 if $e_number == $t_number;
89 # now strip trailing whitespace
90 if ($english =~ /^(.*?)\s+$/s) {
92 my $translated2 = $translated;
93 $translated2 =~ s,\s+$,,;
94 $table{$english2} = $translated2;
98 my $in = Locale::PO->load_file_asarray("po/${iso}.po");
99 $in = Locale::PO->load_file_asarray("po/xcsoar.pot")
103 foreach my $x (@$in) {
104 # see if the translation is useful and needed
105 next if $x->obsolete;
106 my $msgid = eval $x->msgid;
107 next unless length $msgid;
108 my $msgstr = eval $x->msgstr;
109 next if length $msgstr and not $x->fuzzy;
110 next unless exists $table{fold_english $msgid};
112 my $z = $table{fold_english $msgid};
114 # escape special characters
118 push @out, new Locale::PO(-msgid => $msgid,
125 # declare the UTF-8 charset
126 push @out, new Locale::PO(-msgid => '',
127 -msgstr => "Content-Type: text/plain; charset=UTF-8\\nContent-Transfer-Encoding: 8bit\\n");
129 # write temporary file with new translations
131 open FILE, ">:utf8", "output/po/lk8000-${iso}.po" or die $!;
132 foreach my $x (@out) {
135 close FILE or die $!;
137 # generate PO file if it doesn't exist already
138 unless (-f "po/${iso}.po") {
139 system("msginit --locale=$iso --no-translator --input=po/xcsoar.pot --output=po/${iso}.po") == 0
144 system("msgcat --use-first po/${iso}.po output/po/lk8000-${iso}.po --output-file=po/${iso}.po") == 0