[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/src/zope/tal/t
Fixed issue with <pre> and i18n:name
Dmitry Vasiliev
dima at hlabs.spb.ru
Tue May 3 04:09:04 EDT 2005
Log message for revision 30233:
Fixed issue with <pre> and i18n:name
Changed:
U Zope3/branches/ZopeX3-3.0/src/zope/tal/talinterpreter.py
U Zope3/branches/ZopeX3-3.0/src/zope/tal/tests/test_talinterpreter.py
-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/tal/talinterpreter.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/tal/talinterpreter.py 2005-05-02 21:22:32 UTC (rev 30232)
+++ Zope3/branches/ZopeX3-3.0/src/zope/tal/talinterpreter.py 2005-05-03 08:09:03 UTC (rev 30233)
@@ -482,7 +482,10 @@
self.interpret(program)
finally:
self.popStream()
- value = normalize(tmpstream.getvalue())
+ if self.html and self._currentTag == "pre":
+ value = tmpstream.getvalue()
+ else:
+ value = normalize(tmpstream.getvalue())
finally:
self.restoreState(state)
else:
@@ -527,6 +530,7 @@
#
# Use a temporary stream to capture the interpretation of the
# subnodes, which should /not/ go to the output stream.
+ currentTag = self._currentTag
tmpstream = StringIO()
self.pushStream(tmpstream)
try:
@@ -538,7 +542,7 @@
# the top of the i18nStack.
default = tmpstream.getvalue()
if not msgid:
- if self.html and self._currentTag == "pre":
+ if self.html and currentTag == "pre":
msgid = default
else:
msgid = normalize(default)
Modified: Zope3/branches/ZopeX3-3.0/src/zope/tal/tests/test_talinterpreter.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/tal/tests/test_talinterpreter.py 2005-05-02 21:22:32 UTC (rev 30232)
+++ Zope3/branches/ZopeX3-3.0/src/zope/tal/tests/test_talinterpreter.py 2005-05-03 08:09:03 UTC (rev 30233)
@@ -81,6 +81,7 @@
self.engine = DummyEngine()
self.engine.setLocal('foo', MessageID('FoOvAlUe', 'default'))
self.engine.setLocal('bar', 'BaRvAlUe')
+ self.engine.setLocal('raw', ' \tRaW\n ')
def _check(self, program, expected):
result = StringIO()
@@ -194,7 +195,7 @@
def translate(self, msgid, mapping=None,
context=None, target_language=None, default=None):
- self.data.append(msgid)
+ self.data.append((msgid, mapping))
return DummyTranslationDomain.translate(
self,
msgid, mapping, context, target_language, default)
@@ -213,9 +214,12 @@
self.interpreter = TALInterpreter(program, {}, self.engine,
stream=result)
self.interpreter()
- self.assert_('BaRvAlUe' in xlatdmn.data)
- self.assert_('This is text for ${bar_name}.' in
- xlatdmn.data)
+ 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(
'<div>THIS IS TEXT FOR <span>BARVALUE</span>.</div>\n',
result.getvalue())
@@ -227,15 +231,21 @@
xlatdmn = self._getCollectingTranslationDomain()
result = StringIO()
program, macros = self._compile(
+ '<div i18n:translate=""> This is text\n'
+ ' \tfor\n div. </div>'
'<pre i18n:translate=""> This is text\n'
- ' <b>\tfor</b>\n barvalue. </pre>')
+ ' <b>\tfor</b>\n pre. </pre>')
self.interpreter = TALInterpreter(program, {}, self.engine,
stream=result)
self.interpreter()
- self.assert_(' This is text\n <b>\tfor</b>\n barvalue. ' in
- xlatdmn.data)
+ msgids = list(xlatdmn.data)
+ msgids.sort()
+ self.assertEqual(2, len(msgids))
+ self.assertEqual(' This is text\n <b>\tfor</b>\n pre. ', msgids[0][0])
+ self.assertEqual('This is text for div.', msgids[1][0])
self.assertEqual(
- '<pre> THIS IS TEXT\n <B>\tFOR</B>\n BARVALUE. </pre>\n',
+ '<div>THIS IS TEXT FOR DIV.</div>'
+ '<pre> THIS IS TEXT\n <B>\tFOR</B>\n PRE. </pre>\n',
result.getvalue())
# XML mode
@@ -243,6 +253,7 @@
result = StringIO()
parser = TALParser()
parser.parseString(
+ '<?xml version="1.0"?>\n'
'<pre xmlns:i18n="http://xml.zope.org/namespaces/i18n"'
' i18n:translate=""> This is text\n'
' <b>\tfor</b>\n barvalue. </pre>')
@@ -250,12 +261,35 @@
self.interpreter = TALInterpreter(program, {}, self.engine,
stream=result)
self.interpreter()
- self.assert_('This is text <b> for</b> barvalue.' in
- xlatdmn.data)
+ msgids = list(xlatdmn.data)
+ msgids.sort()
+ self.assertEqual(1, len(msgids))
+ self.assertEqual('This is text <b> for</b> barvalue.', msgids[0][0])
self.assertEqual(
+ '<?xml version="1.0"?>\n'
'<pre>THIS IS TEXT <B> FOR</B> BARVALUE.</pre>\n',
result.getvalue())
+ def test_raw_msgids_and_i18ntranslate_i18nname(self):
+ xlatdmn = self._getCollectingTranslationDomain()
+ result = StringIO()
+ program, macros = self._compile(
+ '<div i18n:translate=""> This is text\n \tfor\n'
+ '<pre tal:content="raw" i18n:name="raw"'
+ ' i18n:translate=""></pre>.</div>')
+ self.interpreter = TALInterpreter(program, {}, self.engine,
+ stream=result)
+ self.interpreter()
+ msgids = list(xlatdmn.data)
+ msgids.sort()
+ self.assertEqual(2, len(msgids))
+ self.assertEqual(' \tRaW\n ', msgids[0][0])
+ self.assertEqual('This is text for ${raw}.', msgids[1][0])
+ self.assertEqual({'raw': '<pre> \tRAW\n </pre>'}, msgids[1][1])
+ self.assertEqual(
+ u'<div>THIS IS TEXT FOR <pre> \tRAW\n </pre>.</div>\n',
+ result.getvalue())
+
def test_for_handling_unicode_vars(self):
# Make sure that non-ASCII Unicode is substituted correctly.
# http://collector.zope.org/Zope3-dev/264
More information about the Zope3-Checkins
mailing list