[Zope3-dev] i18n domains vs. unique message ids -OR- why
Shakespearean English was better
Fred L. Drake, Jr.
fred at zope.com
Mon Aug 18 11:23:05 EDT 2003
Philipp von Weitershausen writes:
> The problem with this solution is that there is no way to manually
> specify the message id while still providing a default value with
> both zope.i18n.messageid.MessageIDFactory and the ZCML schema field
> zope.configuration.fields.MessageID. And the above stated problem
> with 'View' just happens to involve these two cases
This is a nuissance, but I think not so bad as you describe.
The real issue is that gettext-style extraction tools are too stupid.
If they would extract _("message id", "default text"), life would be
much easier.
What I've done when I've wanted message ids to be distinct from the
default text is to use a helper function, like this:
------------------------------------------------------------------------
from zope.i18n.messageid import MessageIDFactory
DOMAIN = "zope-widget-examples"
_ = MessageIDFactory(DOMAIN)
def message(msgid, default):
# XXX This treats MessageID objects as mutable objects, but is
# only used when the MessageID is first created. Using a separate
# function is needed since the message catalog tools require that
# _() take exactly one positional string literal argument, else we
# could just call the MessageID constructor directly.
assert msgid.default == msgid
assert msgid.domain == DOMAIN
msgid.default = default
return msgid
------------------------------------------------------------------------
The text in the Python code becomes:
message(_("message id"), "default text")
I'd certainly like to see it become possible to use a simpler form
like:
_("message id", "default text")
but the tools would need to be changed to support this.
-Fred
--
Fred L. Drake, Jr. <fred at zope.com>
PythonLabs at Zope Corporation
More information about the Zope3-dev
mailing list