nathan@11: #!/usr/bin/perl nathan@11: # nathan@11: # po2i18n - Convert plugin po files in into i18n.c-format nathan@11: # nathan@11: # See the README file for copyright information and how to reach the author. nathan@11: # nathan@11: nathan@11: use strict; nathan@11: use warnings; nathan@11: nathan@11: my @LANGS = ( nathan@11: "en_US", nathan@11: "de_DE", nathan@11: "sl_SI", nathan@11: "it_IT", nathan@11: "nl_NL", nathan@11: "pt_PT", nathan@11: "fr_FR", nathan@11: "nn_NO", nathan@11: "fi_FI", nathan@11: "pl_PL", nathan@11: "es_ES", nathan@11: "el_GR", nathan@11: "sv_SE", nathan@11: "ro_RO", nathan@11: "hu_HU", nathan@11: "ca_ES", nathan@11: "ru_RU", nathan@11: "hr_HR", nathan@11: "et_EE", nathan@11: "da_DK", nathan@11: "cs_CZ", nathan@11: "tr_TR" nathan@11: ); nathan@11: nathan@11: my %VERS = ( nathan@11: "en_US" => 10200, nathan@11: "de_DE" => 10200, nathan@11: "sl_SI" => 10200, nathan@11: "it_IT" => 10200, nathan@11: "nl_NL" => 10200, nathan@11: "pt_PT" => 10200, nathan@11: "fr_FR" => 10200, nathan@11: "nn_NO" => 10200, nathan@11: "fi_FI" => 10200, nathan@11: "pl_PL" => 10200, nathan@11: "es_ES" => 10200, nathan@11: "el_GR" => 10200, nathan@11: "sv_SE" => 10200, nathan@11: "ro_RO" => 10200, nathan@11: "hu_HU" => 10200, nathan@11: "ca_ES" => 10200, nathan@11: "ru_RU" => 10302, nathan@11: "hr_HR" => 10307, nathan@11: "et_EE" => 10313, nathan@11: "da_DK" => 10316, nathan@11: "cs_CZ" => 10342, nathan@11: "tr_TR" => 10502 nathan@11: ); nathan@11: nathan@11: nathan@11: my %strings; nathan@11: nathan@11: foreach my $lang (@LANGS) { $strings{$lang} = { }; } nathan@11: nathan@11: nathan@11: sub LoadLanguage(*) { nathan@11: my ($lang) = @_; nathan@11: nathan@11: if (!open FILE, "<", "po/$lang.po") { nathan@11: return 0; nathan@11: } nathan@11: nathan@11: my $msgid = ""; nathan@11: my $msgstr = ""; nathan@11: my $last = 0; # 0=init, 1=msgid was last, 2=msgstr was last nathan@11: nathan@11: while () { nathan@11: chomp; nathan@11: my $line = $_; nathan@11: nathan@11: if ($line =~ /^msgid "(.*)"$/) { nathan@11: if ($last eq 2) { nathan@11: $strings{$lang}->{$msgid} = $msgstr; nathan@11: $strings{"en_US"}->{$msgid} = $msgid; nathan@11: } nathan@11: $msgid = $1; nathan@11: $last = 1; nathan@11: } elsif ($line =~ /^msgstr "(.*)"/) { nathan@11: $msgstr = $1; nathan@11: $last = 2; nathan@11: } elsif ($line =~ /^"(.*)"/) { nathan@11: if ($last eq 1) { nathan@11: $msgid = $msgid . $1; nathan@11: } elsif ($last eq 2) { nathan@11: $msgstr = $msgstr . $1; nathan@11: } nathan@11: } nathan@11: } nathan@11: if ($last eq 2) { nathan@11: $strings{$lang}->{$msgid} = $msgstr; nathan@11: $strings{"en_US"}->{$msgid} = $msgid; nathan@11: } nathan@11: nathan@11: close FILE; nathan@11: } nathan@11: nathan@11: nathan@11: nathan@11: foreach my $lang (@LANGS) { nathan@11: LoadLanguage($lang); nathan@11: } nathan@11: nathan@11: my @msgids = sort keys %{$strings{"en_US"}}; nathan@11: nathan@11: nathan@11: my $silent = 0; nathan@11: nathan@11: while (<>) { nathan@11: my $line = $_; nathan@11: nathan@11: if ($line =~ /^\/\/ START I18N/) { nathan@11: print "// START I18N - automatically generated by po2i18n.pl\n"; nathan@11: for my $msgid (@msgids) { nathan@11: next if $msgid eq ""; nathan@11: nathan@11: my $head = " { "; nathan@11: my $endif = ""; nathan@11: my $versnum = 10200; nathan@11: nathan@11: for my $lang (@LANGS) { nathan@11: if ($VERS{$lang} ne $versnum) { nathan@11: $versnum = $VERS{$lang}; nathan@11: print $endif; nathan@11: print "#if VDRVERSNUM >= $versnum\n"; nathan@11: $endif = "#endif\n"; nathan@11: } nathan@11: my $msgstr = $strings{$lang}->{$msgid}; nathan@11: $msgstr = "" if !defined $msgstr; nathan@11: nathan@11: print "$head\"$msgstr\",\n"; nathan@11: $head = " "; nathan@11: } nathan@11: print $endif; nathan@11: print " },\n"; nathan@11: } nathan@11: $silent = 1; nathan@11: } nathan@11: nathan@11: if (!$silent) { print $line; } nathan@11: nathan@11: if ($line =~ /^\/\/ END I18N/) { nathan@11: print "// END I18N - automatically generated by po2i18n.pl\n"; nathan@11: $silent = 0; nathan@11: } nathan@11: }