-
Notifications
You must be signed in to change notification settings - Fork 0
/
po2xml.pl
executable file
·62 lines (56 loc) · 1.25 KB
/
po2xml.pl
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/perl -w
use strict;
my %idcounts;
my @comment;
my $zh;
my $en;
my $status;
my $id;
while (<>) {
chomp;
unless (m/^".*$/) {
if (m/^#\s*(.*)$/) {
push @comment, $1;
}
elsif (m/^msgid\s*\"(.+)\"$/) {
$en = $1;
}
elsif (m/^msgstr\s*\"(.+)\"$/) {
$zh = $1;
$status = 1;
}
}
if ($status) {
$en =~ s/&/and/;
$id = $en;
$id =~ tr/[A-Z ]/[a-z_]/;
$id =~ s/\W//g;
if (exists $idcounts{$id}) {
$idcounts{$id} ++;
$id = $id.$idcounts{$id};
}
else {
$idcounts{$id} = 1;
}
print " <concept id=\"$id\">\n";
if (@comment == 1) {
print " <desc>$comment[0]</desc>\n";
}
elsif (@comment > 1) {
print " <ldesc>\n";
foreach (@comment) {
print " <para>$_</para>\n";
}
print " </ldesc>\n";
}
print " <term lang=\"en\">$en</term>\n";
print " <term>$zh</term>\n";
print " </concept>\n\n";
{
$status = 0;
undef @comment;
undef $zh;
undef $en;
}
}
}