status.pl 5.85 KB
Newer Older
1 2
#!/usr/bin/perl

Naba Kumar's avatar
Naba Kumar committed
3
## status.pl
4
## Copyright (C) 2000-2001  Kh. Naba Kumar Singh
5 6 7 8 9 10 11 12 13 14 15 16 17
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU Library General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
18
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19

20 21 22 23
## modified 2001-11-05 Andy Piper <andy.piper@freeuk.com>
## - added further countries to the hash table
## - altered XML file output
## - corrected typos
24 25 26 27

=head Status.pl
Usage: status.pl

28 29
This script shows the status of each po file in the current dir.
The translation status is given as a percentage.
30 31 32

=cut

33 34 35 36 37 38
## Output xml file for translation status
my $translation_file = "translations.xml";

## Country code to country name hash map
## Some contry codes may need to be filled.
my $country_hr = {
39 40 41
		"az" => "Azerbaijani",
		"br" => "Breton",
		"bg" => "Bulgarian", 
42 43 44 45 46
		"ca" => "Catalan",
		"cs" => "Czech",
		"da" => "Danish",
		"de" => "German",
		"el" => "Greek",
47 48
		"en_GB" => "British English",
		"en_US" => "American English",
49 50
		"eo" => "Esperanto",
		"es" => "Spanish",
51 52
		"et" => "Estonian",
		"eu" => "Basque",
53 54
		"fi" => "Finnish",
		"fr" => "French",
55
		"he" => "Hebrew",
56 57
		"hr" => "Croatian",
		"hu" => "Hungarian",
58
		"is" => "Icelandic",
59
		"it" => "Italian",
60
		"ja" => "Japanese",
61
		"ko" => "Korean",
62 63
		"lt" => "Lithuanian",
		"ms" => "Malay",
64 65
		"mk" => "Macedonian",
		"nl" => "Dutch",
66
		"nn" => "Norwegian Nynorsk",
67 68
		"no" => "Norwegian",
		"pl" => "Polish",
69 70
		"pt" => "Portuguese",
		"pt_BR" => "Brazilian Portuguese",
71 72 73
		"ro" => "Romanian",
		"ru" => "Russian",
		"sk" => "Slovak",
74 75 76 77
		"sl" => "Slovenian",
		"sr" => "Serbian",
		"sv" => "Swedish",
		"ta" => "Tamil",
78
		"tr" => "Turkish",
79 80 81
		"uk" => "Ukrainian",
		"vi" => "Vietnamese",
		"wa" => "Walloon",
82 83
		"zh_CN.GB2312" => "Simplified Chinese",
		"zh_CN" => "Simplified Chinese",
84
		"zh_TW" => "Traditional Chinese"
85 86
	};

87 88 89 90 91 92
## Generate/update .pot file
system("intltool-update -p");

## Determine missing files.
system("intltool-update --maintain");

93 94 95 96
## Just take the first pot file found as the reference.
my $pot_file = glob("*.pot");
if ($pot_file eq "") {
	print "There is no reference pot file in this directory.\n";
97
	print "Make sure you are running status.pl in a po directory.\n";
98 99 100 101
	print "...... Aborting.\n";
	exit (1);
}

102 103 104 105 106 107
## the appname will be the name of the pot file
$appname = $pot_file;
while ($strip ne ".") {
	$strip = chop ($appname);
}

108 109 110
## Determine the total messages available in this pot file.
my $output = `msgfmt --statistics $pot_file 2>&1`;
my @strs = split (", ", $output);
111 112 113 114 115 116 117 118 119 120 121
my ($pot_fuzzy, $pot_translated, $pot_untranslated) = (0,0,0);
foreach my $term (@strs) {
    if ($term =~ /translated/) {
	($pot_translated) = split (" ", $term);
    } elsif ($term =~ /fuzzy/) {
	($pot_fuzzy) = split (" ", $term);
    } elsif ($term =~ /untranslated/) {
	($pot_untranslated) = split (" ", $term);
    }
}
my $total_messages = $pot_translated + $pot_fuzzy + $pot_untranslated;
122 123 124 125

print   "\n";
print   "\t\tTRANSLATION STATISTICS\n";
print   "\t\tTotal messages: $total_messages\n\n";
126
print   "\tTranslation status given in percentage.\n";
127 128 129
print   "+-------------------------------------------------------+\n";
printf ("|  Po file  |  Translated  |   Fuzzy   |   Untranslated |\n");
print   "+-------------------------------------------------------+\n";
130 131
my @po_files = glob("*.po");

132 133 134 135
open (XMLFILE, ">$translation_file")
  or print STDERR "Can't open $translation_file to write.\n";

my $date_time = gmtime(time());
136 137 138
print XMLFILE "<?xml version=\"1.0\"?>\n";
print XMLFILE "<translationstats>\n";
print XMLFILE "<information>\n";
139
print XMLFILE "\t<application>$appname</application>\n";
140 141 142 143
print XMLFILE "\t<maintainer>Generated by status.pl</maintainer>\n";
print XMLFILE "\t<lastupdate>$date_time GMT</lastupdate>\n";
print XMLFILE "</information>\n\n";
print XMLFILE "<languages>\n";
144

145 146 147 148 149 150 151 152 153
foreach my $po_file (@po_files) {
	if (-f $po_file) {
		my $output = `msgfmt --statistics $po_file 2>&1`;
		
		## print $output, "\n";
		
		my ($translated, $fuzzy, $untranslated) = (0,0,0);
		my @strs = split (", ", $output);
		foreach my $coin (@strs) {
154
			if ($coin =~ /\btranslated\b/) {
155
				($translated) = split (" ", $coin);
156
			} elsif ($coin =~ /\bfuzzy\b/) {
157
				($fuzzy) = split (" ", $coin);
158
			} elsif ($coin =~ /\buntranslated\b/) {
159 160 161
				($untranslated) = split (" ", $coin);
			}
		}
162 163 164 165 166 167
		$untranslated = $total_messages - ($translated + $fuzzy);

		$untranslated *= 100/$total_messages;
		$untranslated = ($untranslated < 0)? 0:$untranslated;
		$untranslated = ($untranslated > 100)? 100:$untranslated;

168
		$translated *= 100/$total_messages;
169 170 171
		$translated = ($translated < 0)? 0:$translated;
		$translated = ($translated > 100)? 100:$translated;

172
		$fuzzy *= 100/$total_messages;
173 174 175 176 177
		$fuzzy = ($fuzzy < 0)? 0:$fuzzy;
		$fuzzy = ($fuzzy > 100)? 100:$fuzzy;

		printf ("|%10s:|    %6.2f    ", $po_file, $translated);
		printf ("|    %6.2f |      %6.2f    |\n", $fuzzy, $untranslated);
178 179 180 181 182 183
		
		my $country_code = $po_file;
		$country_code =~ s/\.po$//;
		my $country = $country_hr->{$country_code};
		$country = ($country ne "")? $country:"-";
		
184
		printf (XMLFILE "\t<sub language=\"$country\" country_code=\"$country_code\" ");
185 186
		printf (XMLFILE "po=\"%6.2f (F:%6.2f, U:%6.2f)\" ", $translated, $fuzzy, $untranslated);
		printf (XMLFILE "docs=\"-\"/>\n");
187 188
	}
}
189
print   "+-------------------------------------------------------+\n";
190 191
print XMLFILE "</languages>\n";
print XMLFILE "</translationstats>\n";
192 193

__END__