[Zope3-checkins] SVN: Zope3/trunk/ Fixed issue #455: tal:content="" does not get translated by i18n:translate=""

Dmitry Vasiliev dima at hlabs.spb.ru
Thu Nov 3 09:23:04 EST 2005


Log message for revision 39869:
  Fixed issue #455: tal:content="" does not get translated by i18n:translate=""
  

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/src/zope/tal/talinterpreter.py
  U   Zope3/trunk/src/zope/tal/tests/test_talinterpreter.py

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2005-11-03 13:08:17 UTC (rev 39868)
+++ Zope3/trunk/doc/CHANGES.txt	2005-11-03 14:23:04 UTC (rev 39869)
@@ -149,6 +149,9 @@
 
     Bug Fixes
 
+      - Fixed issue #455: tal:content="" does not get translated
+        by i18n:translate=""
+
       - Fixed issue #390: Deprecated ``IBaseRequest.body`` and
         ``IBaseRequest.bodyFile``. The latter was simply renamed to
         ``IBaseRequest.bodyStream``. No code assumes anymore that the input

Modified: Zope3/trunk/src/zope/tal/talinterpreter.py
===================================================================
--- Zope3/trunk/src/zope/tal/talinterpreter.py	2005-11-03 13:08:17 UTC (rev 39868)
+++ Zope3/trunk/src/zope/tal/talinterpreter.py	2005-11-03 14:23:04 UTC (rev 39869)
@@ -20,8 +20,6 @@
 import sys
 import warnings
 
-from types import StringType, UnicodeType
-
 # Do not use cStringIO here!  It's not unicode aware. :(
 from StringIO import StringIO
 
@@ -37,9 +35,12 @@
 from zope.tal.talgenerator import TALGenerator
 from zope.tal.translationcontext import TranslationContext
 
+
 # Avoid constructing this tuple over and over
 I18nMessageTypes = (MessageID, Message)
 
+TypesToTranslate = I18nMessageTypes + (str, unicode)
+
 # TODO: In Python 2.4 we can use frozenset() instead of dict.fromkeys()
 BOOLEAN_HTML_ATTRS = dict.fromkeys([
     # List of Boolean attributes in HTML that should be rendered in
@@ -650,16 +651,13 @@
     def do_insertI18nText_tal(self, stuff):
         # TODO: Code duplication is BAD, we need to fix it later
         text = self.engine.evaluateText(stuff[0])
-        if text is None:
-            return
-        if text is self.Default:
-            self.interpret(stuff[1])
-            return
-        if isinstance(text, I18nMessageTypes):
-            text = self.translate(text)
-        elif isinstance(text, (StringType, UnicodeType)):
-            text = self.translate(text)
-        self._writeText(text)
+        if text is not None:
+            if text is self.Default:
+                self.interpret(stuff[1])
+            else:
+                if isinstance(text, TypesToTranslate):
+                    text = self.translate(text)
+                self._writeText(text)
 
     def do_i18nVariable(self, stuff):
         varname, program, expression, structure = stuff
@@ -782,23 +780,21 @@
     def do_insertI18nStructure_tal(self, (expr, repldict, block)):
         # TODO: Code duplication is BAD, we need to fix it later
         structure = self.engine.evaluateStructure(expr)
-        if structure is None:
-            return
-        if structure is self.Default:
-            self.interpret(block)
-            return
-        if isinstance(structure, I18nMessageTypes):
-            text = self.translate(structure)
-        else:
-            text = unicode(structure)
-        if not (repldict or self.strictinsert):
-            # Take a shortcut, no error checking
-            self.stream_write(text)
-            return
-        if self.html:
-            self.insertHTMLStructure(text, repldict)
-        else:
-            self.insertXMLStructure(text, repldict)
+        if structure is not None:
+            if structure is self.Default:
+                self.interpret(block)
+            else:
+                if isinstance(structure, TypesToTranslate):
+                    text = self.translate(structure)
+                else:
+                    text = unicode(structure)
+                if not (repldict or self.strictinsert):
+                    # Take a shortcut, no error checking
+                    self.stream_write(text)
+                elif self.html:
+                    self.insertHTMLStructure(text, repldict)
+                else:
+                    self.insertXMLStructure(text, repldict)
 
     def insertHTMLStructure(self, text, repldict):
         from zope.tal.htmltalparser import HTMLTALParser

Modified: Zope3/trunk/src/zope/tal/tests/test_talinterpreter.py
===================================================================
--- Zope3/trunk/src/zope/tal/tests/test_talinterpreter.py	2005-11-03 13:08:17 UTC (rev 39868)
+++ Zope3/trunk/src/zope/tal/tests/test_talinterpreter.py	2005-11-03 14:23:04 UTC (rev 39869)
@@ -159,6 +159,58 @@
             '<span i18n:translate="" tal:replace="foo"/>')
         self._check(program, 'FOOVALUE\n')
 
+    def test_text_variable_translate(self):
+        program, macros = self._compile(
+            '<span tal:content="bar"/>')
+        self._check(program, '<span>BaRvAlUe</span>\n')
+
+        program, macros = self._compile(
+            '<span i18n:translate="" tal:content="bar"/>')
+        self._check(program, '<span>BARVALUE</span>\n')
+
+        program, macros = self._compile(
+            '<span i18n:translate="" tal:replace="bar"/>')
+        self._check(program, 'BARVALUE\n')
+
+    def test_text_translate(self):
+        program, macros = self._compile(
+            '<span tal:content="string:BaR"/>')
+        self._check(program, '<span>BaR</span>\n')
+
+        program, macros = self._compile(
+            '<span i18n:translate="" tal:content="string:BaR"/>')
+        self._check(program, '<span>BAR</span>\n')
+
+        program, macros = self._compile(
+            '<span i18n:translate="" tal:replace="string:BaR"/>')
+        self._check(program, 'BAR\n')
+
+    def test_structure_text_variable_translate(self):
+        program, macros = self._compile(
+            '<span tal:content="structure bar"/>')
+        self._check(program, '<span>BaRvAlUe</span>\n')
+
+        program, macros = self._compile(
+            '<span i18n:translate="" tal:content="structure bar"/>')
+        self._check(program, '<span>BARVALUE</span>\n')
+
+        program, macros = self._compile(
+            '<span i18n:translate="" tal:replace="structure bar"/>')
+        self._check(program, 'BARVALUE\n')
+
+    def test_structure_text_translate(self):
+        program, macros = self._compile(
+            '<span tal:content="structure string:BaR"/>')
+        self._check(program, '<span>BaR</span>\n')
+
+        program, macros = self._compile(
+            '<span i18n:translate="" tal:content="structure string:BaR"/>')
+        self._check(program, '<span>BAR</span>\n')
+
+        program, macros = self._compile(
+            '<span i18n:translate="" tal:replace="structure string:BaR"/>')
+        self._check(program, 'BAR\n')
+
     def test_replace_with_messageid_and_i18nname(self):
         program, macros = self._compile(
             '<div i18n:translate="" >'



More information about the Zope3-Checkins mailing list