summaryrefslogtreecommitdiffstats
path: root/wiz2pot.pl
blob: 14a51b51ae89997dd057571c43c35de16e6d33ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl
use strict;
use XML::Parser;


sub load_wpo {
    my ($tree, $tag ,$page) = @_;
    
    foreach my $leaf (@$tree) {
	if (ref($leaf) eq 'ARRAY') {
	    $page = load_wpo($leaf, $tag, $page);
	} elsif (ref($leaf) eq 'HASH') {
	    # XML compatibility
	    $leaf->{helpText} =~ s/\\'/\\\\'/g;
	    $leaf->{helpText} =~ s/\\q/\\\\q/g;
	    $leaf->{helpText} =~ s/\\a/\\\\a/g;
	    $page->{$leaf->{helpText}} = "";
	}elsif(ref($leaf)=~ /\w\D/){
	    $tag = $leaf;
	}
    }
    $page;
}

my $xmltree = XML::Parser->new(Style => 'Tree')->parsefile($ARGV[0]);
my $wpo = load_wpo($xmltree);

print STDERR "$ARGV[0] =>";
$ARGV[0] =~ /.*\/(.*)\.wiz.*/;

open(PO, "> ./po/$1.pot");
my $date = `date +%Y-%m-%d\\ %H:%M\\ %z`;
chomp $date;

foreach (keys %{$wpo}) {
    if ($_ ne "") {
	if ($_ eq $wpo->{$_}) {
	    print PO "msgid \"$_\"\nmsgstr \"\"\n\n";
	}
	else {
	    print PO "msgid \"$_\"\nmsgstr \"$wpo->{$_}\"\n\n";
	}
    }
    
}
close PO;
print STDERR "./po/$1.pot\n";