]> git.lyx.org Git - lyx.git/blobdiff - po/pocheck.pl
Update ru.po
[lyx.git] / po / pocheck.pl
index 33f0e94a22ca0b3e3fed099be4f9c20e312573e9..1cd3a8c94e6e1a5f5790c5c1e734189526515b45 100755 (executable)
@@ -1,4 +1,5 @@
 #! /usr/bin/perl -w
+# -*- mode: perl; -*-
 
 # file pocheck.pl
 #
@@ -26,12 +27,14 @@ options is given, in which case we checks only for those requested.
 -q: Check Qt shortcuts
 -s: Check for space at end
 -t: Check for uniform translation
-This option can be given with or without other options.
+These options can be given with or without other options.
+-f: Ignore fuzzy translations
 -w: Only report summary total of errors
+-i: Silent mode, report only errors
 EOT
 
 my %options;
-getopts(":hacmpqstw", \%options);
+getopts(":hacfmpqstwi", \%options);
 
 if (defined($options{h})) { 
   print $usage; 
@@ -40,20 +43,28 @@ if (defined($options{h})) {
 
 my $only_total = defined($options{w});
 delete $options{w} if $only_total;
+my $ignore_fuzzy = defined($options{f});
+delete $options{f} if $ignore_fuzzy;
+my $silent_mode = defined($options{i});
+delete $options{i} if $silent_mode;
 
 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;
-  print "Processing po file '$pofilename'...\n";
+  if (!$silent_mode) {
+    print "Processing po file '$pofilename'...\n";
+  }
 
   open( INPUT, "<$pofilename" )
     || die "Cannot read po file '$pofilename'";
@@ -75,6 +86,10 @@ foreach my $pofilename ( @ARGV ) {
     ( $msgid ) = ( $pofile[$i] =~ m/^msgid "(.*)"/ );
     $i++;
     next unless $msgid;
+    if ($ignore_fuzzy) {
+      my $previous = $pofile[$i - 2];
+      next if $previous =~ m/#,.*fuzzy/;
+    }
     
     # some msgid's are more than one line long, so add those.
     while ( ( $more ) = $pofile[$i] =~ m/^"(.*)"/ ) {
@@ -96,6 +111,9 @@ foreach my $pofilename ( @ARGV ) {
     # (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 =~ s/\[\[.*\]\]$//;
+
     # Check for matching %1$s, etc.
       if ($check_args) {
       my @argstrs = ( $msgid =~ m/%(\d)\$s/g );
@@ -103,7 +121,7 @@ foreach my $pofilename ( @ARGV ) {
         my $n = 0;
         foreach my $arg (@argstrs) { $n = $arg if $arg > $n; }
         if ($n <= 0) { 
-          print "Line $linenum: Problem finding arguments in:\n    $msgid!\n"
+          print "$pofilename, line $linenum: Problem finding arguments in:\n    $msgid!\n"
             unless $only_total;
           ++$bad{"Missing arguments"};
           $warn++;
@@ -111,7 +129,7 @@ foreach my $pofilename ( @ARGV ) {
           foreach my $i (1..$n) {
             my $arg = "%$i\\\$s"; 
             if ( $msgstr !~ m/$arg/ ) {
-              print "Line $linenum: Missing argument `$arg'\n  '$msgid' ==> '$msgstr'\n"
+              print "$pofilename, line $linenum: Missing argument `$arg'\n  '$msgid' ==> '$msgstr'\n"
                 unless $only_total;
               ++$bad{"Missing arguments"};
               $warn++;
@@ -213,14 +231,19 @@ foreach my $pofilename ( @ARGV ) {
       }
     }
   }
-
-  if ($warn) {
-    while (my ($k, $v) = each %bad) { print "$k: $v\n"; }
-    if (scalar(keys %bad) > 1) {
-      print "Total warnings: $warn\n";
+  if (!$silent_mode) {
+    if ($warn) {
+      while (my ($k, $v) = each %bad) { print "$k: $v\n"; }
+      if (scalar(keys %bad) > 1) {
+        print "Total warnings: $warn\n";
+      }
+    } else {
+      print "No warnings!\n";
     }
-  } else {
-    print "No warnings!\n";
+    print "\n";
   }
-  print "\n";
+  $total_warn += $warn;
 }
+
+exit ($total_warn > 0);
+