summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2008-08-17 12:25:39 +0000
committerDave Chapman <dave@dchapman.com>2008-08-17 12:25:39 +0000
commit509c06aa03b17b6330073e2db2170117aeea39e2 (patch)
tree6c2fa538feb1fbfb4a4220a7ca015c3115f3bfae
parent3adf579702cdd0c62e431ae82d8776890fa381a3 (diff)
downloadrockbox-509c06aa03b17b6330073e2db2170117aeea39e2.tar.gz
rockbox-509c06aa03b17b6330073e2db2170117aeea39e2.zip
Add a -s option to genlang to sort a language file into the same order as english.lang
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18303 a1c6a512-1295-4272-9138-f99709370657
-rwxr-xr-xtools/genlang34
1 files changed, 26 insertions, 8 deletions
diff --git a/tools/genlang b/tools/genlang
index cd153163f5..d99e3f0442 100755
--- a/tools/genlang
+++ b/tools/genlang
@@ -38,7 +38,11 @@ Usage: genlang [options] <langv2 file>
38 38
39 -e=<english lang file> 39 -e=<english lang file>
40 Point out the english (original source) file, to use that as master 40 Point out the english (original source) file, to use that as master
41 language template. Used in combination with -b or -u. 41 language template. Used in combination with -b, -u or -s.
42
43 -s
44 Sort the Update language file in the same order as the strings in the
45 English file.
42 46
43 -t=<target> 47 -t=<target>
44 Specify which target you want the translations/phrases for. Required when 48 Specify which target you want the translations/phrases for. Required when
@@ -77,23 +81,25 @@ MOO
77my $prefix = $p; 81my $prefix = $p;
78my $binary = $b; 82my $binary = $b;
79my $update = $u; 83my $update = $u;
84my $sortfile = $s;
80 85
81my $english = $e; 86my $english = $e;
82my $voiceout = $o; 87my $voiceout = $o;
83 88
84my $check = ($binary?1:0) + ($prefix?1:0) + ($update?1:0) + ($voiceout?1:0); 89my $check = ($binary?1:0) + ($prefix?1:0) + ($update?1:0) + ($voiceout?1:0) + ($sortfile?1:0);
85 90
86if($check > 1) { 91if($check > 1) {
87 print "Please use only one of -p, -u, -o and -b\n"; 92 print "Please use only one of -p, -u, -o, -b and -s\n";
88 exit; 93 exit;
89} 94}
90if(!$check) { 95if(!$check) {
91 print "Please use at least one of -p, -u, -o and -b\n"; 96 print "Please use at least one of -p, -u, -o, -b and -s\n";
92 exit; 97 exit;
93} 98}
94 99
95if(($binary || $update || $voiceout) && !$english) { 100
96 print "Please use -e too when you use -b, -o or -u\n"; 101if(($binary || $update || $voiceout || $sortfile) && !$english) {
102 print "Please use -e too when you use -b, -o, -u or -s\n";
97 exit; 103 exit;
98} 104}
99 105
@@ -104,7 +110,7 @@ if($binary && !$target_id) {
104} 110}
105 111
106my $target = $t; 112my $target = $t;
107if(!$target && !$update) { 113if(!$target && !$update && !$sortfile) {
108 print "Please specify a target (with -t)!\n"; 114 print "Please specify a target (with -t)!\n";
109 exit; 115 exit;
110} 116}
@@ -113,6 +119,7 @@ my $verbose=$v;
113my %id; # string to num hash 119my %id; # string to num hash
114my @idnum; # num to string array 120my @idnum; # num to string array
115 121
122my %allphrases; # For sorting - an array of the <phrase> elements
116my %source; # id string to source phrase hash 123my %source; # id string to source phrase hash
117my %dest; # id string to dest phrase hash 124my %dest; # id string to dest phrase hash
118my %voice; # id string to voice phrase hash 125my %voice; # id string to voice phrase hash
@@ -201,6 +208,7 @@ if($english) {
201 my $id; 208 my $id;
202 my $maybeid; 209 my $maybeid;
203 my $withindest; 210 my $withindest;
211 my $numphrases = 0;
204 while(<ENG>) { 212 while(<ENG>) {
205 213
206 # get rid of DOS newlines 214 # get rid of DOS newlines
@@ -268,6 +276,7 @@ if($english) {
268 276
269 if($_ =~ /^ *id: ([^ \t\n]+)/i) { 277 if($_ =~ /^ *id: ([^ \t\n]+)/i) {
270 $maybeid=$1; 278 $maybeid=$1;
279 $sortorder{$maybeid}=$numphrases++;
271 } 280 }
272 } 281 }
273 close(ENG); 282 close(ENG);
@@ -369,7 +378,7 @@ while(<LANG>) {
369 378
370 if($_ =~ /^( *\#|[ \t\n\r]*\z)/) { 379 if($_ =~ /^( *\#|[ \t\n\r]*\z)/) {
371 # comment or empty line - output it if it's part of the header 380 # comment or empty line - output it if it's part of the header
372 if ($header and $update) { 381 if ($header and ($update || $sortfile)) {
373 print($_); 382 print($_);
374 } 383 }
375 next; 384 next;
@@ -403,6 +412,9 @@ while(<LANG>) {
403 # "none" as dest (without quotes) means that this entire 412 # "none" as dest (without quotes) means that this entire
404 # phrase is to be ignored 413 # phrase is to be ignored
405 } 414 }
415 elsif($sortfile) {
416 $allphrases{$idstr}=join('',@phrase);
417 }
406 elsif(!$update) { 418 elsif(!$update) {
407 # we don't do the fully detailed analysis when we "update" 419 # we don't do the fully detailed analysis when we "update"
408 # since we don't do it for a particular target etc 420 # since we don't do it for a particular target etc
@@ -511,6 +523,12 @@ if($update) {
511 } 523 }
512} 524}
513 525
526if ($sortfile) {
527 for(sort { $sortorder{$a} <=> $sortorder{$b} } keys %allphrases) {
528 print $allphrases{$_};
529 }
530}
531
514if($prefix) { 532if($prefix) {
515 # We create a .c and .h file 533 # We create a .c and .h file
516 534