5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
8 # author: Michael Gerz, michael.gerz@teststep.org
10 # This script performs some consistency checks on po files:
12 # 1. Uniform translation of messages that are identical except
13 # for capitalization, shortcuts, and shortcut notation.
14 # 2. Usage of the following elements in both the original and
15 # the translated message (or no usage at all):
16 # shortcuts ("&" and "|..."), trailing space, trailing colon
19 # pocheck.pl po_file po_file ...
21 foreach $pofilename ( @ARGV )
23 print "Processing po file '$pofilename'...\n";
25 open( INPUT, "<$pofilename" )
26 || die "Cannot read po file '$pofilename'";
31 keys( %trans ) = 10000;
33 $noOfLines = $#pofile;
38 while ($i <= $noOfLines) {
39 ( $msgid ) = ( $pofile[$i] =~ m/^msgid "(.*)"/ );
43 # some msgid's are more than one line long, so add those.
44 while ( ( $more ) = $pofile[$i] =~ m/^"(.*)"/ ) {
45 $msgid = $msgid . $more;
49 # now look for the associated msgstr.
50 until ( ( $msgstr ) = ( $pofile[$i] =~ m/^msgstr "(.*)"/ ) ) { $i++; };
52 # again collect any extra lines.
53 while ( ( $i <= $noOfLines ) &&
54 ( ( $more ) = $pofile[$i] =~ m/^"(.*)"/ ) ) {
55 $msgstr = $msgstr . $more;
59 # nothing to do if one of them is empty.
60 # (surely that is always $msgstr?)
61 next if ($msgid eq "" or $msgstr eq "");
63 # Check colon at the end of a message
64 if ( ( $msgid =~ m/: *(\|.*)?$/ ) != ( $msgstr =~ m/: *(\|.*)?$/ ) ) {
65 print( "Missing or unexpected colon:\n" );
66 print( " '$msgid' => '$msgstr'\n" );
70 # Check period at the end of a message; uncomment code if you are paranoid
71 #if ( ( $msgid =~ m/\. *(\|.*)?$/ ) != ( $msgstr =~ m/\. *(\|.*)?$/ ) ) {
72 # print( "Missing or unexpected period:\n" );
73 # print( " '$msgid' => '$msgstr'\n" );
77 # Check space at the end of a message
78 if ( ( $msgid =~ m/ *?(\|.*)?$/ ) != ( $msgstr =~ m/ *?(\|.*)?$/ ) ) {
79 print( "Missing or unexpected space:\n" );
80 print( " '$msgid' => '$msgstr'\n" );
84 # Check for "&" shortcuts
85 if ( ( $msgid =~ m/&[^ ]/ ) != ( $msgstr =~ m/&[^ ]/ ) ) {
86 print( "Missing or unexpected Qt shortcut:\n" );
87 print( " '$msgid' => '$msgstr'\n" );
91 # Check for "|..." shortcuts
92 if ( ( $msgid =~ m/\|[^ ]/ ) != ( $msgstr =~ m/\|[^ ]/ ) ) {
93 print( "Missing or unexpected menu shortcut:\n" );
94 print( " '$msgid' => '$msgstr'\n" );
98 # we now collect these translations in a hash.
99 # this will allow us to check below if we have translated
100 # anything more than one way.
101 $msgid_clean = lc($msgid);
102 $msgstr_clean = lc($msgstr);
104 $msgid_clean =~ s/(.*)\|.*?$/$1/; # strip menu shortcuts
105 $msgstr_clean =~ s/(.*)\|.*?$/$1/;
106 $msgid_clean =~ s/&([^ ])/$1/; # strip Qt shortcuts
107 $msgstr_clean =~ s/&([^ ])/$1/;
109 # this is a hash of hashes. the keys of the outer hash are
110 # cleaned versions of ORIGINAL strings. the keys of the inner hash
111 # are the cleaned versions of their TRANSLATIONS. The value for the
112 # inner hash is an array of the orignal string and translation.
113 $trans{$msgid_clean}{$msgstr_clean} = [ $msgid, $msgstr ];
116 foreach $msgid ( keys %trans ) {
117 # so $ref is a reference to the inner hash.
118 $ref = $trans{$msgid};
119 # @msgstrkeys is an array of the keys of that inner hash.
120 @msgstrkeys = keys %$ref;
122 # do we have more than one such key?
123 if ( $#msgstrkeys > 0 ) {
124 print( "Different translations for '$msgid':\n" );
125 foreach $msgstr ( @msgstrkeys ) {
126 print( " '" . $trans{$msgid}{$msgstr}[0] . "' => '" . $trans{$msgid}{$msgstr}[1] . "'\n" );
132 print( "\nTotal number of warnings: $warn\n\n" );