ERP5 uses Localizer to store message catalogs. Two messages catalog are used:

Please note that translating content will add messages in the catalog each time a string is not found, which increase the ZODB side and can lead to conflicts.

Some translated accessors are generated by ERP5Type, for example:

Pages Templates

Most of this plone How-To on i18n applies here as well.

ERP5 developers must take not to translate content in the default page templates. For example, translating the title of the current document would be a mistake, instead we should use i18n:name constructions.

Python Scripts

Sometimes, accessing the translation machinery from python scripts is necessary, this is achieved by using Products.ERP5Type.Message.Message class, and converting it to string.

The most common use case is to translate the portal_status_message before redirecting.


   1 from Products.ERP5Type.Message import Message
   2 return context.REQUEST.RESPONSE.redirect("%s/view?portal_status_message=%s" %
   3         (context.absolute_url(), Message('erp5_ui', 'You+are+redirected')))
   4 # Note the use of '+' characters, because a redirect URL should not contain spaces

Note that you can specify a mapping for interpolation of ${variables} (see Workflow Scripts example).

XXX This is subject to change at some point, because Message returns strings, and not unicode objects.

XXX What about Base_translateString script ? is it deprecated ?

Workflow Scripts

ERP5Type extended DCWorkflow ( see HowToUseAndDefineWorkflows ) to add a new kind of exception , ValidationFailed. As validation failed messages are stored in the workflow history and visible from the History tab of any ERP5 Document, developers must take not to translate the string before raising the exception, instead you should return a Products.ERP5Type.Message.Message class, so that the Message is translated when the History tab is accessed.

Good Example:

   1 from Products.ERP5Type.Message import Message
   2 N_ = lambda msg, **kw: Message('erp5_ui', msg, **kw)
   4 raise ValidationFailed(N_("Validation of ${object_title} failed.", 
   5                     mapping=dict(object_title=sci['object'].getTitle())))

Then when users with different language selected will view the history of this object, "Validation of ${object_title} failed." will be translated in their language.

FIXME: this part is not covered by any automated test.

Concerns about unicode

When to use unicode ? utf8 encoded strings ? why Base_translateString hack is necessery in pdf templates ?


GuidelinesForI18n (last edited 2008-01-03 13:48:09 by localhost)