mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Made it possible to scan msgid strings for accelerator conflicts, too.
But disabled that for now.
This commit is contained in:
parent
d66ed0e76d
commit
2431fe4711
@ -18,7 +18,7 @@ sub show_version
|
|||||||
|
|
||||||
my $Accelerator_tag;
|
my $Accelerator_tag;
|
||||||
|
|
||||||
sub po_arrays_eq ($$)
|
sub acceleration_arrays_eq ($$)
|
||||||
{
|
{
|
||||||
my($left, $right) = @_;
|
my($left, $right) = @_;
|
||||||
ref($left) eq "ARRAY" or return 0;
|
ref($left) eq "ARRAY" or return 0;
|
||||||
@ -40,17 +40,40 @@ sub check_po_file ($)
|
|||||||
or warn "$po_file_name: $!\n", return 2;
|
or warn "$po_file_name: $!\n", return 2;
|
||||||
foreach my $po (@$pos) {
|
foreach my $po (@$pos) {
|
||||||
next if $po->fuzzy();
|
next if $po->fuzzy();
|
||||||
my $msgstr = $po->msgstr()
|
|
||||||
or next;
|
|
||||||
my($accelerator) = ($msgstr =~ /\Q$Accelerator_tag\E(.)/s)
|
|
||||||
or next;
|
|
||||||
$accelerator = uc($accelerator);
|
|
||||||
my $automatic = $po->automatic()
|
my $automatic = $po->automatic()
|
||||||
or next;
|
or next;
|
||||||
my($contexts) = ($automatic =~ /^accelerator_context\(([^\)]*)\)/)
|
my($ctxnames) = ($automatic =~ /^accelerator_context\(([^\)]*)\)/)
|
||||||
or next;
|
or next;
|
||||||
foreach my $context (split(/\s*,\s*/, $contexts)) {
|
my @ctxnames = split(/\s*,\s*/, $ctxnames);
|
||||||
push @{$accelerators{$accelerator}{$context}}, $po;
|
my @accelerations;
|
||||||
|
if (defined(my $msgstr = $po->msgstr())) {
|
||||||
|
if (my($accelerator) = ($msgstr =~ /\Q$Accelerator_tag\E(.)/s)) {
|
||||||
|
push @accelerations, { PO => $po,
|
||||||
|
ACCELERATOR => $accelerator,
|
||||||
|
LINENO => $po->msgstr_begin_lineno(),
|
||||||
|
STRING => $msgstr,
|
||||||
|
EXPLAIN => "msgstr $msgstr" };
|
||||||
|
}
|
||||||
|
|
||||||
|
# TODO: look for accelerators in plural forms?
|
||||||
|
}
|
||||||
|
# The msgid checking below is disabled because it doesn't
|
||||||
|
# help choose good accelerators for translated strings.
|
||||||
|
elsif (0 && defined(my $msgid = $po->msgid())) {
|
||||||
|
if (my($accelerator) = ($msgid =~ /\Q$Accelerator_tag\E(.)/s)) {
|
||||||
|
push @accelerations, { PO => $po,
|
||||||
|
ACCELERATOR => $accelerator,
|
||||||
|
LINENO => $po->msgid_begin_lineno(),
|
||||||
|
STRING => $msgstr,
|
||||||
|
EXPLAIN => "msgid $msgid" };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach my $acceleration (@accelerations) {
|
||||||
|
foreach my $ctxname (@ctxnames) {
|
||||||
|
push(@{$accelerators{uc $acceleration->{ACCELERATOR}}{$ctxname}},
|
||||||
|
$acceleration);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,26 +81,27 @@ sub check_po_file ($)
|
|||||||
foreach my $accelerator (sort keys %accelerators) {
|
foreach my $accelerator (sort keys %accelerators) {
|
||||||
my $ctxhash = $accelerators{$accelerator};
|
my $ctxhash = $accelerators{$accelerator};
|
||||||
foreach my $outer_ctxname (sort keys %$ctxhash) {
|
foreach my $outer_ctxname (sort keys %$ctxhash) {
|
||||||
# Cannot use "foreach my $pos" directly, because $pos
|
# Cannot use "foreach my $accelerations" directly, because
|
||||||
# would then become an alias and change to 0 below.
|
# $accelerations would then become an alias and change to 0 below.
|
||||||
my $pos = $ctxhash->{$outer_ctxname};
|
my $accelerations = $ctxhash->{$outer_ctxname};
|
||||||
if (ref($pos) eq "ARRAY" && @$pos > 1) {
|
if (ref($accelerations) eq "ARRAY" && @$accelerations > 1) {
|
||||||
my @ctxnames_in_conflict;
|
my @ctxnames_in_conflict;
|
||||||
foreach my $ctxname (sort keys %$ctxhash) {
|
foreach my $ctxname (sort keys %$ctxhash) {
|
||||||
if (po_arrays_eq($ctxhash->{$ctxname}, $pos)) {
|
if (acceleration_arrays_eq($ctxhash->{$ctxname}, $accelerations)) {
|
||||||
push @ctxnames_in_conflict, $ctxname;
|
push @ctxnames_in_conflict, $ctxname;
|
||||||
$ctxhash->{$ctxname} = 0;
|
$ctxhash->{$ctxname} = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
my $ctxnames_in_conflict = join(", ", map(qq("$_"), @ctxnames_in_conflict));
|
my $ctxnames_in_conflict = join(", ", map(qq("$_"), @ctxnames_in_conflict));
|
||||||
warn "$po_file_name: Accelerator conflict for \"$accelerator\" in $ctxnames_in_conflict:\n";
|
warn "$po_file_name: Accelerator conflict for \"$accelerator\" in $ctxnames_in_conflict:\n";
|
||||||
foreach my $po (@$pos) {
|
foreach my $acceleration (@$accelerations) {
|
||||||
my $lineno = $po->msgstr_begin_lineno();
|
my $lineno = $acceleration->{LINENO};
|
||||||
my $msgstr = $po->msgstr();
|
my $explain = $acceleration->{EXPLAIN};
|
||||||
|
|
||||||
# Get a string of unique characters in $msgstr,
|
# Get a string of unique characters in the string,
|
||||||
# preferring characters that start a word.
|
# preferring characters that start a word.
|
||||||
my $displaystr = $msgstr;
|
# FIXME: should remove quotes and resolve \n etc.
|
||||||
|
my $displaystr = $acceleration->{STRING};
|
||||||
$displaystr =~ s/\Q$Accelerator_tag\E//g;
|
$displaystr =~ s/\Q$Accelerator_tag\E//g;
|
||||||
my $suggestions = "";
|
my $suggestions = "";
|
||||||
foreach my $char ($displaystr =~ /\b(\w)/g,
|
foreach my $char ($displaystr =~ /\b(\w)/g,
|
||||||
@ -93,7 +117,7 @@ sub check_po_file ($)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
warn "$po_file_name:$lineno: msgstr $msgstr\n";
|
warn "$po_file_name:$lineno: $explain\n";
|
||||||
if ($suggestions eq "") {
|
if ($suggestions eq "") {
|
||||||
warn "$po_file_name:$lineno: no suggestions :-(\n";
|
warn "$po_file_name:$lineno: no suggestions :-(\n";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user