[Zope3-checkins] CVS: Zope3/src/zope/tal - talgenerator.py:1.9.4.5
Godefroid Chapelle
gotcha at swing.be
Thu Aug 14 11:31:08 EDT 2003
Update of /cvs-repository/Zope3/src/zope/tal
In directory cvs.zope.org:/tmp/cvs-serv11282
Modified Files:
Tag: srichter-i18n-macro-interaction-branch
talgenerator.py
Log Message:
- some refactoring and comments
=== Zope3/src/zope/tal/talgenerator.py 1.9.4.4 => 1.9.4.5 ===
--- Zope3/src/zope/tal/talgenerator.py:1.9.4.4 Thu Aug 14 09:38:46 2003
+++ Zope3/src/zope/tal/talgenerator.py Thu Aug 14 10:31:03 2003
@@ -316,7 +316,7 @@
assert key == "structure"
self.emit("insertStructure", cexpr, attrDict, program)
- def emitI18nVariable(self, varname, action, expression):
+ def emitI18nVariable(self, stuff):
# Used for i18n:name attributes. arg is extra information describing
# how the contents of the variable should get filled in, and it will
# either be a 1-tuple or a 2-tuple. If arg[0] is None, then the
@@ -329,6 +329,7 @@
# calculate the contents of the variable, e.g.
# "I live in <span i18n:name="country"
# tal:replace="here/countryOfOrigin" />"
+ varname, action, expression = stuff
m = _name_rx.match(varname)
if m is None or m.group() != varname:
raise TALError("illegal i18n:name: %r" % varname, self.position)
@@ -624,7 +625,7 @@
self.emitText(repeatWhitespace)
if content:
if varname:
- todo['i18nvar'] = (varname, None, I18N_CONTENT)
+ todo['i18nvar'] = (varname, I18N_CONTENT, None)
todo["content"] = content
self.pushProgram()
else:
@@ -634,14 +635,14 @@
# we're actually replacing then is the contents of the ${name}
# placeholder.
if varname:
- todo['i18nvar'] = (varname, replace, I18N_REPLACE)
+ todo['i18nvar'] = (varname, I18N_EXPRESSION, replace)
else:
todo["replace"] = replace
self.pushProgram()
# i18n:name w/o tal:replace uses the content as the interpolation
# dictionary values
elif varname:
- todo['i18nvar'] = (varname, None, I18N_EXPRESSION)
+ todo['i18nvar'] = (varname, I18N_REPLACE, None)
self.pushProgram()
if msgid is not None:
self.i18nLevel += 1
@@ -734,10 +735,7 @@
# If there's no tal:content or tal:replace in the tag with the
# i18n:name, tal:replace is the default.
- i18nNameAction = I18N_REPLACE
if content:
- if varname:
- i18nNameAction = I18N_CONTENT
self.emitSubstitution(content, {})
# If we're looking at an implicit msgid, emit the insertTranslation
# opcode now, so that the end tag doesn't become part of the implicit
@@ -745,9 +743,12 @@
# the opcode after the i18nVariable opcode so we can better handle
# tags with both of them in them (and in the latter case, the contents
# would be thrown away for msgid purposes).
+ #
+ # Still, we should emit insertTranslation opcode before i18nVariable
+ # in case tal:content, i18n:translate and i18n:name in the same tag
if msgid is not None:
if (not varname) or (
- varname and (varname[2] == I18N_CONTENT)):
+ varname and (varname[1] == I18N_CONTENT)):
self.emitTranslation(msgid, i18ndata)
self.i18nLevel -= 1
if optTag:
@@ -766,21 +767,21 @@
if replace:
self.emitSubstitution(replace, repldict)
elif varname:
- if varname[1] is not None:
- i18nNameAction = I18N_EXPRESSION
# o varname[0] is the variable name
- # o i18nNameAction is either
+ # o varname[1] is either
# - I18N_REPLACE for implicit tal:replace
# - I18N_CONTENT for tal:content
# - I18N_EXPRESSION for explicit tal:replace
- # o varname[1] will be None for the first two actions and the
+ # o varname[2] will be None for the first two actions and the
# replacement tal expression for the third action.
- assert i18nNameAction == varname[2]
- self.emitI18nVariable(varname[0], i18nNameAction, varname[1])
+ assert (varname[1] in [I18N_REPLACE, I18N_CONTENT, I18N_EXPRESSION])
+ self.emitI18nVariable(varname)
# Do not test for "msgid is not None", i.e. we only want to test for
# explicit msgids here. See comment above.
if msgid is not None:
- if varname and (varname[2] <> I18N_CONTENT):
+ # in case tal:content, i18n:translate and i18n:name in the same tag
+ # insertTranslation opcode has already been emitted
+ if varname and (varname[1] <> I18N_CONTENT):
self.emitTranslation(msgid, i18ndata)
if repeat:
self.emitRepeat(repeat)
More information about the Zope3-Checkins
mailing list