Return to Snippet

Revision: 110
at June 30, 2006 07:42 by wsfulmer


Initial Code
## Script (Python) "getTranslatedRefs"
##title=Gets translated refs, backrefs, or both for a given relationship.
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=rel,which,sort_on=None,sort_type=None,sort_order=None

if which == "refs":
    refs = context.getCanonical().getRefs(relationship=rel)
elif which == "brefs":
    refs = context.getCanonical().getBRefs(relationship=rel)
elif which == "all":
    refs = context.getCanonical().getRefs(relationship=rel) + \
           context.getCanonical().getBRefs(relationship=rel)
else:
    raise "Invalid 'which' parameter %s - must be 'refs','brefs' or 'all'."

    
unique = []
for b in refs:
    canonical = b.getCanonical()
    if canonical not in unique:
        unique.append(canonical)
translated = [i.getTranslation(context.getLanguage()) or i for i in unique]
if sort_on:
    results = sequence.sort(translated,((sort_on, sort_type, sort_order),))
else:
    results = translated

return results

Initial URL


Initial Description
This is a general purpose Zope script for your Plone product or Plone custom skin folder. It provides LinugaPlone translation of references, either incoming, outgoing, or both.

Initial Title
Bi-directional references with translations

Initial Tags
python

Initial Language
Python