简体   繁体   English

是否明智地解析* .zcml文件?

[英]Do *.zcml files get parsed i18n wise?

I have named utilities and would like to mark names for later i18n usage. 我已命名实用程序,并希望为以后的i18n用法标记名称。 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. 该实用程序的名称不是可翻译的消息ID,而是内部技术ID。 You cannot use it for translation purposes. 您不能将其用于翻译目的。

If you look at zope.component.zcml you can see the interface for the directive containing: 如果你看一下zope.component.zcml,你可以看到该指令的接口包含:

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. 如果你看一下例如http://wiki.zope.org/zope3/zcml.html,它会告诉你一个属性需要是在ZCML中可以翻译的MessageID类型。

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. 如果你有一个带有MessageID类型属性的ZCML指令,你需要做的就是为ZCML文件定义一个i18n:domain。 The ZCML machinery knows what attributes are translatable itself based on them being of the right type. ZCML机器基于它们是正确的类型,知道哪些属性可以自行翻译。 So you don't need any extra markup to note any attributes like you need in TAL. 所以你不需要任何额外的标记来记录你在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. 总而言之,如果您在Plone内部工作并使用i18ndude提取消息,它将不会从ZCML文件中提取任何消息 - 仅仅因为ZCML中没有定义任何消息,实际上它也显示在Plone UI中的任何位置。

If you have utilities and want to give them translatable names, give them a title attribute, like: 如果您有实用程序并希望为它们提供可翻译的名称,请为它们指定title属性,例如:

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

class MyShortCut(object):

    title = _('My shortcut')

and use the title attribute in the UI. 并在UI中使用title属性。

You do not want to do that. 你不想那样做。 The name attribute is meant for application use, not end-users, and needs to be stable. name属性用于应用程序,而不是最终用户,需要稳定。

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. 可以使用<configure>元素上的i18n_domain="domain"标记转换标题和描述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在.py文件中使用不同的域进行i18n转换 - i18n translation with a different domain in .py files i18n消息:来自多个PO文件的消息的优先级 - i18n messages: precedence of messages from multiple PO files 如何翻译i18n Plone actions.xml - How to translate i18n Plone actions.xml Plone i18n - 每种语言多少钱 - Plone i18n - how much from each Language Plone:从敏捷性xml模型中提取i18n字符串 - Plone: extracting i18n strings from dexterity xml models 您没有在Plone的[genericsetupprofile注册]中为…指定i18n转换域。 - You did not specify an i18n translation domain for … in your [genericsetupprofile registration] in Plone 如何在 browser/configure.zcml 中使用 config.py 和 __init__.py(使用 paster)创建的权限来获得自定义权限? - How do I use a permission created by config.py and __init__.py (using paster) in browser/configure.zcml for a custom permission? zope_i18n_compile_mo_files在Zeo配置上不起作用 - zope_i18n_compile_mo_files doesn't work on a Zeo configuration 如果用户没有渲染视图的权限(在configure.zcml上配置),我如何提高禁止访问权限而不是重定向到login_form? - If a user doesn't have permission to render a View (configured on configure.zcml), how do I raise Forbidden instead of redirecting to login_form? Plone / ZCML:zcml-additional应该位于何处? - Plone/ZCML: Where is/should zcml-additional be located?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM