summaryrefslogtreecommitdiff
path: root/maintenance/language/rebuildLanguage.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2007-01-11 19:06:07 +0000
committerPierre Schmitz <pierre@archlinux.de>2007-01-11 19:06:07 +0000
commita58285fd06c8113c45377c655dd43cef6337e815 (patch)
treedfe31d3d12652352fe44890b4811eda0728faefb /maintenance/language/rebuildLanguage.php
parent20194986f6638233732ba1fc3e838f117d3cc9ea (diff)
Aktualisierung auf MediaWiki 1.9.0
Diffstat (limited to 'maintenance/language/rebuildLanguage.php')
-rw-r--r--maintenance/language/rebuildLanguage.php82
1 files changed, 82 insertions, 0 deletions
diff --git a/maintenance/language/rebuildLanguage.php b/maintenance/language/rebuildLanguage.php
new file mode 100644
index 00000000..1643d30b
--- /dev/null
+++ b/maintenance/language/rebuildLanguage.php
@@ -0,0 +1,82 @@
+<?php
+/**
+ * Rewrite the messages array in the files languages/messages/MessagesXX.php.
+ *
+ * @package MediaWiki
+ * @subpackage Maintenance
+ */
+
+require_once( dirname(__FILE__).'/../commandLine.inc' );
+require_once( 'languages.inc' );
+require_once( 'writeMessagesArray.inc' );
+
+/**
+ * Rewrite a messages array.
+ *
+ * @param $code The language code.
+ * @param $write Write to the messages file?
+ */
+function rebuildLanguage( $code, $write ) {
+ global $wgLanguages, $wg;
+
+ # Get messages
+ $messages = $wgLanguages->getMessages( $code );
+ $messages = $messages['all'];
+
+ # Rewrite messages array
+ $messagesText = writeMessagesArray( $messages, $code == 'en' );
+
+ # Write to the file
+ if ( $write ) {
+ $filename = Language::getMessagesFileName( $code );
+ $contents = file_get_contents( $filename );
+ if ( strpos( $contents, '$messages' ) !== false ) {
+ $new = explode( '$messages', $contents );
+ $new = $new[0];
+ $new .= $messagesText;
+ $new .= "\n?>\n";
+ file_put_contents( $filename, $new );
+ echo "Generated and wrote messages in language $code.\n";
+ }
+ } else {
+ echo "Generated messages in language $code.\n";
+ }
+}
+
+# Show help
+if ( isset( $options['help'] ) ) {
+ echo <<<END
+Run this script to rewrite the messages array in the files languages/messages/MessagesXX.php.
+Parameters:
+ * lang: Language code (default: the installation default language). You can also specify "all" to check all the languages.
+ * help: Show this help.
+Options:
+ * dry-run: Don't write the array to the file.
+
+END;
+ exit();
+}
+
+# Get the language code
+if ( isset( $options['lang'] ) ) {
+ $wgCode = $options['lang'];
+} else {
+ $wgCode = $wgContLang->getCode();
+}
+
+# Get the write options
+$wgWriteToFile = !isset( $options['dry-run'] );
+
+# Get language objects
+$wgLanguages = new languages();
+
+# Write all the language
+if ( $wgCode == 'all' ) {
+ foreach ( $wgLanguages->getLanguages() as $language ) {
+ rebuildLanguage( $language, $wgWriteToFile );
+ }
+} else {
+ rebuildLanguage( $wgCode, $wgWriteToFile );
+}
+
+?>