[Zope3-checkins] CVS: Zope3/src/zope/tal - talgenerator.py:1.5 talinterpreter.py:1.7

Fred L. Drake, Jr. fred@zope.com
Mon, 31 Mar 2003 14:16:26 -0500


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

Modified Files:
	talgenerator.py talinterpreter.py 
Log Message:
Update i18n:attributes to support explicit message IDs.

=== Zope3/src/zope/tal/talgenerator.py 1.4 => 1.5 ===
--- Zope3/src/zope/tal/talgenerator.py:1.4	Thu Mar 20 14:41:27 2003
+++ Zope3/src/zope/tal/talgenerator.py	Mon Mar 31 14:15:55 2003
@@ -455,13 +455,13 @@
         for item in attrlist:
             key = item[0]
             if repldict.has_key(key):
-                expr, xlat = repldict[key]
-                item = item[:2] + ("replace", expr, xlat)
+                expr, xlat, msgid = repldict[key]
+                item = item[:2] + ("replace", expr, xlat, msgid)
                 del repldict[key]
             newlist.append(item)
         # Add dynamic-only attributes
-        for key, (expr, xlat) in repldict.items():
-            newlist.append((key, None, "insert", expr, xlat))
+        for key, (expr, xlat, msgid) in repldict.items():
+            newlist.append((key, None, "insert", expr, xlat, msgid))
         return newlist
 
     def emitStartElement(self, name, attrlist, taldict, metaldict, i18ndict,
@@ -644,16 +644,17 @@
             else:
                 repldict = {}
             if i18nattrs:
-                i18nattrs = i18nattrs.split()
+                i18nattrs = _parseI18nAttributes(i18nattrs, self.position)
             else:
-                i18nattrs = ()
+                i18nattrs = {}
             # Convert repldict's name-->expr mapping to a
             # name-->(compiled_expr, translate) mapping
             for key, value in repldict.items():
-                repldict[key] = self.compileExpression(value), key in i18nattrs
+                ce = self.compileExpression(value)
+                repldict[key] = ce, key in i18nattrs, i18nattrs.get(key)
             for key in i18nattrs:
                 if key not in repldict:
-                    repldict[key] = None, 1
+                    repldict[key] = None, 1, i18nattrs.get(key)
         else:
             repldict = {}
         if replace:
@@ -774,6 +775,22 @@
             self.emitUseMacro(useMacro)
         if defineMacro:
             self.emitDefineMacro(defineMacro)
+
+def _parseI18nAttributes(i18nattrs, position):
+    d = {}
+    for spec in i18nattrs.split(";"):
+        parts = spec.split()
+        if len(parts) > 2:
+            raise TALError("illegal i18n:attributes specification: %r" % spec,
+                           position)
+        if len(parts) == 2:
+            attr, msgid = parts
+        else:
+            # len(parts) == 1
+            attr = parts[0]
+            msgid = None
+        d[attr] = msgid
+    return d
 
 def test():
     t = TALGenerator()


=== Zope3/src/zope/tal/talinterpreter.py 1.6 => 1.7 ===
--- Zope3/src/zope/tal/talinterpreter.py:1.6	Fri Mar 28 11:57:34 2003
+++ Zope3/src/zope/tal/talinterpreter.py	Mon Mar 31 14:15:55 2003
@@ -314,7 +314,7 @@
         if action in ('metal', 'tal', 'xmlns', 'i18n'):
             return self.attrAction(item)
         ok = 1
-        expr, msgid = item[3:]
+        expr, xlat, msgid = item[3:]
         if self.html and name.lower() in BOOLEAN_HTML_ATTRS:
             evalue = self.engine.evaluateBoolean(item[3])
             if evalue is self.Default:
@@ -335,8 +335,8 @@
                         ok = 0
                     value = evalue
         if ok:
-            if msgid:
-                translated = self.i18n_attribute(value)
+            if xlat:
+                translated = self.i18n_attribute(msgid or value)
                 if translated is not None:
                     value = translated
             if value is None: