Index: trunk/extensions/Translate/FFS.php |
— | — | @@ -371,3 +371,72 @@ |
372 | 372 | } |
373 | 373 | |
374 | 374 | } |
| 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 @@ |
114 | 114 | $wgAutoloadClasses['FFS'] = $dir . 'FFS.php'; |
115 | 115 | $wgAutoloadClasses['SimpleFFS'] = $dir . 'FFS.php'; |
116 | 116 | $wgAutoloadClasses['JavaFFS'] = $dir . 'FFS.php'; |
| 117 | +$wgAutoloadClasses['YamlFFS'] = $dir . 'FFS.php'; |
117 | 118 | $wgAutoloadClasses['JavaScriptFFS'] = $dir . 'FFS.php'; |
Index: trunk/extensions/Translate/spyc/loader.php |
— | — | @@ -1,6 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | class TranslateSpyc { |
4 | 4 | |
| 5 | + public static function loadString( $text ) { |
| 6 | + require_once( dirname(__FILE__).'/spyc.php' ); |
| 7 | + return spyc_load( $text ); |
| 8 | + } |
| 9 | + |
5 | 10 | public static function load( $file ) { |
6 | 11 | require_once( dirname(__FILE__).'/spyc.php' ); |
7 | 12 | $text = file_get_contents( $file ); |