| Index: trunk/extensions/Translate/Groups.php |
| — | — | @@ -30,16 +30,19 @@ |
| 31 | 31 | * @return string |
| 32 | 32 | */ |
| 33 | 33 | public function getId(); |
| | 34 | + |
| 34 | 35 | /** |
| 35 | 36 | * Returns the human readable label (as plain text). |
| 36 | 37 | * @return string |
| 37 | 38 | */ |
| 38 | 39 | public function getLabel(); |
| | 40 | + |
| 39 | 41 | /** |
| 40 | 42 | * Returns a longer description about the group. Description can use wiki text. |
| 41 | 43 | * @return string |
| 42 | 44 | */ |
| 43 | 45 | public function getDescription(); |
| | 46 | + |
| 44 | 47 | /** |
| 45 | 48 | * Returns the namespace where messages are placed. |
| 46 | 49 | * @return int |
| — | — | @@ -52,6 +55,7 @@ |
| 53 | 56 | * @return bool |
| 54 | 57 | */ |
| 55 | 58 | public function isMeta(); |
| | 59 | + |
| 56 | 60 | /** |
| 57 | 61 | * If this function returns false, the message group is ignored and treated |
| 58 | 62 | * like it would not be configured at all. Useful for graceful degradation. |
| — | — | @@ -66,12 +70,14 @@ |
| 67 | 71 | * @return FFS or null |
| 68 | 72 | */ |
| 69 | 73 | public function getFFS(); |
| | 74 | + |
| 70 | 75 | /** |
| 71 | 76 | * Returns a message checker object or null. |
| 72 | 77 | * @todo Make an interface for message checkers. |
| 73 | 78 | * @return MessageChecker or null |
| 74 | 79 | */ |
| 75 | 80 | public function getChecker(); |
| | 81 | + |
| 76 | 82 | /** |
| 77 | 83 | * Return a message mangler or null. |
| 78 | 84 | * @todo Make an interface for message manglers |
| — | — | @@ -85,6 +91,7 @@ |
| 86 | 92 | * @return MessageCollection |
| 87 | 93 | */ |
| 88 | 94 | public function initCollection( $code ); |
| | 95 | + |
| 89 | 96 | /** |
| 90 | 97 | * Returns a list of messages in a given language code. For some groups |
| 91 | 98 | * that list may be identical with the translation in the wiki. For other |
| — | — | @@ -93,12 +100,14 @@ |
| 94 | 101 | * @return array |
| 95 | 102 | */ |
| 96 | 103 | public function load( $code ); |
| | 104 | + |
| 97 | 105 | /** |
| 98 | 106 | * Returns message tags. If type is given, only messages keys with that |
| 99 | 107 | * tag is returnted. Otherwise an array[tag => keys] is returnted. |
| 100 | 108 | * @return array |
| 101 | 109 | */ |
| 102 | 110 | public function getTags( $type = null ); |
| | 111 | + |
| 103 | 112 | /** |
| 104 | 113 | * Returns the definition or translation for given message key in given |
| 105 | 114 | * language code. |
| — | — | @@ -145,6 +154,7 @@ |
| 146 | 155 | |
| 147 | 156 | public function getSourceLanguage() { |
| 148 | 157 | $conf = $this->getFromConf( 'BASIC', 'sourcelanguage' ); |
| | 158 | + |
| 149 | 159 | return $conf !== null ? $conf : 'en'; |
| 150 | 160 | } |
| 151 | 161 | |
| — | — | @@ -263,9 +273,11 @@ |
| 264 | 274 | public function getTags( $type = null ) { |
| 265 | 275 | if ( $type === null ) { |
| 266 | 276 | $taglist = array(); |
| | 277 | + |
| 267 | 278 | foreach ( $this->getRawTags() as $type => $patterns ) { |
| 268 | 279 | $taglist[$type] = $this->parseTags( $patterns ); |
| 269 | 280 | } |
| | 281 | + |
| 270 | 282 | return $taglist; |
| 271 | 283 | } else { |
| 272 | 284 | return $this->parseTags( $this->getRawTags( $type ) ); |
| — | — | @@ -371,7 +383,6 @@ |
| 372 | 384 | * custom type of message groups. |
| 373 | 385 | */ |
| 374 | 386 | class FileBasedMessageGroup extends MessageGroupBase { |
| 375 | | - |
| 376 | 387 | /** |
| 377 | 388 | * Constructs a FileBasedMessageGroup from any normal message group. |
| 378 | 389 | * Useful for doing special Gettext exports from any group. |
| — | — | @@ -391,6 +402,7 @@ |
| 392 | 403 | 'targetPattern' => '', |
| 393 | 404 | ), |
| 394 | 405 | ); |
| | 406 | + |
| 395 | 407 | return MessageGroupBase::factory( $conf ); |
| 396 | 408 | } |
| 397 | 409 | |
| — | — | @@ -401,18 +413,21 @@ |
| 402 | 414 | public function load( $code ) { |
| 403 | 415 | $ffs = $this->getFFS(); |
| 404 | 416 | $data = $ffs->read( $code ); |
| | 417 | + |
| 405 | 418 | return $data ? $data['MESSAGES'] : array(); |
| 406 | 419 | } |
| 407 | 420 | |
| 408 | 421 | public function getSourceFilePath( $code ) { |
| 409 | 422 | if ( $this->isSourceLanguage( $code ) ) { |
| 410 | 423 | $pattern = $this->getFromConf( 'FILES', 'definitionFile' ); |
| | 424 | + |
| 411 | 425 | if ( $pattern !== null ) { |
| 412 | 426 | return $this->replaceVariables( $pattern, $code ); |
| 413 | 427 | } |
| 414 | 428 | } |
| 415 | 429 | |
| 416 | 430 | $pattern = $this->getFromConf( 'FILES', 'sourcePattern' ); |
| | 431 | + |
| 417 | 432 | if ( $pattern === null ) { |
| 418 | 433 | throw new MWException( 'No source file pattern defined.' ); |
| 419 | 434 | } |
| — | — | @@ -470,7 +485,6 @@ |
| 471 | 486 | public function isValidLanguage( $code ) { |
| 472 | 487 | return $this->mapCode( $code ) !== 'x-invalidLanguageCode'; |
| 473 | 488 | } |
| 474 | | - |
| 475 | 489 | } |
| 476 | 490 | |
| 477 | 491 | /** |
| — | — | @@ -527,7 +541,6 @@ |
| 528 | 542 | * - Only groups of same type and in the same namespace. |
| 529 | 543 | */ |
| 530 | 544 | class AggregateMessageGroup extends MessageGroupBase { |
| 531 | | - |
| 532 | 545 | public function exists() { |
| 533 | 546 | // Group exists if there are any subgroups. |
| 534 | 547 | $exists = (bool) $this->conf['GROUPS']; |
| — | — | @@ -553,6 +566,7 @@ |
| 554 | 567 | if ( !isset( $this->mangler ) ) { |
| 555 | 568 | $this->mangler = StringMatcher::emptyMatcher(); |
| 556 | 569 | } |
| | 570 | + |
| 557 | 571 | return $this->mangler; |
| 558 | 572 | } |
| 559 | 573 | |
| — | — | @@ -582,8 +596,10 @@ |
| 583 | 597 | |
| 584 | 598 | $groups[$id] = $group; |
| 585 | 599 | } |
| | 600 | + |
| 586 | 601 | $this->groups = $groups; |
| 587 | 602 | } |
| | 603 | + |
| 588 | 604 | return $this->groups; |
| 589 | 605 | } |
| 590 | 606 | |
| — | — | @@ -596,6 +612,7 @@ |
| 597 | 613 | */ |
| 598 | 614 | protected function expandWildcards( $ids ) { |
| 599 | 615 | $hasWild = false; |
| | 616 | + |
| 600 | 617 | foreach ( $ids as $id ) { |
| 601 | 618 | if ( strpos( $id, '*' ) !== false ) { |
| 602 | 619 | $hasWild = true; |
| — | — | @@ -603,10 +620,13 @@ |
| 604 | 621 | } |
| 605 | 622 | } |
| 606 | 623 | |
| 607 | | - if ( !$hasWild ) return $ids; |
| | 624 | + if ( !$hasWild ) { |
| | 625 | + return $ids; |
| | 626 | + } |
| 608 | 627 | |
| 609 | 628 | $matcher = new StringMatcher( '', $ids ); |
| 610 | 629 | $all = array(); |
| | 630 | + |
| 611 | 631 | foreach ( MessageGroups::singleton()->getGroups() as $id => $_ ) { |
| 612 | 632 | if ( $matcher->match( $id ) ) { |
| 613 | 633 | $all[] = $id; |
| — | — | @@ -617,6 +637,7 @@ |
| 618 | 638 | |
| 619 | 639 | public function initCollection( $code ) { |
| 620 | 640 | $messages = array(); |
| | 641 | + |
| 621 | 642 | foreach ( $this->getGroups() as $group ) { |
| 622 | 643 | $cache = new MessageGroupCache( $group ); |
| 623 | 644 | if ( $cache->exists() ) { |
| — | — | @@ -632,6 +653,7 @@ |
| 633 | 654 | $namespace = $this->getNamespace(); |
| 634 | 655 | $definitions = new MessageDefinitions( $namespace, $messages ); |
| 635 | 656 | $collection = MessageCollection::newFromDefinitions( $definitions, $code ); |
| | 657 | + |
| 636 | 658 | $this->setTags( $collection ); |
| 637 | 659 | |
| 638 | 660 | return $collection; |
| — | — | @@ -640,6 +662,7 @@ |
| 641 | 663 | public function getMessage( $key, $code ) { |
| 642 | 664 | $id = TranslateUtils::messageKeyToGroup( $this->getNamespace(), $key ); |
| 643 | 665 | $groups = $this->getGroups(); |
| | 666 | + |
| 644 | 667 | if ( isset( $groups[$id] ) ) { |
| 645 | 668 | return $groups[$id]->getMessage( $key, $code ); |
| 646 | 669 | } else { |
| — | — | @@ -649,9 +672,11 @@ |
| 650 | 673 | |
| 651 | 674 | public function getTags( $type = null ) { |
| 652 | 675 | $tags = array(); |
| | 676 | + |
| 653 | 677 | foreach ( $this->getGroups() as $group ) { |
| 654 | 678 | $tags = array_merge_recursive( $tags, $group->getTags( $type ) ); |
| 655 | 679 | } |
| | 680 | + |
| 656 | 681 | return $tags; |
| 657 | 682 | } |
| 658 | 683 | } |