nathan@11
|
1 |
#!/usr/bin/perl
|
nathan@11
|
2 |
#
|
nathan@11
|
3 |
# po2i18n - Convert plugin po files in into i18n.c-format
|
nathan@11
|
4 |
#
|
nathan@11
|
5 |
# See the README file for copyright information and how to reach the author.
|
nathan@11
|
6 |
#
|
nathan@11
|
7 |
|
nathan@11
|
8 |
use strict;
|
nathan@11
|
9 |
use warnings;
|
nathan@11
|
10 |
|
nathan@11
|
11 |
my @LANGS = (
|
nathan@11
|
12 |
"en_US",
|
nathan@11
|
13 |
"de_DE",
|
nathan@11
|
14 |
"sl_SI",
|
nathan@11
|
15 |
"it_IT",
|
nathan@11
|
16 |
"nl_NL",
|
nathan@11
|
17 |
"pt_PT",
|
nathan@11
|
18 |
"fr_FR",
|
nathan@11
|
19 |
"nn_NO",
|
nathan@11
|
20 |
"fi_FI",
|
nathan@11
|
21 |
"pl_PL",
|
nathan@11
|
22 |
"es_ES",
|
nathan@11
|
23 |
"el_GR",
|
nathan@11
|
24 |
"sv_SE",
|
nathan@11
|
25 |
"ro_RO",
|
nathan@11
|
26 |
"hu_HU",
|
nathan@11
|
27 |
"ca_ES",
|
nathan@11
|
28 |
"ru_RU",
|
nathan@11
|
29 |
"hr_HR",
|
nathan@11
|
30 |
"et_EE",
|
nathan@11
|
31 |
"da_DK",
|
nathan@11
|
32 |
"cs_CZ",
|
nathan@11
|
33 |
"tr_TR"
|
nathan@11
|
34 |
);
|
nathan@11
|
35 |
|
nathan@11
|
36 |
my %VERS = (
|
nathan@11
|
37 |
"en_US" => 10200,
|
nathan@11
|
38 |
"de_DE" => 10200,
|
nathan@11
|
39 |
"sl_SI" => 10200,
|
nathan@11
|
40 |
"it_IT" => 10200,
|
nathan@11
|
41 |
"nl_NL" => 10200,
|
nathan@11
|
42 |
"pt_PT" => 10200,
|
nathan@11
|
43 |
"fr_FR" => 10200,
|
nathan@11
|
44 |
"nn_NO" => 10200,
|
nathan@11
|
45 |
"fi_FI" => 10200,
|
nathan@11
|
46 |
"pl_PL" => 10200,
|
nathan@11
|
47 |
"es_ES" => 10200,
|
nathan@11
|
48 |
"el_GR" => 10200,
|
nathan@11
|
49 |
"sv_SE" => 10200,
|
nathan@11
|
50 |
"ro_RO" => 10200,
|
nathan@11
|
51 |
"hu_HU" => 10200,
|
nathan@11
|
52 |
"ca_ES" => 10200,
|
nathan@11
|
53 |
"ru_RU" => 10302,
|
nathan@11
|
54 |
"hr_HR" => 10307,
|
nathan@11
|
55 |
"et_EE" => 10313,
|
nathan@11
|
56 |
"da_DK" => 10316,
|
nathan@11
|
57 |
"cs_CZ" => 10342,
|
nathan@11
|
58 |
"tr_TR" => 10502
|
nathan@11
|
59 |
);
|
nathan@11
|
60 |
|
nathan@11
|
61 |
|
nathan@11
|
62 |
my %strings;
|
nathan@11
|
63 |
|
nathan@11
|
64 |
foreach my $lang (@LANGS) { $strings{$lang} = { }; }
|
nathan@11
|
65 |
|
nathan@11
|
66 |
|
nathan@11
|
67 |
sub LoadLanguage(*) {
|
nathan@11
|
68 |
my ($lang) = @_;
|
nathan@11
|
69 |
|
nathan@11
|
70 |
if (!open FILE, "<", "po/$lang.po") {
|
nathan@11
|
71 |
return 0;
|
nathan@11
|
72 |
}
|
nathan@11
|
73 |
|
nathan@11
|
74 |
my $msgid = "";
|
nathan@11
|
75 |
my $msgstr = "";
|
nathan@11
|
76 |
my $last = 0; # 0=init, 1=msgid was last, 2=msgstr was last
|
nathan@11
|
77 |
|
nathan@11
|
78 |
while (<FILE>) {
|
nathan@11
|
79 |
chomp;
|
nathan@11
|
80 |
my $line = $_;
|
nathan@11
|
81 |
|
nathan@11
|
82 |
if ($line =~ /^msgid "(.*)"$/) {
|
nathan@11
|
83 |
if ($last eq 2) {
|
nathan@11
|
84 |
$strings{$lang}->{$msgid} = $msgstr;
|
nathan@11
|
85 |
$strings{"en_US"}->{$msgid} = $msgid;
|
nathan@11
|
86 |
}
|
nathan@11
|
87 |
$msgid = $1;
|
nathan@11
|
88 |
$last = 1;
|
nathan@11
|
89 |
} elsif ($line =~ /^msgstr "(.*)"/) {
|
nathan@11
|
90 |
$msgstr = $1;
|
nathan@11
|
91 |
$last = 2;
|
nathan@11
|
92 |
} elsif ($line =~ /^"(.*)"/) {
|
nathan@11
|
93 |
if ($last eq 1) {
|
nathan@11
|
94 |
$msgid = $msgid . $1;
|
nathan@11
|
95 |
} elsif ($last eq 2) {
|
nathan@11
|
96 |
$msgstr = $msgstr . $1;
|
nathan@11
|
97 |
}
|
nathan@11
|
98 |
}
|
nathan@11
|
99 |
}
|
nathan@11
|
100 |
if ($last eq 2) {
|
nathan@11
|
101 |
$strings{$lang}->{$msgid} = $msgstr;
|
nathan@11
|
102 |
$strings{"en_US"}->{$msgid} = $msgid;
|
nathan@11
|
103 |
}
|
nathan@11
|
104 |
|
nathan@11
|
105 |
close FILE;
|
nathan@11
|
106 |
}
|
nathan@11
|
107 |
|
nathan@11
|
108 |
|
nathan@11
|
109 |
|
nathan@11
|
110 |
foreach my $lang (@LANGS) {
|
nathan@11
|
111 |
LoadLanguage($lang);
|
nathan@11
|
112 |
}
|
nathan@11
|
113 |
|
nathan@11
|
114 |
my @msgids = sort keys %{$strings{"en_US"}};
|
nathan@11
|
115 |
|
nathan@11
|
116 |
|
nathan@11
|
117 |
my $silent = 0;
|
nathan@11
|
118 |
|
nathan@11
|
119 |
while (<>) {
|
nathan@11
|
120 |
my $line = $_;
|
nathan@11
|
121 |
|
nathan@11
|
122 |
if ($line =~ /^\/\/ START I18N/) {
|
nathan@11
|
123 |
print "// START I18N - automatically generated by po2i18n.pl\n";
|
nathan@11
|
124 |
for my $msgid (@msgids) {
|
nathan@11
|
125 |
next if $msgid eq "";
|
nathan@11
|
126 |
|
nathan@11
|
127 |
my $head = " { ";
|
nathan@11
|
128 |
my $endif = "";
|
nathan@11
|
129 |
my $versnum = 10200;
|
nathan@11
|
130 |
|
nathan@11
|
131 |
for my $lang (@LANGS) {
|
nathan@11
|
132 |
if ($VERS{$lang} ne $versnum) {
|
nathan@11
|
133 |
$versnum = $VERS{$lang};
|
nathan@11
|
134 |
print $endif;
|
nathan@11
|
135 |
print "#if VDRVERSNUM >= $versnum\n";
|
nathan@11
|
136 |
$endif = "#endif\n";
|
nathan@11
|
137 |
}
|
nathan@11
|
138 |
my $msgstr = $strings{$lang}->{$msgid};
|
nathan@11
|
139 |
$msgstr = "" if !defined $msgstr;
|
nathan@11
|
140 |
|
nathan@11
|
141 |
print "$head\"$msgstr\",\n";
|
nathan@11
|
142 |
$head = " ";
|
nathan@11
|
143 |
}
|
nathan@11
|
144 |
print $endif;
|
nathan@11
|
145 |
print " },\n";
|
nathan@11
|
146 |
}
|
nathan@11
|
147 |
$silent = 1;
|
nathan@11
|
148 |
}
|
nathan@11
|
149 |
|
nathan@11
|
150 |
if (!$silent) { print $line; }
|
nathan@11
|
151 |
|
nathan@11
|
152 |
if ($line =~ /^\/\/ END I18N/) {
|
nathan@11
|
153 |
print "// END I18N - automatically generated by po2i18n.pl\n";
|
nathan@11
|
154 |
$silent = 0;
|
nathan@11
|
155 |
}
|
nathan@11
|
156 |
}
|