r9618 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r9617‎ | r9618 | r9619 >
Date:15:36, 24 June 2005
Author:avar
Status:old
Tags:
Comment:
* (bug 2499) Translation statistics
Modified paths:
  • /trunk/phase3/maintenance/transstat.php (added) (history)

Diff [purge]

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

Status & tagging log