Index: trunk/extensions/Translate/FFS.php |
— | — | @@ -39,7 +39,7 @@ |
40 | 40 | public function setWritePath( $writePath ) { $this->writePath = $writePath; } |
41 | 41 | public function getWritePath() { return $this->writePath; } |
42 | 42 | |
43 | | - public function read( $code ) { |
| 43 | + public function exists( $code = 'en' ) { |
44 | 44 | $filename = $this->group->getSourceFilePath( $code ); |
45 | 45 | if ( $filename === null ) { |
46 | 46 | return false; |
— | — | @@ -49,6 +49,15 @@ |
50 | 50 | return false; |
51 | 51 | } |
52 | 52 | |
| 53 | + return true; |
| 54 | + } |
| 55 | + |
| 56 | + public function read( $code ) { |
| 57 | + if ( !$this->exists( $code ) ) { |
| 58 | + return false; |
| 59 | + } |
| 60 | + |
| 61 | + $filename = $this->group->getSourceFilePath( $code ); |
53 | 62 | $input = file_get_contents( $filename ); |
54 | 63 | if ( $input === false ) { |
55 | 64 | throw new MWException( "Unable to read file $filename" ); |
Index: trunk/extensions/Translate/groups/Shapado/Shapado.yml |
— | — | @@ -24,6 +24,45 @@ |
25 | 25 | |
26 | 26 | --- |
27 | 27 | BASIC: |
| 28 | + id: out-shapado-0-all |
| 29 | + label: All Shapado messages |
| 30 | + display: out/shapado |
| 31 | + meta: yes |
| 32 | + class: AggregateMessageGroup |
| 33 | +GROUPS: |
| 34 | + - out-shapado-ads |
| 35 | + - out-shapado-announcements |
| 36 | + - out-shapado-answers |
| 37 | + - out-shapado-badges |
| 38 | + - out-shapado-closerequests |
| 39 | + - out-shapado-comments |
| 40 | + - out-shapado-doc |
| 41 | + - out-shapado-errors |
| 42 | + - out-shapado-favorites |
| 43 | + - out-shapado-flags |
| 44 | + - out-shapado-global |
| 45 | + - out-shapado-groups |
| 46 | + - out-shapado-imports |
| 47 | + - out-shapado-layouts |
| 48 | + - out-shapado-mailers |
| 49 | + - out-shapado-manage |
| 50 | + - out-shapado-members |
| 51 | + - out-shapado-moderate |
| 52 | + - out-shapado-notifier |
| 53 | + - out-shapado-pages |
| 54 | + - out-shapado-questions |
| 55 | + - out-shapado-searches |
| 56 | + - out-shapado-sessions |
| 57 | + - out-shapado-shared |
| 58 | + - out-shapado-unfavorites |
| 59 | + - out-shapado-users |
| 60 | + - out-shapado-votes |
| 61 | + - out-shapado-welcome |
| 62 | + - out-shapado-widgets |
| 63 | + - out-shapado-wiki |
| 64 | + |
| 65 | +--- |
| 66 | +BASIC: |
28 | 67 | id: out-shapado-ads |
29 | 68 | label: Shapado - Ads |
30 | 69 | display: out/shapado/ads |
Index: trunk/extensions/Translate/Groups.php |
— | — | @@ -227,13 +227,12 @@ |
228 | 228 | |
229 | 229 | class FileBasedMessageGroup extends MessageGroupBase { |
230 | 230 | public function exists() { |
231 | | - return (bool) count( $this->load( 'en' ) ); |
| 231 | + return $this->getFFS()->exists(); |
232 | 232 | } |
233 | 233 | |
234 | 234 | public function load( $code ) { |
235 | 235 | $ffs = $this->getFFS(); |
236 | 236 | $data = $ffs->read( $code ); |
237 | | - |
238 | 237 | return $data ? $data['MESSAGES'] : array(); |
239 | 238 | } |
240 | 239 | |
— | — | @@ -316,3 +315,92 @@ |
317 | 316 | parent::setTags( $collection ); |
318 | 317 | } |
319 | 318 | } |
| 319 | + |
| 320 | + |
| 321 | +/** |
| 322 | + * Groups multiple message groups together as one big group. |
| 323 | + * Limitations: |
| 324 | + * - Only groups of same type and in the same namespace |
| 325 | + */ |
| 326 | +class AggregateMessageGroup extends MessageGroupBase { |
| 327 | + |
| 328 | + public function exists() { |
| 329 | + // Group exists if there is any subgroups |
| 330 | + $exists = (bool) $this->conf['GROUPS']; |
| 331 | + |
| 332 | + if ( !$exists ) { |
| 333 | + trigger_error( __METHOD__ . "[{$this->getId()}]: Group is empty" ); |
| 334 | + } |
| 335 | + |
| 336 | + return $exists; |
| 337 | + } |
| 338 | + |
| 339 | + public function load( $code ) { |
| 340 | + $messages = array(); |
| 341 | + foreach( $this->getGroups() as $group ) { |
| 342 | + $messages += $group->load( $code ); |
| 343 | + } |
| 344 | + return $messages; |
| 345 | + } |
| 346 | + |
| 347 | + public function getMangler() { |
| 348 | + if ( !isset( $this->mangler ) ) { |
| 349 | + $this->mangler = StringMatcher::emptyMatcher(); |
| 350 | + } |
| 351 | + return $this->mangler; |
| 352 | + } |
| 353 | + |
| 354 | + protected function getGroups() { |
| 355 | + if ( !isset( $this->groups ) ) { |
| 356 | + $groups = array(); |
| 357 | + $ids = (array) $this->conf['GROUPS']; |
| 358 | + foreach( $ids as $id ) { |
| 359 | + // Don't try to include self and go to infinite loop |
| 360 | + if ( $id === $this->getId() ) continue; |
| 361 | + $groups[$id] = MessageGroups::getGroup( $id ); |
| 362 | + } |
| 363 | + $this->groups = $groups; |
| 364 | + } |
| 365 | + return $this->groups; |
| 366 | + } |
| 367 | + |
| 368 | + public function initCollection( $code ) { |
| 369 | + $messages = array(); |
| 370 | + foreach( $this->getGroups() as $group ) { |
| 371 | + $cache = new MessageGroupCache( $group ); |
| 372 | + foreach ( $cache->getKeys() as $key ) { |
| 373 | + $messages[$key] = $cache->get( $key ); |
| 374 | + } |
| 375 | + } |
| 376 | + |
| 377 | + $namespace = $this->getNamespace(); |
| 378 | + $definitions = new MessageDefinitions( $namespace, $messages ); |
| 379 | + $collection = MessageCollection::newFromDefinitions( $definitions, $code ); |
| 380 | + $this->setTags( $collection ); |
| 381 | + |
| 382 | + return $collection; |
| 383 | + } |
| 384 | + |
| 385 | + public function getMessage( $key, $code ) { |
| 386 | + foreach( $this->getGroups() as $group ) { |
| 387 | + $message = $group->getMessage( $key, $code ); |
| 388 | + if ( $message !== null ) return $message; |
| 389 | + } |
| 390 | + } |
| 391 | + |
| 392 | + public function getTags( $type = null ) { |
| 393 | + $tags = array(); |
| 394 | + foreach( $this->getGroups() as $group ) { |
| 395 | + //FIXME: is this correct? |
| 396 | + $tags = array_merge_recursive( $tags, $group->getTags( $type ) ); |
| 397 | + } |
| 398 | + return $tags; |
| 399 | + } |
| 400 | + |
| 401 | + protected function setTags( MessageCollection $collection ) { |
| 402 | + foreach( $this->getGroups() as $group ) { |
| 403 | + $group->setTags( $collection ); |
| 404 | + } |
| 405 | + } |
| 406 | + |
| 407 | +} |
\ No newline at end of file |