Changeset 39d2fc7 in git


Ignore:
Timestamp:
15/02/15 23:47:52 (5 years ago)
Author:
Olly Betts <olly@…>
Branches:
line_contents, master, stereo, travis-osx
Children:
a786810
Parents:
42607d0
Message:

lib/po-to-msg.pl: Report file and line number for warnings.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r42607d0 r39d2fc7  
     1Sun Feb 15 23:47:35 GMT 2015  Olly Betts <olly@survex.com>
     2
     3        * lib/po-to-msg.pl: Report file and line number for warnings.
     4
    15Sun Feb 15 23:46:12 GMT 2015  Olly Betts <olly@survex.com>
    26
  • lib/po-to-msg.pl

    r42607d0 r39d2fc7  
    3434# my %uses = ();
    3535
     36my $file;
     37
    3638my %n = ();
    37 my $num_list = Locale::PO->load_file_asarray("$srcdir/survex.pot");
     39my %loc = ();
     40$file = "$srcdir/survex.pot";
     41my $num_list = Locale::PO->load_file_asarray($file);
    3842foreach my $po_entry (@{$num_list}) {
    3943    my $ref = $po_entry->reference;
     
    4246    my $key = $po_entry->msgid;
    4347    my $msg = c_unescape($po_entry->dequote($key));
     48    my $where = $file . ":" . $po_entry->loaded_line_number;
     49    ${$loc{'en'}}[$msgno] = $where;
    4450    if (${$msgs{'en'}}[$msgno]) {
    45         print STDERR "Warning: already had message $msgno for language 'en'\n";
     51        print STDERR "$where: warning: already had message $msgno for language 'en'\n";
    4652    }
    4753    ${$msgs{'en'}}[$msgno] = $msg;
     
    5157for (sort { $a <=> $b } keys %n) {
    5258    if ($_ > $last + 1) {
    53         print STDERR "Unused msg numbers: ", join(" ", $last + 1 .. $_ - 1), "\n";
     59        print STDERR "$file: Unused msg numbers: ", join(" ", $last + 1 .. $_ - 1), "\n";
    5460    }
    5561    $last = $_;
    5662}
    57 print STDERR "Last used msg number: $last\n";
     63print STDERR "$file: Last used msg number: $last\n";
    5864%n = ();
    5965
     
    6268    $language =~ s/\.po$//;
    6369
    64     my $po_hash = Locale::PO->load_file_ashash("$srcdir/$po_file");
     70    $file = "$srcdir/$po_file";
     71    my $po_hash = Locale::PO->load_file_ashash($file);
    6572
    6673    foreach my $po_entry (@{$num_list}) {
     
    7077        my $key = $po_entry->msgid;
    7178        my $ent = $$po_hash{$key};
     79        my $where = $file . ":" . $po_entry->loaded_line_number;
     80        ${$loc{$language}}[$msgno] = $where;
    7281        if (defined $ent) {
    7382            my $msg = c_unescape($po_entry->dequote($ent->msgstr));
    7483            next if $msg eq '';
    7584            if (${$msgs{$language}}[$msgno]) {
    76                 print STDERR "Warning: already had message $msgno for language $language\n";
     85                print STDERR "$where: warning: already had message $msgno for language $language\n";
    7786            }
    7887            ${$msgs{$language}}[$msgno] = $msg;
     
    92101foreach $lang (@langs) {
    93102   my $fnm = $lang;
     103   $file = "$srcdir/$lang.po";
    94104   $fnm =~ s/(_.*)$/\U$1/;
    95105   open OUT, ">$fnm.msg" or die $!;
     
    126136      } else {
    127137         if ($lang ne 'en') {
    128              sanity_check("Message $n in language $lang", $msg, ${$msgs{'en'}}[$n]);
     138             sanity_check("Message $n in language $lang", $msg, ${$msgs{'en'}}[$n], ${$loc{$lang}}[$n]);
    129139         }
    130140      }
     
    138148       print STDERR "Warning: ";
    139149       if ($missing) {
    140            print STDERR "$lang: $missing missing message(s)";
     150           print STDERR "$file: $missing missing message(s)";
    141151           if ($retranslate) {
    142152               print STDERR " and $retranslate requiring retranslation";
    143153           }
    144154       } else {
    145            print STDERR "$lang: $retranslate message(s) requiring retranslation";
    146        }
    147        print STDERR "\n";
     155           print STDERR "$file: $retranslate message(s) requiring retranslation";
     156       }
     157       print STDERR " for $lang\n";
    148158   }
    149159}
    150160
    151161sub sanity_check {
    152    my ($where, $msg, $orig) = @_;
     162   my ($what, $msg, $orig, $where) = @_;
    153163   # FIXME: Only do this if the message has the "c-format" flag.
    154164   # check printf-like specifiers match
     
    159169   while (scalar @pcent_m || scalar @pcent_o) {
    160170       if (!scalar @pcent_m) {
    161            print STDERR "Warning: $where misses out \%spec $pcent_o[0]\n";
     171           print STDERR "$where: warning: $what misses out \%spec $pcent_o[0]\n";
    162172       } elsif (!scalar @pcent_o) {
    163            print STDERR "Warning: $where has extra \%spec $pcent_m[0]\n";
     173           print STDERR "$where: warning: $what has extra \%spec $pcent_m[0]\n";
    164174       } elsif ($pcent_m[0] ne $pcent_o[0]) {
    165            print STDERR "Warning: $where has \%spec $pcent_m[0] instead of $pcent_o[0]\n";
     175           print STDERR "$where: warning: $what has \%spec $pcent_m[0] instead of $pcent_o[0]\n";
    166176       }
    167177       pop @pcent_m;
     
    171181   # Check for missing (or added) ellipses (...)
    172182   if ($msg =~ /\.\.\./ && $orig !~ /\.\.\./) {
    173        print STDERR "Warning: $where has ellipses but original doesn't\n";
     183       print STDERR "$where: warning: $what has ellipses but original doesn't\n";
    174184   } elsif ($msg !~ /\.\.\./ && $orig =~ /\.\.\./) {
    175        print STDERR "Warning: $where is missing ellipses\n";
     185       print STDERR "$where: warning: $what is missing ellipses\n";
    176186   }
    177187
    178188   # Check for missing (or added) menu shortcut (&)
    179189   if ($msg =~ /\&[A-Za-z\xc2-\xf4]/ && $orig !~ /\&[A-Za-z]/) {
    180        print STDERR "Warning: $where has menu shortcut but original doesn't\n";
     190       print STDERR "$where: warning: $what has menu shortcut but original doesn't\n";
    181191   } elsif ($msg !~ /\&[A-Za-z\xc2-\xf4]/ && $orig =~ /\&[A-Za-z]/) {
    182        print STDERR "Warning: $where is missing menu shortcut\n";
     192       print STDERR "$where: warning: $what is missing menu shortcut\n";
    183193   }
    184194
    185195   # Check for missing (or added) double quotes (“ and ”)
    186196   if (scalar($msg =~ s/(?:“|»)/$&/g) != scalar($orig =~ s/“/$&/g)) {
    187        print STDERR "Warning: $where has different numbers of “\n";
     197       print STDERR "$where: warning: $what has different numbers of “\n";
    188198       print STDERR "$orig\n$msg\n\n";
    189199   }
    190200   if (scalar($msg =~ s/(?:”|«)/$&/g) != scalar($orig =~ s/”/$&/g)) {
    191        print STDERR "Warning: $where has different numbers of ”\n";
     201       print STDERR "$where: warning: $what has different numbers of ”\n";
    192202       print STDERR "$orig\n$msg\n\n";
    193203   }
     
    195205   # Check for missing (or added) menu accelerator "##"
    196206   if ($msg =~ /\#\#/ && $orig !~ /\#\#/) {
    197        print STDERR "Warning: $where has menu accelerator but original doesn't\n";
     207       print STDERR "$where: warning: $what has menu accelerator but original doesn't\n";
    198208   } elsif ($msg !~ /\#\#/ && $orig =~ /\#\#/) {
    199        print STDERR "Warning: $where is missing menu accelerator\n";
     209       print STDERR "$where: warning: $what is missing menu accelerator\n";
    200210   } elsif ($orig =~ /\#\#(.*)/) {
    201211       my $acc_o = $1;
    202212       my ($acc_m) = $msg =~ /\#\#(.*)/;
    203213       if ($acc_o ne $acc_m) {
    204            print STDERR "Warning: $where has menu accelerator $acc_m instead of $acc_o\n";
     214           print STDERR "$where: warning: $what has menu accelerator $acc_m instead of $acc_o\n";
    205215       }
    206216   }
     
    208218   # Check for missing (or added) menu accelerator "\t"
    209219   if ($msg =~ /\t/ && $orig !~ /\t/) {
    210        print STDERR "Warning: $where has menu accelerator but original doesn't\n";
     220       print STDERR "$where: warning: $what has menu accelerator but original doesn't\n";
    211221   } elsif ($msg !~ /\t/ && $orig =~ /\t/) {
    212        print STDERR "Warning: $where is missing menu accelerator\n";
     222       print STDERR "$where: warning: $what is missing menu accelerator\n";
    213223   } elsif ($orig =~ /\t(.*)/) {
    214224       my $acc_o = $1;
    215225       my ($acc_m) = $msg =~ /\t(.*)/;
    216226       if ($acc_o ne $acc_m) {
    217            print STDERR "Warning: $where has menu accelerator $acc_m instead of $acc_o\n";
     227           print STDERR "$where: warning: $what has menu accelerator $acc_m instead of $acc_o\n";
    218228       }
    219229   }
Note: See TracChangeset for help on using the changeset viewer.