[Zope3-checkins] SVN: Zope3/trunk/src/zope/ Forward port from 3.3 branch:

Philipp von Weitershausen philikon at philikon.de
Sat May 20 09:32:40 EDT 2006


Log message for revision 68199:
  Forward port from 3.3 branch:
  ------------------------------------------------------------------------
  r68193 | philikon | 2006-05-20 15:03:52 +0200 (Sat, 20 May 2006) | 3 lines
  
  Make the default TALES context aware of other forms of text (e.g. i18n Messages).
  This gets rid of some code duplication in zope.app's TALES context.
  
  ------------------------------------------------------------------------
  r68194 | philikon | 2006-05-20 15:04:50 +0200 (Sat, 20 May 2006) | 4 lines
  
  Added a test for automatic translation of inserted i18n Messages
  (I wasn't sure whether this was working now so I just wrote this test since
  I didn't find any other proof that it would, other than the code).
  
  

Changed:
  U   Zope3/trunk/src/zope/app/pagetemplate/engine.py
  U   Zope3/trunk/src/zope/tal/tests/test_talinterpreter.py
  U   Zope3/trunk/src/zope/tales/tales.py

-=-
Modified: Zope3/trunk/src/zope/app/pagetemplate/engine.py
===================================================================
--- Zope3/trunk/src/zope/app/pagetemplate/engine.py	2006-05-20 13:31:42 UTC (rev 68198)
+++ Zope3/trunk/src/zope/app/pagetemplate/engine.py	2006-05-20 13:32:39 UTC (rev 68199)
@@ -96,15 +96,6 @@
 class ZopeContextBase(Context):
     """Base class for both trusted and untrusted evaluation contexts."""
 
-    def evaluateText(self, expr):
-        text = self.evaluate(expr)
-        if text is self.getDefault() or text is None:
-            return text
-        if isinstance(text, basestring):
-            # text could be a proxied/wrapped object
-            return text
-        return unicode(text)
-
     def evaluateMacro(self, expr):
         macro = Context.evaluateMacro(self, expr)
         return macro

Modified: Zope3/trunk/src/zope/tal/tests/test_talinterpreter.py
===================================================================
--- Zope3/trunk/src/zope/tal/tests/test_talinterpreter.py	2006-05-20 13:31:42 UTC (rev 68198)
+++ Zope3/trunk/src/zope/tal/tests/test_talinterpreter.py	2006-05-20 13:32:39 UTC (rev 68199)
@@ -154,6 +154,16 @@
             '<span i18n:translate="" tal:replace="foo"/>')
         self._check(program, 'FOOVALUE\n')
 
+        # i18n messages defined in Python are translated automatically
+        # (no i18n:translate necessary)
+        program, macros = self._compile(
+            '<span tal:content="foo" />')
+        self._check(program, '<span>FOOVALUE</span>\n')
+
+        program, macros = self._compile(
+            '<span tal:replace="foo" />')
+        self._check(program, 'FOOVALUE\n')
+
     def test_text_variable_translate(self):
         program, macros = self._compile(
             '<span tal:content="bar"/>')

Modified: Zope3/trunk/src/zope/tales/tales.py
===================================================================
--- Zope3/trunk/src/zope/tales/tales.py	2006-05-20 13:31:42 UTC (rev 68198)
+++ Zope3/trunk/src/zope/tales/tales.py	2006-05-20 13:32:39 UTC (rev 68199)
@@ -704,6 +704,9 @@
         text = self.evaluate(expr)
         if text is self.getDefault() or text is None:
             return text
+        if isinstance(text, basestring):
+            # text could already be something text-ish, e.g. a Message object
+            return text
         return unicode(text)
 
     def evaluateStructure(self, expr):



More information about the Zope3-Checkins mailing list