1 |
#!/usr/bin/perl |
2 |
use strict; |
3 |
use XML::Parser; |
4 |
|
5 |
|
6 |
sub wrap { |
7 |
@_[0] =~ s/\\'/\\\\'/g; |
8 |
@_[0] =~ s/\\q/\\\\q/g; |
9 |
@_[0] =~ s/\\a/\\\\a/g; |
10 |
@_[0] =~ s/\\n/\\\\n/g; |
11 |
} |
12 |
|
13 |
sub load_wpo { |
14 |
my ($tree, $tag ,$page) = @_; |
15 |
|
16 |
foreach my $leaf (@$tree) { |
17 |
if (ref($leaf) eq 'ARRAY') { |
18 |
$page = load_wpo($leaf, $tag, $page); |
19 |
} elsif (ref($leaf) eq 'HASH') { |
20 |
# XML compatibility |
21 |
wrap $leaf->{description}; |
22 |
wrap $leaf->{helpText}; |
23 |
wrap $leaf->{wizardTitle}; |
24 |
wrap $leaf->{nextButtonText}; |
25 |
$page->{$leaf->{wizardTitle}} = ""; |
26 |
$page->{$leaf->{helpText}} = ""; |
27 |
$page->{$leaf->{description}} = ""; |
28 |
$page->{$leaf->{nextButtonText}} = ""; |
29 |
} elsif(ref($leaf)=~ /\w\D/){ |
30 |
$tag = $leaf; |
31 |
} |
32 |
} |
33 |
$page; |
34 |
} |
35 |
|
36 |
my $xmltree = XML::Parser->new(Style => 'Tree')->parsefile($ARGV[0]); |
37 |
my $wpo = load_wpo($xmltree); |
38 |
|
39 |
print STDERR "$ARGV[0] =>"; |
40 |
$ARGV[0] =~ /.*\/(.*)\.wiz.*/; |
41 |
|
42 |
open(PO, "> ./po/$1.pot"); |
43 |
my $date = `date +%Y-%m-%d\\ %H:%M%z`; |
44 |
chomp $date; |
45 |
|
46 |
foreach (keys %{$wpo}) { |
47 |
print "$_\n"; |
48 |
$_ ne "" and print PO "msgid \"$_\"\nmsgstr \"\"\n\n"; |
49 |
} |
50 |
close PO; |
51 |
print STDERR "./po/$1.pot\n"; |