00001 <?php
00010 require_once( dirname(__FILE__).'/../commandLine.inc' );
00011 require_once( 'languages.inc' );
00012 require_once( 'writeMessagesArray.inc' );
00013
00024 function rebuildLanguage( $code, $write, $listUnknown, $removeUnknown, $removeDupes, $dupeMsgSource ) {
00025 global $wgLanguages;
00026 $messages = $wgLanguages->getMessages( $code );
00027 $messages = $messages['all'];
00028 if ($removeDupes) {
00029 $messages = removeDupes( $messages, $dupeMsgSource );
00030 }
00031 MessageWriter::writeMessagesToFile( $messages, $code, $write, $listUnknown, $removeUnknown );
00032 }
00033
00041 function removeDupes( $oldMsgArray, $dupeMsgSource ) {
00042 if (file_exists($dupeMsgSource)) {
00043 include($dupeMsgSource);
00044 if (!isset($dupeMessages)) {
00045 echo("There are no duplicated messages in the source file provided.");
00046 exit(1);
00047 }
00048 } else {
00049 echo ("The specified file $dupeMsgSource cannot be found.");
00050 exit(1);
00051 }
00052 $newMsgArray = $oldMsgArray;
00053 foreach ($oldMsgArray as $key => $value) {
00054 if ( array_key_exists( $key, $dupeMessages ) ) {
00055 unset($newMsgArray[$key]);
00056 }
00057 }
00058 return $newMsgArray;
00059 }
00060
00061 # Show help
00062 if ( isset( $options['help'] ) ) {
00063 echo <<<TEXT
00064 Run this script to rewrite the messages array in the files languages/messages/MessagesXX.php.
00065 Parameters:
00066 * lang: Language code (default: the installation default language). You can also specify "all" to check all the languages.
00067 * help: Show this help.
00068 Options:
00069 * dry-run: Do not write the array to the file.
00070 * no-unknown: Do not list the unknown messages.
00071 * remove-unknown: Remove unknown messages.
00072 * remove-duplicates: Remove duplicated messages based on a PHP source file.
00073
00074 TEXT;
00075 exit(1);
00076 }
00077
00078 # Get the language code
00079 if ( isset( $options['lang'] ) ) {
00080 $wgCode = $options['lang'];
00081 } else {
00082 $wgCode = $wgContLang->getCode();
00083 }
00084
00085 # Get the duplicate message source
00086 if ( isset( $options['remove-duplicates'] ) && ( strcmp( $options['remove-duplicates'], '' ) ) ) {
00087 $wgDupeMessageSource = $options['remove-duplicates'];
00088 } else {
00089 $wgDupeMessageSource = '';
00090 }
00091
00092 # Get the options
00093 $wgWriteToFile = !isset( $options['dry-run'] );
00094 $wgListUnknownMessages = !isset( $options['no-unknown'] );
00095 $wgRemoveUnknownMessages = isset( $options['remove-unknown'] );
00096 $wgRemoveDuplicateMessages = isset( $options['remove-duplicates'] );
00097
00098 # Get language objects
00099 $wgLanguages = new languages();
00100
00101 # Write all the language
00102 if ( $wgCode == 'all' ) {
00103 foreach ( $wgLanguages->getLanguages() as $language ) {
00104 rebuildLanguage( $language, $wgWriteToFile, $wgListUnknownMessages, $wgRemoveUnknownMessages, $wgRemoveDuplicateMessages, $wgDupeMessageSource );
00105 }
00106 } else {
00107 rebuildLanguage( $wgCode, $wgWriteToFile, $wgListUnknownMessages, $wgRemoveUnknownMessages, $wgRemoveDuplicateMessages, $wgDupeMessageSource );
00108 }