Add progress handling to GitCommand
[anjuta-git-plugin.git] / plugins / tools / scripts / translation-status.pl
blobec38f9b98e60003e2ef2a82a3e4ec76b8124833b
1 #!/usr/bin/perl
3 ## status.pl
4 ## Copyright (C) Naba Kumar <naba@gnome.org>
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 my ($project_root) = @ARGV;
89 if (!defined ($project_root) || $project_root eq "") {
90 print STDERR "Error: No project\n";
91 exit(1);
93 if ($project_root !~ /^\//) {
94 print STDERR "Error: Project root is not absolute path\n";
95 exit(1);
97 unless (-d "$project_root/po") {
98 print STDERR "Error: Project does not have translations\n";
99 exit(1);
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";
116 exit (1);
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;
140 print "\n";
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) {
152 if (-f $po_file) {
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";
193 __END__