2004-04-24 08:30:26 +00:00
|
|
|
<?php
|
|
|
|
|
# MediaWiki web-based config/installation
|
|
|
|
|
# Copyright (C) 2004 Ashar Voultoiz <thoane@altern.org> and others
|
|
|
|
|
# http://www.mediawiki.org/
|
2004-09-17 15:56:28 +00:00
|
|
|
#
|
2004-04-24 08:30:26 +00:00
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2004-09-17 15:56:28 +00:00
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
2004-04-24 08:30:26 +00:00
|
|
|
# (at your option) any later version.
|
2004-09-17 15:56:28 +00:00
|
|
|
#
|
2004-04-24 08:30:26 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
2004-09-17 15:56:28 +00:00
|
|
|
#
|
2004-04-24 08:30:26 +00:00
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
# http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
|
2004-09-03 18:52:58 +00:00
|
|
|
/**
|
2005-01-12 00:36:16 +00:00
|
|
|
* Usage: php DiffLanguage.php [lang [file]]
|
2004-09-03 18:52:58 +00:00
|
|
|
*
|
2005-01-12 00:36:16 +00:00
|
|
|
* lang: Enter the language code following "Language" of the LanguageXX.php you
|
|
|
|
|
* want to check. If using linux you might need to follow case aka Zh and not
|
|
|
|
|
* zh.
|
2004-09-03 18:52:58 +00:00
|
|
|
*
|
2005-01-12 00:36:16 +00:00
|
|
|
* file: A php language file you want to include to compare mediawiki
|
|
|
|
|
* Language{Lang}.php against (for example Special:Allmessages PHP output).
|
2004-09-03 18:52:58 +00:00
|
|
|
*
|
2005-01-12 00:36:16 +00:00
|
|
|
* The goal is to get a list of messages not yet localised in a languageXX.php
|
|
|
|
|
* file using the language.php file as reference.
|
2006-01-07 13:09:30 +00:00
|
|
|
*
|
2005-01-12 00:36:16 +00:00
|
|
|
* The script then print a list of wgAllMessagesXX keys that aren't localised, a
|
|
|
|
|
* percentage of messages correctly localised and the number of messages to be
|
|
|
|
|
* translated.
|
2006-01-07 13:09:30 +00:00
|
|
|
*
|
2004-09-03 20:33:01 +00:00
|
|
|
* @package MediaWiki
|
|
|
|
|
* @subpackage Maintenance
|
2004-09-03 18:52:58 +00:00
|
|
|
*/
|
2004-04-24 08:30:26 +00:00
|
|
|
|
2004-09-03 18:52:58 +00:00
|
|
|
/** This script run from the commandline */
|
2005-07-06 16:27:15 +00:00
|
|
|
require_once( 'parserTests.inc' );
|
2005-01-12 00:36:16 +00:00
|
|
|
require_once( 'commandLine.inc' );
|
2004-04-24 08:30:26 +00:00
|
|
|
|
2006-01-14 02:49:43 +00:00
|
|
|
if( isset($options['help']) ) { usage(); wfDie(); }
|
2005-07-06 16:27:15 +00:00
|
|
|
|
2005-01-12 00:36:16 +00:00
|
|
|
$wgLanguageCode = ucfirstlcrest($wgLanguageCode);
|
2005-01-30 17:12:34 +00:00
|
|
|
/** Language messages we will use as reference. By default 'en' */
|
|
|
|
|
$referenceMessages = $wgAllMessagesEn;
|
2005-01-31 01:55:02 +00:00
|
|
|
$referenceLanguage = 'En';
|
|
|
|
|
$referenceFilename = 'Language'.$referenceLanguage.'.php';
|
2006-01-07 13:09:30 +00:00
|
|
|
/** Language messages we will test. */
|
2005-01-30 17:12:34 +00:00
|
|
|
$testMessages = array();
|
|
|
|
|
$testLanguage = '';
|
|
|
|
|
/** whereas we use an external language file */
|
|
|
|
|
$externalRef = false;
|
2004-04-24 12:34:10 +00:00
|
|
|
|
2005-01-12 00:36:16 +00:00
|
|
|
# FUNCTIONS
|
2005-01-30 17:12:34 +00:00
|
|
|
/** @todo more informations !! */
|
|
|
|
|
function usage() {
|
2005-07-06 16:27:15 +00:00
|
|
|
echo 'php DiffLanguage.php [lang [file]] [--color=(yes|no|light)]'."\n";
|
2005-01-30 17:12:34 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-12 00:36:16 +00:00
|
|
|
/** Return a given string with first letter upper case, the rest lowercase */
|
|
|
|
|
function ucfirstlcrest($string) {
|
|
|
|
|
return strtoupper(substr($string,0,1)).strtolower(substr($string,1));
|
|
|
|
|
}
|
2004-09-17 15:56:28 +00:00
|
|
|
|
2005-01-30 17:12:34 +00:00
|
|
|
/**
|
|
|
|
|
* Return a $wgAllmessages array shipped in MediaWiki
|
|
|
|
|
* @param string $languageCode Formated language code
|
|
|
|
|
* @return array The MediaWiki default $wgAllMessages array requested
|
|
|
|
|
*/
|
|
|
|
|
function getMediawikiMessages($languageCode = 'En') {
|
|
|
|
|
|
|
|
|
|
$foo = "wgAllMessages$languageCode";
|
2005-08-25 00:49:30 +00:00
|
|
|
global $$foo, $wgSkinNamesEn;
|
2004-09-17 15:56:28 +00:00
|
|
|
|
2005-01-30 17:12:34 +00:00
|
|
|
// it might already be loaded in LocalSettings.php
|
|
|
|
|
if(!isset($$foo)) {
|
|
|
|
|
global $IP;
|
|
|
|
|
$langFile = $IP.'/languages/Language'.$languageCode.'.php';
|
|
|
|
|
if (file_exists( $langFile ) ) {
|
|
|
|
|
print "Including $langFile\n";
|
2005-07-06 16:27:15 +00:00
|
|
|
global $wgNamespaceNamesEn;
|
2005-01-30 17:12:34 +00:00
|
|
|
include($langFile);
|
2006-01-14 02:49:43 +00:00
|
|
|
} else wfDie("ERROR: The file $langFile does not exist !\n");
|
2005-01-30 17:12:34 +00:00
|
|
|
}
|
|
|
|
|
return $$foo;
|
2004-04-24 08:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-30 17:12:34 +00:00
|
|
|
/**
|
|
|
|
|
* Return a $wgAllmessages array in a given file. Language of the array
|
|
|
|
|
* need to be given cause we can not detect which language it provides
|
|
|
|
|
* @param string $filename Filename of the file containing a message array
|
|
|
|
|
* @param string $languageCode Language of the external array
|
|
|
|
|
* @return array A $wgAllMessages array from an external file.
|
|
|
|
|
*/
|
|
|
|
|
function getExternalMessages($filename, $languageCode) {
|
|
|
|
|
print "Including external file $filename.\n";
|
|
|
|
|
include($filename);
|
|
|
|
|
$foo = "wgAllMessages$languageCode";
|
|
|
|
|
return $$foo;
|
|
|
|
|
}
|
2004-04-24 08:30:26 +00:00
|
|
|
|
2005-01-12 00:36:16 +00:00
|
|
|
# MAIN ENTRY
|
|
|
|
|
if ( isset($args[0]) ) {
|
|
|
|
|
$lang = ucfirstlcrest($args[0],1);
|
2004-04-24 08:30:26 +00:00
|
|
|
|
2005-01-30 17:12:34 +00:00
|
|
|
// eventually against another language file we will use as reference instead
|
|
|
|
|
// of the default english language.
|
|
|
|
|
if( isset($args[1])) {
|
|
|
|
|
// we assume the external file contain an array of messages for the
|
|
|
|
|
// lang we are testing
|
|
|
|
|
$referenceMessages = getExternalMessages( $args[1], $lang );
|
|
|
|
|
$referenceLanguage = $lang;
|
2005-01-31 01:55:02 +00:00
|
|
|
$referenceFilename = $args[1];
|
2005-01-30 17:12:34 +00:00
|
|
|
$externalRef = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Load datas from MediaWiki
|
|
|
|
|
$testMessages = getMediawikiMessages($lang);
|
2006-01-07 13:31:29 +00:00
|
|
|
$testLanguage = $lang;
|
2005-01-30 17:12:34 +00:00
|
|
|
} else {
|
|
|
|
|
usage();
|
2006-01-14 02:49:43 +00:00
|
|
|
wfDie();
|
2004-04-24 08:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
2005-07-06 16:27:15 +00:00
|
|
|
/** parsertest is used to do differences */
|
|
|
|
|
$myParserTest =& new ParserTest();
|
2004-04-24 08:30:26 +00:00
|
|
|
|
|
|
|
|
# Get all references messages and check if they exist in the tested language
|
|
|
|
|
$i = 0;
|
2005-01-30 17:12:34 +00:00
|
|
|
|
2005-07-06 16:27:15 +00:00
|
|
|
$msg = "MW Language{$testLanguage}.php against ";
|
2005-01-31 01:55:02 +00:00
|
|
|
if($externalRef) { $msg .= 'external file '; }
|
2005-01-30 17:12:34 +00:00
|
|
|
else { $msg .= 'internal file '; }
|
2005-01-31 01:55:02 +00:00
|
|
|
$msg .= $referenceFilename.' ('.$referenceLanguage."):\n----\n";
|
2005-01-30 17:12:34 +00:00
|
|
|
echo $msg;
|
2005-07-06 16:27:15 +00:00
|
|
|
|
|
|
|
|
// process messages
|
|
|
|
|
foreach($referenceMessages as $index => $ref)
|
2004-04-24 08:30:26 +00:00
|
|
|
{
|
2005-07-06 16:27:15 +00:00
|
|
|
// message is not localized
|
2005-01-30 17:12:34 +00:00
|
|
|
if(!(isset($testMessages[$index]))) {
|
2004-04-24 08:30:26 +00:00
|
|
|
$i++;
|
2005-07-06 16:27:15 +00:00
|
|
|
print "'$index' => \"$ref\",\n";
|
|
|
|
|
// Messages in the same language differs
|
|
|
|
|
} elseif( ($lang == $referenceLanguage) AND ($testMessages[$index] != $ref)) {
|
2005-08-15 18:11:09 +00:00
|
|
|
print "\n$index differs:\n";
|
2005-07-06 16:27:15 +00:00
|
|
|
print $myParserTest->quickDiff($testMessages[$index],$ref,'tested','reference');
|
2004-04-24 08:30:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
2005-07-06 16:27:15 +00:00
|
|
|
|
2005-01-30 17:52:34 +00:00
|
|
|
echo "\n----\n".$msg;
|
2005-01-30 17:12:34 +00:00
|
|
|
echo "$referenceLanguage language is complete at ".number_format((100 - $i/count($wgAllMessagesEn) * 100),2)."%\n";
|
2004-09-17 15:56:28 +00:00
|
|
|
echo "$i unlocalised messages of the ".count($wgAllMessagesEn)." messages available.\n";
|
2005-07-06 16:27:15 +00:00
|
|
|
?>
|