From: Ævar Arnfjörð Bjarmason Date: Fri, 24 Jun 2005 15:36:07 +0000 (+0000) Subject: * (bug 2499) Translation statistics X-Git-Tag: 1.5.0beta1~54 X-Git-Url: http://git.cyclocoop.org/%7D%7Cconcat%7B?a=commitdiff_plain;h=de9f2a12a48c5c911994a5982baacd2671230109;p=lhc%2Fweb%2Fwiklou.git * (bug 2499) Translation statistics --- diff --git a/maintenance/transstat.php b/maintenance/transstat.php new file mode 100644 index 0000000000..fe338b113d --- /dev/null +++ b/maintenance/transstat.php @@ -0,0 +1,85 @@ + + * @bug 2499 + */ + +$langs = array(); +$dir = opendir('languages'); +while ($file = readdir($dir)) { + if (preg_match("/Language(.*?)\.php$/", $file, $m)) { + $langs[] = $m[1]; + } +} + +sort($langs); + +// Cleanup +foreach($langs as $key => $lang) { + if ($lang == 'Utf8' || $lang == '' || $lang == 'Converter') + unset($langs[$key]); +} + +require_once('commandLine.inc'); + +$msgs = array(); +foreach($langs as $lang) { + // Since they aren't loaded by default.. + require_once( 'languages/Language' . $lang . '.php' ); + $arr = 'wgAllMessages' . $lang; + if (@is_array($$arr)) { // Some of them don't have a message array + $msgs[$wgContLang->lcfirst($lang)] = array( + 'total' => count($$arr), + 'redundant' => redundant($$arr), + ); + } else { + $msgs[$wgContLang->lcfirst($lang)] = array( + 'total' => 0, + 'redundant' => 0, + ); + } +} + +$out = "{| border=2 cellpadding=4 cellspacing=0 style=\"background: #f9f9f9; border: 1px #aaa solid; border-collapse: collapse;\" width=100%\n"; +$out .= beginul(); +$out .= li('Language', true); +$out .= li('Translated', true); +$out .= li('%', true); +$out .= li('Untranslated', true); +$out .= li('%', true); +$out .= li('Redundant', true); +$out .= li('%', true); +$out .= endul(); +foreach($msgs as $lang => $stats) { + $out .= beginul(); + $out .= li($wgContLang->getLanguageName(strtr($lang, '_', '-')) . " ($lang)"); // Language + $out .= li($stats['total'] . '/' . $msgs['en']['total']); // Translated + $out .= li(percent($stats['total'], $msgs['en']['total'])); // % Translated + $out .= li($msgs['en']['total'] - $stats['total']); // Untranslated + $out .= li(percent($msgs['en']['total'] - $stats['total'], $msgs['en']['total'])); // % Untranslated + $out .= li($stats['redundant'] . '/' . $stats['total']); // Redundant + $out .= li(percent($stats['redundant'], $stats['total'])); // % Redundant + $out .= endul(); +} +$out = substr($out, 0, -3) . "|}\n"; +echo $out; + +function beginul() { return ''; } +function endul() { return "|-\n"; } +function li($in, $heading = false) { return ($heading ? '!' : '|') . " $in\n"; } +function percent($subset, $total, $accuracy = 2) { return @sprintf( '%.' . $accuracy . 'f%%', 100 * $subset / $total ); } + +// FIXME: This takes an obscene amount of time +function redundant(&$arr) { + global $wgAllMessagesEn; + + $redundant = 0; + foreach(array_keys($arr) as $key) { + if ( ! array_key_exists( $key, $wgAllMessagesEn) ) + ++$redundant; + } + return $redundant; +}