Comment 1 for bug 592753

Revision history for this message
Vincent Fretin (vincent-fretin) wrote :

I usually do:

X = _('some ${data}', mapping=dict(data=1))
zope.i18n.translate(X, context=self.request)

But indeed when you use X as a constant, you don't have necessary the mapping right away.
In this case, what I do is to create a new Message object:

from zope.i18nmessageid import Message
zope.i18n.translate(Message(X, mapping=dict(data=1)), context=self.request)

This is the preferred way to do it right now. You lose the domain and default message when you do unicode(X).

Indeed, it may be less verbose to write:
zope.i18n.translate(X, mapping=dict(data=1), context=self.request)

If somebody change the code of the translate function so you can override mapping like this, I think in this case you should be able to override domain and default as well.