3 * Rewrite the messages array in the files languages/messages/MessagesXX.php.
5 * @addtogroup Maintenance
8 require_once( dirname(__FILE__
).'/../commandLine.inc' );
9 require_once( 'languages.inc' );
10 require_once( 'writeMessagesArray.inc' );
13 * Rewrite a messages array.
15 * @param $code The language code.
16 * @param $write Write to the messages file?
18 function rebuildLanguage( $code, $write ) {
22 $messages = $wgLanguages->getMessages( $code );
23 $messages = $messages['all'];
25 # Rewrite messages array
26 $messagesText = writeMessagesArray( $messages, $code == 'en' );
29 $filename = Language
::getMessagesFileName( $code );
30 $contents = file_get_contents( $filename );
31 if ( strpos( $contents, '$messages' ) !== false ) {
32 $contents = explode( '$messages', $contents );
33 if ( $messagesText . "\n?>\n" == '$messages' . $contents[1] ) {
34 echo "Generated messages for language $code. Same to the current file.\n";
38 $new .= $messagesText;
40 file_put_contents( $filename, $new );
41 echo "Generated and wrote messages for language $code.\n";
43 echo "Generated messages for language $code. Please run the script again (without the parameter \"dry-run\") to write the array to the file.\n";
47 echo "Generated messages for language $code. There seems to be no messages array in the file.\n";
52 if ( isset( $options['help'] ) ) {
54 Run this script to rewrite the messages array in the files languages/messages/MessagesXX.php.
56 * lang: Language code (default: the installation default language). You can also specify "all" to check all the languages.
57 * help: Show this help.
59 * dry-run: Don't write the array to the file.
65 # Get the language code
66 if ( isset( $options['lang'] ) ) {
67 $wgCode = $options['lang'];
69 $wgCode = $wgContLang->getCode();
72 # Get the write options
73 $wgWriteToFile = !isset( $options['dry-run'] );
75 # Get language objects
76 $wgLanguages = new languages();
78 # Write all the language
79 if ( $wgCode == 'all' ) {
80 foreach ( $wgLanguages->getLanguages() as $language ) {
81 rebuildLanguage( $language, $wgWriteToFile );
84 rebuildLanguage( $wgCode, $wgWriteToFile );