3 * Statistics about the localisation.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup MaintenanceLanguage
23 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
24 * @author Antoine Musso <hashar at free dot fr>
26 * Output is posted from time to time on:
27 * http://www.mediawiki.org/wiki/Localisation_statistics
29 $optionsWithArgs = array( 'output' );
31 require_once( __DIR__
. '/../commandLine.inc' );
32 require_once( 'languages.inc' );
33 require_once( __DIR__
. '/StatOutputs.php' );
36 if ( isset( $options['help'] ) ) {
40 # Default output is WikiText
41 if ( !isset( $options['output'] ) ) {
42 $options['output'] = 'wiki';
45 /** Print a usage message*/
46 function showUsage() {
48 Usage: php transstat.php [--help] [--output=csv|text|wiki]
49 --help : this helpful message
50 --output : select an output engine one of:
51 * 'csv' : Comma Separated Values.
52 * 'wiki' : MediaWiki syntax (default).
53 * 'text' : Text with tabs.
54 Example: php maintenance/transstat.php --output=text
62 # Select an output engine
63 switch ( $options['output'] ) {
65 $output = new wikiStatsOutput();
68 $output = new textStatsOutput();
71 $output = new csvStatsOutput();
78 $wgLanguages = new languages();
82 $output->blockstart();
83 $output->element( 'Language', true );
84 $output->element( 'Code', true );
85 $output->element( 'Fallback', true );
86 $output->element( 'Translated', true );
87 $output->element( '%', true );
88 $output->element( 'Obsolete', true );
89 $output->element( '%', true );
90 $output->element( 'Problematic', true );
91 $output->element( '%', true );
94 $wgGeneralMessages = $wgLanguages->getGeneralMessages();
95 $wgRequiredMessagesNumber = count( $wgGeneralMessages['required'] );
97 foreach ( $wgLanguages->getLanguages() as $code ) {
98 # Don't check English, RTL English or dummy language codes
99 if ( $code == 'en' ||
$code == 'enRTL' ||
( is_array( $wgDummyLanguageCodes ) &&
100 isset( $wgDummyLanguageCodes[$code] ) ) ) {
104 # Calculate the numbers
105 $language = Language
::fetchLanguageName( $code );
106 $fallback = $wgLanguages->getFallback( $code );
107 $messages = $wgLanguages->getMessages( $code );
108 $messagesNumber = count( $messages['translated'] );
109 $requiredMessagesNumber = count( $messages['required'] );
110 $requiredMessagesPercent = $output->formatPercent( $requiredMessagesNumber, $wgRequiredMessagesNumber );
111 $obsoleteMessagesNumber = count( $messages['obsolete'] );
112 $obsoleteMessagesPercent = $output->formatPercent( $obsoleteMessagesNumber, $messagesNumber, true );
113 $messagesWithMismatchVariables = $wgLanguages->getMessagesWithMismatchVariables( $code );
114 $emptyMessages = $wgLanguages->getEmptyMessages( $code );
115 $messagesWithWhitespace = $wgLanguages->getMessagesWithWhitespace( $code );
116 $nonXHTMLMessages = $wgLanguages->getNonXHTMLMessages( $code );
117 $messagesWithWrongChars = $wgLanguages->getMessagesWithWrongChars( $code );
118 $problematicMessagesNumber = count( array_unique( array_merge( $messagesWithMismatchVariables, $emptyMessages, $messagesWithWhitespace, $nonXHTMLMessages, $messagesWithWrongChars ) ) );
119 $problematicMessagesPercent = $output->formatPercent( $problematicMessagesNumber, $messagesNumber, true );
122 $output->blockstart();
123 $output->element( "$language" );
124 $output->element( "$code" );
125 $output->element( "$fallback" );
126 $output->element( "$requiredMessagesNumber/$wgRequiredMessagesNumber" );
127 $output->element( $requiredMessagesPercent );
128 $output->element( "$obsoleteMessagesNumber/$messagesNumber" );
129 $output->element( $obsoleteMessagesPercent );
130 $output->element( "$problematicMessagesNumber/$messagesNumber" );
131 $output->element( $problematicMessagesPercent );