Fix a Gtk warning when checking path input in the log viewer.
[anjuta-git-plugin.git] / po / status.pl
blobb604bea6f68b39682a63661b11325fb61d28e482
1 #!/usr/bin/perl
3 ## status.pl
4 ## Copyright (C) 2000-2001 Kh. Naba Kumar Singh
5 ##
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
23 ## - corrected typos
25 =head Status.pl
26 Usage: status.pl
28 This script shows the status of each po file in the current dir.
29 The translation status is given as a percentage.
31 =cut
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.
38 my $country_hr = {
39 "az" => "Azerbaijani",
40 "br" => "Breton",
41 "bg" => "Bulgarian",
42 "ca" => "Catalan",
43 "cs" => "Czech",
44 "da" => "Danish",
45 "de" => "German",
46 "el" => "Greek",
47 "en_GB" => "British English",
48 "en_US" => "American English",
49 "eo" => "Esperanto",
50 "es" => "Spanish",
51 "et" => "Estonian",
52 "eu" => "Basque",
53 "fi" => "Finnish",
54 "fr" => "French",
55 "he" => "Hebrew",
56 "hr" => "Croatian",
57 "hu" => "Hungarian",
58 "is" => "Icelandic",
59 "it" => "Italian",
60 "ja" => "Japanese",
61 "ko" => "Korean",
62 "lt" => "Lithuanian",
63 "ms" => "Malay",
64 "mk" => "Macedonian",
65 "nl" => "Dutch",
66 "nn" => "Norwegian Nynorsk",
67 "no" => "Norwegian",
68 "pl" => "Polish",
69 "pt" => "Portuguese",
70 "pt_BR" => "Brazilian Portuguese",
71 "ro" => "Romanian",
72 "ru" => "Russian",
73 "sk" => "Slovak",
74 "sl" => "Slovenian",
75 "sr" => "Serbian",
76 "sv" => "Swedish",
77 "ta" => "Tamil",
78 "tr" => "Turkish",
79 "uk" => "Ukrainian",
80 "vi" => "Vietnamese",
81 "wa" => "Walloon",
82 "zh_CN.GB2312" => "Simplified Chinese",
83 "zh_CN" => "Simplified Chinese",
84 "zh_TW" => "Traditional Chinese"
87 ## Generate/update .pot file
88 system("intltool-update -p");
90 ## Determine missing files.
91 system("intltool-update --maintain");
93 ## Just take the first pot file found as the reference.
94 my $pot_file = glob("*.pot");
95 if ($pot_file eq "") {
96 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 print "...... Aborting.\n";
99 exit (1);
102 ## the appname will be the name of the pot file
103 $appname = $pot_file;
104 while ($strip ne ".") {
105 $strip = chop ($appname);
108 ## Determine the total messages available in this pot file.
109 my $output = `msgfmt --statistics $pot_file 2>&1`;
110 my @strs = split (", ", $output);
111 my ($pot_fuzzy, $pot_translated, $pot_untranslated) = (0,0,0);
112 foreach my $term (@strs) {
113 if ($term =~ /translated/) {
114 ($pot_translated) = split (" ", $term);
115 } elsif ($term =~ /fuzzy/) {
116 ($pot_fuzzy) = split (" ", $term);
117 } elsif ($term =~ /untranslated/) {
118 ($pot_untranslated) = split (" ", $term);
121 my $total_messages = $pot_translated + $pot_fuzzy + $pot_untranslated;
123 print "\n";
124 print "\t\tTRANSLATION STATISTICS\n";
125 print "\t\tTotal messages: $total_messages\n\n";
126 print "\tTranslation status given in percentage.\n";
127 print "+-------------------------------------------------------+\n";
128 printf ("| Po file | Translated | Fuzzy | Untranslated |\n");
129 print "+-------------------------------------------------------+\n";
130 my @po_files = glob("*.po");
132 open (XMLFILE, ">$translation_file")
133 or print STDERR "Can't open $translation_file to write.\n";
135 my $date_time = gmtime(time());
136 print XMLFILE "<?xml version=\"1.0\"?>\n";
137 print XMLFILE "<translationstats>\n";
138 print XMLFILE "<information>\n";
139 print XMLFILE "\t<application>$appname</application>\n";
140 print XMLFILE "\t<maintainer>Generated by status.pl</maintainer>\n";
141 print XMLFILE "\t<lastupdate>$date_time GMT</lastupdate>\n";
142 print XMLFILE "</information>\n\n";
143 print XMLFILE "<languages>\n";
145 foreach my $po_file (@po_files) {
146 if (-f $po_file) {
147 my $output = `msgfmt --statistics $po_file 2>&1`;
149 ## print $output, "\n";
151 my ($translated, $fuzzy, $untranslated) = (0,0,0);
152 my @strs = split (", ", $output);
153 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 ($untranslated) = split (" ", $coin);
162 $untranslated = $total_messages - ($translated + $fuzzy);
164 $untranslated *= 100/$total_messages;
165 $untranslated = ($untranslated < 0)? 0:$untranslated;
166 $untranslated = ($untranslated > 100)? 100:$untranslated;
168 $translated *= 100/$total_messages;
169 $translated = ($translated < 0)? 0:$translated;
170 $translated = ($translated > 100)? 100:$translated;
172 $fuzzy *= 100/$total_messages;
173 $fuzzy = ($fuzzy < 0)? 0:$fuzzy;
174 $fuzzy = ($fuzzy > 100)? 100:$fuzzy;
176 printf ("|%10s:| %6.2f ", $po_file, $translated);
177 printf ("| %6.2f | %6.2f |\n", $fuzzy, $untranslated);
179 my $country_code = $po_file;
180 $country_code =~ s/\.po$//;
181 my $country = $country_hr->{$country_code};
182 $country = ($country ne "")? $country:"-";
184 printf (XMLFILE "\t<sub language=\"$country\" country_code=\"$country_code\" ");
185 printf (XMLFILE "po=\"%6.2f (F:%6.2f, U:%6.2f)\" ", $translated, $fuzzy, $untranslated);
186 printf (XMLFILE "docs=\"-\"/>\n");
189 print "+-------------------------------------------------------+\n";
190 print XMLFILE "</languages>\n";
191 print XMLFILE "</translationstats>\n";
193 __END__