diff options
author | Dmitry Vasiliev <dima@hlabs.spb.ru> | 2006-07-07 13:45:53 +0000 |
---|---|---|
committer | Dmitry Vasiliev <dima@hlabs.spb.ru> | 2006-07-07 13:45:53 +0000 |
commit | 828aa4ad474f1c4c4e18517ca9919c4a15c25caf (patch) | |
tree | f92aec243f19880654e5c7c299d33eb484ead396 | |
parent | 00bec85b368755107cabd6c1b64d9ec6b86200fa (diff) | |
download | zope-tal-828aa4ad474f1c4c4e18517ca9919c4a15c25caf.tar.gz |
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;
-rw-r--r-- | talinterpreter.py | 16 | ||||
-rw-r--r-- | tests/test_talinterpreter.py | 34 |
2 files changed, 43 insertions, 7 deletions
diff --git a/talinterpreter.py b/talinterpreter.py index fc916ae..5e34e97 100644 --- a/talinterpreter.py +++ b/talinterpreter.py @@ -496,6 +496,10 @@ class TALInterpreter(object): 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 @@ class TALInterpreter(object): 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 @@ class TALInterpreter(object): 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) diff --git a/tests/test_talinterpreter.py b/tests/test_talinterpreter.py index f9158ee..651c0d7 100644 --- a/tests/test_talinterpreter.py +++ b/tests/test_talinterpreter.py @@ -32,6 +32,7 @@ from zope.tal.dummyengine import DummyTranslationDomain from zope.tal.tests import utils from zope.i18nmessageid import Message + class TestCaseBase(unittest.TestCase): def _compile(self, source): @@ -164,6 +165,25 @@ class I18NCornerTestCaseBase(TestCaseBase): '<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 @@ class I18NCornerTestCaseBase(TestCaseBase): '<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 @@ class I18NCornerTestCaseBase(TestCaseBase): ('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 @@ class I18NCornerTestCaseMessage(I18NCornerTestCaseBase): 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 |