ada4db07dbd6fc35b54c705f20b34ba7dd37de2c
2 # MediaWiki web-based config/installation
3 # Copyright (C) 2004 Ashar Voultoiz <thoane@altern.org> and others
4 # http://www.mediawiki.org/
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 # http://www.gnu.org/copyleft/gpl.html
22 * Usage: php DiffLanguage.php [lang [file]]
24 * lang: Enter the language code following "Language" of the LanguageXX.php you
25 * want to check. If using linux you might need to follow case aka Zh and not
28 * file: A php language file you want to include to compare mediawiki
29 * Language{Lang}.php against (for example Special:Allmessages PHP output).
31 * The goal is to get a list of messages not yet localised in a languageXX.php
32 * file using the language.php file as reference.
34 * The script then print a list of wgAllMessagesXX keys that aren't localised, a
35 * percentage of messages correctly localised and the number of messages to be
38 * @addtogroup Maintenance
41 /** This script run from the commandline */
42 require_once( dirname(__FILE__
).'/../parserTests.inc' );
43 require_once( dirname(__FILE__
).'/../commandLine.inc' );
45 if( isset($options['help']) ) { usage(); wfDie(); }
47 $wgLanguageCode = ucfirstlcrest($wgLanguageCode);
48 /** Language messages we will use as reference. By default 'en' */
49 $referenceMessages = $wgAllMessagesEn;
50 $referenceLanguage = 'En';
51 $referenceFilename = 'Language'.$referenceLanguage.'.php';
52 /** Language messages we will test. */
53 $testMessages = array();
55 /** whereas we use an external language file */
59 /** @todo more informations !! */
61 echo 'php DiffLanguage.php [lang [file]] [--color=(yes|no|light)]'."\n";
64 /** Return a given string with first letter upper case, the rest lowercase */
65 function ucfirstlcrest($string) {
66 return strtoupper(substr($string,0,1)).strtolower(substr($string,1));
70 * Return a $wgAllmessages array shipped in MediaWiki
71 * @param string $languageCode Formated language code
72 * @return array The MediaWiki default $wgAllMessages array requested
74 function getMediawikiMessages($languageCode = 'En') {
76 $foo = "wgAllMessages$languageCode";
78 global $wgSkinNamesEn; // potentially unused global declaration?
80 // it might already be loaded in LocalSettings.php
83 $langFile = $IP.'/languages/classes/Language'.$languageCode.'.php';
84 if (file_exists( $langFile ) ) {
85 print "Including $langFile\n";
86 global $wgNamespaceNamesEn; // potentially unused global declaration?
88 } else wfDie("ERROR: The file $langFile does not exist !\n");
94 * Return a $wgAllmessages array in a given file. Language of the array
95 * need to be given cause we can not detect which language it provides
96 * @param string $filename Filename of the file containing a message array
97 * @param string $languageCode Language of the external array
98 * @return array A $wgAllMessages array from an external file.
100 function getExternalMessages($filename, $languageCode) {
101 print "Including external file $filename.\n";
103 $foo = "wgAllMessages$languageCode";
108 if ( isset($args[0]) ) {
109 $lang = ucfirstlcrest($args[0],1);
111 // eventually against another language file we will use as reference instead
112 // of the default english language.
113 if( isset($args[1])) {
114 // we assume the external file contain an array of messages for the
115 // lang we are testing
116 $referenceMessages = getExternalMessages( $args[1], $lang );
117 $referenceLanguage = $lang;
118 $referenceFilename = $args[1];
122 // Load datas from MediaWiki
123 $testMessages = getMediawikiMessages($lang);
124 $testLanguage = $lang;
130 /** parsertest is used to do differences */
131 $myParserTest = new ParserTest();
133 # Get all references messages and check if they exist in the tested language
136 $msg = "MW Language{$testLanguage}.php against ";
137 if($externalRef) { $msg .= 'external file '; }
138 else { $msg .= 'internal file '; }
139 $msg .= $referenceFilename.' ('.$referenceLanguage."):\n----\n";
143 foreach($referenceMessages as $index => $ref)
145 // message is not localized
146 if(!(isset($testMessages[$index]))) {
148 print "'$index' => \"$ref\",\n";
149 // Messages in the same language differs
150 } elseif( ($lang == $referenceLanguage) AND ($testMessages[$index] != $ref)) {
151 print "\n$index differs:\n";
152 print $myParserTest->quickDiff($testMessages[$index],$ref,'tested','reference');
156 echo "\n----\n".$msg;
157 echo "$referenceLanguage language is complete at ".number_format((100 - $i/count($wgAllMessagesEn) * 100),2)."%\n";
158 echo "$i unlocalised messages of the ".count($wgAllMessagesEn)." messages available.\n";