[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [D-I] Checking variables substitutions (was: Re: d-i Welsh test notes)



On Sat, Jan 29, 2005 at 08:15:30AM +0100, Christian Perrier wrote:
> Quoting Dafydd Harries (daf@muse.19inch.net):
> > Ar 26/11/2004 am 06:50, ysgrifennodd Dafydd Harries:
> > >    - "yn rhaniad #" -- I saw this and expected a number after the #. I
> > >      should check this.
> > 
> > I found this was because of a typo in a substitution. I'd typed
> > "#${PARITION}" instead of "#${PARTITION}". Perhaps we could write a
> > script that checks that all the substitution patterns in the msgid are
> > also present in the msgstr.
> 
> Yes, this was mentioned some day, IIRC.
> 
> If some script wizard is ready, please go ahead, folks !

Here is one.  It reports 2 false positives on fr.po and one real error
(my SVN copy is 1 month old).  It looks like almost all languages
contain such errors :(

Denis
#! /usr/bin/perl

sub getVars
{
        my $text = shift;
        my $var = '';
        while ($text =~ m/\G.*?(\$\{[^{}]+\})/g) {
                $var .= $1;
        }
        return $var;
}

$/ = "\n\n";
open (PO, "< $ARGV[0]") or die "Unable to open $ARGV[0]: $!\n";
while (<PO>)
{
        s/"\n"//g;
        (my $msgid) = m/^msgid "(.*)"$/m;
        (my $msgstr) = m/^msgstr "(.*)"$/m;
        next if $msgstr eq '' || m/^#, .*fuzzy/m;
        my $var1 = getVars($msgid);
        my $var2 = getVars($msgstr);
        print if $var1 ne $var2;
}
close (PO);

Reply to: