Current

This document is valid for the current version of Plone.

Translating and creating multilingual content

by Plone Documentation Team last modified Dec 12, 2009 10:33 PM
Contributors: Mikko Ohtamma, Martin Aspeli, Kamon Ayeva, Israel Saeta Pérez
How to translate and handle multilingual content programmatically

Content translations are handled by well-established LinguaPlone add-on product.

Each translation is its own Archetypes content object. Translations are linked together through LinguaPlone catalogs. The base text is called canonical and all other translations are linked into this.

The base class for multilingual content is LinguaItem: http://svn.plone.org/svn/plone/LinguaPlone/tags/2.1.1/Products/LinguaPlone/examples/LinguaItem.py

Translating content

LinguaPlone contains some unit test code which shows how to create translations. You can use context.addTranslation(language_code) and context.getTranslation(language_code) methods.

Example:

from Products.LinguaPlone.I18NBaseObject import AlreadyTranslated

try:
    object.addTranslation(lang)
except AlreadyTranslated:
    # Note: AlreadyTranslated is always risen if Products.Linguaplone is not installed
    pass

translated = object.getTranslation(lang)

For more information see

Querying multi-lingual content

By default, LinguaPlone monkey-patches portal_catalog to return only content queried in the current language of the page view. If you need to refer to other language content in portal_catalog queries, you need to pass a special parameter Language="all" to portal_catalog queries.

Example:

for translation_search in self.portal_catalog.searchResults(Language='all')::
    pass