pocheck.pl: In checking for period at end, treat '...' be equivalent to '…'

This commit is contained in:
Kornel Benko 2017-12-26 10:45:44 +01:00
parent 713fd70e8f
commit 626f607db7

View File

@ -15,13 +15,14 @@ use Getopt::Std;
use Encode qw(encode decode); use Encode qw(encode decode);
sub mylc($); sub mylc($);
sub replaceSynopsis($);
my $usage = <<EOT; my $usage = <<EOT;
pocheck.pl [-acmpqst] po_file [po_file] ... pocheck.pl [-acmpqst] po_file [po_file] ...
This script performs some consistency checks on po files. This script performs some consistency checks on po files.
We check for everything listed here, unless one or more of these We check for everything listed here, unless one or more of these
options is given, in which case we checks only for those requested. options is given, in which case we checks only for those requested.
-a: Check arguments, like %1\$s -a: Check arguments, like %1\$s
-c: Check for colons at end -c: Check for colons at end
@ -39,9 +40,9 @@ EOT
my %options; my %options;
getopts(":hacfmpqstwi", \%options); getopts(":hacfmpqstwi", \%options);
if (defined($options{h})) { if (defined($options{h})) {
print $usage; print $usage;
exit 0; exit 0;
} }
my $only_total = defined($options{w}); my $only_total = defined($options{w});
@ -155,6 +156,9 @@ foreach my $pofilename ( @ARGV ) {
if ($check_periods) { if ($check_periods) {
# Check period at the end of a message; uncomment code if you are paranoid # Check period at the end of a message; uncomment code if you are paranoid
# Convert '...' to '…' first
$msgid = replaceSynopsis($msgid);
$msgstr = replaceSynopsis($msgstr);
if ( ( $msgid =~ m/\. *(\|.*)?$/ ) != ( $msgstr =~ m/\. *(\|.*)?$/ ) ) { if ( ( $msgid =~ m/\. *(\|.*)?$/ ) != ( $msgstr =~ m/\. *(\|.*)?$/ ) ) {
print "Line $linenum: Missing or unexpected period:\n '$msgid' => '$msgstr'\n" print "Line $linenum: Missing or unexpected period:\n '$msgid' => '$msgstr'\n"
unless $only_total; unless $only_total;
@ -257,3 +261,13 @@ sub mylc($)
my ($msg) = @_; my ($msg) = @_;
return(encode('utf-8',lc(decode('utf-8', $msg)))); return(encode('utf-8',lc(decode('utf-8', $msg))));
} }
sub replaceSynopsis($)
{
my ($string) = @_;
return ($string) if ($string !~ /^(.*)\.\.\.(.*)$/);
my ($before, $after) = ($1, $2);
return $string if (($before =~ /\.$/) || ($after =~ /^\./));
return("$before…$after");
}