Back to index

plone3  3.1.7
language.py
Go to the documentation of this file.
00001 import operator
00002 from zope.interface import implements
00003 from zope.component import getMultiAdapter
00004 from plone.portlets.interfaces import IPortletDataProvider
00005 from plone.app.portlets.portlets import base
00006 from plone.app.i18n.locales.browser.selector import LanguageSelector
00007 from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
00008 from Products.CMFPlone import PloneMessageFactory as _
00009 
00010 
00011 class ILanguagePortlet(IPortletDataProvider):
00012     """A portlet which shows the available portal languages.
00013     """
00014 
00015 
00016 class Assignment(base.Assignment):
00017     implements(ILanguagePortlet)
00018 
00019     title = _(u'label_languages', default=u'Languages')
00020 
00021 
00022 class Renderer(base.Renderer):
00023 
00024     def __init__(self, context, request, view, manager, data):
00025         base.Renderer.__init__(self, context, request, view, manager, data)
00026         self.selector=LanguageSelector(context, request, None, None)
00027         self.languages=self.selector.languages()
00028 
00029         def key(info):
00030             return info.get("native", info["name"])
00031         self.languages.sort(key=key)
00032         portal_state = getMultiAdapter((context, request), name=u'plone_portal_state')
00033         self.portal_url = portal_state.portal_url()
00034 
00035     def show(self):
00036         return self.selector.available() and len(self.languages)>1
00037     
00038     @property
00039     def available(self):
00040         return self.show()
00041 
00042     def showFlags(self):
00043         return self.selector.showFlags()
00044 
00045     def update(self):
00046         pass
00047 
00048     render = ViewPageTemplateFile('language.pt')
00049 
00050 
00051 class AddForm(base.NullAddForm):
00052 
00053     def create(self):
00054         return Assignment()