7f0a6fd124fc8e2bdee703ef14051e00dca027f6
3 * Statistics about the localisation.
6 * @subpackage Maintenance
8 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
9 * @author Ashar Voultoiz <thoane@altern.org>
11 * Output is posted from time to time on:
12 * http://meta.wikimedia.org/wiki/Localization_statistics
15 require_once( 'commandLine.inc' );
16 require_once( 'languages.inc' );
18 if ( isset( $options['help'] ) ) {
21 # Default output is WikiText
22 if ( !isset( $options['output'] ) ) {
23 $options['output'] = 'wiki';
26 /** Print a usage message*/
27 function showUsage() {
29 Usage: php transstat.php [--help] [--output=csv|text|wiki]
30 --help : this helpful message
31 --output : select an output engine one of:
32 * 'csv' : Comma Separated Values.
33 * 'wiki' : MediaWiki syntax (default).
34 * 'text' : Text with tabs.
35 Example: php maintenance/transstat.php --output=text
41 /** A general output object. Need to be overriden */
43 function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
44 return @sprintf
( '%.' . $accuracy . 'f%%', 100 * $subset / $total );
47 # Override the following methods
52 function blockstart() {
56 function element( $in, $heading = false ) {
60 /** Outputs WikiText */
61 class wikiStatsOutput
extends statsOutput
{
63 echo "'''Note:''' These statistics can be generated by running <code>php maintenance/transstat.php</code>.\n\n";
64 echo "For additional information on specific languages (the message names, the actual problems, etc.), run <code>php maintenance/checkLanguage.php --lang=foo</code>.\n\n";
65 echo "{| border=2 cellpadding=4 cellspacing=0 style=\"background: #f9f9f9; border: 1px #aaa solid; border-collapse: collapse;\" width=100%\n";
70 function blockstart() {
76 function element( $in, $heading = false ) {
77 echo ($heading ?
'!' : '|') . " $in\n";
79 function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
80 $v = @round
(255 * $subset / $total);
87 $green = sprintf( '%02X', 2 * $v );
90 $red = sprintf('%02X', 2 * ( 255 - $v ) );
94 $color = $red . $green . $blue;
96 $percent = statsOutput
::formatPercent( $subset, $total, $revert, $accuracy );
97 return 'bgcolor="#'. $color .'" | '. $percent;
101 /** Output text. To be used on a terminal for example. */
102 class textStatsOutput
extends statsOutput
{
103 function element( $in, $heading = false ) {
106 function blockend() {
111 /** csv output. Some people love excel */
112 class csvStatsOutput
extends statsOutput
{
113 function element( $in, $heading = false ) {
116 function blockend() {
121 # Select an output engine
122 switch ( $options['output'] ) {
124 $wgOut = new wikiStatsOutput();
127 $wgOut = new textStatsOutput();
130 $wgOut = new csvStatsOutput();
137 $wgLanguages = new languages();
141 $wgOut->blockstart();
142 $wgOut->element( 'Language', true );
143 $wgOut->element( 'Translated', true );
144 $wgOut->element( '%', true );
145 $wgOut->element( 'Obsolete', true );
146 $wgOut->element( '%', true );
147 $wgOut->element( 'Problematic', true );
148 $wgOut->element( '%', true );
151 foreach ( $wgLanguages->getList() as $code ) {
152 # Don't check English or RTL English
153 if ( $code == 'en' ||
$code == 'enRTL' ) {
157 # Calculate the numbers
158 $name = $wgLang->getLanguageName( $code );
159 $translatableMessagesNumber = count( $wgLanguages->getTranslatableMessages() );
160 $localMessagesNumber = count( $wgLanguages->getMessagesFor( $code ) );
161 $translatedMessagesNumber = count( $wgLanguages->getTranslatedMessages( $code ) );
162 $translatedMessagesPercent = $wgOut->formatPercent( $translatedMessagesNumber, $translatableMessagesNumber );
163 $obsoleteMessagesNumber = count( $wgLanguages->getObsoleteMessages( $code ) );
164 $obsoleteMessagesPercent = $wgOut->formatPercent( $obsoleteMessagesNumber, $translatedMessagesNumber, true );
165 $messagesWithoutVariables = $wgLanguages->getMessagesWithoutVariables( $code );
166 $emptyMessages = $wgLanguages->getEmptyMessages( $code );
167 $messagesWithWhitespace = $wgLanguages->getMessagesWithWhitespace( $code );
168 $nonXHTMLMessages = $wgLanguages->getNonXHTMLMessages( $code );
169 $messagesWithWrongChars = $wgLanguages->getMessagesWithWrongChars( $code );
170 $problematicMessagesNumber = count( array_unique( array_merge( $messagesWithoutVariables, $emptyMessages, $messagesWithWhitespace, $nonXHTMLMessages, $messagesWithWrongChars ) ) );
171 $problematicMessagesPercent = $wgOut->formatPercent( $problematicMessagesNumber, $translatedMessagesNumber, true );
174 $wgOut->blockstart();
175 $wgOut->element( "$name ($code)" );
176 $wgOut->element( "$translatedMessagesNumber/$translatableMessagesNumber" );
177 $wgOut->element( $translatedMessagesPercent );
178 $wgOut->element( "$obsoleteMessagesNumber/$translatedMessagesNumber" );
179 $wgOut->element( $obsoleteMessagesPercent );
180 $wgOut->element( "$problematicMessagesNumber/$translatedMessagesNumber" );
181 $wgOut->element( $problematicMessagesPercent );