[Checkins] SVN: zope.app.form/trunk/ ported fix from zope.app.form 3.4.2: translation of display widgets for

Christian Theune ct at gocept.com
Thu Feb 7 12:00:49 EST 2008


Log message for revision 83628:
  ported fix from zope.app.form 3.4.2: translation of display widgets for
  sources
  

Changed:
  U   zope.app.form/trunk/CHANGES.txt
  U   zope.app.form/trunk/setup.py
  U   zope.app.form/trunk/src/zope/app/form/browser/i18n.txt
  U   zope.app.form/trunk/src/zope/app/form/browser/source.py
  U   zope.app.form/trunk/src/zope/app/form/ftesting.zcml

-=-
Modified: zope.app.form/trunk/CHANGES.txt
===================================================================
--- zope.app.form/trunk/CHANGES.txt	2008-02-07 16:59:04 UTC (rev 83627)
+++ zope.app.form/trunk/CHANGES.txt	2008-02-07 17:00:49 UTC (rev 83628)
@@ -8,6 +8,11 @@
 - Translate the title on SequenceWidget's "Add <title>" button.
 
 
+3.4.2 (2008-02-07)
+==================
+
+- Made display widgets for sources translate message IDs correctly.
+
 3.4.1 (2007-10-31)
 ==================
 

Modified: zope.app.form/trunk/setup.py
===================================================================
--- zope.app.form/trunk/setup.py	2008-02-07 16:59:04 UTC (rev 83627)
+++ zope.app.form/trunk/setup.py	2008-02-07 17:00:49 UTC (rev 83628)
@@ -62,6 +62,7 @@
       namespace_packages=['zope', 'zope.app'],
       extras_require={"test": ['zope.app.testing',
                                'zope.app.securitypolicy',
+                               'zc.sourcefactory',
                                'zope.app.zcmlfiles']},
       install_requires=[
           "setuptools",

Modified: zope.app.form/trunk/src/zope/app/form/browser/i18n.txt
===================================================================
--- zope.app.form/trunk/src/zope/app/form/browser/i18n.txt	2008-02-07 16:59:04 UTC (rev 83627)
+++ zope.app.form/trunk/src/zope/app/form/browser/i18n.txt	2008-02-07 17:00:49 UTC (rev 83628)
@@ -116,3 +116,38 @@
   ...Auffrischen...
   ...Hinzuf...
   ...Objektname...
+
+
+Source widgets
+--------------
+
+Titles of terms are translated by the source widgets. Let's create a source
+for which the terms create message ids:
+
+  >>> import zc.sourcefactory.basic
+  >>> from zope.i18nmessageid import MessageFactory
+  >>> _ = MessageFactory('coffee')
+  >>> class Coffees(zc.sourcefactory.basic.BasicSourceFactory):
+  ...     def getValues(self):
+  ...         return ['arabica', 'robusta', 'liberica', 'excelsa']
+  ...     def getTitle(self, value):
+  ...         return _(value, default='Translated %s' % value)
+
+
+  >>> import zope.schema
+  >>> from zope.publisher.browser import TestRequest
+  >>> coffee = zope.schema.Choice(
+  ...    __name__ = 'coffee',
+  ...    title=u"Kinds of coffee beans",
+  ...    source=Coffees())
+  >>> request = TestRequest()
+  >>> widget = zope.app.form.browser.source.SourceDisplayWidget(
+  ...     coffee, coffee.source, request)
+  >>> print widget()
+  Nothing
+  >>> from zope.app.form.browser.interfaces import IBrowserWidget
+  >>> IBrowserWidget.providedBy(widget)
+  True
+  >>> widget.setRenderedValue('arabica')
+  >>> print widget()
+  Translated arabica

Modified: zope.app.form/trunk/src/zope/app/form/browser/source.py
===================================================================
--- zope.app.form/trunk/src/zope/app/form/browser/source.py	2008-02-07 16:59:04 UTC (rev 83627)
+++ zope.app.form/trunk/src/zope/app/form/browser/source.py	2008-02-07 17:00:49 UTC (rev 83628)
@@ -83,7 +83,7 @@
     def renderTermForDisplay(self, term):
         # Provide a rendering of `term` for display; this is not for
         # use when generating a select list.
-        return xml.sax.saxutils.escape(term.title)
+        return xml.sax.saxutils.escape(self._translate(term.title))
 
 
 class SourceSequenceDisplayWidget(SourceDisplayWidget):
@@ -262,7 +262,7 @@
         terms = []
         for value in results:
             term = self.terms.getTerm(value)
-            terms.append((term.title, term.token))
+            terms.append((self._translate(term.title), term.token))
         terms.sort()
 
         apply = self._translate(_("SourceInputWidget-apply", default="Apply"))
@@ -283,7 +283,7 @@
     def renderTermForDisplay(self, term):
         # Provide a rendering of `term` for display; this is not for
         # use when generating a select list.
-        return xml.sax.saxutils.escape(term.title)
+        return xml.sax.saxutils.escape(self._translate(term.title))
 
     required = property(lambda self: self.context.required)
 
@@ -469,7 +469,7 @@
                                   default="Apply"))
         for value in results:
             term = self.terms.getTerm(value)
-            terms.append((term.title, term.token))
+            terms.append((self._translate(term.title), term.token))
         terms.sort()
         return (
             '<select name="%s.selection:list" multiple>\n'

Modified: zope.app.form/trunk/src/zope/app/form/ftesting.zcml
===================================================================
--- zope.app.form/trunk/src/zope/app/form/ftesting.zcml	2008-02-07 16:59:04 UTC (rev 83627)
+++ zope.app.form/trunk/src/zope/app/form/ftesting.zcml	2008-02-07 17:00:49 UTC (rev 83628)
@@ -50,6 +50,8 @@
       login="globalmgr"
       password="globalmgrpw" />
 
-  <grant role="zope.Manager" principal="zope.globalmgr" />
+    <grant role="zope.Manager" principal="zope.globalmgr" />
 
+    <include package="zc.sourcefactory" />
+
 </configure>



More information about the Checkins mailing list