[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/ Merged revision
30152 from the trunk:
Dmitry Vasiliev
dima at hlabs.spb.ru
Mon Apr 25 05:58:15 EDT 2005
Log message for revision 30153:
Merged revision 30152 from the trunk:
Fixed issue 314: i18n:translate removes line breaks
from <pre>...</pre> contents
Changed:
U Zope3/branches/ZopeX3-3.0/doc/CHANGES.txt
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/doc/CHANGES.txt
===================================================================
--- Zope3/branches/ZopeX3-3.0/doc/CHANGES.txt 2005-04-25 08:24:39 UTC (rev 30152)
+++ Zope3/branches/ZopeX3-3.0/doc/CHANGES.txt 2005-04-25 09:58:15 UTC (rev 30153)
@@ -10,6 +10,9 @@
Bug Fixes
+ - Fixed issue 314 (i18n:translate removes line breaks
+ from <pre>...</pre> contents).
+
- Fixed issue 394 (starting zope with command -C arg
causes request.form to contain '-C':'').
Modified: Zope3/branches/ZopeX3-3.0/src/zope/tal/talinterpreter.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/tal/talinterpreter.py 2005-04-25 08:24:39 UTC (rev 30152)
+++ Zope3/branches/ZopeX3-3.0/src/zope/tal/talinterpreter.py 2005-04-25 09:58:15 UTC (rev 30153)
@@ -243,6 +243,7 @@
# 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
@@ -336,7 +337,7 @@
if evalue is None:
ok = 0
value = evalue
-
+
if ok:
if xlat:
translated = self.translate(msgid or value, value, {})
@@ -536,8 +537,11 @@
# 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:
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-04-25 08:24:39 UTC (rev 30152)
+++ Zope3/branches/ZopeX3-3.0/src/zope/tal/tests/test_talinterpreter.py 2005-04-25 09:58:15 UTC (rev 30153)
@@ -23,6 +23,7 @@
from zope.tal.taldefs import METALError, I18NError
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
@@ -62,7 +63,7 @@
class MacroFunkyErrorTest(TestCaseBase):
-
+
def test_div_in_p_using_macro(self):
dummy, macros = self._compile('<p metal:define-macro="M">Booh</p>')
engine = DummyEngine(macros)
@@ -187,8 +188,7 @@
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 = []
@@ -201,6 +201,10 @@
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 '
@@ -216,6 +220,42 @@
'<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(
+ '<pre i18n:translate=""> This is text\n'
+ ' <b>\tfor</b>\n barvalue. </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)
+ self.assertEqual(
+ '<pre> THIS IS TEXT\n <B>\tFOR</B>\n BARVALUE. </pre>\n',
+ result.getvalue())
+
+ # XML mode
+ xlatdmn = self._getCollectingTranslationDomain()
+ result = StringIO()
+ parser = TALParser()
+ parser.parseString(
+ '<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(
+ '<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
More information about the Zope3-Checkins
mailing list