Wednesday, December 24, 2008

Translating messages in python controller scripts

For some reason, using Plone's MesageFactory didn't work for me. However, context.translate() does all the work. Call it like so:
context.translate(
msgid = u'some_message',
default = u'Some message',
domain = 'myproductsi18domain')

and make sure you have something like
"Domain: myproductsi18domain\n"

#. Default: "Some message"
#: skins/myproduct/your_controller_script.cpy:18
msgid = "some_message"
msgstr = "Een bericht"

in the relevant file (probably i18n/myproductsi18ndomain-nl.po).

This has the disadvantage that the message strings are not recognized by i18ndude, so i18ndude will not automatically create the relevant strings for you in your .pot file. There's a workaround for this, but that's another blog post.

No comments: