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 * https://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';
35 if ( isset( $options['help'] ) ) {
39 # Default output is WikiText
40 if ( !isset( $options['output'] ) ) {
41 $options['output'] = 'wiki';
44 /** Print a usage message*/
45 function showUsage() {
47 Usage: php transstat.php [--help] [--output=csv|text|wiki]
48 --help : this helpful message
49 --output : select an output engine one of:
50 * 'csv' : Comma Separated Values.
51 * 'wiki' : MediaWiki syntax (default).
52 * 'text' : Text with tabs.
53 Example: php maintenance/transstat.php --output=text
59 # Select an output engine
60 switch ( $options['output'] ) {
62 $output = new WikiStatsOutput();
65 $output = new TextStatsOutput();
68 $output = new CsvStatsOutput();
75 $wgLanguages = new Languages();
79 $output->blockstart();
80 $output->element( 'Language', true );
81 $output->element( 'Code', true );
82 $output->element( 'Fallback', true );
83 $output->element( 'Translated', true );
84 $output->element( '%', true );
85 $output->element( 'Obsolete', true );
86 $output->element( '%', true );
87 $output->element( 'Problematic', true );
88 $output->element( '%', true );
91 $wgGeneralMessages = $wgLanguages->getGeneralMessages();
92 $wgRequiredMessagesNumber = count( $wgGeneralMessages['required'] );
94 foreach ( $wgLanguages->getLanguages() as $code ) {
95 # Don't check English, RTL English or dummy language codes
96 if ( $code == 'en' ||
$code == 'enRTL' ||
( is_array( $wgDummyLanguageCodes ) &&
97 isset( $wgDummyLanguageCodes[$code] ) )
102 # Calculate the numbers
103 $language = Language
::fetchLanguageName( $code );
104 $fallback = $wgLanguages->getFallback( $code );
105 $messages = $wgLanguages->getMessages( $code );
106 $messagesNumber = count( $messages['translated'] );
107 $requiredMessagesNumber = count( $messages['required'] );
108 $requiredMessagesPercent = $output->formatPercent(
109 $requiredMessagesNumber,
110 $wgRequiredMessagesNumber
112 $obsoleteMessagesNumber = count( $messages['obsolete'] );
113 $obsoleteMessagesPercent = $output->formatPercent(
114 $obsoleteMessagesNumber,
118 $messagesWithMismatchVariables = $wgLanguages->getMessagesWithMismatchVariables( $code );
119 $emptyMessages = $wgLanguages->getEmptyMessages( $code );
120 $messagesWithWhitespace = $wgLanguages->getMessagesWithWhitespace( $code );
121 $nonXHTMLMessages = $wgLanguages->getNonXHTMLMessages( $code );
122 $messagesWithWrongChars = $wgLanguages->getMessagesWithWrongChars( $code );
123 $problematicMessagesNumber = count( array_unique( array_merge(
124 $messagesWithMismatchVariables,
126 $messagesWithWhitespace,
128 $messagesWithWrongChars
130 $problematicMessagesPercent = $output->formatPercent(
131 $problematicMessagesNumber,
137 $output->blockstart();
138 $output->element( "$language" );
139 $output->element( "$code" );
140 $output->element( "$fallback" );
141 $output->element( "$requiredMessagesNumber/$wgRequiredMessagesNumber" );
142 $output->element( $requiredMessagesPercent );
143 $output->element( "$obsoleteMessagesNumber/$messagesNumber" );
144 $output->element( $obsoleteMessagesPercent );
145 $output->element( "$problematicMessagesNumber/$messagesNumber" );
146 $output->element( $problematicMessagesPercent );