Index: trunk/extensions/Translate/utils/TranslationHelpers.php |
— | — | @@ -345,7 +345,7 @@ |
346 | 346 | |
347 | 347 | $code = $this->targetLanguage; |
348 | 348 | $definition = trim( strval( $this->getDefinition() ) ); |
349 | | - $definition = str_replace( "\n", "<newline/>", $definition ); |
| 349 | + $definition = self::wrapUntranslatable( $definition ); |
350 | 350 | |
351 | 351 | $memckey = wfMemckey( 'translate-tmsug-badcodes-' . $serviceName ); |
352 | 352 | $unsupported = $wgMemc->get( $memckey ); |
— | — | @@ -376,7 +376,7 @@ |
377 | 377 | |
378 | 378 | if ( $response->responseStatus === 200 ) { |
379 | 379 | $text = Sanitizer::decodeCharReferences( $response->responseData->translatedText ); |
380 | | - $text = str_replace( "<newline/>", "\n", $text ); |
| 380 | + $text = self::unwrapUntranslatable( $text ); |
381 | 381 | $text = $this->suggestionField( $text ); |
382 | 382 | return Html::rawElement( 'div', null, self::legend( $serviceName ) . $text . self::clear() ); |
383 | 383 | } elseif ( $response->responseDetails === 'invalid translation language pair' ) { |
— | — | @@ -421,7 +421,7 @@ |
422 | 422 | |
423 | 423 | $code = $this->targetLanguage; |
424 | 424 | $definition = trim( strval( $this->getDefinition() ) ); |
425 | | - $definition = str_replace( "\n", "<newline/>", $definition ); |
| 425 | + $definition = self::wrapUntranslatable( $definition ); |
426 | 426 | |
427 | 427 | $memckey = wfMemckey( 'translate-tmsug-badcodes-' . $serviceName ); |
428 | 428 | $unsupported = $wgMemc->get( $memckey ); |
— | — | @@ -478,11 +478,24 @@ |
479 | 479 | $ret = $req->getContent(); |
480 | 480 | $text = preg_replace( '~<string.*>(.*)</string>~', '\\1', $ret ); |
481 | 481 | $text = Sanitizer::decodeCharReferences( $text ); |
482 | | - $text = trim( preg_replace( "~\s*<newline></newline>\s*~", "\n", $text ) ); |
| 482 | + $text = self::unwrapUntranslatable( $text ); |
483 | 483 | $text = $this->suggestionField( $text ); |
484 | 484 | return Html::rawElement( 'div', null, self::legend( $serviceName ) . $text . self::clear() ); |
485 | 485 | } |
486 | 486 | |
| 487 | + protected static function wrapUntranslatable( $text ) { |
| 488 | + $text = str_replace( "\n", "!N!", $text ); |
| 489 | + $wrap = '<span class="notranslate">\0</span>'; |
| 490 | + $text = preg_replace( '~%[^% ]+%|\$\d|{VAR:[^}]+}|{?{(PLURAL|GRAMMAR|GENDER):[^|]+\||%(\d\$)?[sd]~', $wrap, $text ); |
| 491 | + return $text; |
| 492 | + } |
| 493 | + |
| 494 | + protected static function unwrapUntranslatable( $text ) { |
| 495 | + $text = str_replace( '!N!', "\n", $text ); |
| 496 | + $text = preg_replace( '~<span class="notranslate">(.*?)</span>~', '\1', $text ); |
| 497 | + return $text; |
| 498 | + } |
| 499 | + |
487 | 500 | protected function getApertiumSuggestion( $serviceName, $config ) { |
488 | 501 | global $wgMemc; |
489 | 502 | |