[Zope3-checkins] SVN: Zope3/trunk/ Fixed issue 314: i18n:translate
removes line breaks
Dmitry Vasiliev
dima at hlabs.spb.ru
Mon Apr 25 04:24:39 EDT 2005
Log message for revision 30152:
Fixed issue 314: i18n:translate removes line breaks
from <pre>...</pre> contents
Changed:
U Zope3/trunk/doc/CHANGES.txt
U Zope3/trunk/src/zope/tal/talinterpreter.py
U Zope3/trunk/src/zope/tal/tests/test_talinterpreter.py
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2005-04-25 07:41:11 UTC (rev 30151)
+++ Zope3/trunk/doc/CHANGES.txt 2005-04-25 08:24:39 UTC (rev 30152)
@@ -40,7 +40,7 @@
namespace::
/++preferences++/zmi/folder/sortedby
-
+
* Preferences are easily accessible in Python code::
>>> prefs = IUserPreferences(context)
@@ -591,6 +591,9 @@
Bug Fixes
+ - Fixed issue #314: i18n:translate removes line breaks
+ from <pre>...</pre> contents
+
- The getAdapters function on site managers returned None when
adapter factories returned None. These values should not be
included in the output and now aren't.
@@ -1828,5 +1831,3 @@
- FTP support (not sure if this works)
- XML-RPC support (not sure if this works)
-
-
Modified: Zope3/trunk/src/zope/tal/talinterpreter.py
===================================================================
--- Zope3/trunk/src/zope/tal/talinterpreter.py 2005-04-25 07:41:11 UTC (rev 30151)
+++ Zope3/trunk/src/zope/tal/talinterpreter.py 2005-04-25 08:24:39 UTC (rev 30152)
@@ -348,6 +348,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
@@ -655,8 +656,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/trunk/src/zope/tal/tests/test_talinterpreter.py
===================================================================
--- Zope3/trunk/src/zope/tal/tests/test_talinterpreter.py 2005-04-25 07:41:11 UTC (rev 30151)
+++ Zope3/trunk/src/zope/tal/tests/test_talinterpreter.py 2005-04-25 08:24:39 UTC (rev 30152)
@@ -24,6 +24,7 @@
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 @@
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 @@
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 @@
'<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
More information about the Zope3-Checkins
mailing list