summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtools/genlang2131
1 files changed, 84 insertions, 47 deletions
diff --git a/tools/genlang2 b/tools/genlang2
index 7d363d4cf7..e9c21fb65c 100755
--- a/tools/genlang2
+++ b/tools/genlang2
@@ -70,7 +70,7 @@ my $update = $u;
70 70
71my $english = $e; 71my $english = $e;
72 72
73my $check = $binary?1:0 + $prefix?1:0 + $update?1:0; 73my $check = ($binary?1:0) + ($prefix?1:0) + ($update?1:0);
74 74
75if($check > 1) { 75if($check > 1) {
76 print "Please use only one of -p, -u and -b\n"; 76 print "Please use only one of -p, -u and -b\n";
@@ -209,8 +209,10 @@ if($english) {
209 209
210# a function that compares the english phrase with the translated one. 210# a function that compares the english phrase with the translated one.
211# compare source strings and desc 211# compare source strings and desc
212
213# Then output the updated version!
212sub compare { 214sub compare {
213 my ($engref, $locref)=@_; 215 my ($idstr, $engref, $locref)=@_;
214 my ($edesc, $ldesc); 216 my ($edesc, $ldesc);
215 my ($esource, $lsource); 217 my ($esource, $lsource);
216 my $mode=0; 218 my $mode=0;
@@ -230,28 +232,52 @@ sub compare {
230 } 232 }
231 } 233 }
232 234
235 my @show;
236 my @source;
237
233 $mode = 0; 238 $mode = 0;
234 for my $l (@$locref) { 239 for my $l (@$locref) {
235 if($l =~ /^ *desc: (.*)/) { 240 if($l =~ /^ *desc: (.*)/) {
236 $ldesc=$1; 241 $ldesc=$1;
242 if($edesc ne $ldesc) {
243 $l = "### The 'desc' field differs from the english!\n### the previously used desc is commented below:\n### desc: $ldesc\n desc: $edesc\n";
244 }
245 push @show, $l;
237 } 246 }
238 elsif($l =~ / *\<source\>/i) { 247 elsif($l =~ / *\<source\>/i) {
239 $mode=1; 248 $mode=1;
249 push @show, $l;
240 } 250 }
241 elsif($mode) { 251 elsif($mode) {
242 if($l =~ / *\<\/source\>/i) { 252 if($l =~ / *\<\/source\>/i) {
243 last; 253 $mode = 0;
254 print @show;
255 if($esource ne $lsource) {
256 print "### The <source> section differs from the english!\n",
257 "### the previously used one is commented below:\n";
258 for(split("\n", $lsource)) {
259 print "### $_\n";
260 }
261 print $esource;
262 }
263 else {
264 print $lsource;
265 }
266 undef @show; # start over
267
268 push @show, $l;
269 }
270 else {
271 $lsource .= "$l";
244 } 272 }
245 $lsource .= "$l"; 273 }
274 else {
275 push @show, $l;
246 } 276 }
247 } 277 }
248 278
249 if($edesc ne $ldesc) { 279
250 print "### The 'desc' field differs from the english!\n"; 280 print @show;
251 }
252 if($esource ne $lsource) {
253 print "### The <source> section differs from the english!\n";
254 }
255} 281}
256 282
257my $idcount; # counter for lang ID numbers 283my $idcount; # counter for lang ID numbers
@@ -295,34 +321,44 @@ while(<LANG>) {
295 my $idstr = $phrase{'id'}; 321 my $idstr = $phrase{'id'};
296 my $idnum; 322 my $idnum;
297 323
298 # Use the ID name to figure out which id number range we should 324 if($dest =~ /^none\z/i) {
299 # use for this phrase. Voice-only strings are separated. 325 # "none" as dest means that this entire phrase is to be
300 if($idstr =~ /^VOICE/) { 326 # ignored
301 $idnum = $voiceid++; 327 print "dest is NONE!\n";
302 } 328 }
303 else { 329 else {
304 $idnum = $idcount++;
305 }
306 330
307 $id{$idstr} = $idnum; 331 # Use the ID name to figure out which id number range we
308 $idnum[$idnum]=$idstr; 332 # should use for this phrase. Voice-only strings are
333 # separated.
309 334
310 $source{$idstr}=$src; 335 if($idstr =~ /^VOICE/) {
311 $dest{$idstr}=$dest; 336 $idnum = $voiceid++;
312 $voice{$idstr}=$voice; 337 }
338 else {
339 $idnum = $idcount++;
340 }
341
342 $id{$idstr} = $idnum;
343 $idnum[$idnum]=$idstr;
344
345 $source{$idstr}=$src;
346 $dest{$idstr}=$dest;
347 $voice{$idstr}=$voice;
348
349 if($verbose) {
350 print "id: $phrase{id} ($idnum)\n";
351 print "source: $src\n";
352 print "dest: $dest\n";
353 print "voice: $voice\n";
354 }
313 355
314 if($verbose) { 356 undef $src;
315 print "id: $phrase{id} ($idnum)\n"; 357 undef $dest;
316 print "source: $src\n"; 358 undef $voice;
317 print "dest: $dest\n"; 359 undef %phrase;
318 print "voice: $voice\n";
319 } 360 }
320 361
321 undef $src;
322 undef $dest;
323 undef $voice;
324 undef %phrase;
325
326 if($update) { 362 if($update) {
327 my $e = $english{$idstr}; 363 my $e = $english{$idstr};
328 364
@@ -330,10 +366,12 @@ while(<LANG>) {
330 # compare original english with this! 366 # compare original english with this!
331 my @eng = split("\n", $english{$idstr}); 367 my @eng = split("\n", $english{$idstr});
332 368
333 compare(\@eng, \@phrase); 369 compare($idstr, \@eng, \@phrase);
370
371 $english{$idstr}=""; # clear it
334 } 372 }
335 else { 373 else {
336 print "### This phrase is not used, remove it!\n"; 374 print "### $idstr: The phrase is not used. Skipped\n";
337 } 375 }
338 } 376 }
339 undef @phrase; 377 undef @phrase;
@@ -342,9 +380,6 @@ while(<LANG>) {
342 380
343 # starts with a slash, this _ends_ this section 381 # starts with a slash, this _ends_ this section
344 $m = pop @m; # get back old value, the previous level's tag 382 $m = pop @m; # get back old value, the previous level's tag
345 if($update) {
346 print "$ll";
347 }
348 next; 383 next;
349 } # end of tag close 384 } # end of tag close
350 385
@@ -352,9 +387,6 @@ while(<LANG>) {
352 387
353 push @m, $m; # store old value 388 push @m, $m; # store old value
354 $m = $1; 389 $m = $1;
355 if($update) {
356 print "$ll";
357 }
358 next; 390 next;
359 } 391 }
360 392
@@ -362,13 +394,22 @@ while(<LANG>) {
362 my ($name, $val)=($1, $2); 394 my ($name, $val)=($1, $2);
363 &$m($_, $name, $val); 395 &$m($_, $name, $val);
364 } 396 }
365 if($update) {
366 print "$ll";
367 }
368
369} 397}
370close(LANG); 398close(LANG);
371 399
400if($update) {
401 my $any=0;
402 for(keys %english) {
403 if($english{$_}) {
404 print "###\n",
405 "### This phrase below was not present in the translated file\n",
406 "<phrase>\n";
407 print $english{$_};
408 print "</phrase>\n";
409 }
410 }
411}
412
372if($prefix) { 413if($prefix) {
373 # We create a .c and .h file 414 # We create a .c and .h file
374 415
@@ -499,7 +540,3 @@ if($verbose) {
499 } 540 }
500} 541}
501 542
502#print "* phrase *\n";
503#for(keys %phrase) {
504# print "$_\n";
505#}