[Zope3-checkins] CVS: Zope3/src/zope/tal - dummyengine.py:1.12 talgenerator.py:1.10 talinterpreter.py:1.27

Stephan Richter srichter at cosmos.phy.tufts.edu
Fri Aug 8 20:05:32 EDT 2003


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

Modified Files:
	dummyengine.py talgenerator.py talinterpreter.py 
Log Message:
Fixed a couple of bugs in TAL. There are two more tests in the branch that 
are failing, but they uncover a deep, deep issue, so that we all (Barry,
Fred and I) will try on Monday again.


=== Zope3/src/zope/tal/dummyengine.py 1.11 => 1.12 ===
--- Zope3/src/zope/tal/dummyengine.py:1.11	Tue Jun  3 11:20:06 2003
+++ Zope3/src/zope/tal/dummyengine.py	Fri Aug  8 19:04:56 2003
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# Copyright (c) 2001, 2002, 2003 Zope Corporation and Contributors.
 # All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
@@ -12,14 +12,16 @@
 #
 ##############################################################################
 """Dummy TAL expression engine so that I can test out the TAL implementation.
-"""
 
+$Id$
+"""
 import re
 
 from zope.interface import implements
 from zope.tal.taldefs import NAME_RE, TALExpressionError, ErrorInfo
 from zope.tal.interfaces import ITALExpressionCompiler, ITALExpressionEngine
 from zope.i18n.interfaces import ITranslationService
+from zope.i18n.messageid import MessageID
 
 Default = object()
 
@@ -87,6 +89,7 @@
         else:
             type = "path"
             expr = expression
+
         if type in ("string", "str"):
             return expr
         if type in ("path", "var", "global", "local"):
@@ -127,6 +130,8 @@
 
     def evaluateText(self, expr):
         text = self.evaluate(expr)
+        if isinstance(text, (str, unicode, MessageID)):
+            return text
         if text is not None and text is not Default:
             text = str(text)
         return text
@@ -227,6 +232,11 @@
         # If the domain is a string method, then transform the string
         # by calling that method.
 
+        # MessageID attributes override arguments
+        if isinstance(msgid, MessageID):
+            domain = msgid.domain
+            mapping = msgid.mapping
+            default = msgid.default
 
         # simulate an unknown msgid by returning None
         if msgid == "don't translate me":


=== Zope3/src/zope/tal/talgenerator.py 1.9 => 1.10 ===
--- Zope3/src/zope/tal/talgenerator.py:1.9	Tue Jul 29 10:15:22 2003
+++ Zope3/src/zope/tal/talgenerator.py	Fri Aug  8 19:04:56 2003
@@ -64,6 +64,7 @@
             self.source_file = source_file
             self.emit("setSourceFile", source_file)
         self.i18nContext = TranslationContext()
+        self.i18nLevel = 0
 
     def getCode(self):
         assert not self.stack
@@ -347,8 +348,6 @@
             assert action == I18N_EXPRESSION
             key, expr = parseSubstitution(expression)
             cexpr = self.compileExpression(expr)
-        # XXX Would key be anything but 'text' or None?
-        assert key in ('text', None)
         self.emit('i18nVariable', varname, program, cexpr)
 
     def emitTranslation(self, msgid, i18ndata):
@@ -521,6 +520,11 @@
         varname = i18ndict.get('name')
         i18ndata = i18ndict.get('data')
 
+        if varname and not self.i18nLevel:
+            raise I18NError(
+                "i18n:name can only occur inside a translation unit",
+                position)
+
         if i18ndata and not msgid:
             raise I18NError("i18n:data must be accompanied by i18n:translate",
                             position)
@@ -635,6 +639,7 @@
             todo['i18nvar'] = (varname, None)
             self.pushProgram()
         if msgid is not None:
+            self.i18nLevel += 1
             todo['msgid'] = msgid
         if i18ndata:
             todo['i18ndata'] = i18ndata
@@ -733,8 +738,10 @@
         # the opcode after the i18nVariable opcode so we can better handle
         # tags with both of them in them (and in the latter case, the contents
         # would be thrown away for msgid purposes).
-        if msgid is not None and not varname:
-            self.emitTranslation(msgid, i18ndata)
+        if msgid is not None:
+            if not varname:
+                self.emitTranslation(msgid, i18ndata)
+            self.i18nLevel -= 1
         if optTag:
             self.emitOptTag(name, optTag, isend)
         elif not isend:


=== Zope3/src/zope/tal/talinterpreter.py 1.26 => 1.27 ===
--- Zope3/src/zope/tal/talinterpreter.py:1.26	Fri Aug  8 06:43:53 2003
+++ Zope3/src/zope/tal/talinterpreter.py	Fri Aug  8 19:04:56 2003
@@ -487,6 +487,12 @@
             # Evaluate the value to be associated with the variable in the
             # i18n interpolation dictionary.
             value = self.engine.evaluate(expression)
+
+            # evaluate() does not do any I18n, so we do it here. 
+            if isinstance(value, MessageID):
+                # Translate this now.
+                value = self.engine.translate(value)
+
         # Either the i18n:name tag is nested inside an i18n:translate in which
         # case the last item on the stack has the i18n dictionary and string
         # representation, or the i18n:name and i18n:translate attributes are




More information about the Zope3-Checkins mailing list