Merge "Adding ResourceLoader module "jquery.jStorage""
[lhc/web/wiklou.git] / maintenance / language / transstat.php
1 <?php
2 /**
3 * Statistics about the localisation.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup MaintenanceLanguage
22 *
23 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
24 * @author Antoine Musso <hashar at free dot fr>
25 *
26 * Output is posted from time to time on:
27 * http://www.mediawiki.org/wiki/Localisation_statistics
28 */
29 $optionsWithArgs = array( 'output' );
30
31 require_once( __DIR__ . '/../commandLine.inc' );
32 require_once( 'languages.inc' );
33 require_once( __DIR__ . '/StatOutputs.php' );
34
35
36 if ( isset( $options['help'] ) ) {
37 showUsage();
38 }
39
40 # Default output is WikiText
41 if ( !isset( $options['output'] ) ) {
42 $options['output'] = 'wiki';
43 }
44
45 /** Print a usage message*/
46 function showUsage() {
47 print <<<TEXT
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
55
56 TEXT;
57 exit( 1 );
58 }
59
60
61
62 # Select an output engine
63 switch ( $options['output'] ) {
64 case 'wiki':
65 $output = new wikiStatsOutput();
66 break;
67 case 'text':
68 $output = new textStatsOutput();
69 break;
70 case 'csv':
71 $output = new csvStatsOutput();
72 break;
73 default:
74 showUsage();
75 }
76
77 # Languages
78 $wgLanguages = new languages();
79
80 # Header
81 $output->heading();
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 );
92 $output->blockend();
93
94 $wgGeneralMessages = $wgLanguages->getGeneralMessages();
95 $wgRequiredMessagesNumber = count( $wgGeneralMessages['required'] );
96
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] ) ) ) {
101 continue;
102 }
103
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 );
120
121 # Output them
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 );
132 $output->blockend();
133 }
134
135 # Footer
136 $output->footer();