#! /usr/bin/perl -w
+# -*- mode: perl; -*-
# file pocheck.pl
#
use strict;
use warnings;
use Getopt::Std;
+use Encode qw(encode decode);
+
+sub mylc($);
my $usage = <<EOT;
pocheck.pl [-acmpqst] po_file [po_file] ...
my $check_args = (!%options or defined($options{a}));
my $check_colons = (!%options or defined($options{c}));
-my $check_spaces = (!%options or defined($options{m}));
+my $check_spaces = (!%options or defined($options{s}));
my $check_periods = (!%options or defined($options{p}));
my $check_qt = (!%options or defined($options{q}));
-my $check_menu = (!%options or defined($options{s}));
+my $check_menu = (!%options or defined($options{m}));
my $check_trans = (!%options or defined($options{t}));
my %trans;
+my $total_warn = 0;
+
foreach my $pofilename ( @ARGV ) {
my %bad;
if (!$silent_mode) {
my $warn = 0;
my $i = 0;
- my ($msgid, $msgstr, $more);
+ my ($msgid, $msgid_trans, $msgstr, $more);
while ($i <= $noOfLines) {
my $linenum = $i;
# (surely that is always $msgstr?)
next if ($msgid eq "" or $msgstr eq "");
+ # discard [[...]] from the end of msgid, this is used only as hint to translation
+ $msgid_trans = $msgid; # used for uniform translation
+ $msgid =~ s/\[\[.*\]\]$//;
+
# Check for matching %1$s, etc.
if ($check_args) {
my @argstrs = ( $msgid =~ m/%(\d)\$s/g );
# we now collect these translations in a hash.
# this will allow us to check below if we have translated
# anything more than one way.
- my $msgid_clean = lc($msgid);
- my $msgstr_clean = lc($msgstr);
+ my $msgid_clean = lc($msgid_trans);
+ my $msgstr_clean = mylc($msgstr);
$msgid_clean =~ s/(.*)\|.*?$/$1/; # strip menu shortcuts
$msgstr_clean =~ s/(.*)\|.*?$/$1/;
# cleaned versions of ORIGINAL strings. the keys of the inner hash
# are the cleaned versions of their TRANSLATIONS. The value for the
# inner hash is an array of the orignal string and translation.
- $trans{$msgid_clean}{$msgstr_clean} = [ $msgid, $msgstr, $linenum ];
+ $trans{$msgid_clean}{$msgstr_clean} = [ $msgid_trans, $msgstr, $linenum ];
}
if ($check_trans) {
}
print "\n";
}
+ $total_warn += $warn;
+}
+
+exit ($total_warn > 0);
+
+# Use lowercase also for non-ascii chars
+sub mylc($)
+{
+ my ($msg) = @_;
+ return(encode('utf-8',lc(decode('utf-8', $msg))));
}