mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-13 18:17:39 -04:00
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
This commit is contained in:
parent
3adf579702
commit
509c06aa03
1 changed files with 26 additions and 8 deletions
|
@ -38,7 +38,11 @@ Usage: genlang [options] <langv2 file>
|
||||||
|
|
||||||
-e=<english lang file>
|
-e=<english lang file>
|
||||||
Point out the english (original source) file, to use that as master
|
Point out the english (original source) file, to use that as master
|
||||||
language template. Used in combination with -b or -u.
|
language template. Used in combination with -b, -u or -s.
|
||||||
|
|
||||||
|
-s
|
||||||
|
Sort the Update language file in the same order as the strings in the
|
||||||
|
English file.
|
||||||
|
|
||||||
-t=<target>
|
-t=<target>
|
||||||
Specify which target you want the translations/phrases for. Required when
|
Specify which target you want the translations/phrases for. Required when
|
||||||
|
@ -77,23 +81,25 @@ MOO
|
||||||
my $prefix = $p;
|
my $prefix = $p;
|
||||||
my $binary = $b;
|
my $binary = $b;
|
||||||
my $update = $u;
|
my $update = $u;
|
||||||
|
my $sortfile = $s;
|
||||||
|
|
||||||
my $english = $e;
|
my $english = $e;
|
||||||
my $voiceout = $o;
|
my $voiceout = $o;
|
||||||
|
|
||||||
my $check = ($binary?1:0) + ($prefix?1:0) + ($update?1:0) + ($voiceout?1:0);
|
my $check = ($binary?1:0) + ($prefix?1:0) + ($update?1:0) + ($voiceout?1:0) + ($sortfile?1:0);
|
||||||
|
|
||||||
if($check > 1) {
|
if($check > 1) {
|
||||||
print "Please use only one of -p, -u, -o and -b\n";
|
print "Please use only one of -p, -u, -o, -b and -s\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
if(!$check) {
|
if(!$check) {
|
||||||
print "Please use at least one of -p, -u, -o and -b\n";
|
print "Please use at least one of -p, -u, -o, -b and -s\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(($binary || $update || $voiceout) && !$english) {
|
|
||||||
print "Please use -e too when you use -b, -o or -u\n";
|
if(($binary || $update || $voiceout || $sortfile) && !$english) {
|
||||||
|
print "Please use -e too when you use -b, -o, -u or -s\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +110,7 @@ if($binary && !$target_id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
my $target = $t;
|
my $target = $t;
|
||||||
if(!$target && !$update) {
|
if(!$target && !$update && !$sortfile) {
|
||||||
print "Please specify a target (with -t)!\n";
|
print "Please specify a target (with -t)!\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
@ -113,6 +119,7 @@ my $verbose=$v;
|
||||||
my %id; # string to num hash
|
my %id; # string to num hash
|
||||||
my @idnum; # num to string array
|
my @idnum; # num to string array
|
||||||
|
|
||||||
|
my %allphrases; # For sorting - an array of the <phrase> elements
|
||||||
my %source; # id string to source phrase hash
|
my %source; # id string to source phrase hash
|
||||||
my %dest; # id string to dest phrase hash
|
my %dest; # id string to dest phrase hash
|
||||||
my %voice; # id string to voice phrase hash
|
my %voice; # id string to voice phrase hash
|
||||||
|
@ -201,6 +208,7 @@ if($english) {
|
||||||
my $id;
|
my $id;
|
||||||
my $maybeid;
|
my $maybeid;
|
||||||
my $withindest;
|
my $withindest;
|
||||||
|
my $numphrases = 0;
|
||||||
while(<ENG>) {
|
while(<ENG>) {
|
||||||
|
|
||||||
# get rid of DOS newlines
|
# get rid of DOS newlines
|
||||||
|
@ -268,6 +276,7 @@ if($english) {
|
||||||
|
|
||||||
if($_ =~ /^ *id: ([^ \t\n]+)/i) {
|
if($_ =~ /^ *id: ([^ \t\n]+)/i) {
|
||||||
$maybeid=$1;
|
$maybeid=$1;
|
||||||
|
$sortorder{$maybeid}=$numphrases++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close(ENG);
|
close(ENG);
|
||||||
|
@ -369,7 +378,7 @@ while(<LANG>) {
|
||||||
|
|
||||||
if($_ =~ /^( *\#|[ \t\n\r]*\z)/) {
|
if($_ =~ /^( *\#|[ \t\n\r]*\z)/) {
|
||||||
# comment or empty line - output it if it's part of the header
|
# comment or empty line - output it if it's part of the header
|
||||||
if ($header and $update) {
|
if ($header and ($update || $sortfile)) {
|
||||||
print($_);
|
print($_);
|
||||||
}
|
}
|
||||||
next;
|
next;
|
||||||
|
@ -403,6 +412,9 @@ while(<LANG>) {
|
||||||
# "none" as dest (without quotes) means that this entire
|
# "none" as dest (without quotes) means that this entire
|
||||||
# phrase is to be ignored
|
# phrase is to be ignored
|
||||||
}
|
}
|
||||||
|
elsif($sortfile) {
|
||||||
|
$allphrases{$idstr}=join('',@phrase);
|
||||||
|
}
|
||||||
elsif(!$update) {
|
elsif(!$update) {
|
||||||
# we don't do the fully detailed analysis when we "update"
|
# we don't do the fully detailed analysis when we "update"
|
||||||
# since we don't do it for a particular target etc
|
# since we don't do it for a particular target etc
|
||||||
|
@ -511,6 +523,12 @@ if($update) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($sortfile) {
|
||||||
|
for(sort { $sortorder{$a} <=> $sortorder{$b} } keys %allphrases) {
|
||||||
|
print $allphrases{$_};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if($prefix) {
|
if($prefix) {
|
||||||
# We create a .c and .h file
|
# We create a .c and .h file
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue