[Checkins] SVN: Zope3/trunk/ Merged revisions 69021 and 69024 from the 3.3 branch:

Dmitry Vasiliev dima at hlabs.spb.ru
Fri Jul 7 09:45:54 EDT 2006


Log message for revision 69025:
  Merged revisions 69021 and 69024 from the 3.3 branch:
  
    - Fixed issue 646: TAL interpreter doesn't translate i18n Messages
      when inserted as attributes;
  
    - TAL interpreter now properly translate i18n Messages when inserted
      as structure;
  

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	2006-07-07 13:08:31 UTC (rev 69024)
+++ Zope3/trunk/doc/CHANGES.txt	2006-07-07 13:45:53 UTC (rev 69025)
@@ -16,6 +16,14 @@
 
     Bug fixes
 
+      - TAL interpreter didn't translate i18n Messages when inserted
+        as structure;
+
+      - Fixed issue 667: ZPT repeat "oddness"
+
+      - Fixed issue 646: TAL interpreter doesn't translate i18n
+        Messages when inserted as attributes;
+
       - Fixed issue 665: ZCML swallowing KeyboardInterrupt / SystemExit.
 
       - Fixed issue 525: DateWidget ru-format.

Modified: Zope3/trunk/src/zope/tal/talinterpreter.py
===================================================================
--- Zope3/trunk/src/zope/tal/talinterpreter.py	2006-07-07 13:08:31 UTC (rev 69024)
+++ Zope3/trunk/src/zope/tal/talinterpreter.py	2006-07-07 13:45:53 UTC (rev 69025)
@@ -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))]
@@ -744,7 +748,10 @@
         if structure is self.Default:
             self.interpret(block)
             return
-        text = unicode(structure)
+        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)
@@ -761,10 +768,9 @@
             if structure is self.Default:
                 self.interpret(block)
             else:
-                if isinstance(structure, TypesToTranslate):
-                    text = self.translate(structure)
-                else:
-                    text = unicode(structure)
+                if not isinstance(structure, TypesToTranslate):
+                    structure = unicode(structure)
+                text = self.translate(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	2006-07-07 13:08:31 UTC (rev 69024)
+++ Zope3/trunk/src/zope/tal/tests/test_talinterpreter.py	2006-07-07 13:45:53 UTC (rev 69025)
@@ -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"/>')
@@ -203,6 +223,16 @@
             '<span i18n:translate="" tal:replace="structure bar"/>')
         self._check(program, 'BARVALUE\n')
 
+        # i18n messages defined in Python are translated automatically
+        # (no i18n:translate necessary)
+        program, macros = self._compile(
+            '<span tal:content="structure foo"/>')
+        self._check(program, '<span>FOOVALUE</span>\n')
+
+        program, macros = self._compile(
+            '<span tal:replace="structure foo"/>')
+        self._check(program, 'FOOVALUE\n')
+
     def test_structure_text_translate(self):
         program, macros = self._compile(
             '<span tal:content="structure string:BaR"/>')
@@ -315,7 +345,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 +496,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