r53755 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53754‎ | r53755 | r53756 >
Date:19:11, 25 July 2009
Author:nikerabbit
Status:ok
Tags:
Comment:
(one kind of) Yaml file format support
Modified paths:
  • /trunk/extensions/Translate/FFS.php (modified) (history)
  • /trunk/extensions/Translate/_autoload.php (modified) (history)
  • /trunk/extensions/Translate/spyc/loader.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/FFS.php
@@ -371,3 +371,72 @@
372372 }
373373
374374 }
 375+
 376+class YamlFFS extends SimpleFFS {
 377+
 378+ //
 379+ // READ
 380+ //
 381+
 382+ public function readFromVariable( $data ) {
 383+ $authors = $messages = array();
 384+
 385+ # Authors first
 386+ $matches = array();
 387+ preg_match_all( '/^#\s*Author:\s*(.*)$/m', $data, $matches );
 388+ $authors = $matches[1];
 389+
 390+ # Then messages
 391+ $messages = TranslateSpyc::loadString( $data );
 392+ $messages = $this->group->getMangler()->mangle( $messages );
 393+
 394+ return array(
 395+ 'AUTHORS' => $authors,
 396+ 'MESSAGES' => $messages,
 397+ );
 398+ }
 399+
 400+ //
 401+ // WRITE
 402+ //
 403+
 404+ protected function writeReal( MessageCollection $collection ) {
 405+ $output = $this->doHeader( $collection );
 406+ $output .= $this->doAuthors( $collection );
 407+
 408+ $mangler = $this->group->getMangler();
 409+
 410+ $messages = array();
 411+ foreach ( $collection as $key => $m ) {
 412+ $key = $mangler->unmangle( $key );
 413+ $value = $m->translation();
 414+ $value = str_replace( TRANSLATE_FUZZY, '', $value );
 415+ if ( $value === '' ) continue;
 416+
 417+ $messages[$key] = $value;
 418+ }
 419+ $output .= TranslateSpyc::dump( $messages );
 420+ return $output;
 421+ }
 422+
 423+ protected function doHeader( MessageCollection $collection ) {
 424+ global $wgSitename;
 425+ $code = $collection->code;
 426+ $name = TranslateUtils::getLanguageName( $code );
 427+ $native = TranslateUtils::getLanguageName( $code, true );
 428+ $output = "# Messages for $name ($native)\n";
 429+ $output .= "# Exported from $wgSitename\n";
 430+ return $output;
 431+ }
 432+
 433+ protected function doAuthors( MessageCollection $collection ) {
 434+ $output = '';
 435+ $authors = $collection->getAuthors();
 436+ $authors = $this->filterAuthors( $authors, $collection->code );
 437+ foreach ( $authors as $author ) {
 438+ $output .= "# Author: $author\n";
 439+ }
 440+ return $output;
 441+ }
 442+
 443+}
Index: trunk/extensions/Translate/_autoload.php
@@ -113,4 +113,5 @@
114114 $wgAutoloadClasses['FFS'] = $dir . 'FFS.php';
115115 $wgAutoloadClasses['SimpleFFS'] = $dir . 'FFS.php';
116116 $wgAutoloadClasses['JavaFFS'] = $dir . 'FFS.php';
 117+$wgAutoloadClasses['YamlFFS'] = $dir . 'FFS.php';
117118 $wgAutoloadClasses['JavaScriptFFS'] = $dir . 'FFS.php';
Index: trunk/extensions/Translate/spyc/loader.php
@@ -1,6 +1,11 @@
22 <?php
33 class TranslateSpyc {
44
 5+ public static function loadString( $text ) {
 6+ require_once( dirname(__FILE__).'/spyc.php' );
 7+ return spyc_load( $text );
 8+ }
 9+
510 public static function load( $file ) {
611 require_once( dirname(__FILE__).'/spyc.php' );
712 $text = file_get_contents( $file );

Status & tagging log