开发者

Do *.zcml files get parsed i18n wise?

I have named utilities and would like to mark names for later i18n usage. Is this the right way?

开发者_运维知识库
<utility
  name="Home"
  i18n:attributes="name"
  provides=".interfaces..."
  factory=".shortcut...." />


The utility's name is not a translatable message id, but an internal technical id. You cannot use it for translation purposes.

If you look at zope.component.zcml you can see the interface for the directive containing:

class IUtilityDirective(IBasicComponentInformation):
    """Register a utility."""

    name = zope.schema.TextLine(
        title=_("Name"),
        description=_("Name of the registration.  This is used by"
                      " application code when locating a utility."),
        required=False)

If you look at for example http://wiki.zope.org/zope3/zcml.html it will tell you that an attribute needs to be of type MessageID to be translatable in ZCML.

If you have a ZCML directive with an attribute of type MessageID, all you need to do is to define an i18n:domain for the ZCML file. The ZCML machinery knows what attributes are translatable itself based on them being of the right type. So you don't need any extra markup to note any attributes like you need in TAL.

All that said, if you work inside Plone and use i18ndude to extract messages, it won't extract any messages from ZCML files - simply because there's not a single message being defined in ZCML, that's also actually shown anywhere in the Plone UI.

If you have utilities and want to give them translatable names, give them a title attribute, like:

from zope.i18nmessageid import MessageFactory
_ = MessageFactory('mydomain')

class MyShortCut(object):

    title = _('My shortcut')

and use the title attribute in the UI.


You do not want to do that. The name attribute is meant for application use, not end-users, and needs to be stable.

If you translate it, then you'll have to translate all named look-ups through-out your code too!

Titles and descriptions can be translated, using the i18n_domain="domain" marker on the <configure> element.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜