claws.i18n.status.pl 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. #!/usr/bin/perl
  2. #
  3. # claws.i18n.stats.pl - Generate statistics for Claws Mail po directory.
  4. #
  5. # Copyright (C) 2003-2023 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. use warnings;
  10. use strict;
  11. use File::Which;
  12. # constants -----------------------------------------------------------------
  13. my %lang = (
  14. 'bg.po' => {
  15. 'out' => 0, 'name' => 'Bulgarian',
  16. 'last' => 'Yasen Pramatarov <yasen@lindeas.com>',
  17. },
  18. 'ca.po' => {
  19. 'out' => 1, 'name' => 'Catalan',
  20. 'last' => 'David Medina <opensusecatala@gmail.com>',
  21. },
  22. 'cs.po' => {
  23. 'out' => 1, 'name' => 'Czech',
  24. 'last' => 'David Vachulka <david@konstrukce-cad.com>',
  25. },
  26. 'da.po' => {
  27. 'out' => 1, 'name' => 'Danish',
  28. 'last' => 'Erik P. Olsen <epodata@gmail.com>',
  29. },
  30. 'de.po' => {
  31. 'out' => 1, 'name' => 'German',
  32. 'last' => 'Simon Legner <simon.legner@gmail.com>',
  33. },
  34. 'el_GR.po' => {
  35. 'out' => 1, 'name' => 'Greek',
  36. 'last' => 'Haris Karachristianidis <hariskar@cryptolab.net>',
  37. },
  38. 'en_GB.po' => {
  39. 'out' => 1, 'name' => 'British English', 'lazy' => 1,
  40. 'last' => 'Paul Mangan <paul@claws-mail.org>',
  41. },
  42. 'eo.po' => {
  43. 'out' => 0, 'name' => 'Esperanto',
  44. 'last' => 'Sian Mountbatten <poenikatu@fastmail.co.uk>',
  45. },
  46. 'es.po' => {
  47. 'out' => 1, 'name' => 'Spanish',
  48. 'last' => 'Ricardo Mones <ricardo@mones.org>',
  49. },
  50. 'fi.po' => {
  51. 'out' => 1, 'name' => 'Finnish',
  52. 'last' => 'Flammie Pirinen <flammie@iki.fi>',
  53. },
  54. 'fr.po' => {
  55. 'out' => 1, 'name' => 'French',
  56. 'last' => 'Tristan Chabredier <wwp@claws-mail.org>',
  57. },
  58. 'he.po' => {
  59. 'out' => 0, 'name' => 'Hebrew',
  60. 'last' => 'Isratine Citizen <genghiskhan@gmx.ca>',
  61. },
  62. 'hu.po' => {
  63. 'out' => 1, 'name' => 'Hungarian',
  64. 'last' => 'P&aacute;der Rezs&#337; <rezso@rezso.net>',
  65. },
  66. 'id_ID.po' => {
  67. 'out' => 1, 'name' => 'Indonesian',
  68. 'last' => 'MSulchan Darmawan <bleketux@gmail.com>',
  69. },
  70. 'it.po' => {
  71. 'out' => 1, 'name' => 'Italian',
  72. 'last' => 'Luigi Votta <luigi.vtt@gmail.com>',
  73. },
  74. 'ja.po' => {
  75. 'out' => 1, 'name' => 'Japanese',
  76. 'last' => 'UTUMI Hirosi <utuhiro78@yahoo.co.jp>',
  77. },
  78. 'lt.po' => {
  79. 'out' => 0, 'name' => 'Lithuanian',
  80. 'last' => 'Mindaugas Baranauskas <embar@super.lt>',
  81. },
  82. 'nb.po' => {
  83. 'out' => 1, 'name' => 'Norwegian Bokm&aring;l',
  84. 'last' => 'Petter Adsen <petter@synth.no>',
  85. },
  86. 'nl.po' => {
  87. 'out' => 1, 'name' => 'Dutch',
  88. 'last' => 'Marcel Pol <mpol@gmx.net>',
  89. },
  90. 'pl.po' => {
  91. 'out' => 1, 'name' => 'Polish',
  92. 'last' => '&#x141;ukasz Wojni&#x142;owicz <lukasz.wojnilowicz@gmail.com>',
  93. },
  94. 'pt_BR.po' => {
  95. 'out' => 1, 'name' => 'Brazilian Portuguese',
  96. 'last' => 'Frederico Goncalves Guimaraes <fggdebian@yahoo.com.br>',
  97. },
  98. 'pt_PT.po' => {
  99. 'out' => 1, 'name' => 'Portuguese',
  100. 'last' => 'Hugo Carvalho <hugokarvalho@hotmail.com>',
  101. },
  102. 'ro.po' => {
  103. 'out' => 1, 'name' => 'Romanian',
  104. 'last' => 'Cristian Secar&#259; <liste@secarica.ro>',
  105. },
  106. 'ru.po' => {
  107. 'out' => 1, 'name' => 'Russian',
  108. 'last' => 'Mikhail Kurinnoi <viewizard@viewizard.com>',
  109. },
  110. 'sk.po' => {
  111. 'out' => 1, 'name' => 'Slovak',
  112. 'last' => 'Slavko <slavino@slavino.sk>',
  113. },
  114. 'sq.po' => {
  115. 'out' => 1, 'name' => 'Albanian',
  116. 'last' => 'Besnik Bleta <besnik@programeshqip.org>',
  117. },
  118. 'sv.po' => {
  119. 'out' => 1, 'name' => 'Swedish',
  120. 'last' => 'Andreas Rönnquist <gusnan@openmailbox.org>',
  121. },
  122. 'tr.po' => {
  123. 'out' => 1, 'name' => 'Turkish',
  124. 'last' => 'Numan Demirdöğen <if.gnu.linux@gmail.com>',
  125. },
  126. 'uk.po' => {
  127. 'out' => 0, 'name' => 'Ukrainian',
  128. 'last' => 'YUP <yupadmin@gmail.com>',
  129. },
  130. 'zh_CN.po' => {
  131. 'out' => 0, 'name' => 'Simplified Chinese',
  132. 'last' => 'Rob <rbnwmk@gmail.com>',
  133. },
  134. 'zh_TW.po' => {
  135. 'out' => 1, 'name' => 'Traditional Chinese',
  136. 'last' => 'Mark Chang <mark.cyj@gmail.com>',
  137. },
  138. );
  139. my %barcolornorm = (
  140. default => 'white',
  141. partially => 'lightblue',
  142. completed => 'blue',
  143. );
  144. my %barcoloraged = (
  145. default => 'white',
  146. partially => 'lightgrey', # ligth red '#FFA0A0',
  147. completed => 'grey', # darker red '#FF7070',
  148. );
  149. my %barcolorcheat = ( # remarks translations with revision dates in the future
  150. default => 'white',
  151. partially => 'yellow',
  152. completed => 'red',
  153. );
  154. my ($barwidth, $barheight) = (500, 12); # pixels
  155. my $transolddays = 120; # days to consider a translation is old, so probably unmaintained.
  156. my $transoldmonths = $transolddays / 30;
  157. my $transneedthresold = 0.75; # percent/100
  158. my ($msgfmt, $date, $grep, $cut) = map {
  159. my $bin = which($_); die "missing '$_' binary" unless defined $bin; $bin
  160. } qw(msgfmt date grep cut);
  161. my $averageitem = {'name' => 'Project average', 'out' => 1, 'last' => ''};
  162. my $contactaddress = 'translations@thewildbeast.co.uk';
  163. # code begins here ----------------------------------------------------------
  164. sub get_current_date {
  165. my $utc = qx{$date --utc};
  166. chop $utc;
  167. $utc =~ /(\S+)(\s+)(\S+)(\s+)(\S+)(\s+)(\S+)(\D+)(\d+)/;
  168. return "$5-$3-$9 at $7"."$8";
  169. }
  170. sub get_trans_age {
  171. my ($y, $m, $d) = @_;
  172. return ($y * 365) + ($m * 31) + $d;
  173. }
  174. my (undef, undef, undef, $mday, $mon, $year, undef, undef) = gmtime(time);
  175. $year += 1900;
  176. $mon++;
  177. my $cage = get_trans_age($year, $mon, $mday); # get current "age"
  178. # drawing a language status row
  179. sub print_lang {
  180. my ($langmap, $trans, $fuzzy, $untrans, $tage, $oddeven) = @_;
  181. return if not $langmap->{'out'};
  182. my $lang = $langmap->{'name'};
  183. my $person = $langmap->{'last'};
  184. my $total = $trans + $fuzzy + $untrans;
  185. if ($tage == 0) { $tage = $cage; } # hack for average translation
  186. # print STDERR $cage, " ", $tage, "\n";
  187. my ($barcolor, $pname, $pemail);
  188. if (($cage - $tage) < 0) {
  189. $barcolor = \%barcolorcheat;
  190. } else {
  191. $barcolor = (($cage - $tage) > $transolddays)? \%barcoloraged : \%barcolornorm ;
  192. }
  193. $_ = $person;
  194. if (/(.+)\s+\<(.+)\>/) {
  195. $pname = $1; $pemail = $2;
  196. } else {
  197. $pname = $pemail = $contactaddress;
  198. }
  199. print '<tr', ($oddeven? ' bgcolor=#EFEFEF': ''), ">\n<td>\n";
  200. if ($lang eq $averageitem->{'name'}) {
  201. print "<b>$lang</b>";
  202. } else {
  203. print "<a href=\"mailto:%22$pname%22%20<$pemail>\">$lang</a>";
  204. }
  205. print "</td>\n";
  206. print "<td>\n<table style='border: solid 1px black; width: $barwidth'",
  207. " border='0' cellspacing='0' cellpadding='0'><tr>\n";
  208. my $barlen = ($trans / $total) * $barwidth;
  209. print "<td style='width:$barlen", "px; height:$barheight",
  210. "px;' bgcolor=\"$$barcolor{completed}\"></td>\n";
  211. my $barlen2 = ($fuzzy / $total) * $barwidth;
  212. print "<td style='width:$barlen2", "px' bgcolor=\"$$barcolor{partially}\"></td>\n";
  213. my $barlen3 = $barwidth - $barlen2 - $barlen;
  214. print "<td style='width:$barlen3", "px' bgcolor=\"$$barcolor{default}\"></td>\n";
  215. print "</tr>\n</table>\n</td>\n\n<td style='text-align: right'>",
  216. int(($trans / $total) * 10000) / 100, "%</td>\n";
  217. my $transtatus = (($trans / $total) < $transneedthresold)
  218. ? '<font size="+1" color="red"> * </font>': '';
  219. print "<td>$transtatus</td>\n</tr>\n";
  220. }
  221. sub tens {
  222. my ($i) = @_;
  223. return (($i > 9)? "$i" : "0$i");
  224. }
  225. my $datetimenow = get_current_date();
  226. # get project version from changelog (project dependent code :-/ )
  227. my $genversion = 'Unknown';
  228. my $changelog = '../Changelog';
  229. if (-s $changelog) {
  230. my $head = which('head');
  231. if (defined $head) {
  232. $_ = qx{$head -1 $changelog};
  233. if (/\S+\s+\S+\s+(\S+)/) { $genversion = $1; }
  234. }
  235. } else {
  236. my $git = which('git');
  237. if (defined $git) {
  238. $_ = qx{$git describe --abbrev=0};
  239. if (/(\d+\.\d+\.\d)/) { $genversion = $1; }
  240. }
  241. }
  242. # start
  243. print qq ~<div class=indent>
  244. <b>Translation Status (on $datetimenow for $genversion)</b>
  245. <div class=indent>
  246. <table cellspacing=0 cellpadding=2>~;
  247. # table header
  248. print qq ~<tr bgcolor=#cccccc>
  249. <th align=left>Language</th>
  250. <th>Translated|Fuzzy|Untranslated</th>
  251. <th>Percent</th>
  252. <th></th>
  253. </tr>~;
  254. # get files
  255. my @pofiles;
  256. opendir(PODIR, ".") || die("Error: can't open current directory\n");
  257. push(@pofiles,(readdir(PODIR)));
  258. closedir(PODIR);
  259. my @sorted_pofiles = sort(@pofiles);
  260. # iterate them
  261. my ($alang, $atran, $afuzz, $auntr, $oddeven) = (0, 0, 0, 0, 0);
  262. foreach my $pofile (@sorted_pofiles) {
  263. $_ = $pofile;
  264. if (/.+\.po$/ && defined($lang{$pofile}) ) {
  265. print STDERR "Processing $_\n"; # be a little informative
  266. ++$alang;
  267. my ($transage, $tran, $fuzz, $untr) = (0, 0, 0, 0);
  268. $_ = qx{$msgfmt -c --statistics -o /dev/null $pofile 2>&1};
  269. if (/([0-9]+)\s+translated/) {
  270. $tran = $1;
  271. }
  272. if (/([0-9]+)\s+fuzzy/) {
  273. $fuzz = $1;
  274. }
  275. if (/([0-9]+)\s+untranslated/) {
  276. $untr = $1;
  277. }
  278. # print STDERR "Translated [$tran] Fuzzy [$fuzz] Untranslated [$untr]\n";
  279. $atran += $tran;
  280. $afuzz += $fuzz;
  281. $auntr += $untr;
  282. if ($lang{$pofile}->{'lazy'}) {
  283. $tran = $tran + $fuzz;
  284. $untr = "0";
  285. $fuzz = "0";
  286. $transage = $cage;
  287. } else {
  288. $_ = qx{$grep 'PO-Revision-Date:' $pofile | $cut -f2 -d:};
  289. if (/\s+(\d+)\-(\d+)\-(\d+)/) {
  290. $transage = get_trans_age($1, $2, $3);
  291. }
  292. }
  293. print_lang($lang{$pofile}, $tran, $fuzz, $untr, $transage, $oddeven);
  294. $oddeven = $oddeven? 0: 1;
  295. }
  296. }
  297. # average results for the project
  298. print "<tr>\n<td colspan=3 height=8></td>\n<tr>";
  299. print_lang($averageitem, $atran, $afuzz, $auntr, 0, 0);
  300. # table footer
  301. print "</table>\n";
  302. print qq ~</div>
  303. </div>~;
  304. # done