Ignore:
Timestamp:
25 Feb 2012, 10:21:54 (13 years ago)
Author:
Henrik Bettermann
Message:

Internationalize ReSTDisplayWidget which now returns a dictionary with different tranlations.

Different languages must be separated by <<xy>> whereas
xy is the language code. Text parts without correct leading
language separator - usually the first part has no language
descriptor - are interpreted as texts in the portal's language.
The latter can be configured in waeup.srp.utils.utils.SIRPUtils.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/widgets/restwidget.py

    r7385 r7702  
    1818"""A widget that renders restructured text.
    1919"""
     20from zope.component import getUtility
    2021from zope.formlib.widget import renderElement, DisplayWidget
    2122from waeup.sirp.utils.helpers import ReST2HTML
     23from waeup.sirp.interfaces import ISIRPUtils
    2224
    2325
     
    2729
    2830    def __call__(self):
     31        """The ReSTDisplayWidget transforms a ReST text string into
     32        a dictionary.
     33
     34        Different languages must be separated by `<<xy>>` whereas
     35        xy is the language code. Text parts without correct leading
     36        language separator - usually the first part has no language
     37        descriptor - are interpreted as texts in the portal's language.
     38        The latter can be configured in waeup.srp.utils.utils.SIRPUtils.
     39        """
    2940        if self._renderedValueSet():
    3041            value = self._data
     
    3344        if value == self.context.missing_value:
    3445            return ""
    35         return renderElement(u'div id="rest"',
    36                              contents=ReST2HTML(value))
     46        parts = value.split('>>')
     47        elements = {}
     48        lang = getUtility(ISIRPUtils).PORTAL_LANGUAGE
     49        for part in parts:
     50            if part[2:4] == u'<<':
     51                lang = part[0:2].lower()
     52                text = part[4:]
     53                elements[lang] = renderElement(u'div id="rest"',
     54                    contents=ReST2HTML(text))
     55            else:
     56                text = part
     57                elements[lang] = renderElement(u'div id="rest"',
     58                    contents=ReST2HTML(text))
     59        return elements
Note: See TracChangeset for help on using the changeset viewer.