logo       

cvs: pear /I18N/Messages Translate.php: msg#00458

Subject: cvs: pear /I18N/Messages Translate.php
cain            Wed Jun 26 11:24:12 2002 EDT

  Modified files:              
    /pear/I18N/Messages Translate.php 
  Log:
  - enhanced the translateMarkUp a bit, now u can also translate longer text 
with newlines in it etc properly
  - look for html characters in the code too
  
Index: pear/I18N/Messages/Translate.php
diff -u pear/I18N/Messages/Translate.php:1.5 
pear/I18N/Messages/Translate.php:1.6
--- pear/I18N/Messages/Translate.php:1.5        Fri Jun 21 06:16:09 2002
+++ pear/I18N/Messages/Translate.php    Wed Jun 26 11:24:11 2002
@@ -16,7 +16,7 @@
 // | Authors: Wolfram Kriesing <wolfram@xxxxxxxxxxx>                      |
 // +----------------------------------------------------------------------+
 //
-//  $Id: Translate.php,v 1.5 2002/06/21 10:16:09 cain Exp $
+//  $Id: Translate.php,v 1.6 2002/06/26 15:24:11 cain Exp $
 
 # we have to move this to some more common place in PEAR
 # this is just a quick hack here :-)
@@ -54,7 +54,7 @@
     *   @var    array   $possibleMarkUpDelimiters
     */
     var $possibleMarkUpDelimiters = array(
-                                    '>\s*'                          =>  
'\s*<', // this mostly applies, that a text is inbetween '>' and '<'
+                                    '>[^<]*'                        =>  
'[^>]*<', // this mostly applies, that a text is inbetween '>' and '<'
                                     '<\s*input .*value=["\']?\s*'   =>  
'\s*["\']?.*>'  // this is for input button's values
                                 );
 
@@ -223,13 +223,20 @@
         foreach( $this->translated['strings'] as $aString )             // 
search for each single string and try to translate it
         {
             $lastSubpattern = '$2';
-            $englishString = preg_quote($aString['string']);
+            // we use 2 strings that we search for, one is the real text as 
from the db
+            // the second $htmlSourceString is the source string but with all 
non html characters
+            // translated using htmlentities, in case someone has been 
programming proper html :-)
+            $sourceString = preg_quote(trim($aString['string']));
+            $htmlSourceString = 
preg_quote(htmlentities(trim($aString['string'])));
             // escape all slashes, since preg_quote doenst do that :-(
-            $englishString = str_replace('/','\/',$englishString);
+            $sourceString = str_replace('/','\/',$sourceString);
+            $htmlSourceString = str_replace('/','\/',$htmlSourceString);
 
             if( $aString['numSubPattern'] )         // if the string is a 
regExp, we need to update $lastSubpattern
             {
-                $englishString = $aString['string'];// we should not 
preg_quote the string
+                $sourceString = $aString['string'];// we should not preg_quote 
the string
+                $htmlSourceString = htmlentities($aString['string']);// we 
should not preg_quote the string
+
                 $lastSubpattern = '$'.( 2 + $aString['numSubPattern'] );    // 
set $lastSubpattern properly
             }
 
@@ -242,7 +249,7 @@
             // 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>
+            $res[1] = array_reverse($res[1]);   // ... if we wouldnt reverse 
all would become $<lastNumber>
             foreach( $res[0] as $index=>$aRes )
             {
                 $aRes = preg_quote($aRes);
@@ -251,7 +258,17 @@
 
             foreach( $this->possibleMarkUpDelimiters as $begin=>$end )  // go 
thru all the delimiters and try to translate the strings
             {
-                $input = preg_replace(  
'/('.$begin.')'.$englishString.'('.$end.')/i' ,
+                // replace all spaces in the source string by \s* so that 
there can be spaces
+                // as many as one wants and even newlines
+                $sourceString = preg_replace('/\s+/','\\s*',$sourceString);
+                $htmlSourceString = 
preg_replace('/\s+/s','\\s*',$htmlSourceString);
+
+                $input = preg_replace(  
'/('.$begin.')'.$sourceString.'('.$end.')/i' ,
+                                        '$1'.$translated."$lastSubpattern" ,
+                                        $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.')/is' ,
                                         '$1'.$translated."$lastSubpattern" ,
                                         $input );
             }



-- 
PEAR CVS Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
science.linguis...    culture.sf.lite...    video.mplayer.c...    yellowdog.gener...    ietf.rfc822/199...    emacs.help/2002...    redhat.release....    kernel.speakup/...    java.openejb.de...    debian.devel.gt...    xfree86.newbie/...    bug-tracking.ma...    pam/2003-05/msg...    games.devel.ope...    user-groups.lin...    music.pancham/2...    network.mq.deve...    web.html.genera...    arklinux.bugs/2...    linux.ecasound/...    qnx.openqnx.dev...    org.user-groups...    file-systems.sf...    trustix.contrib...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe