diff options
author | Dmitry Vasiliev <dima@hlabs.spb.ru> | 2005-04-25 08:24:39 +0000 |
---|---|---|
committer | Dmitry Vasiliev <dima@hlabs.spb.ru> | 2005-04-25 08:24:39 +0000 |
commit | a528f668a52f15c064a215da73171acb14d194aa (patch) | |
tree | 251595fa3fde79b3d0383faeea33dfb7c12132b1 | |
parent | c68f94c23638e2df823be1fc8bd74677c68f9311 (diff) | |
download | zope-tal-a528f668a52f15c064a215da73171acb14d194aa.tar.gz |
Fixed issue 314: i18n:translate removes line breaks
from <pre>...</pre> contents
-rw-r--r-- | talinterpreter.py | 8 | ||||
-rw-r--r-- | tests/test_talinterpreter.py | 50 |
2 files changed, 54 insertions, 4 deletions
diff --git a/talinterpreter.py b/talinterpreter.py index 8d45a76..fda5fe5 100644 --- a/talinterpreter.py +++ b/talinterpreter.py @@ -348,6 +348,7 @@ class TALInterpreter(object): # for start tags with no attributes; those are optimized down # to rawtext events. Hence, there is no special "fast path" # for that case. + self._currentTag = name L = ["<", name] append = L.append col = self.col + _len(name) + 1 @@ -655,8 +656,11 @@ class TALInterpreter(object): # message id. All other useful information will be in the i18ndict on # the top of the i18nStack. default = tmpstream.getvalue() - if msgid == '': - msgid = normalize(default) + if not msgid: + if self.html and self._currentTag == "pre": + msgid = default + else: + msgid = normalize(default) self.i18nStack.pop() # See if there is was an i18n:data for msgid if len(stuff) > 2: diff --git a/tests/test_talinterpreter.py b/tests/test_talinterpreter.py index d71378c..9a8e655 100644 --- a/tests/test_talinterpreter.py +++ b/tests/test_talinterpreter.py @@ -24,6 +24,7 @@ from StringIO import StringIO from zope.tal.taldefs import METALError, I18NError, TAL_VERSION from zope.tal.htmltalparser import HTMLTALParser +from zope.tal.talparser import TALParser from zope.tal.talinterpreter import TALInterpreter from zope.tal.dummyengine import DummyEngine, DummyTranslationDomain from zope.tal.tests import utils @@ -260,8 +261,7 @@ class I18NCornerTestCaseBase(TestCaseBase): self._check(program, '<div>THIS IS TEXT FOR <span>BARVALUE</span>.</div>\n') - def test_for_correct_msgids(self): - + def _getCollectingTranslationDomain(self): class CollectingTranslationDomain(DummyTranslationDomain): data = [] @@ -274,6 +274,10 @@ class I18NCornerTestCaseBase(TestCaseBase): xlatdmn = CollectingTranslationDomain() self.engine.translationDomain = xlatdmn + return xlatdmn + + def test_for_correct_msgids(self): + xlatdmn = self._getCollectingTranslationDomain() result = StringIO() program, macros = self._compile( '<div i18n:translate="">This is text for ' @@ -289,6 +293,48 @@ class I18NCornerTestCaseBase(TestCaseBase): '<div>THIS IS TEXT FOR <span>BARVALUE</span>.</div>\n', result.getvalue()) + def test_for_raw_msgids(self): + # Test for Issue 314: i18n:translate removes line breaks from + # <pre>...</pre> contents + # HTML mode + 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 pre. </pre>') + self.interpreter = TALInterpreter(program, {}, self.engine, + stream=result) + self.interpreter() + self.assert_('This is text for div.' in xlatdmn.data) + self.assert_(' This is text\n <b>\tfor</b>\n pre. ' in + xlatdmn.data) + self.assertEqual( + '<div>THIS IS TEXT FOR DIV.</div>' + '<pre> THIS IS TEXT\n <B>\tFOR</B>\n PRE. </pre>\n', + result.getvalue()) + + # XML mode + xlatdmn = self._getCollectingTranslationDomain() + 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>') + program, macros = parser.getCode() + self.interpreter = TALInterpreter(program, {}, self.engine, + stream=result) + self.interpreter() + self.assert_('This is text <b> for</b> barvalue.' in + xlatdmn.data) + self.assertEqual( + '<?xml version="1.0"?>\n' + '<pre>THIS IS TEXT <B> FOR</B> BARVALUE.</pre>\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 |