claws.i18n.status.pl 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. #!/usr/bin/perl -w
  2. #
  3. # claws.i18n.stats.pl - Generate statistics for Claws Mail po directory.
  4. #
  5. # Copyright (C) 2003-2008 by Ricardo Mones <ricardo@mones.org>,
  6. # Paul Mangan <paul@claws-mail.org>
  7. # This program is released under the GNU General Public License.
  8. #
  9. # constants -----------------------------------------------------------------
  10. %langname = (
  11. 'bg.po' => 'Bulgarian',
  12. 'ca.po' => 'Catalan',
  13. 'cs.po' => 'Czech',
  14. 'de.po' => 'German',
  15. 'en_GB.po' => 'British English',
  16. 'es.po' => 'Spanish',
  17. 'fi.po' => 'Finnish',
  18. 'fr.po' => 'French',
  19. 'hu.po' => 'Hungarian',
  20. 'it.po' => 'Italian',
  21. 'nl.po' => 'Dutch',
  22. 'pl.po' => 'Polish',
  23. 'pt_BR.po' => 'Brazilian Portuguese',
  24. 'ru.po' => 'Russian',
  25. 'sv.po' => 'Swedish',
  26. 'zh_CN.po' => 'Simpilified Chinese',
  27. );
  28. %lasttranslator = (
  29. 'bg.po' => 'Yasen Pramatarov <yasen@lindeas.com>',
  30. 'ca.po' => 'Miquel Oliete <ktalanet@yahoo.es>',
  31. 'cs.po' => 'David Vachulka <david@konstrukce-cad.com>',
  32. 'de.po' => 'Stephan Sachse <white@dev-zero.com>',
  33. 'en_GB.po' => 'Paul Mangan <paul@claws-mail.org>',
  34. 'es.po' => 'Ricardo Mones Lastra <ricardo@mones.org>',
  35. 'fi.po' => 'Flammie Pirinen <flammie@iki.fi>',
  36. 'fr.po' => 'Tristan Chabredier <wwp@claws-mail.org>',
  37. 'hu.po' => 'P&aacute;der Rezs&#337; <rezso@rezso.net>',
  38. 'it.po' => 'Andrea Spadaccini <a.spadaccini@catania.linux.it>',
  39. 'nl.po' => 'Marcel Pol <mpol@gmx.net>',
  40. 'pl.po' => 'Emilian Nowak <emil5@go2.pl>',
  41. 'pt_BR.po' => 'Frederico Goncalves Guimaraes <fggdebian@yahoo.com.br>',
  42. 'ru.po' => 'Aleksei Miheev <aleksei@miheev.info>',
  43. 'sv.po' => 'Lars Persson Fink <lars.p.fink@gmail.com>',
  44. 'zh_CN.po' => 'Ralgh Young <bamanzi@gmail.com>',
  45. );
  46. %barcolornorm = (
  47. default => 'white',
  48. partially => 'lightblue',
  49. completed => 'blue',
  50. );
  51. %barcoloraged = (
  52. default => 'white',
  53. partially => 'lightgrey', # ligth red '#FFA0A0',
  54. completed => 'grey', # darker red '#FF7070',
  55. );
  56. %barcolorcheat = ( # remarks translations with revision dates in the future
  57. default => 'white',
  58. partially => 'yellow',
  59. completed => 'red',
  60. );
  61. $barwidth = 500; # pixels
  62. $barheight = 12; # pixels
  63. $transolddays = 90; # days to consider a translation is old, so probably unmaintained.
  64. $transoldmonths = $transolddays / 30;
  65. $transneedthresold = 0.75; # percent/100
  66. $msgfmt = '/usr/bin/msgfmt';
  67. $averagestr = 'Project average';
  68. $contactaddress = 'translations@thewildbeast.co.uk';
  69. # $pagehead = '../../claws.i18n.head.php';
  70. # $pagetail = '../../claws.i18n.tail.php';
  71. # code begins here ----------------------------------------------------------
  72. sub get_current_date {
  73. $date = `date --utc`;
  74. chop $date;
  75. $date =~ /(\S+)(\s+)(\S+)(\s+)(\S+)(\s+)(\S+)(\D+)(\d+)/;
  76. $datetimenow = "$5-$3-$9 at $7"."$8";
  77. }
  78. sub get_trans_age {
  79. my ($y, $m, $d) = @_;
  80. return ($y * 365) + ($m * 31) + $d;
  81. }
  82. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime(time);
  83. $year += 1900;
  84. $mon++;
  85. $cage = get_trans_age($year,$mon,$mday); # get current "age"
  86. # drawing a language status row
  87. sub print_lang {
  88. my ($lang, $person, $trans, $fuzzy, $untrans, $tage, $oddeven) = @_;
  89. $total = $trans + $fuzzy + $untrans;
  90. if ($tage == 0) { $tage = $cage; } # hack for average translation
  91. print STDERR $cage, " ", $tage, "\n";
  92. if (($cage - $tage) < 0) {
  93. $barcolor = \%barcolorcheat;
  94. } else {
  95. $barcolor = (($cage - $tage) > $transolddays)? \%barcoloraged : \%barcolornorm ;
  96. }
  97. $_ = $person;
  98. if (/(.+)\s+\<(.+)\>/) { $pname = $1; $pemail = $2; } else { $pname = $pemail = $contactaddress; }
  99. print "<tr";
  100. if ($oddeven > 0) { print " bgcolor=#EFEFEF"; }
  101. print ">\n<td>\n";
  102. if ($lang eq $averagestr) {
  103. print "<b>$lang</b>";
  104. } else {
  105. print "<a href=\"mailto:%22$pname%22%20<$pemail>\">$lang</a>";
  106. }
  107. print "</td>\n";
  108. print "<td>\n<table style='border: solid 1px black; width: $barwidth' border='0' cellspacing='0' cellpadding='0'><tr>\n";
  109. $barlen = ($trans / $total) * $barwidth;
  110. print "<td style='width:$barlen", "px; height:$barheight", "px;' bgcolor=\"$$barcolor{completed}\"></td>\n";
  111. $barlen2 = ($fuzzy / $total) * $barwidth;
  112. print "<td style='width:$barlen2", "px' bgcolor=\"$$barcolor{partially}\"></td>\n";
  113. $barlen3 = $barwidth - $barlen2 - $barlen;
  114. print "<td style='width:$barlen3", "px' bgcolor=\"$$barcolor{default}\"></td>\n";
  115. print "</tr>\n</table>\n</td>\n\n<td style='text-align: right'>", int(($trans / $total) * 10000) / 100, "%</td>\n";
  116. if (($lang eq $langname{'en_GB.po'}) or ($lang eq $averagestr)) { $trans = $total; } # hack for en_GB and average results
  117. $transtatus = (($trans / $total) < $transneedthresold)? '<font size="+1" color="red"> * </font>': '';
  118. print "<td>$transtatus</td>\n</tr>\n";
  119. }
  120. sub tens {
  121. my ($i) = @_;
  122. return (($i > 9)? "$i" : "0$i");
  123. }
  124. get_current_date();
  125. # get project version from changelog (project dependent code :-/ )
  126. $_ = `head -1 ../ChangeLog`;
  127. if (/\S+\s+\S+\s+(\S+)/) { $genversion = $1; } else { $genversion = 'Unknown'; }
  128. $numlang = keys(%langname);
  129. # print `cat $pagehead`;
  130. #
  131. # make it a here-doc
  132. #print <<ENDOFHEAD;
  133. # removed for being included
  134. #ENDOFHEAD
  135. # start
  136. print qq ~<div class=indent>
  137. <b>Translation Status (on $datetimenow for $genversion)</b>
  138. <div class=indent>
  139. <table cellspacing=0 cellpadding=2>~;
  140. # table header
  141. print qq ~<tr bgcolor=#cccccc>
  142. <th align=left>Language</th>
  143. <th>Translated|Fuzzy|Untranslated</th>
  144. <th>Percent</th>
  145. <th></th>
  146. </tr>~;
  147. # get files
  148. opendir(PODIR, ".") || die("Error: can't open current directory\n");
  149. push(@pofiles,(readdir(PODIR)));
  150. closedir(PODIR);
  151. @sorted_pofiles = sort(@pofiles);
  152. # iterate them
  153. $alang = $atran = $afuzz = $auntr = $oddeven = 0;
  154. foreach $pofile (@sorted_pofiles) {
  155. $_ = $pofile;
  156. if (/.+\.po$/ && defined($langname{$pofile}) ) {
  157. print STDERR "Processing $_\n"; # be a little informative
  158. ++$alang;
  159. $transage = $tran = $fuzz = $untr = 0;
  160. $_ = `$msgfmt -c --statistics -o /dev/null $pofile 2>&1`;
  161. if (/([0-9]+)\s+translated/) {
  162. $tran = $1;
  163. }
  164. if (/([0-9]+)\s+fuzzy/) {
  165. $fuzz = $1;
  166. }
  167. if (/([0-9]+)\s+untranslated/) {
  168. $untr = $1;
  169. }
  170. # print STDERR "Translated [$tran] Fuzzy [$fuzz] Untranslated [$untr]\n";
  171. $atran += $tran;
  172. $afuzz += $fuzz;
  173. $auntr += $untr;
  174. $_ = `grep 'PO-Revision-Date:' $pofile | cut -f2 -d:`;
  175. if (/\s+(\d+)\-(\d+)\-(\d+)/) {
  176. $transage = get_trans_age($1,$2,$3);
  177. }
  178. print_lang($langname{$pofile},$lasttranslator{$pofile},$tran,$fuzz,$untr,$transage, $oddeven);
  179. if ($oddeven == 1) { $oddeven = 0 } else { $oddeven++; }
  180. }
  181. }
  182. # average results for the project
  183. print "<tr>\n<td colspan=3 height=8></td>\n<tr>";
  184. print_lang($averagestr,'',$atran,$afuzz,$auntr,0,0);
  185. # table footer
  186. print "</table>\n";
  187. # end
  188. # print "<br>Number of languages supported: $alang <br>";
  189. print qq ~<p>
  190. Languages marked with <font size="+1" color="red"> *</font>
  191. really need your help to be completed.
  192. <p>
  193. The ones with grey bars are <i>probably unmaintained</i> because
  194. translation is more than $transoldmonths months old, anyway, trying
  195. to contact current translator first is usually a good idea before
  196. submitting an updated one.<p><b>NOTE</b>: if you are the translator
  197. of one of them and don't want to see your language bar in grey you
  198. should manually update the <tt>PO-Revision-Date</tt> field in the .po
  199. file header (or, alternatively, use a tool which does it for you).
  200. <br>
  201. </div>
  202. </div>~;
  203. # print `cat $pagetail`;
  204. #
  205. # make it a here-doc
  206. #print <<ENDOFTAIL;
  207. # removed for being included
  208. #ENDOFTAIL
  209. # done