cvs: pear /I18N/Messages Translate.php
| From: | Wolfram Kriesing | Date: | Sun, 07 Apr 2002 17:55:57 +0000 |
| Subject: | cvs: pear /I18N/Messages Translate.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-3111@lists.php.net to get a copy of this message | ||
cain Sun Apr 7 13:55:57 2002 EDT
Modified files:
/pear/I18N/Messages Translate.php
Log:
- added comment
- made the spaceholder start at $1 not $2 anymore, as it used to be
Index: pear/I18N/Messages/Translate.php
diff -u pear/I18N/Messages/Translate.php:1.2 pear/I18N/Messages/Translate.php:1.3
--- pear/I18N/Messages/Translate.php:1.2 Tue Feb 12 12:25:05 2002
+++ pear/I18N/Messages/Translate.php Sun Apr 7 13:55:56 2002
@@ -16,7 +16,7 @@
// | Authors: Wolfram Kriesing <wolfram@kriesing.de> |
// +----------------------------------------------------------------------+
//
-// $Id: Translate.php,v 1.2 2002/02/12 17:25:05 cain Exp $
+// $Id: Translate.php,v 1.3 2002/04/07 17:55:56 cain Exp $
# we have to move this to some more common place in PEAR
# this is just a quick hack here :-)
@@ -44,6 +44,13 @@
* this way we prevent from translating each HTML-tag, which definetly wouldnt work :-)
* those delimiters might also work on any other markup language, like xml - but not tested
*
+ * NOTE: if you have php inside such a tag then you have to use an extra filter
+ * since <a href="">< ?=$var? ></a> would find the php-tags and
see them as delimiters
+ * which results in < ?=$var? > can not be translated, see sf.net/projects/simpletpl,
there
+ * is a filter in 'SimpleTemplate/Filter/Basic::applyTranslateFunction' which solves
this
+ * it wraps a given function/method around it so that it finally will be:
+ * <a href="">< ?=translateThis($var)? ></a>
+ *
* @var array $possibleMarkUpDelimiters
*/
var $possibleMarkUpDelimiters = array(
@@ -228,6 +235,17 @@
$translated = htmlentities($aString['translated']);
else
$translated = $aString['translated'];
+
+ // in the DB the spaceholders start with $1, but here we need it
+ // to start with $2, that's what the following does
+ preg_match_all ( '/\$(\d)/' , $translated , $res );
+ $res[0] = array_reverse($res[0]); // reverse the arrays, since we replace $1 by $2
and then $2 by $3 ...
+ $res[1] = array_reverse($res[1]); // ... if we wouldnt reverse all would be
$<lastNumber>
+ foreach( $res[0] as $index=>$aRes )
+ {
+ $aRes = preg_quote($aRes);
+ $translated = preg_replace( '/'.$aRes.'/' ,
'\$'.($res[1][$index]+1) , $translated );
+ }
foreach( $this->possibleMarkUpDelimiters as $begin=>$end ) // go thru all the
delimiters and try to translate the strings
{