Index: trunk/phase3/languages/LanguageConverter.php |
— | — | @@ -199,6 +199,24 @@ |
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 | + * @param string $title the "title" or "alt" text |
| 209 | + * @param string $text the text to be converted |
| 210 | + * @param string $toVariant the target language code |
| 211 | + * @return string like ' alt="yyyy"' or ' title="yyyy"' |
| 212 | + */ |
| 213 | + protected function captionConvert( $title, $text, $toVariant ) { |
| 214 | + // we convert captions except URL |
| 215 | + if( !strpos( $text, '://' ) ) |
| 216 | + $text = $this->translate($text, $toVariant); |
| 217 | + return " $title=\"$text\""; |
| 218 | + } |
| 219 | + |
| 220 | + /** |
203 | 221 | * dictionary-based conversion |
204 | 222 | * |
205 | 223 | * @param string $text the text to be converted |
— | — | @@ -248,8 +266,14 @@ |
249 | 267 | |
250 | 268 | $ret = $this->translate($m[0], $toVariant); |
251 | 269 | $mstart = $m[1]+strlen($m[0]); |
| 270 | + |
| 271 | + // enable convertsion of '<img alt="xxxx" ... ' or '<span title="xxxx" ... ' |
| 272 | + $captionpattern = '/\s(title|alt)\s*=\s*"([\s\S]*?)"/e'; |
| 273 | + $replacement = "\$this->captionConvert('\\1', '\\2', \$toVariant)"; |
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($captionpattern, $replacement, $mark); |
| 277 | + $ret .= $mark; |
254 | 278 | $ret .= $this->translate($m[0], $toVariant); |
255 | 279 | $mstart = $m[1] + strlen($m[0]); |
256 | 280 | } |