Index: trunk/phase3/languages/LanguageConverter.php |
— | — | @@ -199,6 +199,25 @@ |
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
| 203 | + * caption convert, base on preg_replace_callback |
| 204 | + * |
| 205 | + * to convert text in "title" or "alt", like '<img alt="text" ... ' |
| 206 | + * or '<span title="text" ... ' |
| 207 | + * |
| 208 | + * @return string like ' alt="yyyy"' or ' title="yyyy"' |
| 209 | + * @private |
| 210 | + */ |
| 211 | + function captionConvert( $matches ) { |
| 212 | + // we convert captions except URL |
| 213 | + $toVariant = $this->getPreferredVariant(); |
| 214 | + $title = $matches[1]; |
| 215 | + $text = $matches[2]; |
| 216 | + if( !strpos( $text, '://' ) ) |
| 217 | + $text = $this->translate($text, $toVariant); |
| 218 | + return " $title=\"$text\""; |
| 219 | + } |
| 220 | + |
| 221 | + /** |
203 | 222 | * dictionary-based conversion |
204 | 223 | * |
205 | 224 | * @param string $text the text to be converted |
— | — | @@ -248,8 +267,13 @@ |
249 | 268 | |
250 | 269 | $ret = $this->translate($m[0], $toVariant); |
251 | 270 | $mstart = $m[1]+strlen($m[0]); |
| 271 | + |
| 272 | + // enable convertsion of '<img alt="xxxx" ... ' or '<span title="xxxx" ... ' |
| 273 | + $captionpattern = '/\s(title|alt)\s*=\s*"([\s\S]*?)"/'; |
252 | 274 | foreach($matches as $m) { |
253 | | - $ret .= substr($text, $mstart, $m[1]-$mstart); |
| 275 | + $mark = substr($text, $mstart, $m[1]-$mstart); |
| 276 | + $mark = preg_replace_callback($captionpattern, array(&$this, 'captionConvert'), $mark); |
| 277 | + $ret .= $mark; |
254 | 278 | $ret .= $this->translate($m[0], $toVariant); |
255 | 279 | $mstart = $m[1] + strlen($m[0]); |
256 | 280 | } |