tufte layout files:
[lyx.git] / po / pocheck.pl
blob69bc405b2b947b1c1b9a59f5a850cebdee2b8d97
1 #! /usr/bin/perl -w
3 # file pocheck.pl
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
18 # Invocation:
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'";
27 @pofile = <INPUT>;
28 close( INPUT );
30 undef( %trans );
31 keys( %trans ) = 10000;
33 $noOfLines = $#pofile;
35 $warn = 0;
37 $i = 0;
38 while ($i <= $noOfLines) {
39 if ( ( $msgid ) = ( $pofile[$i] =~ m/^msgid "(.*)"/ ) ) {
40 $i++;
41 while ( ( $more ) = $pofile[$i] =~ m/^"(.*)"/ ) {
42 $msgid = $msgid . $more;
43 $i++;
46 until ( ( $msgstr ) = ( $pofile[$i] =~ m/^msgstr "(.*)"/ ) ) { $i++; };
47 $i++;
48 while ( ( $i <= $noOfLines ) &&
49 ( ( $more ) = $pofile[$i] =~ m/^"(.*)"/ ) ) {
50 $msgstr = $msgstr . $more;
51 $i++;
54 if ( $msgid ne "" && $msgstr ne "" ) {
56 # Check colon at the end of a message
57 if ( ( $msgid =~ m/: *(\|.*)?$/ ) != ( $msgstr =~ m/: *(\|.*)?$/ ) ) {
58 print( "Missing or unexpected colon:\n" );
59 print( " '$msgid' => '$msgstr'\n" );
60 $warn++;
63 # Check period at the end of a message; uncomment code if you are paranoid
64 #if ( ( $msgid =~ m/\. *(\|.*)?$/ ) != ( $msgstr =~ m/\. *(\|.*)?$/ ) ) {
65 # print( "Missing or unexpected period:\n" );
66 # print( " '$msgid' => '$msgstr'\n" );
67 # $warn++;
70 # Check space at the end of a message
71 if ( ( $msgid =~ m/ *?(\|.*)?$/ ) != ( $msgstr =~ m/ *?(\|.*)?$/ ) ) {
72 print( "Missing or unexpected space:\n" );
73 print( " '$msgid' => '$msgstr'\n" );
74 $warn++;
77 # Check for "&" shortcuts
78 if ( ( $msgid =~ m/&[^ ]/ ) != ( $msgstr =~ m/&[^ ]/ ) ) {
79 print( "Missing or unexpected Qt shortcut:\n" );
80 print( " '$msgid' => '$msgstr'\n" );
81 $warn++;
84 # Check for "|..." shortcuts
85 if ( ( $msgid =~ m/\|[^ ]/ ) != ( $msgstr =~ m/\|[^ ]/ ) ) {
86 print( "Missing or unexpected menu shortcut:\n" );
87 print( " '$msgid' => '$msgstr'\n" );
88 $warn++;
91 $msgid_clean = lc($msgid);
92 $msgstr_clean = lc($msgstr);
94 $msgid_clean =~ s/(.*)\|.*?$/$1/; # strip menu shortcuts
95 $msgstr_clean =~ s/(.*)\|.*?$/$1/;
96 $msgid_clean =~ s/&([^ ])/$1/; # strip Qt shortcuts
97 $msgstr_clean =~ s/&([^ ])/$1/;
99 $trans{$msgid_clean}{$msgstr_clean} = [ $msgid, $msgstr ];
101 } else {
102 $i++;
106 foreach $msgid ( keys %trans ) {
107 $ref = $trans{$msgid};
108 @msgstrkeys = keys %$ref;
110 if ( $#msgstrkeys > 0 ) {
111 print( "Different translations for '$msgid':\n" );
112 foreach $msgstr ( @msgstrkeys ) {
113 print( " '" . $trans{$msgid}{$msgstr}[0] . "' => '" . $trans{$msgid}{$msgstr}[1] . "'\n" );
115 $warn++;
119 print( "\nTotal number of warnings: $warn\n\n" );