[Zope3-checkins] CVS: Zope3/src/zope/tal/tests -
test_htmltalparser.py:1.7 test_talinterpreter.py:1.5
Fred L. Drake, Jr.
fred at zope.com
Thu Aug 14 14:23:55 EDT 2003
Update of /cvs-repository/Zope3/src/zope/tal/tests
In directory cvs.zope.org:/tmp/cvs-serv6527/tests
Modified Files:
test_htmltalparser.py test_talinterpreter.py
Log Message:
Merge fixes from srichter-i18n-macro-interaction-branch:
- fix handling of nested translations with tal:content/replace and i18n:name
- port fix for #539 in collector from Zope 2.x (onerror)
- added relevant tests
- minor refactoring, added comments, and cleanup
Thanks go to Stephan Richter and Godefroid Chapelle for identifying
and fixing these corner cases.
=== Zope3/src/zope/tal/tests/test_htmltalparser.py 1.6 => 1.7 ===
--- Zope3/src/zope/tal/tests/test_htmltalparser.py:1.6 Fri Aug 8 19:04:59 2003
+++ Zope3/src/zope/tal/tests/test_htmltalparser.py Thu Aug 14 13:23:21 2003
@@ -602,6 +602,37 @@
('rawtextColumn', ('</span>\n', 0))
])
+ def test_i18n_name_with_content(self):
+ self._run_check('<div i18n:translate="">This is text for '
+ '<span i18n:translate="" tal:content="bar" i18n:name="bar_name"/>.'
+ '</div>', [
+('setPosition', (1, 0)),
+('beginScope', {'i18n:translate': ''}),
+('startTag', ('div', [('i18n:translate', '', 'i18n')])),
+('insertTranslation',
+ ('',
+ [('rawtextOffset', ('This is text for ', 17)),
+ ('setPosition', (1, 40)),
+ ('beginScope',
+ {'tal:content': 'bar', 'i18n:name': 'bar_name', 'i18n:translate': ''}),
+ ('i18nVariable',
+ ('bar_name',
+ [('startTag',
+ ('span',
+ [('i18n:translate', '', 'i18n'),
+ ('tal:content', 'bar', 'tal'),
+ ('i18n:name', 'bar_name', 'i18n')])),
+ ('insertTranslation',
+ ('',
+ [('insertText', ('$bar$', []))])),
+ ('rawtextOffset', ('</span>', 7))],
+ None)),
+ ('endScope', ()),
+ ('rawtextOffset', ('.', 1))])),
+('endScope', ()),
+('rawtextOffset', ('</div>', 6))
+ ])
+
def test_i18n_name_implicit_value(self):
# input/test22.html
self._run_check('''\
=== Zope3/src/zope/tal/tests/test_talinterpreter.py 1.4 => 1.5 ===
--- Zope3/src/zope/tal/tests/test_talinterpreter.py:1.4 Fri Aug 8 19:04:59 2003
+++ Zope3/src/zope/tal/tests/test_talinterpreter.py Thu Aug 14 13:23:21 2003
@@ -131,6 +131,75 @@
I18NError, self._compile,
'<span i18n:translate="" i18n:name="color_name">green</span>')
+ def test_translate_static_text_as_dynamic(self):
+ program, macros = self._compile(
+ '<div i18n:translate="">This is text for '
+ '<span i18n:translate="" tal:content="bar" i18n:name="bar_name"/>.'
+ '</div>')
+ self._check(program,
+ '<div>THIS IS TEXT FOR <span>BARVALUE</span>.</div>\n')
+
+ def test_translate_static_text_as_dynamic_from_bytecode(self):
+ program = [('version', '1.4'),
+ ('mode', 'html'),
+('setPosition', (1, 0)),
+('beginScope', {'i18n:translate': ''}),
+('startTag', ('div', [('i18n:translate', '', 'i18n')])),
+('insertTranslation',
+ ('',
+ [('rawtextOffset', ('This is text for ', 17)),
+ ('setPosition', (1, 40)),
+ ('beginScope',
+ {'tal:content': 'bar', 'i18n:name': 'bar_name', 'i18n:translate': ''}),
+ ('i18nVariable',
+ ('bar_name',
+ [('startTag',
+ ('span',
+ [('i18n:translate', '', 'i18n'),
+ ('tal:content', 'bar', 'tal'),
+ ('i18n:name', 'bar_name', 'i18n')])),
+ ('insertTranslation',
+ ('',
+ [('insertText', ('$bar$', []))])),
+ ('rawtextOffset', ('</span>', 7))],
+ None)),
+ ('endScope', ()),
+ ('rawtextOffset', ('.', 1))])),
+('endScope', ()),
+('rawtextOffset', ('</div>', 6))
+]
+ self._check(program,
+ '<div>THIS IS TEXT FOR <span>BARVALUE</span>.</div>\n')
+
+ def test_for_correct_msgids(self):
+
+ class CollectingTranslationService(DummyTranslationService):
+ data = []
+
+ def translate(self, msgid, domain=None, mapping=None,
+ context=None, target_language=None, default=None):
+ self.data.append(msgid)
+ return DummyTranslationService.translate(
+ self,
+ msgid, domain, mapping, context, target_language, default)
+
+ xlatsvc = CollectingTranslationService()
+ self.engine.translationService = xlatsvc
+ result = StringIO()
+ program, macros = self._compile(
+ '<div i18n:translate="">This is text for '
+ '<span i18n:translate="" tal:content="bar" '
+ 'i18n:name="bar_name"/>.</div>')
+ self.interpreter = TALInterpreter(program, {}, self.engine,
+ stream=result)
+ self.interpreter()
+ self.assert_('BaRvAlUe' in xlatsvc.data)
+ self.assert_('This is text for ${bar_name}.' in
+ xlatsvc.data)
+ self.assertEqual(
+ '<div>THIS IS TEXT FOR <span>BARVALUE</span>.</div>\n',
+ result.getvalue())
+
class I18NErrorsTestCase(TestCaseBase):
More information about the Zope3-Checkins
mailing list