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( 'maintenance/commandLine.inc' );
16 require_once( 'languages.inc' );
18 if ( isset( $options['help'] ) ) {
22 # Default output is WikiText
23 if ( !isset( $options['output'] ) ) {
24 $options['output'] = 'wiki';
27 /** Print a usage message*/
28 function showUsage() {
30 Usage: php transstat.php [--help] [--output=csv|text|wiki]
31 --help : this helpful message
32 --output : select an output engine one of:
33 * 'csv' : Comma Separated Values.
34 * 'wiki' : MediaWiki syntax (default).
35 * 'metawiki' : MediaWiki syntax used for Meta-Wiki.
36 * 'text' : Text with tabs.
37 Example: php maintenance/transstat.php --output=text
43 /** A general output object. Need to be overriden */
45 function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
46 return @sprintf
( '%.' . $accuracy . 'f%%', 100 * $subset / $total );
49 # Override the following methods
54 function blockstart() {
58 function element( $in, $heading = false ) {
62 /** Outputs WikiText */
63 class wikiStatsOutput
extends statsOutput
{
66 $version = SpecialVersion
::getVersion( $IP );
67 echo "'''Statistics are based on:''' <code>" . $version . "</code>\n\n";
68 echo "'''Note:''' These statistics can be generated by running <code>php maintenance/language/transstat.php</code>.\n\n";
69 echo "For additional information on specific languages (the message names, the actual problems, etc.), run <code>php maintenance/language/checkLanguage.php --lang=foo</code>.\n\n";
70 echo '{| border="2" cellpadding="4" cellspacing="0" style="background-color: #F9F9F9; border: 1px #AAAAAA solid; border-collapse: collapse;" width="100%"'."\n";
75 function blockstart() {
81 function element( $in, $heading = false ) {
82 echo ($heading ?
'!' : '|') . " $in\n";
84 function formatPercent( $subset, $total, $revert = false, $accuracy = 2 ) {
85 $v = @round
(255 * $subset / $total);
92 $green = sprintf( '%02X', 2 * $v );
95 $red = sprintf('%02X', 2 * ( 255 - $v ) );
99 $color = $red . $green . $blue;
101 $percent = statsOutput
::formatPercent( $subset, $total, $revert, $accuracy );
102 return 'bgcolor="#'. $color .'" | '. $percent;
106 /** Outputs WikiText and appends category and text only used for Meta-Wiki */
107 class metawikiStatsOutput
extends wikiStatsOutput
{
109 echo "See [[MediaWiki localisation]] to learn how you can help translating MediaWiki.\n\n";
114 echo "\n[[Category:Localisation|Statistics]]\n";
118 /** Output text. To be used on a terminal for example. */
119 class textStatsOutput
extends statsOutput
{
120 function element( $in, $heading = false ) {
123 function blockend() {
128 /** csv output. Some people love excel */
129 class csvStatsOutput
extends statsOutput
{
130 function element( $in, $heading = false ) {
133 function blockend() {
138 # Select an output engine
139 switch ( $options['output'] ) {
141 $wgOut = new wikiStatsOutput();
144 $wgOut = new metawikiStatsOutput();
147 $wgOut = new textStatsOutput();
150 $wgOut = new csvStatsOutput();
157 $wgLanguages = new languages();
161 $wgOut->blockstart();
162 $wgOut->element( 'Language', true );
163 $wgOut->element( 'Translated', true );
164 $wgOut->element( '%', true );
165 $wgOut->element( 'Obsolete', true );
166 $wgOut->element( '%', true );
167 $wgOut->element( 'Problematic', true );
168 $wgOut->element( '%', true );
171 $wgGeneralMessages = $wgLanguages->getGeneralMessages();
172 $wgRequiredMessagesNumber = count( $wgGeneralMessages['required'] );
174 foreach ( $wgLanguages->getLanguages() as $code ) {
175 # Don't check English or RTL English
176 if ( $code == 'en' ||
$code == 'enRTL' ) {
180 # Calculate the numbers
181 $language = $wgContLang->getLanguageName( $code );
182 $messages = $wgLanguages->getMessages( $code );
183 $messagesNumber = count( $messages['translated'] );
184 $requiredMessagesNumber = count( $messages['required'] );
185 $requiredMessagesPercent = $wgOut->formatPercent( $requiredMessagesNumber, $wgRequiredMessagesNumber );
186 $obsoleteMessagesNumber = count( $messages['obsolete'] );
187 $obsoleteMessagesPercent = $wgOut->formatPercent( $obsoleteMessagesNumber, $messagesNumber, true );
188 $messagesWithoutVariables = $wgLanguages->getMessagesWithoutVariables( $code );
189 $emptyMessages = $wgLanguages->getEmptyMessages( $code );
190 $messagesWithWhitespace = $wgLanguages->getMessagesWithWhitespace( $code );
191 $nonXHTMLMessages = $wgLanguages->getNonXHTMLMessages( $code );
192 $messagesWithWrongChars = $wgLanguages->getMessagesWithWrongChars( $code );
193 $problematicMessagesNumber = count( array_unique( array_merge( $messagesWithoutVariables, $emptyMessages, $messagesWithWhitespace, $nonXHTMLMessages, $messagesWithWrongChars ) ) );
194 $problematicMessagesPercent = $wgOut->formatPercent( $problematicMessagesNumber, $messagesNumber, true );
197 $wgOut->blockstart();
198 $wgOut->element( "$language ($code)" );
199 $wgOut->element( "$requiredMessagesNumber/$wgRequiredMessagesNumber" );
200 $wgOut->element( $requiredMessagesPercent );
201 $wgOut->element( "$obsoleteMessagesNumber/$messagesNumber" );
202 $wgOut->element( $obsoleteMessagesPercent );
203 $wgOut->element( "$problematicMessagesNumber/$messagesNumber" );
204 $wgOut->element( $problematicMessagesPercent );