[Zope3-checkins] SVN: Zope3/trunk/src/zope/tal/t In case of tal:content, i18n:translate only MessageID/Message

Dmitry Vasiliev dima at hlabs.spb.ru
Fri May 20 03:41:14 EDT 2005


Log message for revision 30455:
  In case of tal:content, i18n:translate only MessageID/Message
  objects should be translated
  

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

-=-
Modified: Zope3/trunk/src/zope/tal/talinterpreter.py
===================================================================
--- Zope3/trunk/src/zope/tal/talinterpreter.py	2005-05-20 05:53:26 UTC (rev 30454)
+++ Zope3/trunk/src/zope/tal/talinterpreter.py	2005-05-20 07:41:14 UTC (rev 30455)
@@ -572,6 +572,17 @@
     bytecode_handlers["insertText"] = do_insertText
     bytecode_handlers["insertI18nText"] = do_insertText
 
+    def _writeText(self, text):
+        # '&' must be done first!
+        s = text.replace(
+            "&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
+        self._stream_write(s)
+        i = s.rfind('\n')
+        if i < 0:
+            self.col += len(s)
+        else:
+            self.col = len(s) - (i + 1)
+
     def do_insertText_tal(self, stuff):
         text = self.engine.evaluateText(stuff[0])
         if text is None:
@@ -586,15 +597,7 @@
                 ' deprecated and will be removed in 3.3.'
                 ' Use explicit i18n:translate="" instead.', DeprecationWarning)
             text = self.engine.translate(text)
-        # '&' must be done first!
-        s = text.replace(
-            "&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
-        self._stream_write(s)
-        i = s.rfind('\n')
-        if i < 0:
-            self.col = self.col + len(s)
-        else:
-            self.col = len(s) - (i + 1)
+        self._writeText(text)
 
     def do_insertI18nText_tal(self, stuff):
         # TODO: Code duplication is BAD, we need to fix it later
@@ -604,16 +607,9 @@
         if text is self.Default:
             self.interpret(stuff[1])
             return
-        text = self.translate(text, text, {})
-        # '&' must be done first!
-        s = text.replace(
-            "&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
-        self._stream_write(s)
-        i = s.rfind('\n')
-        if i < 0:
-            self.col = self.col + len(s)
-        else:
-            self.col = len(s) - (i + 1)
+        if isinstance(text, (MessageID, Message)):
+            text = self.engine.translate(text)
+        self._writeText(text)
 
     def do_i18nVariable(self, stuff):
         varname, program, expression, structure = stuff
@@ -744,7 +740,10 @@
         if structure is self.Default:
             self.interpret(block)
             return
-        text = self.translate(structure, structure, {})
+        if isinstance(structure, (MessageID, Message)):
+            text = self.engine.translate(structure)
+        else:
+            text = unicode(structure)
         if not (repldict or self.strictinsert):
             # Take a shortcut, no error checking
             self.stream_write(text)

Modified: Zope3/trunk/src/zope/tal/tests/test_talinterpreter.py
===================================================================
--- Zope3/trunk/src/zope/tal/tests/test_talinterpreter.py	2005-05-20 05:53:26 UTC (rev 30454)
+++ Zope3/trunk/src/zope/tal/tests/test_talinterpreter.py	2005-05-20 07:41:14 UTC (rev 30455)
@@ -239,7 +239,7 @@
             '<span i18n:translate="" tal:content="bar" i18n:name="bar_name"/>.'
             '</div>')
         self._check(program,
-                    '<div>THIS IS TEXT FOR <span>BARVALUE</span>.</div>\n')
+                    '<div>THIS IS TEXT FOR <span>BaRvAlUe</span>.</div>\n')
 
     def test_translate_static_text_as_dynamic_from_bytecode(self):
         program =  [('version', TAL_VERSION),
@@ -301,12 +301,11 @@
         self.interpreter()
         msgids = list(xlatdmn.data)
         msgids.sort()
-        self.assertEqual(2, len(msgids))
-        self.assertEqual('BaRvAlUe', msgids[0][0])
-        self.assertEqual('This is text for ${bar_name}.', msgids[1][0])
-        self.assertEqual({'bar_name': '<span>BARVALUE</span>'}, msgids[1][1])
+        self.assertEqual(1, len(msgids))
+        self.assertEqual('This is text for ${bar_name}.', msgids[0][0])
+        self.assertEqual({'bar_name': '<span>BaRvAlUe</span>'}, msgids[0][1])
         self.assertEqual(
-            '<div>THIS IS TEXT FOR <span>BARVALUE</span>.</div>\n',
+            '<div>THIS IS TEXT FOR <span>BaRvAlUe</span>.</div>\n',
             result.getvalue())
 
     def test_i18ntranslate_i18nname_and_attributes(self):



More information about the Zope3-Checkins mailing list