1 |
#!/usr/bin/perl |
2 |
use strict; |
3 |
use XML::Parser; |
4 |
|
5 |
|
6 |
sub load_wpo { |
7 |
my ($tree, $tag, $page) = @_; |
8 |
|
9 |
foreach my $leaf (@$tree) { |
10 |
if (ref($leaf) eq 'ARRAY') { |
11 |
$page = load_wpo($leaf, $tag, $page); |
12 |
} elsif (ref($leaf) eq 'HASH') { |
13 |
# XML compatibility |
14 |
$leaf->{to} =~ s/\\'/\\\\'/g; |
15 |
$leaf->{to} =~ s/\\q/\\\\q/g; |
16 |
$leaf->{to} =~ s/\\a/\\\\a/g; |
17 |
$leaf->{from} =~ s/\\'/\\\\'/g; |
18 |
$leaf->{from} =~ s/\\q/\\\\q/g; |
19 |
$leaf->{from} =~ s/\\a/\\\\a/g; |
20 |
$page->{$leaf->{from}} = $leaf->{to}; |
21 |
} elsif (ref($leaf) =~ /\w\D/) { |
22 |
$tag = $leaf; |
23 |
} |
24 |
} |
25 |
$page; |
26 |
} |
27 |
|
28 |
my $xmltree = XML::Parser->new(Style => 'Tree')->parsefile($ARGV[0]); |
29 |
my $wpo = load_wpo($xmltree); |
30 |
|
31 |
my %lang = (fr => '"Language-Team: French <fr@li.org>\n" |
32 |
"MIME-Version: 1.0\n" |
33 |
"Content-Type: text/plain; charset=ISO-8859-1\n" |
34 |
"Content-Transfer-Encoding: 8bit\n"', |
35 |
en => '"Language-Team: English <en@li.org>\n" |
36 |
"MIME-Version: 1.0\n" |
37 |
"Content-Type: text/plain; charset=ISO-8859-1\n" |
38 |
"Content-Transfer-Encoding: 8bit\n"', |
39 |
it => '"Language-Team: Italian <it@li.org>\n" |
40 |
"MIME-Version: 1.0\n" |
41 |
"Content-Type: text/plain; charset=ISO-8859-1\n" |
42 |
"Content-Transfer-Encoding: 8bit\n"', |
43 |
de => => '"Language-Team: German <de@li.org>\n" |
44 |
"MIME-Version: 1.0\n" |
45 |
"Content-Type: text/plain; charset=ISO-8859-1\n" |
46 |
"Content-Transfer-Encoding: 8bit\n"', |
47 |
es => => '"Language-Team: Spanish <es@li.org>\n" |
48 |
"MIME-Version: 1.0\n" |
49 |
"Content-Type: text/plain; charset=ISO-8859-1\n" |
50 |
"Content-Transfer-Encoding: 8bit\n"'); |
51 |
|
52 |
print STDERR "$ARGV[0] =>"; |
53 |
$ARGV[0] =~ m!.*/(.*)\.(.*)\.!; |
54 |
|
55 |
my $PO; |
56 |
open($PO, "> ./po/$1_$2.po"); |
57 |
my $date = `date +%Y-%m-%d\\ %H:%M%z`; |
58 |
chomp $date; |
59 |
print $PO 'msgid "" |
60 |
msgstr "" |
61 |
"Project-Id-Version: drakwizard 0.1\n" |
62 |
"POT-Creation-Date: '.$date.'\n" |
63 |
"PO-Revision-Date: '.$date.'\n" |
64 |
"Last-Translator: Arnaud Desmons <adesmons@mandrakesoft.com>\n" |
65 |
'.$lang{$2}.' |
66 |
"X-Generator: wpo2pl 0.1\n" |
67 |
|
68 |
'; |
69 |
|
70 |
foreach (keys %$wpo) { |
71 |
if ($_ ne "") { |
72 |
if ($_ eq $wpo->{$_}) { |
73 |
print $PO qq(msgid "$_"\nmsgstr ""\n\n); |
74 |
} |
75 |
else { |
76 |
print $PO qq(msgid "$_"\nmsgstr "$wpo->{$_}"\n\n); |
77 |
} |
78 |
} |
79 |
|
80 |
} |
81 |
close $PO; |
82 |
print STDERR "./po/$1_$2.po\n"; |