[Checkins] SVN: Zope3/branches/3.3/ Fixed issue 646: TAL interpreter doesn't translate i18n Messages

Dmitry Vasiliev dima at hlabs.spb.ru
Fri Jul 7 08:17:20 EDT 2006


Log message for revision 69021:
  Fixed issue 646: TAL interpreter doesn't translate i18n Messages
  when inserted as attributes
  

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

-=-
Modified: Zope3/branches/3.3/doc/CHANGES.txt
===================================================================
--- Zope3/branches/3.3/doc/CHANGES.txt	2006-07-07 10:47:37 UTC (rev 69020)
+++ Zope3/branches/3.3/doc/CHANGES.txt	2006-07-07 12:17:19 UTC (rev 69021)
@@ -10,6 +10,9 @@
 
     Bugfixes
 
+      - Fixed issue 646: TAL interpreter doesn't translate i18n
+        Messages when inserted as attributes;
+
       - Fixed issue 665: ZCML swallowing KeyboardInterrupt and SystemExit.
 
       - Fixed issue 645: zope.testbrowser truncates document content after

Modified: Zope3/branches/3.3/src/zope/tal/talinterpreter.py
===================================================================
--- Zope3/branches/3.3/src/zope/tal/talinterpreter.py	2006-07-07 10:47:37 UTC (rev 69020)
+++ Zope3/branches/3.3/src/zope/tal/talinterpreter.py	2006-07-07 12:17:19 UTC (rev 69021)
@@ -496,6 +496,10 @@
                 translated = self.translate(msgid or value, value)
                 if translated is not None:
                     value = translated
+            elif isinstance(value, I18nMessageTypes):
+                translated = self.translate(value)
+                if translated is not None:
+                    value = translated
             if value is None:
                 value = name
             return ["%s=%s" % (name, quote(value))]

Modified: Zope3/branches/3.3/src/zope/tal/tests/test_talinterpreter.py
===================================================================
--- Zope3/branches/3.3/src/zope/tal/tests/test_talinterpreter.py	2006-07-07 10:47:37 UTC (rev 69020)
+++ Zope3/branches/3.3/src/zope/tal/tests/test_talinterpreter.py	2006-07-07 12:17:19 UTC (rev 69021)
@@ -32,6 +32,7 @@
 from zope.tal.tests import utils
 from zope.i18nmessageid import Message
 
+
 class TestCaseBase(unittest.TestCase):
 
     def _compile(self, source):
@@ -164,6 +165,25 @@
             '<span tal:replace="foo" />')
         self._check(program, 'FOOVALUE\n')
 
+    def test_attributes_translation(self):
+        program, macros = self._compile(
+            '<span tal:attributes="test bar"/>')
+        self._check(program, '<span test="BaRvAlUe" />\n')
+
+        program, macros = self._compile(
+            '<span test="bar" i18n:attributes="test"/>')
+        self._check(program, '<span test="BAR" />\n')
+
+        program, macros = self._compile(
+            '<span tal:attributes="test bar" i18n:attributes="test"/>')
+        self._check(program, '<span test="BARVALUE" />\n')
+
+        # i18n messages defined in Python are translated automatically
+        # (no i18n:attributes necessary)
+        program, macros = self._compile(
+            '<span tal:attributes="test foo"/>')
+        self._check(program, '<span test="FOOVALUE" />\n')
+
     def test_text_variable_translate(self):
         program, macros = self._compile(
             '<span tal:content="bar"/>')
@@ -315,7 +335,7 @@
    ('endScope', ()),
    ('rawtextOffset', ('.', 1))])),
 ('endScope', ()),
-('rawtextOffset', ('</div>', 6)) 
+('rawtextOffset', ('</div>', 6))
 ]
         self._check(program,
                     '<div>THIS IS TEXT FOR <span>BARVALUE</span>.</div>\n')
@@ -466,7 +486,7 @@
         return Message(msgid, domain=domain, default=default, mapping=mapping)
 
 class UnusedExplicitDomainTestCase(I18NCornerTestCaseMessage):
-    
+
     def setUp(self):
         # MultipleDomainsDummyEngine is a Engine
         # where default domain transforms to uppercase



More information about the Checkins mailing list