Changeset 7701


Ignore:
Timestamp:
25 Feb 2012, 06:53:45 (13 years ago)
Author:
Henrik Bettermann
Message:

Define preferred languages in SIRPUtils and merge language viewlets to a single viewlet.

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

Legend:

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

    r7694 r7701  
    1818import grok
    1919from urllib import urlencode
    20 from zope.component import getMultiAdapter, queryAdapter
     20from zope.component import getMultiAdapter, queryAdapter, getUtility
    2121from zope.interface import Interface
    2222from zope.location.interfaces import ISite
     
    2929    IFacultiesContainer, IFaculty, IDepartment, ICourse, ICertificate,
    3030    ICertificateCourse, IBreadcrumbContainer, IUniversity, IUsersContainer)
    31 from waeup.sirp.interfaces import (ISIRPObject, ISIRPXMLExporter,
    32                                    ISIRPXMLImporter, IDataCenter, IUserAccount)
     31from waeup.sirp.interfaces import (
     32    ISIRPUtils, ISIRPObject, ISIRPXMLExporter,
     33    ISIRPXMLImporter, IDataCenter, IUserAccount)
    3334from waeup.sirp.browser.layout import SIRPPage, default_primary_nav_template
    3435from waeup.sirp.utils.helpers import get_user_account
     
    207208                    )
    208209
    209 class LanguageLink(grok.Viewlet):
    210     """ An entry in the language selector.
    211 
    212     This is only a baseclass that won't be rendered actually. Deriving
    213     viewlets can override certain values and will be rendered with the
    214     values set here as default.
    215     """
    216     grok.baseclass()
     210class LanguagesLink(grok.Viewlet):
     211    """ The language selector itself.
     212    """
    217213    grok.viewletmanager(LanguageManager)
    218214    grok.context(ISIRPObject)
    219215    grok.require('waeup.Public')
    220     lang = 'de'
    221     title = u'Deutsch'
     216    title = u'Languages'
    222217
    223218    def render(self):
    224         args = {'lang':self.lang, 'view_name':self.view.__name__}
    225         url = self.view.url(
    226             self.context) + '/@@change_language?%s' % urlencode(args)
    227         return u'| <a href="%s" title="%s">%s</a> ' % (url,self.title,self.lang)
    228 
    229 class English(LanguageLink):
    230     """A link to switch to English.
    231     """
    232     lang = 'en'
    233     title = u'English'
    234 
    235 class French(LanguageLink):
    236     """A link to switch to French.
    237     """
    238     lang = 'fr'
    239     title = u'Fran&ccedil;ais'
    240 
    241 class German(LanguageLink):
    242     """A link to switch to German.
    243     """
    244     lang = 'de'
    245     title = u'Deutsch'
    246 
    247 class Hausa(LanguageLink):
    248     """A link to switch to Hausa.
    249     """
    250     lang = 'ha'
    251     title = u'Hausa'
    252 
    253 class Yoruba(LanguageLink):
    254     """A link to switch to Yoruba.
    255     """
    256     lang = 'yo'
    257     title = u'Yoruba'
    258 
     219        preferred_languages = getUtility(ISIRPUtils).PREFERRED_LANGUAGES_DICT
     220        html = u''
     221        for key, value in sorted(
     222            preferred_languages.items(), key=lambda lang: lang[1][0]):
     223            args = {'lang':key, 'view_name':self.view.__name__}
     224            url = self.view.url(
     225                self.context) + '/@@change_language?%s' % urlencode(args)
     226            html += u'| <a href="%s" title="%s">%s</a> ' % (url, value[1], key)
     227        return html
    259228
    260229# Problem with circular references. Disabled for now...
  • main/waeup.sirp/trunk/src/waeup/sirp/utils/utils.py

    r7681 r7701  
    4343    # (e.g. object histories).
    4444    PORTAL_LANGUAGE = 'en'
     45
     46    PREFERRED_LANGUAGES_DICT = {
     47        'en':(1, u'English'),
     48        'fr':(2, u'Fran&ccedil;ais'),
     49        'de':(3, u'Deutsch'),
     50        'ha':(4, u'Hausa'),
     51        'yo':(5, u'Yoruba'),
     52        }
    4553
    4654    def getInstTypeDict(self):
Note: See TracChangeset for help on using the changeset viewer.