mirror of
https://github.com/rkd77/elinks.git
synced 2025-01-03 14:57:44 -05:00
v1.4 supports a new option: --msgid-fallback.
This commit is contained in:
parent
8e1b6011bb
commit
96cc86bc64
@ -7,7 +7,7 @@ use Locale::PO qw();
|
|||||||
use Getopt::Long qw(GetOptions :config bundling gnu_compat);
|
use Getopt::Long qw(GetOptions :config bundling gnu_compat);
|
||||||
use autouse 'Pod::Usage' => qw(pod2usage);
|
use autouse 'Pod::Usage' => qw(pod2usage);
|
||||||
|
|
||||||
my $VERSION = "1.3";
|
my $VERSION = "1.4";
|
||||||
|
|
||||||
sub show_version
|
sub show_version
|
||||||
{
|
{
|
||||||
@ -16,7 +16,13 @@ sub show_version
|
|||||||
-exitval => 0});
|
-exitval => 0});
|
||||||
}
|
}
|
||||||
|
|
||||||
my $Accelerator_tag;
|
# The character that precedes accelerators in strings.
|
||||||
|
# Set with the --accelerator-tag=CHARACTER option.
|
||||||
|
my $Opt_accelerator_tag;
|
||||||
|
|
||||||
|
# True if, for missing or fuzzy translations, the msgid string should
|
||||||
|
# be checked instead of msgstr. Set with the --msgid-fallback option.
|
||||||
|
my $Opt_msgid_fallback;
|
||||||
|
|
||||||
sub acceleration_arrays_eq ($$)
|
sub acceleration_arrays_eq ($$)
|
||||||
{
|
{
|
||||||
@ -39,16 +45,18 @@ sub check_po_file ($)
|
|||||||
my $pos = Locale::PO->load_file_asarray($po_file_name)
|
my $pos = Locale::PO->load_file_asarray($po_file_name)
|
||||||
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();
|
|
||||||
my $automatic = $po->automatic()
|
my $automatic = $po->automatic()
|
||||||
or next;
|
or next;
|
||||||
my($ctxnames) = ($automatic =~ /^accelerator_context\(([^\)]*)\)/)
|
my($ctxnames) = ($automatic =~ /^accelerator_context\(([^\)]*)\)/)
|
||||||
or next;
|
or next;
|
||||||
my @ctxnames = split(/\s*,\s*/, $ctxnames);
|
my @ctxnames = split(/\s*,\s*/, $ctxnames);
|
||||||
my @accelerations;
|
my @accelerations;
|
||||||
if (defined(my $msgstr = $po->msgstr())) {
|
my $msgid = $po->msgid();
|
||||||
if (my($accelerator) = ($msgstr =~ /\Q$Accelerator_tag\E(.)/s)) {
|
my $msgstr = $po->msgstr();
|
||||||
|
if ($po->dequote($msgstr) ne "" && !$po->fuzzy()) {
|
||||||
|
if (my($accelerator) = ($msgstr =~ /\Q$Opt_accelerator_tag\E(.)/s)) {
|
||||||
push @accelerations, { PO => $po,
|
push @accelerations, { PO => $po,
|
||||||
|
CTXNAMES => \@ctxnames,
|
||||||
ACCELERATOR => $accelerator,
|
ACCELERATOR => $accelerator,
|
||||||
LINENO => $po->msgstr_begin_lineno(),
|
LINENO => $po->msgstr_begin_lineno(),
|
||||||
STRING => $msgstr,
|
STRING => $msgstr,
|
||||||
@ -57,14 +65,13 @@ sub check_po_file ($)
|
|||||||
|
|
||||||
# TODO: look for accelerators in plural forms?
|
# TODO: look for accelerators in plural forms?
|
||||||
}
|
}
|
||||||
# The msgid checking below is disabled because it doesn't
|
elsif ($Opt_msgid_fallback && $po->dequote($msgid) ne "") {
|
||||||
# help choose good accelerators for translated strings.
|
if (my($accelerator) = ($msgid =~ /\Q$Opt_accelerator_tag\E(.)/s)) {
|
||||||
elsif (0 && defined(my $msgid = $po->msgid())) {
|
|
||||||
if (my($accelerator) = ($msgid =~ /\Q$Accelerator_tag\E(.)/s)) {
|
|
||||||
push @accelerations, { PO => $po,
|
push @accelerations, { PO => $po,
|
||||||
|
CTXNAMES => \@ctxnames,
|
||||||
ACCELERATOR => $accelerator,
|
ACCELERATOR => $accelerator,
|
||||||
LINENO => $po->msgid_begin_lineno(),
|
LINENO => $po->msgid_begin_lineno(),
|
||||||
STRING => $msgstr,
|
STRING => $msgid,
|
||||||
EXPLAIN => "msgid $msgid" };
|
EXPLAIN => "msgid $msgid" };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,7 +109,7 @@ sub check_po_file ($)
|
|||||||
# preferring characters that start a word.
|
# preferring characters that start a word.
|
||||||
# FIXME: should remove quotes and resolve \n etc.
|
# FIXME: should remove quotes and resolve \n etc.
|
||||||
my $displaystr = $acceleration->{STRING};
|
my $displaystr = $acceleration->{STRING};
|
||||||
$displaystr =~ s/\Q$Accelerator_tag\E//g;
|
$displaystr =~ s/\Q$Opt_accelerator_tag\E//g;
|
||||||
my $suggestions = "";
|
my $suggestions = "";
|
||||||
foreach my $char ($displaystr =~ /\b(\w)/g,
|
foreach my $char ($displaystr =~ /\b(\w)/g,
|
||||||
$displaystr =~ /(\w)/g) {
|
$displaystr =~ /(\w)/g) {
|
||||||
@ -111,7 +118,7 @@ sub check_po_file ($)
|
|||||||
|
|
||||||
# But don't suggest unavailable characters.
|
# But don't suggest unavailable characters.
|
||||||
SUGGESTION: foreach my $char (split(//, $suggestions)) {
|
SUGGESTION: foreach my $char (split(//, $suggestions)) {
|
||||||
foreach my $ctxname (@ctxnames_in_conflict) {
|
foreach my $ctxname (@{$acceleration->{CTXNAMES}}) {
|
||||||
$suggestions =~ s/\Q$char\E//, next SUGGESTION
|
$suggestions =~ s/\Q$char\E//, next SUGGESTION
|
||||||
if exists $accelerators{uc($char)}{$ctxname};
|
if exists $accelerators{uc($char)}{$ctxname};
|
||||||
}
|
}
|
||||||
@ -135,15 +142,16 @@ sub check_po_file ($)
|
|||||||
GetOptions("accelerator-tag=s" => sub {
|
GetOptions("accelerator-tag=s" => sub {
|
||||||
my($option, $value) = @_;
|
my($option, $value) = @_;
|
||||||
die "Cannot use multiple --accelerator-tag options\n"
|
die "Cannot use multiple --accelerator-tag options\n"
|
||||||
if defined($Accelerator_tag);
|
if defined($Opt_accelerator_tag);
|
||||||
die "--accelerator-tag requires a single-character argument\n"
|
die "--accelerator-tag requires a single-character argument\n"
|
||||||
if length($value) != 1;
|
if length($value) != 1;
|
||||||
$Accelerator_tag = $value;
|
$Opt_accelerator_tag = $value;
|
||||||
},
|
},
|
||||||
|
"msgid-fallback" => \$Opt_msgid_fallback,
|
||||||
"help" => sub { pod2usage({-verbose => 1, -exitval => 0}) },
|
"help" => sub { pod2usage({-verbose => 1, -exitval => 0}) },
|
||||||
"version" => \&show_version)
|
"version" => \&show_version)
|
||||||
or exit 2;
|
or exit 2;
|
||||||
$Accelerator_tag = "~" unless defined $Accelerator_tag;
|
$Opt_accelerator_tag = "~" unless defined $Opt_accelerator_tag;
|
||||||
print(STDERR "$0: missing file operand\n"), exit 2 unless @ARGV;
|
print(STDERR "$0: missing file operand\n"), exit 2 unless @ARGV;
|
||||||
|
|
||||||
my $max_error = 0;
|
my $max_error = 0;
|
||||||
@ -179,6 +187,7 @@ or merged with B<msgmerge>.
|
|||||||
|
|
||||||
B<check-accelerator-conflicts.pl> reads the F<I<language>.po> file
|
B<check-accelerator-conflicts.pl> reads the F<I<language>.po> file
|
||||||
named on the command line and reports any conflicts to standard error.
|
named on the command line and reports any conflicts to standard error.
|
||||||
|
It also tries to suggest replacements for the conflicting accelerators.
|
||||||
|
|
||||||
B<check-accelerator-conflicts.pl> does not access the source files to
|
B<check-accelerator-conflicts.pl> does not access the source files to
|
||||||
which F<I<language>.po> refers. Thus, it does not matter if the line
|
which F<I<language>.po> refers. Thus, it does not matter if the line
|
||||||
@ -201,6 +210,18 @@ B<--accelerator-tag="~">. The option must be given to each program
|
|||||||
separately because there is no standard way to save this information
|
separately because there is no standard way to save this information
|
||||||
in the PO file.
|
in the PO file.
|
||||||
|
|
||||||
|
=item B<--msgid-fallback>
|
||||||
|
|
||||||
|
If the C<msgstr> is empty or the entry is fuzzy, check the C<msgid>
|
||||||
|
instead. Without this option, B<check-accelerator-conflicts.pl>
|
||||||
|
completely ignores such entries.
|
||||||
|
|
||||||
|
This option also causes B<check-accelerator-conflicts.pl> not to
|
||||||
|
suggest accelerators that would conflict with a C<msgid> that was thus
|
||||||
|
checked. Following these suggestions may lead to bad choices for
|
||||||
|
accelerators, because the conflicting C<msgid> will eventually be
|
||||||
|
shadowed by a C<msgstr> that may use a different accelerator.
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
=head1 ARGUMENTS
|
=head1 ARGUMENTS
|
||||||
|
Loading…
Reference in New Issue
Block a user