* move checkLanguage() in its own file (still using globals though).
* adapt Languages class so it can be overriden (s/private/protected/)
FIXME: lack documentation
--- /dev/null
+<?php
+/**
+ * Copyright (C) 2007 Ashar Voultoiz <hashar@altern.org>
+ *
+ * Based on dumpBackup:
+ * Copyright (C) 2005 Brion Vibber <brion@pobox.com>
+ *
+ * http://www.mediawiki.org
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ */
+
+#
+# Lacking documentation. An example is:
+# php checkExtensioni18n.php /opt/mw/extensions/CentralAuth/CentralAuth.i18n.php wgCentralAuthMessages
+#
+
+require_once( dirname(__FILE__).'/../commandLine.inc' );
+require_once( 'languages.inc' );
+require_once( 'checkLanguage.inc' );
+
+class extensionLanguages extends languages {
+ private $mExt18nFilename, $mExtArrayName ;
+ private $mExtArray;
+
+ function __construct( $ext18nFilename, $extArrayName ) {
+ $exif = false;
+ $this->mExt18nFilename = $ext18nFilename;
+ $this->mExtArrayName = $extArrayName;
+
+ $this->mIgnoredMessages = array() ;
+ $this->mOptionalMessages = array() ;
+
+ if ( file_exists( $this->mExt18nFilename ) ) {
+ require_once( $this->mExt18nFilename );
+ $this->mExtArray = ${$this->mExtArrayName} ;
+ $this->mLanguages = array_keys( $this->mExtArray );
+ } else {
+ wfDie( "File $this->mExt18nFilename not found\n" );
+ }
+ }
+
+ protected function loadRawMessages( $code ) {
+ if ( isset( $this->mRawMessages[$code] ) ) {
+ return;
+ }
+ if( isset( $this->mExtArray[$code] ) ) {
+ $this->mRawMessages[$code] = $this->mExtArray[$code] ;
+ } else {
+ $this->mRawMessages[$code] = array();
+ }
+ }
+
+ public function getLanguages() {
+ return $this->mLanguages;
+ }
+}
+
+
+function usage() {
+// Usage
+print <<<END
+Usage: php checkExtensioni18n.php <filename> <arrayname>
+
+
+END;
+die;
+}
+
+// Check arguments
+if ( isset( $argv[0] ) ) {
+
+ if (file_exists( $argv[0] ) ) {
+ $filename = $argv[0];
+ } else {
+ print "Unable to open file '{$argv[0]}'\n";
+ usage();
+ }
+
+ if ( isset( $argv[1] ) ) {
+ $arrayname = $argv[1];
+ } else {
+ print "You must give an array name to be checked\n";
+ usage();
+ }
+} else {
+ usage();
+}
+
+$extLanguages = new extensionLanguages($filename, $arrayname);
+
+// Stuff needed by the checkLanguage routine (globals)
+$wgGeneralMessages = $extLanguages->getGeneralMessages();
+$wgRequiredMessagesNumber = count( $wgGeneralMessages['required'] );
+$wgDisplayLevel = 2;
+$wgChecks = array( 'untranslated', 'obsolete', 'variables', 'empty', 'whitespace', 'xhtml', 'chars' );
+
+foreach( $extLanguages->getLanguages() as $lang ) {
+ if( $lang == 'en' ) {
+ print "Skipped english language\n";
+ continue;
+ }
+ checkLanguage( $extLanguages, $lang );
+/*
+ print "== $lang ==\n";
+ print count($ext->getUntranslatedMessages( $lang ) ) . "\n";
+ print count($ext->getEmptyMessages( $lang ) ) . "\n";
+*/
+}
+
+?>
--- /dev/null
+<?php
+/**
+ * Check a language.
+ *
+ * @todo Stop with globals.
+ * @param $code The language code.
+ */
+function checkLanguage( $wgLanguages, $code ) {
+ global $wgGeneralMessages, $wgRequiredMessagesNumber, $wgDisplayLevel, $wgLinks, $wgWikiLanguage, $wgChecks;
+
+ # Get messages
+ $messages = $wgLanguages->getMessages( $code );
+ $messagesNumber = count( $messages['translated'] );
+
+ # Skip the checks if specified
+ if ( $wgDisplayLevel == 0 ) {
+ return;
+ }
+
+ # Untranslated messages
+ if ( in_array( 'untranslated', $wgChecks ) ) {
+ $untranslatedMessages = $wgLanguages->getUntranslatedMessages( $code );
+ $untranslatedMessagesNumber = count( $untranslatedMessages );
+ $wgLanguages->outputMessagesList( $untranslatedMessages, $code, "\n$untranslatedMessagesNumber messages of $wgRequiredMessagesNumber are not translated to $code, but exist in en:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
+ }
+
+ # Duplicate messages
+ if ( in_array( 'duplicate', $wgChecks ) ) {
+ $duplicateMessages = $wgLanguages->getDuplicateMessages( $code );
+ $duplicateMessagesNumber = count( $duplicateMessages );
+ $wgLanguages->outputMessagesList( $duplicateMessages, $code, "\n$duplicateMessagesNumber messages of $messagesNumber are translated the same in en and $code:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
+ }
+
+ # Obsolete messages
+ if ( in_array( 'obsolete', $wgChecks ) ) {
+ $obsoleteMessages = $messages['obsolete'];
+ $obsoleteMessagesNumber = count( $obsoleteMessages );
+ $wgLanguages->outputMessagesList( $obsoleteMessages, $code, "\n$obsoleteMessagesNumber messages of $messagesNumber are not exist in en (or are in the ignored list), but still exist in $code:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
+ }
+
+ # Messages without variables
+ if ( in_array( 'variables', $wgChecks ) ) {
+ $messagesWithoutVariables = $wgLanguages->getMessagesWithoutVariables( $code );
+ $messagesWithoutVariablesNumber = count( $messagesWithoutVariables );
+ $wgLanguages->outputMessagesList( $messagesWithoutVariables, $code, "\n$messagesWithoutVariablesNumber messages of $messagesNumber in $code don't use some variables while en uses them:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
+ }
+
+ # Empty messages
+ if ( in_array( 'empty', $wgChecks ) ) {
+ $emptyMessages = $wgLanguages->getEmptyMessages( $code );
+ $emptyMessagesNumber = count( $emptyMessages );
+ $wgLanguages->outputMessagesList( $emptyMessages, $code, "\n$emptyMessagesNumber messages of $messagesNumber in $code are empty or -:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
+ }
+
+ # Messages with whitespace
+ if ( in_array( 'whitespace', $wgChecks ) ) {
+ $messagesWithWhitespace = $wgLanguages->getMessagesWithWhitespace( $code );
+ $messagesWithWhitespaceNumber = count( $messagesWithWhitespace );
+ $wgLanguages->outputMessagesList( $messagesWithWhitespace, $code, "\n$messagesWithWhitespaceNumber messages of $messagesNumber in $code have a trailing whitespace:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
+ }
+
+ # Non-XHTML messages
+ if ( in_array( 'xhtml', $wgChecks ) ) {
+ $nonXHTMLMessages = $wgLanguages->getNonXHTMLMessages( $code );
+ $nonXHTMLMessagesNumber = count( $nonXHTMLMessages );
+ $wgLanguages->outputMessagesList( $nonXHTMLMessages, $code, "\n$nonXHTMLMessagesNumber messages of $messagesNumber in $code are not well-formed XHTML:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
+ }
+
+ # Messages with wrong characters
+ if ( in_array( 'chars', $wgChecks ) ) {
+ $messagesWithWrongChars = $wgLanguages->getMessagesWithWrongChars( $code );
+ $messagesWithWrongCharsNumber = count( $messagesWithWrongChars );
+ $wgLanguages->outputMessagesList( $messagesWithWrongChars, $code, "\n$messagesWithWrongCharsNumber messages of $messagesNumber in $code include hidden chars which should not be used in the messages:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
+ }
+}
+?>
require_once( dirname(__FILE__).'/../commandLine.inc' );
require_once( 'languages.inc' );
-
-/**
- * Check a language.
- *
- * @param $code The language code.
- */
-function checkLanguage( $code ) {
- global $wgLanguages, $wgGeneralMessages, $wgRequiredMessagesNumber, $wgDisplayLevel, $wgLinks, $wgWikiLanguage, $wgChecks;
-
- # Get messages
- $messages = $wgLanguages->getMessages( $code );
- $messagesNumber = count( $messages['translated'] );
-
- # Skip the checks if specified
- if ( $wgDisplayLevel == 0 ) {
- return;
- }
-
- # Untranslated messages
- if ( in_array( 'untranslated', $wgChecks ) ) {
- $untranslatedMessages = $wgLanguages->getUntranslatedMessages( $code );
- $untranslatedMessagesNumber = count( $untranslatedMessages );
- $wgLanguages->outputMessagesList( $untranslatedMessages, $code, "\n$untranslatedMessagesNumber messages of $wgRequiredMessagesNumber are not translated to $code, but exist in en:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
- }
-
- # Duplicate messages
- if ( in_array( 'duplicate', $wgChecks ) ) {
- $duplicateMessages = $wgLanguages->getDuplicateMessages( $code );
- $duplicateMessagesNumber = count( $duplicateMessages );
- $wgLanguages->outputMessagesList( $duplicateMessages, $code, "\n$duplicateMessagesNumber messages of $messagesNumber are translated the same in en and $code:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
- }
-
- # Obsolete messages
- if ( in_array( 'obsolete', $wgChecks ) ) {
- $obsoleteMessages = $messages['obsolete'];
- $obsoleteMessagesNumber = count( $obsoleteMessages );
- $wgLanguages->outputMessagesList( $obsoleteMessages, $code, "\n$obsoleteMessagesNumber messages of $messagesNumber are not exist in en (or are in the ignored list), but still exist in $code:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
- }
-
- # Messages without variables
- if ( in_array( 'variables', $wgChecks ) ) {
- $messagesWithoutVariables = $wgLanguages->getMessagesWithoutVariables( $code );
- $messagesWithoutVariablesNumber = count( $messagesWithoutVariables );
- $wgLanguages->outputMessagesList( $messagesWithoutVariables, $code, "\n$messagesWithoutVariablesNumber messages of $messagesNumber in $code don't use some variables while en uses them:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
- }
-
- # Empty messages
- if ( in_array( 'empty', $wgChecks ) ) {
- $emptyMessages = $wgLanguages->getEmptyMessages( $code );
- $emptyMessagesNumber = count( $emptyMessages );
- $wgLanguages->outputMessagesList( $emptyMessages, $code, "\n$emptyMessagesNumber messages of $messagesNumber in $code are empty or -:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
- }
-
- # Messages with whitespace
- if ( in_array( 'whitespace', $wgChecks ) ) {
- $messagesWithWhitespace = $wgLanguages->getMessagesWithWhitespace( $code );
- $messagesWithWhitespaceNumber = count( $messagesWithWhitespace );
- $wgLanguages->outputMessagesList( $messagesWithWhitespace, $code, "\n$messagesWithWhitespaceNumber messages of $messagesNumber in $code have a trailing whitespace:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
- }
-
- # Non-XHTML messages
- if ( in_array( 'xhtml', $wgChecks ) ) {
- $nonXHTMLMessages = $wgLanguages->getNonXHTMLMessages( $code );
- $nonXHTMLMessagesNumber = count( $nonXHTMLMessages );
- $wgLanguages->outputMessagesList( $nonXHTMLMessages, $code, "\n$nonXHTMLMessagesNumber messages of $messagesNumber in $code are not well-formed XHTML:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
- }
-
- # Messages with wrong characters
- if ( in_array( 'chars', $wgChecks ) ) {
- $messagesWithWrongChars = $wgLanguages->getMessagesWithWrongChars( $code );
- $messagesWithWrongCharsNumber = count( $messagesWithWrongChars );
- $wgLanguages->outputMessagesList( $messagesWithWrongChars, $code, "\n$messagesWithWrongCharsNumber messages of $messagesNumber in $code include hidden chars which should not be used in the messages:", $wgDisplayLevel, $wgLinks, $wgWikiLanguage );
- }
-}
+require_once( 'checkLanguage.inc' );
# Show help
if ( isset( $options['help'] ) ) {
if ( $wgCode == 'all' ) {
foreach ( $wgLanguages->getLanguages() as $language ) {
if ( $language != 'en' && $language != 'enRTL' ) {
- checkLanguage( $language );
+ checkLanguage( $wgLanguages, $language );
}
}
} else {
} else if ( $wgCode == 'enRTL' ) {
echo "Current selected language is RTL English, which cannot be checked.\n";
} else {
- checkLanguage( $wgCode );
+ checkLanguage( $wgLanguages, $wgCode );
}
}
require_once( 'messageTypes.inc' );
class languages {
- private $mLanguages; # List of languages
- private $mRawMessages; # Raw list of the messages in each language
- private $mMessages; # Messages in each language (except for English), divided to groups
- private $mGeneralMessages; # General messages in English, divided to groups
- private $mIgnoredMessages; # All the messages which should be exist only in the English file
- private $mOptionalMessages; # All the messages which may be translated or not, depending on the language
+ protected $mLanguages; # List of languages
+ protected $mRawMessages; # Raw list of the messages in each language
+ protected $mMessages; # Messages in each language (except for English), divided to groups
+ protected $mGeneralMessages; # General messages in English, divided to groups
+ protected $mIgnoredMessages; # All the messages which should be exist only in the English file
+ protected $mOptionalMessages; # All the messages which may be translated or not, depending on the language
/**
* Load the list of languages: all the Messages*.php
*
* @param $code The langauge code.
*/
- private function loadRawMessages( $code ) {
+ protected function loadRawMessages( $code ) {
if ( isset( $this->mRawMessages[$code] ) ) {
return;
}