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

Re: [D-I] Checking variables substitutions



On Sun, Jan 30, 2005 at 09:59:30PM +0100, Christian Perrier wrote:
> Denis, you could enhance the script by not checking the variable order
> of appearance. So, having:
> 
> msgid "blah blah ${VAR1} blah blah ${VAR2}"
> 
> and 
> 
> msgstr "blah blah ${VAR2} blah blah ${VAR1}"
> 
> 
> would not be reported. Such inversion often happens because of
> differences in languages syntax and this gives a lot of false
> positives in some languages.

I thought about it and already wrote this other script, but I am unsure
whether it is better to hide such swappings.  Anyway here it is.

Denis
#! /usr/bin/perl -w

use strict;

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

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

Reply to: