summaryrefslogtreecommitdiff
path: root/tools/updatelang
diff options
context:
space:
mode:
Diffstat (limited to 'tools/updatelang')
-rwxr-xr-xtools/updatelang49
1 files changed, 32 insertions, 17 deletions
diff --git a/tools/updatelang b/tools/updatelang
index a05011e645..94f6fd1e8c 100755
--- a/tools/updatelang
+++ b/tools/updatelang
@@ -6,11 +6,15 @@
6# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 6# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7# \/ \/ \/ \/ \/ 7# \/ \/ \/ \/ \/
8# 8#
9# Copyright (C) 2020 Solomon Peachy 9# Copyright (C) 2020-2024 Solomon Peachy
10# 10#
11 11
12use utf8; 12use utf8;
13use File::Basename; 13use File::Basename;
14use Unicode::Normalize;
15
16use open qw( :std :encoding(UTF-8) );
17binmode(STDOUT, ":encoding(UTF-8)");
14 18
15sub trim { 19sub trim {
16 my ($string) = @_; 20 my ($string) = @_;
@@ -72,6 +76,7 @@ sub parselangfile {
72# $l = "*"; 76# $l = "*";
73 } 77 }
74 78
79 $w = NFD($w); # Unicode decompose
75 $thisphrase{$pos}->{$l} = $w; 80 $thisphrase{$pos}->{$l} = $w;
76 } 81 }
77 } 82 }
@@ -158,7 +163,7 @@ sub reduceformat($) {
158################## 163##################
159 164
160if($#ARGV != 2) { 165if($#ARGV != 2) {
161 print "Usage: updatelang <english.lang> <otherlang> <outfile|->\n"; 166 print "Usage: [ENGLISHORDER=1] updatelang <english.lang> <otherlang> <outfile|->\n";
162 exit; 167 exit;
163} 168}
164 169
@@ -402,9 +407,9 @@ foreach my $id (@langorder) {
402 407
403 my $sane = $lang{$id}{'dest'}{$tgt}; 408 my $sane = $lang{$id}{'dest'}{$tgt};
404 $sane =~ s/^~?(.*)/$1/; # Strip off leading ~ if it's there as it's not a legal character otherwise 409 $sane =~ s/^~?(.*)/$1/; # Strip off leading ~ if it's there as it's not a legal character otherwise
405 if ($sane =~ tr/"~//) { 410 if ($sane =~ tr/"~<>//) {
406 # If it has suspicious characters that are not allowed 411 # If it has suspicious characters that are not allowed
407 $lang{$id}{'notes'} .= "### The <dest> section for '$id:$tgt' has some suspicious characters (eg '~'), please double-check!\n"; 412 $lang{$id}{'notes'} .= "### The <dest> section for '$id:$tgt' has some suspicious characters (eg \",~,<,>), please double-check!\n";
408# print "#!! '$id:$tgt' suspicious characters\n"; 413# print "#!! '$id:$tgt' suspicious characters\n";
409 } 414 }
410 } 415 }
@@ -476,9 +481,9 @@ foreach my $id (@langorder) {
476 } 481 }
477 my $sane = $lang{$id}{'voice'}{$tgt}; 482 my $sane = $lang{$id}{'voice'}{$tgt};
478 $sane =~ s/^~?(.*)/$1/; # Strip off leading ~ if it's there as it's not a legal character otherwise 483 $sane =~ s/^~?(.*)/$1/; # Strip off leading ~ if it's there as it's not a legal character otherwise
479 if ($sane =~ tr/%"~//) { 484 if ($sane =~ tr/%"~:\[\]<>{}\|//) {
480 # If it has suspicious characters that are not normally voiced.. 485 # Suspicious characters that are not typically voiced..
481 $lang{$id}{'notes'} .= "### The <voice> section for '$id:$tgt' has some suspicious characters (eg '%' or '~'), please double-check!\n"; 486 $lang{$id}{'notes'} .= "### The <voice> section for '$id:$tgt' has some suspicious characters (eg %,\",~,:,<,>,[,],{,},|), please correct!\n";
482# print "#!! '$id:$tgt' suspicious characters\n"; 487# print "#!! '$id:$tgt' suspicious characters\n";
483 } 488 }
484 if ($lang{$id}{'voice'}{$tgt} =~ /\.\.\./) { 489 if ($lang{$id}{'voice'}{$tgt} =~ /\.\.\./) {
@@ -502,7 +507,14 @@ foreach (@langheader) {
502 print $fh $_; 507 print $fh $_;
503} 508}
504 509
505my @finalorder = @langorder; # TODO make configurable vs @englishorder 510my @finalorder;
511
512if ($ENV{'ENGLISHORDER'}) {
513 @finalorder = @englishorder;
514} else {
515 @finalorder = @langorder;
516}
517
506foreach my $id (@finalorder) { 518foreach my $id (@finalorder) {
507 if (!defined($english{$id})) { 519 if (!defined($english{$id})) {
508 next; 520 next;
@@ -531,10 +543,11 @@ foreach my $id (@finalorder) {
531 %lp = combinetgts(%{$lang{$id}{'source'}}); 543 %lp = combinetgts(%{$lang{$id}{'source'}});
532 print $fh " <source>\n"; 544 print $fh " <source>\n";
533 foreach my $tgt (sort(keys(%lp))) { 545 foreach my $tgt (sort(keys(%lp))) {
534 if ($lp{$tgt} eq 'none') { 546 my $w = NFC($lp{$tgt});
535 print $fh " $tgt: $lp{$tgt}\n"; 547 if ($w eq 'none') {
548 print $fh " $tgt: $w\n";
536 } else { 549 } else {
537 print $fh " $tgt: \"$lp{$tgt}\"\n"; 550 print $fh " $tgt: \"$w\"\n";
538 } 551 }
539 } 552 }
540 print $fh " </source>\n"; 553 print $fh " </source>\n";
@@ -543,10 +556,11 @@ foreach my $id (@finalorder) {
543 %lp = combinetgts(%{$lang{$id}{'dest'}}); 556 %lp = combinetgts(%{$lang{$id}{'dest'}});
544 print $fh " <dest>\n"; 557 print $fh " <dest>\n";
545 foreach my $tgt (sort(keys(%lp))) { 558 foreach my $tgt (sort(keys(%lp))) {
546 if ($lp{$tgt} eq 'none') { 559 my $w = NFC($lp{$tgt});
547 print $fh " $tgt: $lp{$tgt}\n"; 560 if ($w eq 'none') {
561 print $fh " $tgt: $w\n";
548 } else { 562 } else {
549 print $fh " $tgt: \"$lp{$tgt}\"\n"; 563 print $fh " $tgt: \"$w\"\n";
550 } 564 }
551 } 565 }
552 print $fh " </dest>\n"; 566 print $fh " </dest>\n";
@@ -555,10 +569,11 @@ foreach my $id (@finalorder) {
555 %lp = combinetgts(%{$lang{$id}{'voice'}}); 569 %lp = combinetgts(%{$lang{$id}{'voice'}});
556 print $fh " <voice>\n"; 570 print $fh " <voice>\n";
557 foreach my $tgt (sort(keys(%lp))) { 571 foreach my $tgt (sort(keys(%lp))) {
558 if ($lp{$tgt} eq 'none') { 572 my $w = NFC($lp{$tgt});
559 print $fh " $tgt: $lp{$tgt}\n"; 573 if ($w eq 'none') {
574 print $fh " $tgt: $w\n";
560 } else { 575 } else {
561 print $fh " $tgt: \"$lp{$tgt}\"\n"; 576 print $fh " $tgt: \"$w\"\n";
562 } 577 }
563 } 578 }
564 print $fh " </voice>\n"; 579 print $fh " </voice>\n";