plonezopezcml

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...." />

Solution

  • 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.