r72543 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72542‎ | r72543 | r72544 >
Date:18:10, 7 September 2010
Author:roberthl
Status:deferred
Tags:
Comment:
Translate:
- Add 'magic' functionality to magic-export-2.php.
- Note: Still need to improve code quality, but both 'special' and 'magic' export now seems to work.
Modified paths:
  • /trunk/extensions/Translate/scripts/magic-export-2.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/scripts/magic-export-2.php
@@ -71,9 +71,18 @@
7272 if ( !file_exists( $file ) ) continue;
7373
7474 include( $file );
75 - if( !isset( $aliases ) ) continue;
76 - $messagesOld[$group->getId()] = $aliases;
77 - unset( $aliases );
 75+ switch( $type ) {
 76+ case 'special':
 77+ if( !isset( $aliases ) ) continue;
 78+ $messagesOld[$group->getId()] = $aliases;
 79+ unset( $aliases );
 80+ break;
 81+ case 'magic':
 82+ if( !isset( $magicWords ) ) continue;
 83+ $messagesOld[$group->getId()] = $magicWords;
 84+ unset( $magicWords );
 85+ break;
 86+ }
7887
7988 $handles[$group->getId()] = fopen( $options['target'] . '/' . $filename, 'w' );
8089
@@ -83,7 +92,7 @@
8493 // Write header.
8594 foreach( $handles as $handle ) {
8695 if( $type === 'special' ) {
87 - fwrite( $handle, <<<EOT
 96+ fwrite( $handle, <<<EOT
8897 <?php
8998
9099 /**
@@ -97,6 +106,18 @@
98107 EOT
99108 );
100109 } else {
 110+ fwrite( $handle, <<<EOT
 111+
 112+/**
 113+ * Internationalisation file for magic
 114+ *
 115+ * @file
 116+ * @ingroup Extensions
 117+ */
 118+
 119+\$magicWords = array();
 120+EOT
 121+ );
101122 }
102123 }
103124
@@ -150,13 +171,36 @@
151172 }
152173 }
153174 if( count( $messagesOut ) > 0 ) {
154 - $out = "\n\n/** {$namesEn[$l]} ({$namesNative[$l]}) */\n\$aliases['{$l}'] = array(\n";
 175+ switch( $options['type'] ) {
 176+ case 'special':
 177+ $out = "\n\n/** {$namesEn[$l]} ({$namesNative[$l]}) */\n\$aliases['{$l}'] = array(\n";
 178+ break;
 179+ case 'magic':
 180+ $out = "\n\n/** {$namesEn[$l]} ({$namesNative[$l]}) */\n\$magicWords['{$l}'] = array(\n";
 181+ break;
 182+ }
155183 foreach( $messagesOut as $key => $translations ) {
156184 foreach( $translations as $id => $translation ) {
157185 $translations[$id] = addslashes( $translation );
 186+ if( $options['type'] === 'magic' ) {
 187+ if( $translation === '0' ) {
 188+ unset( $translations[$id] );
 189+ }
 190+ }
158191 }
159192 $translations = implode( "', '", $translations );
160 - $out .= "\t'$key' => array( '$translations' ),\n";
 193+ switch( $options['type'] ) {
 194+ case 'special':
 195+ $out .= "\t'$key' => array( '$translations' ),\n";
 196+ break;
 197+ case 'magic':
 198+ if( $messagesOld['ext-babel']['en'][$key][0] === 0 ) {
 199+ $out .= "\t'$key' => array( 0, '$translations' ),\n";
 200+ } else {
 201+ $out .= "\t'$key' => array( '$translations' ),\n";
 202+ }
 203+ break;
 204+ }
161205 }
162206 $out .= ");";
163207 fwrite( $handle, $out );

Status & tagging log