-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpot2xml
executable file
·33 lines (22 loc) · 883 Bytes
/
pot2xml
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
#!/usr/bin/perl
#my $regex = /msgctxt "/g;
my $num_args = $#ARGV + 1;
if($num_args != 2) {
print "Missing argument: you must specify the file to convert and the output file!\n\n";
exit;
}
my $input = $ARGV[0];
my $output = $ARGV[1];
# Read file and write to string variable
open INPUT, '<', $input or die "Can't open file $input";
my $potstring = do { local $/; <INPUT> };
close INPUT or die "Problem while closing file $pot";
open my $xml, '>', $output or die "Can't write to file $output";
print $xml "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
print $xml "<resources>\n\n";
while($potstring =~ /msgctxt "(.*)"\nmsgid "(.*)"\nmsgstr "(.*)"/g) {
#while($potstring =~ /msgctxt "(.*)"\nmsgid "(.*)"\nmsgstr "(.*)"/g) {
print $xml "\t<string name=\"$1\">$3</string>\n";
}
print $xml "\n</resources>\n";
close $xml or die "Problem closing file $pot";