claws.i18n.status.pl 7.8 KB

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