zope.i18n.translate overrides mapping if passed a message
Bug #592753 reported by
Christian Theune
This bug affects 3 people
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
zope.i18n |
Won't Fix
|
Medium
|
Christian Theune |
Bug Description
When using the module-level translation function passing in a message ID like shown below the interpolation will not happen because the translate function overrides the passed-in mapping with the (empty) default of the message object.
from foo import MessageFactory as _
X = _('some ${data}')
zope.i18n.
A work around for users is to explicitly turn the message ID back into a unicode object:
zope.i18n.
To post a comment you must log in.
I usually do:
X = _('some ${data}', mapping= dict(data= 1)) translate( X, context= self.request)
zope.i18n.
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 translate( Message( X, mapping= dict(data= 1)), context= self.request)
zope.i18n.
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: translate( X, mapping= dict(data= 1), context= self.request)
zope.i18n.
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.