[Zope3-checkins] CVS: Zope3/src/zope/tal - talgenerator.py:1.9.4.3

Fred L. Drake, Jr. fred at zope.com
Fri Aug 8 17:31:39 EDT 2003


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

Modified Files:
      Tag: srichter-i18n-macro-interaction-branch
	talgenerator.py 
Log Message:
simply disallow i18n:name unless there's a containing translation unit


=== Zope3/src/zope/tal/talgenerator.py 1.9.4.2 => 1.9.4.3 ===
--- Zope3/src/zope/tal/talgenerator.py:1.9.4.2	Fri Aug  8 14:54:22 2003
+++ Zope3/src/zope/tal/talgenerator.py	Fri Aug  8 16:31:35 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
@@ -519,10 +520,10 @@
         varname = i18ndict.get('name')
         i18ndata = i18ndict.get('data')
 
-
-        if msgid == "" and varname and not (content or replace):
-            raise I18NError("it does not make sense to use i18n:translate "
-                            "and i18n:name in the same tag.", position)
+        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",
@@ -638,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
@@ -736,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:




More information about the Zope3-Checkins mailing list