fe338b113d6f94ae1b7f59cf0dcceebdb0124133
[lhc/web/wiklou.git] / maintenance / transstat.php
1 <?php
2 /**
3 * @package MediaWiki
4 * @subpackage Maintenance
5 *
6 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
7 * @bug 2499
8 */
9
10 $langs = array();
11 $dir = opendir('languages');
12 while ($file = readdir($dir)) {
13 if (preg_match("/Language(.*?)\.php$/", $file, $m)) {
14 $langs[] = $m[1];
15 }
16 }
17
18 sort($langs);
19
20 // Cleanup
21 foreach($langs as $key => $lang) {
22 if ($lang == 'Utf8' || $lang == '' || $lang == 'Converter')
23 unset($langs[$key]);
24 }
25
26 require_once('commandLine.inc');
27
28 $msgs = array();
29 foreach($langs as $lang) {
30 // Since they aren't loaded by default..
31 require_once( 'languages/Language' . $lang . '.php' );
32 $arr = 'wgAllMessages' . $lang;
33 if (@is_array($$arr)) { // Some of them don't have a message array
34 $msgs[$wgContLang->lcfirst($lang)] = array(
35 'total' => count($$arr),
36 'redundant' => redundant($$arr),
37 );
38 } else {
39 $msgs[$wgContLang->lcfirst($lang)] = array(
40 'total' => 0,
41 'redundant' => 0,
42 );
43 }
44 }
45
46 $out = "{| border=2 cellpadding=4 cellspacing=0 style=\"background: #f9f9f9; border: 1px #aaa solid; border-collapse: collapse;\" width=100%\n";
47 $out .= beginul();
48 $out .= li('Language', true);
49 $out .= li('Translated', true);
50 $out .= li('%', true);
51 $out .= li('Untranslated', true);
52 $out .= li('%', true);
53 $out .= li('Redundant', true);
54 $out .= li('%', true);
55 $out .= endul();
56 foreach($msgs as $lang => $stats) {
57 $out .= beginul();
58 $out .= li($wgContLang->getLanguageName(strtr($lang, '_', '-')) . " ($lang)"); // Language
59 $out .= li($stats['total'] . '/' . $msgs['en']['total']); // Translated
60 $out .= li(percent($stats['total'], $msgs['en']['total'])); // % Translated
61 $out .= li($msgs['en']['total'] - $stats['total']); // Untranslated
62 $out .= li(percent($msgs['en']['total'] - $stats['total'], $msgs['en']['total'])); // % Untranslated
63 $out .= li($stats['redundant'] . '/' . $stats['total']); // Redundant
64 $out .= li(percent($stats['redundant'], $stats['total'])); // % Redundant
65 $out .= endul();
66 }
67 $out = substr($out, 0, -3) . "|}\n";
68 echo $out;
69
70 function beginul() { return ''; }
71 function endul() { return "|-\n"; }
72 function li($in, $heading = false) { return ($heading ? '!' : '|') . " $in\n"; }
73 function percent($subset, $total, $accuracy = 2) { return @sprintf( '%.' . $accuracy . 'f%%', 100 * $subset / $total ); }
74
75 // FIXME: This takes an obscene amount of time
76 function redundant(&$arr) {
77 global $wgAllMessagesEn;
78
79 $redundant = 0;
80 foreach(array_keys($arr) as $key) {
81 if ( ! array_key_exists( $key, $wgAllMessagesEn) )
82 ++$redundant;
83 }
84 return $redundant;
85 }