diff options
author | Dave Chapman <dave@dchapman.com> | 2008-08-17 12:25:39 +0000 |
---|---|---|
committer | Dave Chapman <dave@dchapman.com> | 2008-08-17 12:25:39 +0000 |
commit | 509c06aa03b17b6330073e2db2170117aeea39e2 (patch) | |
tree | 6c2fa538feb1fbfb4a4220a7ca015c3115f3bfae | |
parent | 3adf579702cdd0c62e431ae82d8776890fa381a3 (diff) | |
download | rockbox-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-x | tools/genlang | 34 |
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 | |||
77 | my $prefix = $p; | 81 | my $prefix = $p; |
78 | my $binary = $b; | 82 | my $binary = $b; |
79 | my $update = $u; | 83 | my $update = $u; |
84 | my $sortfile = $s; | ||
80 | 85 | ||
81 | my $english = $e; | 86 | my $english = $e; |
82 | my $voiceout = $o; | 87 | my $voiceout = $o; |
83 | 88 | ||
84 | my $check = ($binary?1:0) + ($prefix?1:0) + ($update?1:0) + ($voiceout?1:0); | 89 | my $check = ($binary?1:0) + ($prefix?1:0) + ($update?1:0) + ($voiceout?1:0) + ($sortfile?1:0); |
85 | 90 | ||
86 | if($check > 1) { | 91 | if($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 | } |
90 | if(!$check) { | 95 | if(!$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 | ||
95 | if(($binary || $update || $voiceout) && !$english) { | 100 | |
96 | print "Please use -e too when you use -b, -o or -u\n"; | 101 | if(($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 | ||
106 | my $target = $t; | 112 | my $target = $t; |
107 | if(!$target && !$update) { | 113 | if(!$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; | |||
113 | my %id; # string to num hash | 119 | my %id; # string to num hash |
114 | my @idnum; # num to string array | 120 | my @idnum; # num to string array |
115 | 121 | ||
122 | my %allphrases; # For sorting - an array of the <phrase> elements | ||
116 | my %source; # id string to source phrase hash | 123 | my %source; # id string to source phrase hash |
117 | my %dest; # id string to dest phrase hash | 124 | my %dest; # id string to dest phrase hash |
118 | my %voice; # id string to voice phrase hash | 125 | my %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 | ||
526 | if ($sortfile) { | ||
527 | for(sort { $sortorder{$a} <=> $sortorder{$b} } keys %allphrases) { | ||
528 | print $allphrases{$_}; | ||
529 | } | ||
530 | } | ||
531 | |||
514 | if($prefix) { | 532 | if($prefix) { |
515 | # We create a .c and .h file | 533 | # We create a .c and .h file |
516 | 534 | ||