Manual calls to translate

by Plone Documentation Team last modified Nov 01, 2009 07:48 PM
When you directly call the 'translate' method in your code, there are some changes.

If you have any of these imports, you cannot use them anymore:

Products.CMFPlone.utils.utranslate
Products.PageTemplates.GlobalTranslationService.getGlobalTranslationService

Instead you need to use zope.i18n.translate directly. See this example changeset from Poi.

The tricky thing here is that the order of the arguments has changed so you probably need some more changes. The old call signature was this:

utranslate(domain, msgid, mapping=None, context=None,
           target_language=None, default=None)

And the new is this:

translate(msgid, domain=None, mapping=None, context=None,
          target_language=None, default=None)

So:

  • msgid is now the first instead of the second call
  • domain is now optional
And one more tricky thing (and this changeset does that not completely correctly): when you specify the context you first had to pass a content object (usually the page, image, folder etc you are looking at) but now you need to pass in the request instead. This changeset fixes it for the Poi product.