[Zope3-checkins] CVS: Zope3/src/zope/tal - talinterpreter.py:1.3

Nathan R. Yergler nathan@yergler.net
Tue, 25 Mar 2003 10:48:02 -0500


Update of /cvs-repository/Zope3/src/zope/tal
In directory cvs.zope.org:/tmp/cvs-serv30088

Modified Files:
	talinterpreter.py 
Log Message:
Fixed talinterpreter to watch out for unknown translation message id.
The Plone people would like the i18n translation to return
the default text when the message ID is not found in the
translation table and there is an explicit message ID.

example:
<span i18n:translate="explict id">default text</span>
will now return
<span>default text</span>
if "explicit id" is not in the translation table instead of None (as previous)
        


=== Zope3/src/zope/tal/talinterpreter.py 1.2 => 1.3 ===
--- Zope3/src/zope/tal/talinterpreter.py:1.2	Wed Dec 25 09:15:29 2002
+++ Zope3/src/zope/tal/talinterpreter.py	Tue Mar 25 10:47:32 2003
@@ -526,8 +526,10 @@
         # We only care about the evaluated contents if we need an implicit
         # message id.  All other useful information will be in the i18ndict on
         # the top of the i18nStack.
+
+        default = normalize(tmpstream.getvalue())
         if msgid == '':
-            msgid = normalize(tmpstream.getvalue())
+            msgid = default
         self.i18nStack.pop()
         # See if there is was an i18n:data for msgid
         if len(stuff) > 2:
@@ -540,6 +542,20 @@
         # want to escape stuff like ${name} <= "<b>Timmy</b>".
         #s = escape(xlated_msgid)
         s = xlated_msgid
+
+        # watch out for unknown translation message id
+        # The Plone people would like the i18n translation to return
+        # the default text when the message ID is not found in the
+        # translation table and there is an explicit message ID.
+        # example:
+        # <span i18n:translate="explict id">default text</span>
+        # will return
+        # <span>default text</span>
+        # if "explicit id" is not in the translation table
+        
+        if s is None:
+            s = default or msgid
+            
         # If there are i18n variables to interpolate into this string, better
         # do it now.
         self._stream_write(s)