[Zope3-dev] Use case not covered for translation of message ids
Godefroid Chapelle
gotcha at bubblenet.be
Sat Sep 18 10:07:30 EDT 2004
Hi,
while working at the mountain sprint on the port of message ids to Z2,
we found out that the following use case is not covered :
<div tal:content="string:My content item is of type ${type_msgid}." />
where type_msgid is a MessageID that a developer did define in Python
code for instance.
Currently, the message id is not translated : the id itself is
concatenated to the text in the string expression.
This use case can be seen as wrong : the text "My content item is of
type" won't be translated.
Ideally the template developer should have written :
<div i18n:translate="">My content item is of type <span
tal:replace="type_msgid" i18n:name="type" />.</div>
Anyway, in the first case, the developer made his part of the job
correctly : he said that this value should be translated. So we think
that even if the template is badly written, the message id should be
translated.
Please find hereunder a fix to class StringExpr from
zope/tales/expressions.py that solves this situation by allowing the
user to see the translation so that he can go and beat the template
designer ;-)
from zope.i18n.messageid import MessageID
def __call__(self, econtext):
vvals = []
for var in self._vars:
v = var(econtext)
if isinstance(v, MessageID):
v = econtext.translate(v, domain=v.domain
mapping=v.mapping, default=v.default)
vvals.append(v)
return self._expr % tuple(vvals)
--
Godefroid with Jurgen Kartnaller
More information about the Zope3-dev
mailing list