[Zope3-dev] Use case not covered for translation of message ids
Jim Fulton
jim at zope.com
Thu Sep 23 04:05:03 EDT 2004
Godefroid Chapelle wrote:
> 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.
Good. This is correct behavior.
> This use case can be seen as wrong : the text "My content item is of
> type" won't be translated.
I don't know what the use case is. The behavior is correct.
> 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>
Yup
> 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.
I don't agree. Message IDs are just strings. They must be treated
as strings unless explicitly treated otherwise. The fact, as you
reported in a later message, that ZPT sometimes erroniously translates
implicitly is not a reason to do so now.
It makes no sense, in the above example, to try to guess that the
author intended to insert a translated string into the middle
of an untranslated English sentance.
The only sane alternave that I can see is to *not* treat message ids
as strings so that they can't cause accidental translation by being
incidentally used as strings. I think that this would be too great
a change without much more debate.
> 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)
Sorry, I have to reject this.
Jim
--
Jim Fulton mailto:jim at zope.com Python Powered!
CTO (540) 361-1714 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org
More information about the Zope3-dev
mailing list