Revision: 46068
Author: philip
Date: 2009-01-23 07:56:04 +0000 (Fri, 23 Jan 2009)
Log Message:
-----------
Enable language conversion
in "alt" and "title" attributes.
Modified Paths:
--------------
trunk/phase3/languages/LanguageConverter.php
Modified: trunk/phase3/languages/LanguageConverter.php
===================================================================
--- trunk/phase3/languages/LanguageConverter.php 2009-01-23 07:36:06 UTC
(rev 46067)
+++ trunk/phase3/languages/LanguageConverter.php 2009-01-23 07:56:04 UTC
(rev 46068)
@@ -199,6 +199,24 @@
}
/**
+ * caption convert, base on preg_replace_callback
+ *
+ * to convert text in "title" or "alt", like '<img alt="text" ... '
+ * or '<span title="text" ... '
+ *
+ * @param string $title the "title" or "alt" text
+ * @param string $text the text to be converted
+ * @param string $toVariant the target language code
+ * @return string like ' alt="yyyy"' or ' title="yyyy"'
+ */
+ protected function captionConvert( $title, $text, $toVariant ) {
+ // we convert captions except URL
+ if( !strpos( $text, '://' ) )
+ $text = $this->translate($text, $toVariant);
+ return " $title=\"$text\"";
+ }
+
+ /**
* dictionary-based conversion
*
* @param string $text the text to be converted
@@ -248,8 +266,14 @@
$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]*?)"/e';
+ $replacement = "\$this->captionConvert('\\1', '\\2',
\$toVariant)";
foreach($matches as $m) {
- $ret .= substr($text, $mstart, $m[1]-$mstart);
+ $mark = substr($text, $mstart, $m[1]-$mstart);
+ $mark = preg_replace($captionpattern, $replacement,
$mark);
+ $ret .= $mark;
$ret .= $this->translate($m[0], $toVariant);
$mstart = $m[1] + strlen($m[0]);
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs