foreach( $res[0] as $index=>$aRes )
{
$aRes = preg_quote($aRes);
$translated = preg_replace( '/'.$aRes.'/' , '\$'.($res[1][$index]+1) , $translated );
}
}
else
{
// in none regExp's source strings we better quote the chars which could be
// mistakenly seen as regExp chars
$sourceString = preg_quote(trim($aString['string']));
$htmlSourceString = preg_quote(htmlentities(trim($aString['string'])));
// escape all slashes, since preg_quote doenst do that :-(
$sourceString = str_replace('/','\/',$sourceString);
$htmlSourceString = str_replace('/','\/',$htmlSourceString);
}
foreach( $this->possibleMarkUpDelimiters as $delimiters ) // go thru all the delimiters and try to translate the strings
{
// FIXXME there might be a major problem:
// which are possible delimtier :-(
// {else}
// class="naviItem"
// nowrap>
//
//
$numSubPatterns = array(0,0);
$begin = $delimiters[0];
$end = $delimiters[1];
if( isset($delimiters[2]) ) $numSubPatterns[0] = $delimiters[2];
if( isset($delimiters[3]) ) $numSubPatterns[1] = $delimiters[3];
// replace all spaces in the source string by \s* so that there can be spaces
// as many as one wants
// and even newlines (the modifier s in the preg_replace takes care of that)
$sourceString = preg_replace('/\s+/','\\s*',$sourceString);
$htmlSourceString = preg_replace('/\s+/s','\\s*',$htmlSourceString);
$_hashCode = md5($input);
$input = preg_replace( '/('.$begin.')'.$sourceString.'('.$end.')/sU'.$addModifier ,
'$1'.$translated.'$'.($lastSubpattern+$numSubPatterns[0]) ,
$input );
// if the regExp above didnt have no effect try this one with all html characters translated
// if we wouldnt check this i had the effect that something was translated twice ...
// dont know exactly why but it did :-)
if( $_hashCode == md5($input) )
{
// try also to translate the string with all non-HTML-characters translated using htmlentities
// may be someone was creating proper html :-)
$input = preg_replace( '/('.$begin.')'.$htmlSourceString.'('.$end.')/sU'.$addModifier ,
'$1'.$translated.'$'.($lastSubpattern+$numSubPatterns[0]) ,
$input );
}
}
}
return $input;
}
/**
*
*
* @access public
* @author Wolfram Kriesing
* @version 02/04/14
* @param string the url to a translation tool
* @return
*/
/* function addTranslatorLinks( $input , $url )
{
$linkBegin = ' T ';
foreach( $this->_translated['strings'] as $aString ) // search for each single string and try to translate it
{
$englishString = preg_quote($aString['string']);
if( $aString['numSubPattern'] ) // if the string is a regExp, we need to update $lastSubpattern
{
$englishString = $aString['string'];// we should not preg_quote the string
$lastSubpattern = '$'.( 2 + $aString['numSubPattern'] ); // set $lastSubpattern properly
}
$link = $linkBegin.urlencode($englishString).$linkEnd;
$input = preg_replace( '/(\s*>\s*)('.$englishString.')(\s*<\/a>)/isU' , '$1$2$3'.$link , $input );
$input = preg_replace( '/(\s*)('.$englishString.')(.*<\/select>)/isU' , '$1$2$3'.$link , $input );
$input = preg_replace( '/(]*type=.?(button|submit|reset)[^>]*value=.?\s*)'.
'('.$englishString.')([^>]*>)/isU' , '$1$3$4'.$link , $input );
}
return $input;
}
# '>\s*' => '\s*<', // this mostly applies, that a text is inbetween '>' and '<'
# '<\s*input .*value=["\']?\s*' => '\s*["\']?.*>' // this is for input button's values
*/
} // end of class
?>
|