1
0
Fork 0
forked from len0rd/rockbox

lang: Complain if there are multiple target matches for a given string

The tooling will always use the *final* match, which may or may not be
what is desired.  Treat this as a bug, and complain appropriately.

However, there is a special case.  The RTC set screen uses strings that
include the device button names. There should be an entry for the
specific device, but if not, we wanted to fall back to the string
specified by the 'rtc' feature flag as opposed to falling back to the
default, empty string.

To still support this, add a special "FALLBACK" value; If we end up
using this for a device, the tooling will treat this as a bug, and
complain accordingly.

This should fix FS#13615 and FS13616, and may introduce build failures
on targets that are missing appropriate entries.  We'll see.

Change-Id: Ie78bb247f968e19d450a0fbf6e1177b6d01126a1
This commit is contained in:
Solomon Peachy 2025-05-04 08:44:01 -04:00
parent 336d42c72b
commit a88ef80560
3 changed files with 60 additions and 76 deletions

View file

@ -235,6 +235,7 @@ sub readenglish {
my $withindest;
my $numphrases = 0;
my $numusers = 1; # core is already in the users map
my $deststr;
while(<ENG>) {
@ -243,8 +244,7 @@ sub readenglish {
if($_ =~ /^ *\<phrase\>/) {
# this is the start of a phrase
}
elsif($_ =~ /\<\/phrase\>/) {
} elsif($_ =~ /\<\/phrase\>/) {
# if id is something, when we count and store this phrase
if($id) {
@ -253,8 +253,7 @@ sub readenglish {
# Assign an ID number to this entry
$idmap[$user]{$id}=$vidnum[$user];
$vidnum[$user]++;
}
else {
} else {
# Assign an ID number to this entry
$idmap[$user]{$id}=$idnum[$user];
$idnum[$user]++;
@ -266,8 +265,7 @@ sub readenglish {
}
undef @phrase;
$id="";
}
elsif($_ ne "\n") {
} elsif($_ ne "\n") {
# gather everything related to this phrase
push @phrase, $_;
if($_ =~ /^ *\<dest\>/i) {
@ -278,12 +276,10 @@ sub readenglish {
$withindest=0;
if($deststr && ($deststr !~ /^none\z/i)) {
# we unconditionally always use all IDs when the "update"
# feature is used
die ("Missing specific target match for $maybeid\n") if ($deststr eq '"FALLBACK"');
$id = $maybeid;
# print "DEST: use this id $id\n";
}
else {
} else {
# print "skip $maybeid for $name\n";
}
}
@ -293,11 +289,24 @@ sub readenglish {
# model name isn't "ours"
dest($_, $name, $val);
if($dest) {
# Store the current dest string. If this target matches
# multiple strings, it will get updated several times.
$deststr = $dest;
}
## If $dest is nonnull (ie we have a match for this target)
## if $deststr is null, accept
## if $name is '*', accept
## if $name is not '*' and $deststr is not null, COMPLAIN.
if ($dest) {
if (!$deststr) {
$deststr = $dest;
} elsif ($name eq '*') {
$deststr = $dest;
} elsif ($deststr ne 'none' && $val ne '"FALLBACK"') {
die("multiple matches on $maybeid ($name:$val / $deststr)\n");
} elsif ($deststr ne 'none' && $val eq '"FALLBACK"') {
# Ignore FALLBACK row if we already have a match
} else {
$deststr = $dest;
}
}
}
}

View file

@ -555,6 +555,7 @@ foreach my $id (@finalorder) {
print $fh " <source>\n";
foreach my $tgt (sort(keys(%lp))) {
my $w = NFC($lp{$tgt});
next if ($w eq 'FALLBACK');
if ($w eq 'none') {
print $fh " $tgt: $w\n";
} else {
@ -568,6 +569,7 @@ foreach my $id (@finalorder) {
print $fh " <dest>\n";
foreach my $tgt (sort(keys(%lp))) {
my $w = NFC($lp{$tgt});
next if ($w eq 'FALLBACK');
if ($w eq 'none') {
print $fh " $tgt: $w\n";
} else {
@ -581,6 +583,7 @@ foreach my $id (@finalorder) {
print $fh " <voice>\n";
foreach my $tgt (sort(keys(%lp))) {
my $w = NFC($lp{$tgt});
next if ($w eq 'FALLBACK');
if ($w eq 'none') {
print $fh " $tgt: $w\n";
} else {