4 ## Copyright (C) Naba Kumar <naba@gnome.org>
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 2 of the License, or
9 ## (at your option) any later version.
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU Library General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program; if not, write to the Free Software
18 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 ## modified 2001-11-05 Andy Piper <andy.piper@freeuk.com>
21 ## - added further countries to the hash table
22 ## - altered XML file output
28 This script shows the status of
each po file
in the current dir
.
29 The translation status is
given as a percentage
.
33 ## Output xml file for translation status
34 my $translation_file = "translations.xml";
36 ## Country code to country name hash map
37 ## Some contry codes may need to be filled.
39 "az" => "Azerbaijani",
47 "en_GB" => "British English",
48 "en_US" => "American English",
66 "nn" => "Norwegian Nynorsk",
70 "pt_BR" => "Brazilian Portuguese",
82 "zh_CN.GB2312" => "Simplified Chinese",
83 "zh_CN" => "Simplified Chinese",
84 "zh_TW" => "Traditional Chinese"
87 my ($project_root) = @ARGV;
89 if (!defined ($project_root) || $project_root eq "") {
90 print STDERR
"Error: No project\n";
93 if ($project_root !~ /^\//) {
94 print STDERR
"Error: Project root is not absolute path\n";
97 unless (-d
"$project_root/po") {
98 print STDERR
"Error: Project does not have translations\n";
102 chdir("$project_root/po");
104 ## Generate/update .pot file
105 system("intltool-update -p");
107 ## Determine missing files.
108 system("intltool-update --maintain");
110 ## Just take the first pot file found as the reference.
111 my $pot_file = glob("*.pot");
112 if ($pot_file eq "") {
113 print "There is no reference pot file in this directory.\n";
114 print "Make sure you are running status.pl in a po directory.\n";
115 print "...... Aborting.\n";
119 ## the appname will be the name of the pot file
120 $appname = $pot_file;
121 while ($strip ne ".") {
122 $strip = chop ($appname);
125 ## Determine the total messages available in this pot file.
126 my $output = `msgfmt --statistics $pot_file 2>&1`;
127 my @strs = split (", ", $output);
128 my ($pot_fuzzy, $pot_translated, $pot_untranslated) = (0,0,0);
129 foreach my $term (@strs) {
130 if ($term =~ /translated/) {
131 ($pot_translated) = split (" ", $term);
132 } elsif ($term =~ /fuzzy/) {
133 ($pot_fuzzy) = split (" ", $term);
134 } elsif ($term =~ /untranslated/) {
135 ($pot_untranslated) = split (" ", $term);
138 my $total_messages = $pot_translated + $pot_fuzzy + $pot_untranslated;
141 print "\t\tTRANSLATION STATISTICS\n";
142 print "\t\tTotal messages: $total_messages\n\n";
143 print "\tTranslation status given in percentage.\n";
144 print "+----------------------------------------------------------------------------+\n";
145 printf ("| Po file | Language | Translated | Fuzzy | Untranslated |\n");
146 print "+----------------------------------------------------------------------------+\n";
147 my @po_files = glob("*.po");
149 my $date_time = gmtime(time());
151 foreach my $po_file (@po_files) {
153 my $output = `msgfmt --statistics $po_file 2>&1`;
155 ## print $output, "\n";
157 my ($translated, $fuzzy, $untranslated) = (0,0,0);
158 my @strs = split (", ", $output);
159 foreach my $coin (@strs) {
160 if ($coin =~ /\btranslated\b/) {
161 ($translated) = split (" ", $coin);
162 } elsif ($coin =~ /\bfuzzy\b/) {
163 ($fuzzy) = split (" ", $coin);
164 } elsif ($coin =~ /\buntranslated\b/) {
165 ($untranslated) = split (" ", $coin);
168 $untranslated = $total_messages - ($translated + $fuzzy);
170 $untranslated *= 100/$total_messages;
171 $untranslated = ($untranslated < 0)?
0:$untranslated;
172 $untranslated = ($untranslated > 100)?
100:$untranslated;
174 $translated *= 100/$total_messages;
175 $translated = ($translated < 0)?
0:$translated;
176 $translated = ($translated > 100)?
100:$translated;
178 $fuzzy *= 100/$total_messages;
179 $fuzzy = ($fuzzy < 0)?
0:$fuzzy;
180 $fuzzy = ($fuzzy > 100)?
100:$fuzzy;
182 my $country_code = $po_file;
183 $country_code =~ s/\.po$//;
184 my $country = $country_hr->{$country_code};
185 $country = ($country ne "")?
$country:"-";
187 printf ("|%10s |%21s | %6.2f ", $po_file, $country, $translated);
188 printf ("| %6.2f | %6.2f |\n", $fuzzy, $untranslated);
191 print "+----------------------------------------------------------------------------+\n";