claws.i18n.status.pl 7.8 KB

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