[Zope-Checkins] CVS: Zope3/lib/python/Zope/TAL - TALInterpreter.py:1.79.2.1
Barry Warsaw
barry@wooz.org
Tue, 25 Jun 2002 20:05:09 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/TAL
In directory cvs.zope.org:/tmp/cvs-serv9520
Modified Files:
Tag: tal-i18n-refactor-branch
TALInterpreter.py
Log Message:
First pass at refactoring the i18n tal attribute handling. Some stuff
works better, some stuff is broken (which is why this is on a
branch). In particular i18n:name + tal:content now works, as does
i18n:name + implicit tal:replace, but i18n:name + (explicit)
tal:replace is broken. Checkpointing so I can work on this at home.
Specific changes:
normalize(): Factor this out since both implicit message ids and
implicit $name substitutions need to be whitespace normalized.
interpret(): Fixed the formatting of the self.debug output.
do_i18nVariable(): Be sure to whitespace normalize the implicit $name
substitution value.
do_insertTranslation(): Use the refactored normalize() function.
=== Zope3/lib/python/Zope/TAL/TALInterpreter.py 1.79 => 1.79.2.1 ===
]
+def normalize(text):
+ # Now we need to normalize the whitespace in implicit message ids and
+ # implicit $name substitution values by stripping leading and trailing
+ # whitespace, and folding all internal whitespace to a single space.
+ return ' '.join(text.split())
+
+
class AltTALGenerator(TALGenerator):
def __init__(self, repldict, expressionCompiler=None, xml=0):
@@ -192,8 +199,8 @@
try:
if self.debug:
for (opcode, args) in program:
- s = "%sdo_%s%s\n" % (" "*self.level, opcode,
- repr(args))
+ s = "%sdo_%s(%s)\n" % (" "*self.level, opcode,
+ repr(args))
if len(s) > 80:
s = s[:76] + "...\n"
sys.stderr.write(s)
@@ -478,7 +485,7 @@
try:
tmpstream = StringIO()
self.interpret(stuff[1], tmpstream)
- value = tmpstream.getvalue()
+ value = normalize(tmpstream.getvalue())
finally:
self.restoreState(state)
else:
@@ -517,11 +524,7 @@
# message id. All other useful information will be in the i18ndict on
# the top of the i18nStack.
if msgid == '':
- msgid = tmpstream.getvalue()
- # Now we need to normalize the whitespace in the implicit message
- # id by stripping leading and trailing whitespace, and folding all
- # internal whitespace to a single space.
- msgid = ' '.join(msgid.split())
+ msgid = normalize(tmpstream.getvalue())
self.i18nStack.pop()
# See if there is was an i18n:data for msgid
if len(stuff) > 2: