Personal tools
You are here: Home Weblog Archive 2006 October 07 Get a translated object in a particular language
Document Actions
  • Send this page to somebody
  • Print this page
  • Add Bookmarklet

Get a translated object in a particular language

by tibi last modified 2006-10-07 04:13
Filed Under:

Sometimes there is a need to get a translated piece of content in a particular language. Some examples include messing around with ATVM or stitching together a front page for a multilanguage website from editable content (site editors love pretty interfaces where they can tweak and edit every piece of a website). This piece of code is a bit older, but still does the job well. The boundLanguages/getLanguageBindings thing could be replaced with getPreferredLanguage() and I'm pretty sure LinguaPlone got a prettier API than this, but it's a starting point in the right direction. I probably should replace this code more "modern" stuff when I get the time.

#bind context=context

page='training_description'

boundLanguages = context.portal_languages.getLanguageBindings()
prefLang = boundLanguages[0]
obj = getattr(context, page, None)
if obj == None:
return ""
trans = obj.getTranslations()

if trans.has_key(prefLang):
return trans[prefLang][0].CookedBody()
else:
return obj.CookedBody()
Weblog
Atom
RDF
RSS 2.0
Powered by Quills
Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: