Index: trunk/extensions/Translate/Translate.php |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
13 | 13 | */ |
14 | 14 | |
15 | | -define( 'TRANSLATE_VERSION', '9 (2008-07-08:1)' ); |
| 15 | +define( 'TRANSLATE_VERSION', '9 (2008-07-13:1)' ); |
16 | 16 | |
17 | 17 | $wgExtensionCredits['specialpage'][] = array( |
18 | 18 | 'name' => 'Translate', |
— | — | @@ -25,6 +25,7 @@ |
26 | 26 | // Setup class autoloads |
27 | 27 | $dir = dirname(__FILE__) . '/'; |
28 | 28 | require_once( $dir . '_autoload.php' ); |
| 29 | +#require_once( $dir . 'MessageFunctions.php' ); |
29 | 30 | |
30 | 31 | $wgExtensionMessagesFiles['Translate'] = $dir . 'Translate.i18n.php'; |
31 | 32 | $wgExtensionAliasesFiles['Translate'] = $dir . 'Translate.alias.php'; |
Index: trunk/extensions/Translate/scripts/alias-export.php |
— | — | @@ -0,0 +1,84 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Script to export translations of one message group to file(s). |
| 5 | + * |
| 6 | + * @author Niklas Laxstrom |
| 7 | + * |
| 8 | + * @copyright Copyright © 2008, Niklas Laxström |
| 9 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 10 | + * @file |
| 11 | + */ |
| 12 | + |
| 13 | +$optionsWithArgs = array( 'lang', 'target', 'group' ); |
| 14 | +require( dirname(__FILE__) . '/cli.inc' ); |
| 15 | + |
| 16 | +function showUsage() { |
| 17 | + STDERR( <<<EOT |
| 18 | +Alias exporter. |
| 19 | + |
| 20 | +Usage: php aliasexport.php [options...] |
| 21 | + |
| 22 | +Options: |
| 23 | + --target Target directory for exported files |
| 24 | + --lang Comma separated list of language codes |
| 25 | + --group Group id |
| 26 | +EOT |
| 27 | +); |
| 28 | + exit( 1 ); |
| 29 | +} |
| 30 | + |
| 31 | +if ( isset($options['help']) || $args === 1 ) { |
| 32 | + showUsage(); |
| 33 | +} |
| 34 | + |
| 35 | +if ( !isset($options['target']) ) { |
| 36 | + STDERR( "You need to specify target directory" ); |
| 37 | + exit(1); |
| 38 | +} |
| 39 | +if ( !isset($options['lang']) ) { |
| 40 | + STDERR( "You need to specify languages to export" ); |
| 41 | + exit(1); |
| 42 | +} |
| 43 | + |
| 44 | +if ( !is_writable( $options['target'] ) ) { |
| 45 | + STDERR( "Target directory is not writable" ); |
| 46 | + exit(1); |
| 47 | +} |
| 48 | + |
| 49 | +$langs = array_map( 'trim', explode( ',', $options['lang'] ) ); |
| 50 | + |
| 51 | + |
| 52 | +if ( !file_exists(TRANSLATE_ALIASFILE) || !is_readable(TRANSLATE_ALIASFILE) ) { |
| 53 | + STDERR( "Alias file not defined" ); |
| 54 | + exit(1); |
| 55 | +} |
| 56 | + |
| 57 | +$defines = file_get_contents( TRANSLATE_ALIASFILE ); |
| 58 | +$sections = preg_split( "/\n\n/", $defines, -1, PREG_SPLIT_NO_EMPTY ); |
| 59 | + |
| 60 | +foreach ( $sections as $section ) { |
| 61 | + $lines = array_map( 'trim', preg_split( "/\n/", $section ) ); |
| 62 | + $name = ''; |
| 63 | + foreach ( $lines as $line ) { |
| 64 | + if ( $line === '' ) continue; |
| 65 | + if ( strpos( $line, '=' ) === false ) { |
| 66 | + if ( $name === '' ) { |
| 67 | + $name = $line; |
| 68 | + } else { |
| 69 | + throw new MWException( "Trying to define name twice: " . $line ); |
| 70 | + } |
| 71 | + } else { |
| 72 | + list( $key, $value ) = array_map( 'trim', explode( '=', $line, 2 ) ); |
| 73 | + if ( $key === 'file' ) $file = $value; |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + if ( $name !== '' ) { |
| 78 | + // Fake a group |
| 79 | + $group = new AliasMessageGroup( $name ); |
| 80 | + $group->setMessageFile( $file ); |
| 81 | + $group->setVariableName( 'aliases' ); |
| 82 | + $writer = $group->getWriter(); |
| 83 | + $writer->fileExport( $langs, $options['target'] ); |
| 84 | + } |
| 85 | +} |
Property changes on: trunk/extensions/Translate/scripts/alias-export.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 86 | + native |
Index: trunk/extensions/Translate/_autoload.php |
— | — | @@ -19,6 +19,7 @@ |
20 | 20 | |
21 | 21 | $wgAutoloadClasses['MessageChecks'] = $dir . 'MessageChecks.php'; |
22 | 22 | $wgAutoloadClasses['MessageGroups'] = $dir . 'MessageGroups.php'; |
| 23 | +$wgAutoloadClasses['AliasMessageGroup'] = $dir . 'MessageGroups.php'; |
23 | 24 | |
24 | 25 | $wgAutoloadClasses['MessageCollection'] = $dir . 'Message.php'; |
25 | 26 | $wgAutoloadClasses['TMessage'] = $dir . 'Message.php'; |
Index: trunk/extensions/Translate/README |
— | — | @@ -34,6 +34,7 @@ |
35 | 35 | |
36 | 36 | == Changes in version 10 == |
37 | 37 | |
| 38 | +* 2008-07-13:1 experimental alias-export for extensions |
38 | 39 | * 2008-07-08:1 simple edit stats with phplot |
39 | 40 | * 2008-07-05:1 fuzzy.php was ignoring the namespace |
40 | 41 | * 2008-07-04:2 |
Index: trunk/extensions/Translate/MessageGroups.php |
— | — | @@ -371,6 +371,57 @@ |
372 | 372 | } |
373 | 373 | } |
374 | 374 | |
| 375 | +class AliasMessageGroup extends ExtensionMessageGroup { |
| 376 | + |
| 377 | + public function fillCollection( MessageCollection $collection ) { |
| 378 | + $this->fill( $collection ); |
| 379 | + $this->fillContents( $collection ); |
| 380 | + } |
| 381 | + |
| 382 | + |
| 383 | + function fill( MessageCollection $messages ) { |
| 384 | + $cache = $this->load( $messages->code ); |
| 385 | + foreach ( $messages->keys() as $key ) { |
| 386 | + if ( isset($cache[$key]) ) { |
| 387 | + if ( is_array($cache[$key]) ) { |
| 388 | + $messages[$key]->infile = implode( ',', $cache[$key] ); |
| 389 | + } else { |
| 390 | + $messages[$key]->infile = $cache[$key]; |
| 391 | + } |
| 392 | + } |
| 393 | + } |
| 394 | + } |
| 395 | + |
| 396 | + public function fillContents( MessageCollection $collection ) { |
| 397 | + $data = TranslateUtils::getMessageContent( 'sp-translate-data-SpecialPageAliases', $collection->code ); |
| 398 | + |
| 399 | + if ( !$data ) return; |
| 400 | + |
| 401 | + $lines = array_map( 'trim', explode( "\n", $data ) ); |
| 402 | + $array = array(); |
| 403 | + foreach ( $lines as $line ) { |
| 404 | + if ( $line === '' || $line[0] === '#' || $line[0] === '<' ) continue; |
| 405 | + if ( strpos( $line, '=' ) === false ) continue; |
| 406 | + |
| 407 | + list( $name, $values ) = array_map( 'trim', explode( '=', $line, 2 ) ); |
| 408 | + if ( $name === '' || $values === '' ) continue; |
| 409 | + |
| 410 | + if ( isset($collection[$name]) ) { |
| 411 | + $collection[$name]->database = $values; |
| 412 | + } |
| 413 | + } |
| 414 | + |
| 415 | + } |
| 416 | + |
| 417 | + public function getWriter() { |
| 418 | + $writer = new WikiExtensionFormatWriter( $this ); |
| 419 | + $writer->variableName = $this->getVariableName(); |
| 420 | + $writer->commaToArray = true; |
| 421 | + return $writer; |
| 422 | + } |
| 423 | + |
| 424 | +} |
| 425 | + |
375 | 426 | class CoreMostUsedMessageGroup extends CoreMessageGroup { |
376 | 427 | protected $label = 'MediaWiki messages (most used)'; |
377 | 428 | protected $id = 'core-mostused'; |
Index: trunk/extensions/Translate/ffs/Wiki.php |
— | — | @@ -58,6 +58,7 @@ |
59 | 59 | } |
60 | 60 | |
61 | 61 | class WikiFormatWriter extends SimpleFormatWriter { |
| 62 | + public $commaToArray = false; |
62 | 63 | |
63 | 64 | public function makeHeader( $handle, $code ) { |
64 | 65 | list( $name, $native ) = $this->getLanguageNames($code); |
— | — | @@ -156,6 +157,19 @@ |
157 | 158 | fwrite( $handle, str_repeat( ' ', $pad - strlen($key) ) ); |
158 | 159 | fwrite( $handle, ' => ' ); |
159 | 160 | |
| 161 | + if ( $this->commaToArray ) { |
| 162 | + fwrite( $handle, 'array( ' ); |
| 163 | + $values = array_map( 'trim', explode( ',', $value ) ); |
| 164 | + $values = array_map( array( __CLASS__, 'quote' ), $values ); |
| 165 | + fwrite( $handle, implode( ', ', $values ) ); |
| 166 | + fwrite( $handle, " ),\n" ); |
| 167 | + } else { |
| 168 | + fwrite( $handle, self::quote($value) ); |
| 169 | + fwrite( $handle, ",\n" ); |
| 170 | + } |
| 171 | + } |
| 172 | + |
| 173 | + public static function quote( $value ) { |
160 | 174 | # Check for the appropriate apostrophe and add the value |
161 | 175 | # Quote \ here, because it needs always escaping |
162 | 176 | $value = addcslashes( $value, '\\' ); |
— | — | @@ -188,7 +202,6 @@ |
189 | 203 | } |
190 | 204 | } |
191 | 205 | |
192 | | - fwrite( $handle, $quote . $value . $quote ); |
193 | | - fwrite( $handle, ",\n" ); |
| 206 | + return $quote . $value . $quote; |
194 | 207 | } |
195 | 208 | } |