开发者

Translating content in filesystem for a Plone product

开发者 https://www.devze.com 2023-03-26 15:47 出处:网络
I\'m trying to get certain strings in a .py file translated, using the i18n machinery.Translating .pt 开发者_C百科files is not a problem, but whenever I try to translate using _(\'Something\') in Pyth

I'm trying to get certain strings in a .py file translated, using the i18n machinery. Translating .pt 开发者_C百科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?


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.


if you are seeking for how-tos you should probably read these docs:

  • http://plone.org/documentation/kb/i18n-for-developers
  • http://readthedocs.org/docs/collective-docs/en/latest/i18n/localization.html

Bye, Giacomo


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:

  1. do not concat Message objects. "text %s" % _('translation') will not work, as well as "text" + _('translation')
  2. if you do not send the text to the browser through a template, it may not be translated. for example if you generate a email you need to translate the Message object manually
0

精彩评论

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

关注公众号