blob: 8466fd9890c61cb559825c34fdce947864e62a58 (
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#!/usr/bin/perl
@ARGV == 2 || die "Usage: $0 <source-dir> <dest-dir>\n";
my $source_dir = shift @ARGV;
my $target_dir = shift @ARGV;
if( ! -d $target_dir )
{
system('mkdir', '-p', $target_dir);
}
my %target_strings;
if( open F, "find $source_dir -type f -name '*.po' |" )
{
while( chomp( my $file = readline F ) )
{
if( open L, "< $file" )
{
my $content = 0;
my ( $lang, $basename ) = $file =~ m{.+/(\w+)/([^/]+)\.po$};
$lang = lc $lang;
$lang =~ s/_/-/g;
if( open D, "> $target_dir/$basename.$lang.lua" )
{
printf "Generating %-40s ", "$target_dir/$basename.$lang.lua";
my ( $k, $v );
while( chomp( my $line = readline L ) )
{
if( $line =~ /^msgid "(.+)"/ )
{
$k = $1;
}
elsif( $k && $line =~ /^msgstr "(.*)"/ )
{
$v = $1;
}
elsif( $k && defined($v) && $line =~ /^"(.+)"/ )
{
$v .= $1;
}
else
{
if( $k && defined($v) && length($v) > 0 )
{
$v =~ s/\\(['"\\])/$1/g;
$v =~ s/(['\\])/\\$1/g;
printf D "%s='%s'\n", $k, $v;
$content++;
}
$k = $v = undef;
}
}
print $content ? "done ($content strings)\n" : "empty\n";
close D;
unlink("$target_dir/$basename.$lang.lua")
unless( $content > 0 );
}
close L;
}
}
close F;
}
|