claws.i18n.status.pl 8.4 KB

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