Index: trunk/extensions/Translate/FFS.php |
— | — | @@ -380,8 +380,19 @@ |
381 | 381 | abstract protected function footer(); |
382 | 382 | |
383 | 383 | public function readFromVariable( $data ) { |
384 | | - /* Pre-processing */ |
| 384 | + /* Parse authors list */ |
| 385 | + $authors = preg_replace( "#/\* Translators\:\n(.*?)\n \*/(.*)#s", '$1', $data ); |
| 386 | + if( $authors === $data ) { |
| 387 | + $authors = array(); |
| 388 | + } else { |
| 389 | + $authors = explode( "\n", $authors ); |
| 390 | + for( $i = 0; $i < count( $authors ); $i++ ) { |
| 391 | + $authors[$i] = substr( $authors[$i], 6 ); |
| 392 | + } |
| 393 | + } |
385 | 394 | |
| 395 | + /* Pre-processing of messages */ |
| 396 | + |
386 | 397 | // Find the start and end of the data section (enclosed in curly braces). |
387 | 398 | $dataStart = strpos( $data, '{' ); |
388 | 399 | $dataEnd = strrpos( $data, '}' ); |
— | — | @@ -397,7 +408,7 @@ |
398 | 409 | // Strip excess whitespace. |
399 | 410 | $data = trim( $data ); |
400 | 411 | |
401 | | - /* Per-key message */ |
| 412 | + /* Per-key message processing */ |
402 | 413 | |
403 | 414 | // Break in to segments. |
404 | 415 | $data = explode( "\",\n", $data ); |
— | — | @@ -407,11 +418,10 @@ |
408 | 419 | // Add back trailing quote, removed by explosion. |
409 | 420 | $segment .= '"'; |
410 | 421 | |
411 | | - // Concatenate separate strings. |
| 422 | + // Concatenate separated strings. |
412 | 423 | $segment = explode( '" +', $segment ); |
413 | 424 | for( $i = 0; $i < count( $segment ); $i++ ) { |
414 | | - $segment[$i] = ltrim( $segment[$i] ); |
415 | | - $segment[$i] = ltrim( $segment[$i], '"' ); |
| 425 | + $segment[$i] = ltrim( ltrim( $segment[$i] ), '"' ); |
416 | 426 | } |
417 | 427 | $segment = implode( $segment ); |
418 | 428 | |
— | — | @@ -420,37 +430,36 @@ |
421 | 431 | |
422 | 432 | // Break in to key and message. |
423 | 433 | $segments = explode( ': "', $segment ); |
424 | | - $key = $segments[ 0 ]; |
425 | | - $value = $segments[1]; |
426 | 434 | |
427 | | - // Strip excess whitespace from key and value. |
428 | | - $key = trim( $key ); |
429 | | - $value = trim( $value ); |
| 435 | + // Strip excess whitespace from key and value, then quotation marks. |
| 436 | + $key = trim( trim( $segments[0] ), '\'"' ); |
| 437 | + $value = trim( trim( $segments[1] ), '\'"' ); |
430 | 438 | |
431 | | - // Strip quotation marks. |
432 | | - $key = trim( $key, '\'"' ); |
433 | | - $value = trim( $value, '\'"' ); |
434 | | - |
435 | | - // Unescape any JavaScript and append to message array. |
| 439 | + // Unescape any JavaScript string syntax and append to message array. |
436 | 440 | $messages[$key] = self::unescapeJsString( $value ); |
437 | 441 | } |
438 | 442 | |
439 | 443 | $messages = $this->group->getMangler()->mangle( $messages ); |
440 | 444 | |
441 | | - // FIXME: authors missing? |
442 | | - |
443 | | - return array( 'MESSAGES' => $messages ); |
| 445 | + return array( |
| 446 | + 'AUTHORS' => $authors, |
| 447 | + 'MESSAGES' => $messages |
| 448 | + ); |
444 | 449 | } |
445 | 450 | |
446 | 451 | public function writeIntoVariable( MessageCollection $collection ) { |
447 | 452 | $r = $this->header( $collection->code, $collection->getAuthors() ); |
448 | 453 | |
| 454 | + $mangler = $this->group->getMangler(); |
| 455 | + |
449 | 456 | // Get and write messages. |
450 | 457 | foreach ( $collection as $message ) { |
451 | | - $key = $this->transformKey( Xml::escapeJsString( $message->key() ) ); |
452 | | - $value = Xml::escapeJsString( $message->translation() ); |
| 458 | + $key = $mangler->unmangle( $message->key() ); |
| 459 | + $key = $this->transformKey( Xml::escapeJsString( $key ) ); |
453 | 460 | |
454 | | - $r .= " {$key}: \"{$value}\",\n\n"; |
| 461 | + $translation = Xml::escapeJsString( $message->translation() ); |
| 462 | + |
| 463 | + $r .= " {$key}: \"{$translation}\",\n\n"; |
455 | 464 | } |
456 | 465 | |
457 | 466 | // Strip last comma, re-add trailing newlines. |
— | — | @@ -461,19 +470,12 @@ |
462 | 471 | } |
463 | 472 | |
464 | 473 | protected function authorsList( $authors ) { |
465 | | - if( count( $authors ) > 0 ) { |
466 | | - foreach ( $authors as $author ) { |
467 | | - $authorsList .= " * - $author\n"; |
468 | | - } |
469 | | - return <<<EOT |
470 | | -/* Translators: |
471 | | -$authorsList */ |
| 474 | + if( count( $authors ) === 0 ) return ''; |
472 | 475 | |
473 | | - |
474 | | -EOT; |
475 | | - } else { |
476 | | - return ''; |
| 476 | + foreach ( $authors as $author ) { |
| 477 | + $authorsList .= " * - $author\n"; |
477 | 478 | } |
| 479 | + return "/* Translators:\n$authorsList */\n\n"; |
478 | 480 | } |
479 | 481 | |
480 | 482 | private static function unescapeJsString( $string ) { |
— | — | @@ -547,14 +549,8 @@ |
548 | 550 | } |
549 | 551 | |
550 | 552 | protected function header( $code, $authors ) { |
551 | | - |
552 | 553 | $authorsList = $this->authorsList( $authors ); |
553 | | - |
554 | | - return <<<EOT |
555 | | -{$authorsList}var I18n = { |
556 | | - |
557 | | - |
558 | | -EOT; |
| 554 | + return "{$authorsList}var I18n = {\n\n"; |
559 | 555 | } |
560 | 556 | |
561 | 557 | protected function footer() { |