Index: trunk/phase3/languages/LanguageConverter.php |
— | — | @@ -21,8 +21,6 @@ |
22 | 22 | var $mVariants, $mVariantFallbacks, $mVariantNames; |
23 | 23 | var $mTablesLoaded = false; |
24 | 24 | var $mTables; |
25 | | - var $mManualAddTables; |
26 | | - var $mManualRemoveTables; |
27 | 25 | var $mNamespaceTables; |
28 | 26 | var $mTitleDisplay=''; |
29 | 27 | var $mDoTitleConvert=true, $mDoContentConvert=true; |
— | — | @@ -88,8 +86,6 @@ |
89 | 87 | $this->mManualLevel[$v]=array_key_exists($v,$manualLevel) |
90 | 88 | ?$manualLevel[$v] |
91 | 89 | :'bidirectional'; |
92 | | - $this->mManualAddTables[$v] = array(); |
93 | | - $this->mManualRemoveTables[$v] = array(); |
94 | 90 | $this->mNamespaceTables[$v] = array(); |
95 | 91 | $this->mFlags[$v] = $v; |
96 | 92 | } |
— | — | @@ -374,7 +370,7 @@ |
375 | 371 | * prepare manual conversion table |
376 | 372 | * @private |
377 | 373 | */ |
378 | | - function prepareManualConv( $convRule ){ |
| 374 | + function applyManualConv( $convRule ){ |
379 | 375 | // use syntax -{T|zh:TitleZh;zh-tw:TitleTw}- for custom conversion in title |
380 | 376 | $title = $convRule->getTitle(); |
381 | 377 | if( $title ){ |
— | — | @@ -385,42 +381,24 @@ |
386 | 382 | //apply manual conversion table to global table |
387 | 383 | $convTable = $convRule->getConvTable(); |
388 | 384 | $action = $convRule->getRulesAction(); |
389 | | - foreach( $convTable as $v => $t ) { |
390 | | - if( !in_array( $v, $this->mVariants ) )continue; |
| 385 | + foreach( $convTable as $variant => $pair ) { |
| 386 | + if( !in_array( $variant, $this->mVariants ) )continue; |
391 | 387 | if( $action=="add" ) { |
392 | | - foreach( $t as $from => $to ) { |
| 388 | + foreach( $pair as $from => $to ) { |
393 | 389 | // to ensure that $from and $to not be left blank |
394 | 390 | // so $this->translate() could always return a string |
395 | 391 | if ( $from || $to ) |
396 | 392 | // more efficient than array_merge(), about 2.5 times. |
397 | | - $this->mManualAddTables[$v][$from] = $to; |
| 393 | + $this->mTables[$variant]->setPair( $from, $to ); |
398 | 394 | } |
399 | 395 | } |
400 | 396 | elseif ( $action == "remove" ) { |
401 | | - foreach ( $t as $from=>$to ) { |
402 | | - if ( $from || $to ) |
403 | | - $this->mManualRemoveTables[$v][$from] = $to; |
404 | | - } |
| 397 | + $this->mTables[$variant]->removeArray( $pair ); |
405 | 398 | } |
406 | 399 | } |
407 | 400 | } |
408 | 401 | |
409 | 402 | /** |
410 | | - * apply manual conversion from $this->mManualAddTables and $this->mManualRemoveTables |
411 | | - * @private |
412 | | - */ |
413 | | - function applyManualConv(){ |
414 | | - //apply manual conversion table to global table |
415 | | - foreach($this->mVariants as $v) { |
416 | | - if (count($this->mManualAddTables[$v]) > 0) { |
417 | | - $this->mTables[$v]->mergeArray($this->mManualAddTables[$v]); |
418 | | - } |
419 | | - if (count($this->mManualRemoveTables[$v]) > 0) |
420 | | - $this->mTables[$v]->removeArray($this->mManualRemoveTables[$v]); |
421 | | - } |
422 | | - } |
423 | | - |
424 | | - /** |
425 | 403 | * Convert text using a parser object for context |
426 | 404 | * @public |
427 | 405 | */ |
— | — | @@ -530,28 +508,25 @@ |
531 | 509 | $tarray = StringUtils::explode( $this->mMarkup['end'], $text ); |
532 | 510 | $text = ''; |
533 | 511 | |
534 | | - $marks = array(); |
535 | 512 | foreach ( $tarray as $txt ) { |
| 513 | + |
536 | 514 | $marked = explode( $this->mMarkup['begin'], $txt, 2 ); |
| 515 | + |
| 516 | + if( $this->mDoContentConvert ) |
| 517 | + // Bug 19620: should convert a string immediately after a new rule added. |
| 518 | + $text .= $this->autoConvert( $marked[0], $plang ); |
| 519 | + |
537 | 520 | if ( array_key_exists( 1, $marked ) ) { |
538 | 521 | $crule = new ConverterRule($marked[1], $this); |
539 | 522 | $crule->parse( $plang ); |
540 | | - $marked[1] = $crule->getDisplay(); |
541 | | - $this->prepareManualConv( $crule ); |
| 523 | + $text .= $crule->getDisplay(); |
| 524 | + $this->applyManualConv( $crule ); |
542 | 525 | } |
543 | 526 | else |
544 | | - $marked[0] .= $this->mMarkup['end']; |
545 | | - array_push( $marks, $marked ); |
| 527 | + $text .= $this->mMarkup['end']; |
| 528 | + |
546 | 529 | } |
547 | | - $this->applyManualConv(); |
548 | | - foreach ( $marks as $marked ) { |
549 | | - if( $this->mDoContentConvert ) |
550 | | - $text .= $this->autoConvert( $marked[0], $plang ); |
551 | | - else |
552 | | - $text .= $marked[0]; |
553 | | - if( array_key_exists( 1, $marked ) ) |
554 | | - $text .= $marked[1]; |
555 | | - } |
| 530 | + |
556 | 531 | // Remove the last delimiter (wasn't real) |
557 | 532 | $text = substr( $text, 0, -strlen( $this->mMarkup['end'] ) ); |
558 | 533 | |