我正在尝试使用 i18n 机器翻译 .py 文件中的某些字符串。翻译 .pt 文件不是问题,但每当我尝试在文件系统上的 Python 代码中使用 _('Something') 进行翻译时,它总是给出英语文本(这是默认值),而不是应该存在的挪威语文本。所以我可以看到 python 代码的英文输出,而其他页面模板位则被正确翻译。
有没有类似的方法或类似的东西?
I'm trying to get certain strings in a .py file translated, using the i18n machinery. Translating .pt files is not a problem, but whenever I try to translate using _('Something') in Python code on the filesystem, it always gives English text (which is the default) instead of the Norwegian text that should be there. So I can see output from python code in English, while other Page Templates bits are correctly translated.
Is there a how-to or something similar for this?
发布评论
评论(3)
如果您正在寻找操作方法,您可能应该阅读这些文档:
再见,
贾科莫
if you are seeking for how-tos you should probably read these docs:
Bye,
Giacomo
_('Something')
使用的域名是否与您在包含翻译的挪威语 .po 文件中使用的域名相同?它们应该是相同的,因此不要在一种情况下使用“plone”,在另一种情况下使用“my.domain”。此外,对下划线函数的调用本身并不翻译字符串;而是调用下划线函数。它只创建一个可以翻译的字符串。如果该字符串直接在模板中自行结束,则应将
i18n:translate=""
添加到该标记,可能还需要匹配 i18n:domain。否则,您应该手动调用
translate
方法,如 http://readthedocs.org/docs/collective-docs/en/latest/i18n/localization.html#manually-translated-message-ids。阅读Plone 4 迁移指南 了解 Plone 3 和 4 之间可能存在的一些差异 你在这里。Is the domain name used for
_('Something')
the same as what you use in the Norwegian .po file that has the translation? They should be the same, so do not use 'plone' in one case and 'my.domain' in the other.Also, the call to the underscore function does not in itself translate the string; it only creates a string that can be translated. If this string ends up on its own directly in a template, you should add
i18n:translate=""
to that tag, probably with a matching i18n:domain.Otherwise you should manually call the
translate
method, as in http://readthedocs.org/docs/collective-docs/en/latest/i18n/localization.html#manually-translated-message-ids. Read the Plone 4 migration guide for some differences between Plone 3 and 4 that might bite you here.请注意,_() 不会在调用时翻译文本,而是返回一个 Message 对象,该对象在模板中呈现时将被翻译。
这意味着:
"text %s" % _('translation')
将不起作用,"text" + _('translation')
也不起作用be aware that _() does not translate the text at call, but returns a Message object which will be translated when rendered in a template.
That means:
"text %s" % _('translation')
will not work, as well as"text" + _('translation')