r53041 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53040‎ | r53041 | r53042 >
Date:11:45, 10 July 2009
Author:philip
Status:deferred (Comments)
Tags:
Comment:
(bug 19620) Allow to convert a string immediately after a new rule added.
Modified paths:
  • /trunk/phase3/languages/LanguageConverter.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/LanguageConverter.php
@@ -21,8 +21,6 @@
2222 var $mVariants, $mVariantFallbacks, $mVariantNames;
2323 var $mTablesLoaded = false;
2424 var $mTables;
25 - var $mManualAddTables;
26 - var $mManualRemoveTables;
2725 var $mNamespaceTables;
2826 var $mTitleDisplay='';
2927 var $mDoTitleConvert=true, $mDoContentConvert=true;
@@ -88,8 +86,6 @@
8987 $this->mManualLevel[$v]=array_key_exists($v,$manualLevel)
9088 ?$manualLevel[$v]
9189 :'bidirectional';
92 - $this->mManualAddTables[$v] = array();
93 - $this->mManualRemoveTables[$v] = array();
9490 $this->mNamespaceTables[$v] = array();
9591 $this->mFlags[$v] = $v;
9692 }
@@ -374,7 +370,7 @@
375371 * prepare manual conversion table
376372 * @private
377373 */
378 - function prepareManualConv( $convRule ){
 374+ function applyManualConv( $convRule ){
379375 // use syntax -{T|zh:TitleZh;zh-tw:TitleTw}- for custom conversion in title
380376 $title = $convRule->getTitle();
381377 if( $title ){
@@ -385,42 +381,24 @@
386382 //apply manual conversion table to global table
387383 $convTable = $convRule->getConvTable();
388384 $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;
391387 if( $action=="add" ) {
392 - foreach( $t as $from => $to ) {
 388+ foreach( $pair as $from => $to ) {
393389 // to ensure that $from and $to not be left blank
394390 // so $this->translate() could always return a string
395391 if ( $from || $to )
396392 // more efficient than array_merge(), about 2.5 times.
397 - $this->mManualAddTables[$v][$from] = $to;
 393+ $this->mTables[$variant]->setPair( $from, $to );
398394 }
399395 }
400396 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 );
405398 }
406399 }
407400 }
408401
409402 /**
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 - /**
425403 * Convert text using a parser object for context
426404 * @public
427405 */
@@ -530,28 +508,25 @@
531509 $tarray = StringUtils::explode( $this->mMarkup['end'], $text );
532510 $text = '';
533511
534 - $marks = array();
535512 foreach ( $tarray as $txt ) {
 513+
536514 $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+
537520 if ( array_key_exists( 1, $marked ) ) {
538521 $crule = new ConverterRule($marked[1], $this);
539522 $crule->parse( $plang );
540 - $marked[1] = $crule->getDisplay();
541 - $this->prepareManualConv( $crule );
 523+ $text .= $crule->getDisplay();
 524+ $this->applyManualConv( $crule );
542525 }
543526 else
544 - $marked[0] .= $this->mMarkup['end'];
545 - array_push( $marks, $marked );
 527+ $text .= $this->mMarkup['end'];
 528+
546529 }
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+
556531 // Remove the last delimiter (wasn't real)
557532 $text = substr( $text, 0, -strlen( $this->mMarkup['end'] ) );
558533

Follow-up revisions

RevisionCommit summaryAuthorDate
r56491Follow up on r53041. Fix a __NOCC__ failure caused by myself and I'm stupid t...philip04:16, 17 September 2009

Comments

#Comment by PhiLiP (talk | contribs)   11:48, 10 July 2009

Here is a example to tell what I have done on r53041:

Before parsing, suppose we input a string like: FooBar -{H|zh-cn:Foo; zh-tw:Bar}- FooBar -{-|zh-cn:Foo; zh-tw:Bar}- FooBar

In zh-cn mode, it should represent as: FooBar FooFoo FooBar

And in zh-tw mode: FooBar BarBar FooBar

Status & tagging log