[Zope-Checkins] CVS: Zope3/lib/python/Zope/TAL - TALInterpreter.py:1.78

Barry Warsaw barry@wooz.org
Mon, 17 Jun 2002 20:15:46 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/TAL
In directory cvs.zope.org:/tmp/cvs-serv23224/lib/python/Zope/TAL

Modified Files:
	TALInterpreter.py 
Log Message:
do_insertTranslation(): Always evaluate the program, not just if we
have an implicit message id.  Doing this will give us some useful
information we might always need, such as any i18n:name attributes and
their values.

Only set the msgid to the contents of the stream if we have an
implicit message id.

translate(): Watch out for i18ndict == None (set it to an empty
dictionary if so).


=== Zope3/lib/python/Zope/TAL/TALInterpreter.py 1.77 => 1.78 ===
         self.i18nStack.append((i18ndict, srepr))
         msgid = stuff[0]
+        # We need to evaluate the content of the tag because that will give us
+        # several useful pieces of information.  First, the contents will
+        # include an implicit message id, if no explicit one was given.
+        # Second, it will evaluate any i18nVariable definitions in the body of
+        # the translation (necessary for $varname substitutions).
+        #
+        # Use a temporary stream to capture the interpretation of the
+        # subnodes, which should /not/ go to the output stream.
+        tmpstream = StringIO()
+        self.interpret(stuff[1], tmpstream)
+        # 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.
         if msgid == '':
-            # The content is the implicit message id.  Use a temporary stream
-            # to capture the interpretation of the subnodes, which should
-            # /not/ go to the output stream.
-            tmpstream = StringIO()
-            self.interpret(stuff[1], tmpstream)
             msgid = tmpstream.getvalue()
             # Now we need to normalize the whitespace in the implicit message
             # id by stripping leading and trailing whitespace, and folding all
@@ -584,6 +592,8 @@
 
     def translate(self, msgid, i18ndict=None, obj=None):
         # XXX is this right?
+        if i18ndict is None:
+            i18ndict = {}
         if obj:
             i18ndict.update(obj)
         # XXX need to fill this in with TranslationService calls.  For now,