Changeset 7702 for main


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.

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py

    r7700 r7702  
    292292    @property
    293293    def frontpage(self):
    294         return self.context['configuration'].frontpage_html
     294        portal_language = getUtility(ISIRPUtils).PORTAL_LANGUAGE
     295        lang = self.request.cookies.get('sirp.language', portal_language)
     296        return self.context['configuration'].frontpage_dict.get(lang,'')
    295297
    296298class AdministrationPage(SIRPPage):
     
    623625        _('Add session configuration'),
    624626        _('Remove selected')]
    625 
    626     form_fields = grok.AutoFields(IConfigurationContainer)
    627     form_fields['frontpage_html'].for_display = True
     627    form_fields = grok.AutoFields(IConfigurationContainer).omit('frontpage_dict')
    628628
    629629    def update(self):
     
    638638        return super(ConfigurationContainerManageFormPage, self).update()
    639639
    640     def frontpage(self):
     640    def _frontpage(self):
    641641        view = ConfigurationContainerDisplayFormPage(
    642642            self.context,self.request)
     
    647647    def save(self, **data):
    648648        self.applyData(self.context, **data)
    649         self.context.frontpage_html = self.frontpage()
     649        self.context.frontpage_dict = self._frontpage()
    650650        self.flash(_('Settings have been saved.'))
    651651        return
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/static/waeup-base.css

    r7684 r7702  
    104104}
    105105
     106textarea {
     107  font-family: Courier, "Courier New", monospace;
     108}
     109
    106110 /* IE doesn't like the footer tag*/
    107111.footer {
  • main/waeup.sirp/trunk/src/waeup/sirp/frontpage.rst

    r6361 r7702  
    3030
    3131Text
     32
     33>>de<<
     34Dies ist die Standard-Startseite des Portals. Sie wurde in der Markup-Sprache
     35`reStructuredText (reST) <http://docutils.sourceforge.net/docs/user/rst/quickref.html>`_
     36geschrieben.
     37
     38Weitere reST-Beispiele zur Einführung:
     39
     401. Überschrift
     41==============
     42
     43Text
     44
     451.2 Überschrift
     46---------------
     47
     48Text
     49
     502. Überschrift
     51==============
     52
     53Text
     54
     552.1 Überschrift
     56---------------
     57
     58Text
     59
     602.2 Überschrift
     61---------------
     62
     63Text
  • main/waeup.sirp/trunk/src/waeup/sirp/interfaces.py

    r7677 r7702  
    1818import os
    1919import re
     20import codecs
    2021import zope.i18nmessageid
    2122from datetime import datetime
     
    4445VALIDATED = 'courses validated'
    4546
    46 default_frontpage = u'' + open(os.path.join(
    47         os.path.dirname(__file__), 'frontpage.rst'), 'rb').read()
     47default_frontpage = u'' + codecs.open(os.path.join(
     48        os.path.dirname(__file__), 'frontpage.rst'),
     49        encoding='utf-8', mode='rb').read()
    4850
    4951def SimpleSIRPVocabulary(*terms):
     
    416418        )
    417419
    418     frontpage_html = schema.Text(
    419         title = u'Content in HTML format',
     420    frontpage_dict = schema.Dict(
     421        title = u'Content as language dictionary with values in html format',
    420422        required = False,
     423        default = {},
    421424        )
    422425
  • 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.