[Zope-Checkins] CVS: Zope3/lib/python/Zope/TAL - TALGenerator.py:1.52.16.3.4.12

Barry Warsaw barry@wooz.org
Tue, 11 Jun 2002 15:34:07 -0400


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

Modified Files:
      Tag: fdrake-tal-i18n-branch
	TALGenerator.py 
Log Message:
Support for i18n:data attribute.  Specific changes:

emitTranslation(): Add the i18ndata to the method args.  If i18ndata
is not None, then it is an expression which will be used to find the
object referenced by the i18n:data attribute.  Thus it must be parsed
and compiled and then added to the insertTranslation opcode.

emitStartElement(): The prohibition is now that i18n:data must be
accompanied by an explicit message id (i.e. i18n:translate must exist
and its value must not be the empty string).

If i18n:data is given, we need to add it to the todo dict so it can
get evaluated in the emitEndElement().

emitEndElement(): Extract the i18n:data expression and add it to the
emitTranslation() call.


=== Zope3/lib/python/Zope/TAL/TALGenerator.py 1.52.16.3.4.11 => 1.52.16.3.4.12 ===
         self.emit('i18nVariable', varname, cexpr, program)
 
-    def emitTranslation(self, msgid):
+    def emitTranslation(self, msgid, i18ndata):
         program = self.popProgram()
-        self.emit('insertTranslation', msgid, program)
+        if i18ndata is None:
+            self.emit('insertTranslation', msgid, program)
+        else:
+            key, expr = parseSubstitution(i18ndata)
+            cexpr = self.compileExpression(expr)
+            assert key == 'text'
+            self.emit('insertTranslation', msgid, program, cexpr)
 
     def emitDefineMacro(self, macroName):
         program = self.popProgram()
@@ -484,9 +490,10 @@
         # interpretation phase.
         msgid = i18ndict.get("translate")
         varname = i18ndict.get('name')
+        i18ndata = i18ndict.get('data')
 
-        if i18ndict.has_key("data") and not i18ndict.has_key("name"):
-            raise I18NError("i18n:data must be accompanied by i18n:name",
+        if i18ndata and not msgid:
+            raise I18NError("i18n:data must be accompanied by i18n:translate",
                             position)
         
         if len(metaldict) > 1 and (defineMacro or useMacro):
@@ -588,6 +595,8 @@
             self.pushProgram()
         if msgid is not None:
             todo['msgid'] = msgid
+        if i18ndata:
+            todo['i18ndata'] = i18ndata
         optTag = omitTag is not None or TALtag
         if optTag:
             todo["optional tag"] = omitTag, TALtag
@@ -650,6 +659,7 @@
         msgid = todo.get('msgid')
         i18ncontext = todo.get("i18ncontext")
         varname = todo.get('i18nvar')
+        i18ndata = todo.get('i18ndata')
 
         if implied > 0:
             if defineMacro or useMacro or defineSlot or fillSlot:
@@ -664,7 +674,7 @@
         if content:
             self.emitSubstitution(content, {})
         if msgid is not None:
-            self.emitTranslation(msgid)
+            self.emitTranslation(msgid, i18ndata)
         if optTag:
             self.emitOptTag(name, optTag, isend)
         elif not isend: