Ignore:
Timestamp:
22 Feb 2012, 08:27:56 (13 years ago)
Author:
Henrik Bettermann
Message:

Implement Language switch in the topbar and add some German translations for demonstration.

File:
1 edited

Legend:

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

    r7461 r7674  
    1717##
    1818import grok
     19import zope.i18nmessageid
     20from urllib import urlencode
    1921from zope.component import getMultiAdapter, queryAdapter
    2022from zope.interface import Interface
     
    3335from waeup.sirp.utils.helpers import get_user_account
    3436
     37_ = zope.i18nmessageid.MessageFactory('waeup.sirp')
     38
    3539grok.templatedir('templates')
    3640grok.context(ISIRPObject) # Make ISIRPObject the default context
     
    4145class BreadCrumbManager(grok.ViewletManager):
    4246    grok.name('breadcrumbs')
     47
     48class LanguageManager(grok.ViewletManager):
     49    grok.name('languages')
    4350
    4451class ActionBar(grok.ViewletManager):
     
    200207                    url = self.view.url(breadcrumb.context, breadcrumb.target)
    201208                    )
     209
     210class LanguageLink(grok.Viewlet):
     211    """ An entry in the language selector.
     212
     213    This is only a baseclass that won't be rendered actually. Deriving
     214    viewlets can override certain values and will be rendered with the
     215    values set here as default.
     216    """
     217    grok.baseclass()
     218    grok.viewletmanager(LanguageManager)
     219    grok.context(ISIRPObject)
     220    grok.require('waeup.Public')
     221    lang = 'de'
     222    title = u'Deutsch'
     223
     224    def render(self):
     225        args = {'lang':self.lang, 'view_name':self.view.__name__}
     226        url = self.view.url(
     227            self.context) + '/@@change_language?%s' % urlencode(args)
     228        return u'| <a href="%s" title="%s">%s</a> ' % (url,self.title,self.lang)
     229
     230class English(LanguageLink):
     231    """A link to switch to English.
     232    """
     233    lang = 'en'
     234    title = u'English'
     235
     236class French(LanguageLink):
     237    """A link to switch to French.
     238    """
     239    lang = 'fr'
     240    title = u'Fran&ccedil;ais'
     241
     242class German(LanguageLink):
     243    """A link to switch to German.
     244    """
     245    lang = 'de'
     246    title = u'Deutsch'
     247
     248class Hausa(LanguageLink):
     249    """A link to switch to Hausa.
     250    """
     251    lang = 'ha'
     252    title = u'Hausa'
     253
     254class Yoruba(LanguageLink):
     255    """A link to switch to Yoruba.
     256    """
     257    lang = 'yo'
     258    title = u'Yoruba'
    202259
    203260
     
    623680
    624681    pnav = 1
    625     tab_title = u'Academics'
     682    tab_title = _(u'Academics')
    626683
    627684    @property
     
    638695    grok.order(6)
    639696    grok.require('waeup.Anonymous')
    640     tab_title = u'Enquiries'
     697    tab_title = _(u'Enquiries')
    641698    pnav = 2
    642699
Note: See TracChangeset for help on using the changeset viewer.