]>
pere.pagekite.me Git - homepage.git/blob - linux/check_po_consistency
3 # Author: Petter Reinholdtsen <pere@td.org.uit.no>
5 # Source: http://www.student.uit.no/~pere/linux/
7 # Check .po files for consistency. Write two files msg-all and
10 # Usage: $0 <po-files>
17 my ($pofile, %translation, @problem, %msgstrs, %files);
21 for $pofile ( @ARGV ) {
22 open(POFILE
, "<$pofile") || next;
24 my ($next, $msgid, $msgstr);
27 $_ = $next || <POFILE
>;
33 s/^\#.+$//; # Remove comments
37 if (/^msgid (\".+)/) {
53 if (/^msgstr (\".+)/) {
65 add_translation
($pofile, $msgid, $msgstr);
76 my ($pofile, $msgid, $msgstr) = @_;
77 # print " Translation: $msgid = $msgstr\n";
79 $msgstrs{"$msgid\t$msgstr"}++;
80 $files{"$msgid\t$msgstr"} = $pofile;
81 if ( !defined($translation{$msgid}) ) {
82 push(@{$translation{$msgid}}, $msgstr);
84 if ( ! in_array
($msgstr, $translation{$msgid}) ) {
85 push(@{$translation{$msgid}}, $msgstr);
86 push(@problem, $msgid) unless grep($msgid, @problem);
93 my ($str, $aref) = @_;
96 return 1 if ($test eq $str);
102 my ($fp, $msgid) = @_;
103 print $fp "\nmsgid $msgid\n";
105 for $msgstr (sort @{$translation{$msgid}}) {
106 print $fp "msgstr $msgstr # (" . $msgstrs{"$msgid\t$msgstr"}. ") " or die;
107 print $fp "[" . $files{"$msgid\t$msgstr"} . "]" or die if $showfile;
108 print $fp "\n" or die;
114 # Remove leading space and '&' before comparing
121 return lc($aa) cmp lc($bb);
126 my ($count, $icount) = (0,0);
128 open (ALL
, ">msg-all");
129 print "Creating msg-all\n";
131 open (INCONS
, ">msg-inconsistent");
132 print "Creating msg-inconsistent\n";
133 for $msgid (sort kde_magic_sort
keys %translation ) {
135 output_transl
(ALL
, $msgid);
138 if ( 1 < scalar(@{$translation{$msgid}}) ) {
140 output_transl
(INCONS
, $msgid);
143 print ALL
"\n#Total # of messages: $count\n" if ($opt_a);
144 print INCONS
"\n#Total inconsistent: $icount of $count (",
145 int(100*$icount/$count), "%)\n";
148 close(ALL
) if ($opt_a);