Index: trunk/phase3/languages/LanguageConverter.php |
— | — | @@ -192,7 +192,7 @@ |
193 | 193 | // see if the preference is set in the request |
194 | 194 | $ret = $wgRequest->getText( 'variant' ); |
195 | 195 | |
196 | | - if ( $ret ) { |
| 196 | + if ( !$ret ) { |
197 | 197 | $ret = $wgRequest->getVal( 'uselang' ); |
198 | 198 | } |
199 | 199 | |
— | — | @@ -539,28 +539,69 @@ |
540 | 540 | } |
541 | 541 | |
542 | 542 | /** |
543 | | - * Convert a text fragment. |
| 543 | + * Convert a text array. |
544 | 544 | * |
545 | | - * @param string $text text to be converted |
| 545 | + * @param string $tarray text array to be converted |
546 | 546 | * @param string $plang preferred variant |
547 | 547 | * @return string converted text |
548 | 548 | * @private |
549 | 549 | */ |
550 | | - function convertFragment( $text, $plang ) { |
551 | | - $marked = explode( $this->mMarkup['begin'], $text, 2 ); |
| 550 | + function convertArray( $tarray, $plang ) { |
| 551 | + $beginlen = strlen( $this->mMarkup['begin'] ); |
552 | 552 | $converted = ''; |
| 553 | + $middle = ''; |
553 | 554 | |
554 | | - $converted .= $this->autoConvert( $marked[0], $plang ); |
| 555 | + foreach ( $tarray as $text ) { |
| 556 | + // for nested use |
| 557 | + if( $middle ) { |
| 558 | + $text = $middle . $text; |
| 559 | + $middle = ''; |
| 560 | + } |
555 | 561 | |
556 | | - if ( array_key_exists( 1, $marked ) ) { |
557 | | - $crule = new ConverterRule( $marked[1], $this ); |
| 562 | + // find first and last begin markup(s) |
| 563 | + $firstbegin = strpos( $text, $this->mMarkup['begin'] ); |
| 564 | + $lastbegin = strrpos( $text, $this->mMarkup['begin'] ); |
| 565 | + |
| 566 | + // if $text contains no begin markup, |
| 567 | + // append $text restore end markup to $converted |
| 568 | + if( $firstbegin === false ) { |
| 569 | + $converted .= $text; |
| 570 | + $converted .= $this->mMarkup['end']; |
| 571 | + continue; |
| 572 | + } |
| 573 | + |
| 574 | + // split $text into $left and $right, |
| 575 | + // omit the begin markup in $right |
| 576 | + $left = substr( $text, 0, $firstbegin ); |
| 577 | + $right = substr( $text, $lastbegin + $beginlen ); |
| 578 | + |
| 579 | + // always convert $left and append it to $converted |
| 580 | + // for nested case, $left is blank but can also be converted |
| 581 | + $converted .= $this->autoConvert( $left, $plang ); |
| 582 | + |
| 583 | + // parse and apply manual rule from $right |
| 584 | + $crule = new ConverterRule( $right, $this ); |
558 | 585 | $crule->parse( $plang ); |
559 | | - $converted .= $crule->getDisplay(); |
| 586 | + $right = $crule->getDisplay(); |
560 | 587 | $this->applyManualConv( $crule ); |
561 | | - } else { |
562 | | - $converted .= $this->mMarkup['end']; |
| 588 | + |
| 589 | + // if $text contains only one begin markup, |
| 590 | + // append $left and $right to $converted. |
| 591 | + // |
| 592 | + // otherwise it's a nested use like "-{-{}-}-", |
| 593 | + // this should be handled properly. |
| 594 | + if( $firstbegin === $lastbegin ) { |
| 595 | + $converted .= $right; |
| 596 | + } |
| 597 | + else { |
| 598 | + // not omit the first begin markup |
| 599 | + $middle = substr( $text, $firstbegin, $lastbegin - $firstbegin ); |
| 600 | + $middle .= $right; |
| 601 | + //print $middle; |
| 602 | + } |
563 | 603 | } |
564 | | - |
| 604 | + // Remove the last delimiter (wasn't real) |
| 605 | + $converted = substr( $converted, 0, - strlen( $this->mMarkup['end'] ) ); |
565 | 606 | return $converted; |
566 | 607 | } |
567 | 608 | |
— | — | @@ -586,14 +627,8 @@ |
587 | 628 | $plang = $this->getPreferredVariant(); |
588 | 629 | |
589 | 630 | $tarray = StringUtils::explode( $this->mMarkup['end'], $text ); |
590 | | - $converted = ''; |
| 631 | + $converted = $this->convertArray( $tarray, $plang ); |
591 | 632 | |
592 | | - foreach ( $tarray as $txt ) { |
593 | | - $converted .= $this->convertFragment( $txt, $plang ); |
594 | | - } |
595 | | - |
596 | | - // Remove the last delimiter (wasn't real) |
597 | | - $converted = substr( $converted, 0, - strlen( $this->mMarkup['end'] ) ); |
598 | 633 | return $converted; |
599 | 634 | } |
600 | 635 | |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -295,6 +295,7 @@ |
296 | 296 | * (bug 22051) Returing false in SpecialContributionsBeforeMainOutput hook now |
297 | 297 | stops normal output |
298 | 298 | * Send new password e-mail in users preference language |
| 299 | +* LanguageConverter now support nested using of manual convert syntax like "-{-{}-}-" |
299 | 300 | |
300 | 301 | === Bug fixes in 1.16 === |
301 | 302 | |
Index: trunk/phase3/maintenance/parserTests.txt |
— | — | @@ -6962,6 +6962,17 @@ |
6963 | 6963 | !! end |
6964 | 6964 | |
6965 | 6965 | !! test |
| 6966 | +Nested using of manual convert syntax |
| 6967 | +!! options |
| 6968 | +language=zh variant=zh-hk |
| 6969 | +!! input |
| 6970 | +Nested: -{zh-hans:Hi -{zh-cn:China;zh-sg:Singapore;}-;zh-hant:Hello -{zh-tw:Taiwan;zh-hk:H-{ong}- K-{}-ong;}-;}-! |
| 6971 | +!! result |
| 6972 | +<p>Nested: Hello Hong Kong! |
| 6973 | +</p> |
| 6974 | +!! end |
| 6975 | + |
| 6976 | +!! test |
6966 | 6977 | Do not convert roman numbers to language variants |
6967 | 6978 | !! options |
6968 | 6979 | language=sr variant=sr-ec |