Merge "Fix positioning of jQuery.tipsy tooltip arrows"
[mediawiki.git] / maintenance / language / transstat.php
blob4a853b0f322c3c986bc7e65141a7fab0a1ede1ae
1 <?php
2 /**
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
20 * @file
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'] ) ) {
36 showUsage();
39 # Default output is WikiText
40 if ( !isset( $options['output'] ) ) {
41 $options['output'] = 'wiki';
44 /** Print a usage message*/
45 function showUsage() {
46 print <<<TEXT
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
55 TEXT;
56 exit( 1 );
59 # Select an output engine
60 switch ( $options['output'] ) {
61 case 'wiki':
62 $output = new WikiStatsOutput();
63 break;
64 case 'text':
65 $output = new TextStatsOutput();
66 break;
67 case 'csv':
68 $output = new CsvStatsOutput();
69 break;
70 default:
71 showUsage();
74 # Languages
75 $wgLanguages = new Languages();
77 # Header
78 $output->heading();
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 );
89 $output->blockend();
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] ) )
98 ) {
99 continue;
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,
115 $messagesNumber,
116 true
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,
125 $emptyMessages,
126 $messagesWithWhitespace,
127 $nonXHTMLMessages,
128 $messagesWithWrongChars
129 ) ) );
130 $problematicMessagesPercent = $output->formatPercent(
131 $problematicMessagesNumber,
132 $messagesNumber,
133 true
136 # Output them
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 );
147 $output->blockend();
150 # Footer
151 $output->footer();