- $reg = '/'.$codefix . $scriptfix . $prefix . '<[^>]+>|&[a-zA-Z#][a-z0-9]+;' . $marker . $htmlfix . '/s';
-
- $matches = preg_split($reg, $text, -1, PREG_SPLIT_OFFSET_CAPTURE);
-
- $m = array_shift($matches);
-
- $ret = $this->translate($m[0], $toVariant);
- $mstart = $m[1]+strlen($m[0]);
-
- // enable convertsion of '<img alt="xxxx" ... ' or '<span title="xxxx" ... '
- $captionpattern = '/\s(title|alt)\s*=\s*"([\s\S]*?)"/';
- foreach($matches as $m) {
- $mark = substr($text, $mstart, $m[1]-$mstart);
- $mark = preg_replace_callback($captionpattern, array(&$this, 'captionConvert'), $mark);
- $ret .= $mark;
- $ret .= $this->translate($m[0], $toVariant);
- $mstart = $m[1] + strlen($m[0]);
- }
- wfProfileOut( $fname );
+ $reg = '/' . $codefix . $scriptfix . $prefix .
+ '<[^>]+>|&[a-zA-Z#][a-z0-9]+;' . $marker . $htmlfix . '/s';
+
+ $matches = preg_split( $reg, $text, - 1, PREG_SPLIT_OFFSET_CAPTURE );
+
+ $m = array_shift( $matches );
+
+ $ret = $this->translate( $m[0], $toVariant );
+ $mstart = $m[1] + strlen( $m[0] );
+
+ // enable convertsion of '<img alt="xxxx" ... '
+ // or '<span title="xxxx" ... '
+ $captionpattern = '/\s(title|alt)\s*=\s*"([\s\S]*?)"/';
+
+ $trtext = '';
+ $trtextmark = "\0";
+ $notrtext = array();
+ foreach ( $matches as $m ) {
+ $mark = substr( $text, $mstart, $m[1] - $mstart );
+ $mark = preg_replace_callback( $captionpattern,
+ array( &$this, 'captionConvert' ),
+ $mark );
+ // Let's convert the trtext only once,
+ // it would give us more performance improvement
+ $notrtext[] = $mark;
+ $trtext .= $m[0] . $trtextmark;
+ $mstart = $m[1] + strlen( $m[0] );
+ }
+ $notrtext[] = '';
+ $trtext = $this->translate( $trtext, $toVariant );
+ $trtext = StringUtils::explode( $trtextmark, $trtext );
+ foreach ( $trtext as $t ) {
+ $ret .= array_shift( $notrtext );
+ $ret .= $t;
+ }
+ wfProfileOut( __METHOD__ );