Index: trunk/extensions/Translate/groupStatistics.php |
— | — | @@ -0,0 +1,158 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Statistics about message groups. |
| 5 | + * |
| 6 | + * @addtogroup Maintenance |
| 7 | + * |
| 8 | + * @author Niklas Laxstrom |
| 9 | + * |
| 10 | + * @copyright Copyright © 2007, Niklas Laxström |
| 11 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 12 | + */ |
| 13 | + |
| 14 | +$optionsWithArgs = array( 'groups', 'output' ); |
| 15 | + |
| 16 | +function stderr( $message ) { |
| 17 | + static $stderr = null; |
| 18 | + if (is_null($stderr)) $stderr = fopen( "php://stderr", "wt" ); |
| 19 | + fwrite( $stderr, $message . "\n" ); |
| 20 | +} |
| 21 | + |
| 22 | +$MY_IP = "../../maintenance"; |
| 23 | +require_once( $MY_IP . '/commandLine.inc' ); |
| 24 | +require_once( $IP . '/maintenance/language/StatOutputs.php' ); |
| 25 | + |
| 26 | +if ( isset( $options['help'] ) ) { |
| 27 | + showUsage(); |
| 28 | +} |
| 29 | + |
| 30 | +# Default output is WikiText |
| 31 | +if ( !isset( $options['output'] ) ) { |
| 32 | + $options['output'] = 'wiki'; |
| 33 | +} |
| 34 | + |
| 35 | +/** Print a usage message*/ |
| 36 | +function showUsage() { |
| 37 | + $msg = <<<END |
| 38 | +Usage: php transstat.php [--help] [--output=csv|text|wiki] --groups |
| 39 | + --help : this helpful message |
| 40 | + --group : comma separated list of groups |
| 41 | + --output : select an output engine one of: |
| 42 | + * 'csv' : Comma Separated Values. |
| 43 | + * 'wiki' : MediaWiki syntax (default). |
| 44 | + * 'metawiki' : MediaWiki syntax used for Meta-Wiki. |
| 45 | + * 'text' : Text with tabs. |
| 46 | +Example: php maintenance/transstat.php --output=text |
| 47 | + |
| 48 | +END; |
| 49 | + stderr( $msg ); |
| 50 | + die( 1 ); |
| 51 | +} |
| 52 | + |
| 53 | + |
| 54 | +# Select an output engine |
| 55 | +switch ( $options['output'] ) { |
| 56 | + case 'wiki': |
| 57 | + $out = new wikiStatsOutput(); |
| 58 | + break; |
| 59 | + case 'metawiki': |
| 60 | + $out = new metawikiStatsOutput(); |
| 61 | + break; |
| 62 | + case 'text': |
| 63 | + $out = new textStatsOutput(); |
| 64 | + break; |
| 65 | + case 'csv': |
| 66 | + $out = new csvStatsOutput(); |
| 67 | + break; |
| 68 | + default: |
| 69 | + showUsage(); |
| 70 | +} |
| 71 | + |
| 72 | +if ( !isset($options['groups']) ) { |
| 73 | + showUsage(); |
| 74 | +} |
| 75 | + |
| 76 | +// Get groups from input |
| 77 | +$groups = array(); |
| 78 | +$reqGroups = array_map( 'trim', explode( ',', $options['groups'] ) ); |
| 79 | + |
| 80 | +// List of all groups |
| 81 | +$allGroups = MessageGroups::singleton()->getGroups(); |
| 82 | + |
| 83 | +// Get list of valid groups |
| 84 | +foreach ( $reqGroups as $id ) { |
| 85 | + if ( array_key_exists( $id, $allGroups ) ) { |
| 86 | + $groups[$id] = $allGroups[$id]; |
| 87 | + } else { |
| 88 | + stderr( "Unknown group $id" ); |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +// List of all customized languages. |
| 93 | +$languages = Language::getLanguageNames( true ); |
| 94 | + |
| 95 | +// Default sorting order by language code, users can sort wiki output by any |
| 96 | +// column, if it is supported. |
| 97 | +ksort( $languages ); |
| 98 | + |
| 99 | +// Output headers |
| 100 | +$out->heading(); |
| 101 | +$out->blockstart(); |
| 102 | +$out->element( 'Code', true ); |
| 103 | +$out->element( 'Language', true ); |
| 104 | +foreach ( $groups as $g ) { |
| 105 | + // Add unprocessed description of group as heading |
| 106 | + $out->element( $g->getLabel(), true ); |
| 107 | +} |
| 108 | +$out->blockend(); |
| 109 | + |
| 110 | + |
| 111 | +// Perform the statistic calculations on every language |
| 112 | +foreach ( $languages as $code => $name ) { |
| 113 | + // Here we assume that all testing languages like enRTL are filtered by |
| 114 | + // missing core translations file. |
| 115 | + |
| 116 | + $out->blockstart(); |
| 117 | + $out->element( $code ); |
| 118 | + $out->element( $name ); |
| 119 | + |
| 120 | + |
| 121 | + foreach ( $groups as $g ) { |
| 122 | + // Initialise messages |
| 123 | + $messages = new MessageCollection; |
| 124 | + $definitions = $g->getDefinitions(); |
| 125 | + foreach ( $definitions as $key => $definition ) { |
| 126 | + $messages->add( new TMessage( $key, $definition ) ); |
| 127 | + } |
| 128 | + |
| 129 | + $bools = $g->getBools(); |
| 130 | + foreach ( array_merge($bools['ignored'], $bools['optional']) as $key ) { |
| 131 | + unset($messages[$key]); |
| 132 | + } |
| 133 | + |
| 134 | + // Store the count of real messages for later calculation. |
| 135 | + $total = count( $messages ); |
| 136 | + |
| 137 | + // Get all translations. Could this be done more efficient? |
| 138 | + TranslateUtils::fillContents( $messages, $code ); |
| 139 | + $g->fill( $messages, $code ); |
| 140 | + |
| 141 | + // Remove untranslated messages from the list |
| 142 | + foreach ( $messages as $key => $o ) { |
| 143 | + if ( $o->translation === null ) { |
| 144 | + unset( $messages[$key] ); |
| 145 | + } |
| 146 | + } |
| 147 | + |
| 148 | + // Count the completion percent and output it |
| 149 | + $translated = count( $messages ); |
| 150 | + $out->element( $out->formatPercent( $translated, $total, |
| 151 | + /* Inverted color */ false, /* Decimals */ 2 ) |
| 152 | + ); |
| 153 | + } |
| 154 | + |
| 155 | + $out->blockend(); |
| 156 | +} |
| 157 | + |
| 158 | +# Finally output footer |
| 159 | +$out->footer(); |
Property changes on: trunk/extensions/Translate/groupStatistics.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 160 | + native |