3

ユーティリティに名前を付けましたが、後で i18n を使用するために名前をマークしたいと思います。これは正しい方法ですか?

<utility
  name="Home"
  i18n:attributes="name"
  provides=".interfaces..."
  factory=".shortcut...." />
4

2 に答える 2

10

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.

于 2011-08-01T15:11:57.127 に答える
6

あなたはそれをしたくありません。このname属性は、エンドユーザーではなくアプリケーションでの使用を目的としており、安定している必要があります。

それを翻訳する場合は、コード全体ですべての名前付きルックアップも翻訳する必要があります。

要素のi18n_domain="domain"マーカーを使用して、タイトルと説明を翻訳できます。<configure>

于 2011-08-01T15:11:04.933 に答える