[Checkins] SVN: z3c.pt/trunk/ Fixed undefined name 'static' error in i18n attributes handling and added quoting to i18n attributes.

Hanno Schlichting plone at hannosch.info
Sat Jun 14 05:40:47 EDT 2008


Log message for revision 87387:
  Fixed undefined name 'static' error in i18n attributes handling and added quoting to i18n attributes.
  

Changed:
  U   z3c.pt/trunk/docs/HISTORY.txt
  U   z3c.pt/trunk/src/z3c/pt/i18n.txt
  U   z3c.pt/trunk/src/z3c/pt/translation.py

-=-
Modified: z3c.pt/trunk/docs/HISTORY.txt
===================================================================
--- z3c.pt/trunk/docs/HISTORY.txt	2008-06-14 09:21:15 UTC (rev 87386)
+++ z3c.pt/trunk/docs/HISTORY.txt	2008-06-14 09:40:47 UTC (rev 87387)
@@ -4,6 +4,9 @@
 Version 0.8.x
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+- Fixed undefined name 'static' error in i18n attributes handling and added
+  quoting to i18n attributes.
+
 - Added condition to the valid attributes on tags in the tal namespace.
 
 - Made sure the traceback from the *first* template exception

Modified: z3c.pt/trunk/src/z3c/pt/i18n.txt
===================================================================
--- z3c.pt/trunk/src/z3c/pt/i18n.txt	2008-06-14 09:21:15 UTC (rev 87386)
+++ z3c.pt/trunk/src/z3c/pt/i18n.txt	2008-06-14 09:40:47 UTC (rev 87387)
@@ -111,3 +111,65 @@
   <div>
     <p>Mock translation of '${count} bananas.'.</p>
   </div>
+
+Translation of tag attributes
+-----------------------------
+
+A simple example to start with.
+  
+  >>> body = """\
+  ... <div xmlns="http://www.w3.org/1999/xhtml"
+  ...      xmlns:i18n="http://xml.zope.org/namespaces/i18n">
+  ...   <span i18n:domain="test" title="Simple Title" i18n:attributes="title">
+  ...     Default
+  ...   </span>
+  ... </div>"""
+
+Not passing a language:
+
+  >>> template = PageTemplate(body)
+  >>> print template.render()
+  <div>
+    <span title="Simple Title">
+      Default
+    </span>
+  </div>
+
+Passing German:
+
+  >>> print template.render(target_language='de')
+  <div>
+    <span title="Mock translation of 'Simple Title'.">
+      Default
+    </span>
+  </div>
+
+Use an explicit msgid:
+
+  >>> body = """\
+  ... <div xmlns="http://www.w3.org/1999/xhtml"
+  ...      xmlns:i18n="http://xml.zope.org/namespaces/i18n">
+  ...   <span i18n:domain="test" title="Simple Title"
+  ...         i18n:attributes="title title_simple">
+  ...     Default
+  ...   </span>
+  ... </div>"""
+
+Not passing a language:
+
+  >>> template = PageTemplate(body)
+  >>> print template.render()
+  <div>
+    <span title="Simple Title">
+      Default
+    </span>
+  </div>
+
+Passing German:
+
+  >>> print template.render(target_language='de')
+  <div>
+    <span title="Mock translation of 'title_simple'.">
+      Default
+    </span>
+  </div>

Modified: z3c.pt/trunk/src/z3c/pt/translation.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/translation.py	2008-06-14 09:21:15 UTC (rev 87386)
+++ z3c.pt/trunk/src/z3c/pt/translation.py	2008-06-14 09:40:47 UTC (rev 87387)
@@ -284,15 +284,17 @@
                         raise ValueError, "Message id not allowed in conjunction with " + \
                                           "a dynamic attribute."
 
-                    value = types.value(msgid)
+                    value = types.value('"%s"' % msgid)
 
-                    if variable in static:
-                        expression = _translate(value, default=attributes[variable])
+                    if variable in attributes:
+                        default = '"%s"' % attributes[variable]
+                        expression = _translate(value, default=default)
                     else:
                         expression = _translate(value)
                 else:
-                    if variable in dynamic or variable in static:
-                        expression = _translate(attributes[variable])
+                    if variable in dynamic or variable in attributes:
+                        text = '"%s"' % attributes[variable]
+                        expression = _translate(text)
                     else:
                         raise ValueError, "Must be either static or dynamic attribute " + \
                                           "when no message id is supplied."



More information about the Checkins mailing list