Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes
plone.app.i18n.locales.browser.selector.LanguageSelector Class Reference
Inheritance diagram for plone.app.i18n.locales.browser.selector.LanguageSelector:
Inheritance graph
[legend]
Collaboration diagram for plone.app.i18n.locales.browser.selector.LanguageSelector:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def update
def available
def languages
def showFlags

Public Attributes

 context
 request
 view
 manager
 tool
 portal_url

Static Public Attributes

tuple render = ZopeTwoPageTemplateFile('languageselector.pt')

Private Attributes

 __parent__

Detailed Description

Language selector.

  >>> ls = LanguageSelector(None, dict(), None, None)
  >>> ls
  <plone.app.i18n.locales.browser.selector.LanguageSelector object at ...>

  >>> ls.update()
  >>> ls.available()
  False
  >>> ls.languages()
  []
  >>> ls.showFlags()
  False

  >>> class Tool(object):
  ...     use_cookie_negotiation = False
  ...
  ...     def __init__(self, **kw):
  ...         self.__dict__.update(kw)
  ...
  ...     def showFlags(self):
  ...         return True
  ...
  ...     def getAvailableLanguageInformation(self):
  ...         return dict(en={'selected' : True}, de={'selected' : False},
  ...                     nl={'selected' : True})
  ...
  ...     def getLanguageBindings(self):
  ...         # en = selected by user, nl = default, [] = other options
  ...         return ('en', 'nl', [])

  >>> ls.tool = Tool()
  >>> ls.available()
  False

  >>> ls.tool = Tool(use_cookie_negotiation=True)
  >>> ls.available()
  True
  >>> ls.languages()
  [{'code': 'nl', 'selected': False}, {'code': 'en', 'selected': True}]
  >>> ls.showFlags()
  True

  >>> class NewTool(Tool):
  ...     always_show_selector = False
  ...
  ...     def showSelector(self):
  ...         return bool(self.use_cookie_negotiation or self.always_show_selector)

  >>> ls.tool = NewTool()
  >>> ls.available()
  False

  >>> ls.tool = NewTool(use_cookie_negotiation=True)
  >>> ls.available()
  True

  >>> ls.tool = NewTool(always_show_selector=True)
  >>> ls.available()
  True

  >>> class Dummy(object):
  ...     def getPortalObject(self):
  ...         return self
  ...
  ...     def absolute_url(self):
  ...         return 'absolute url'

  >>> context = Dummy()
  >>> context.portal_url = Dummy()
  >>> ls = LanguageSelector(context, dict(), None, None)
  >>> ls.portal_url
  'absolute url'

Definition at line 10 of file selector.py.


Constructor & Destructor Documentation

def plone.app.i18n.locales.browser.selector.LanguageSelector.__init__ (   self,
  context,
  request,
  view,
  manager 
)

Definition at line 89 of file selector.py.

00089 
00090     def __init__(self, context, request, view, manager):
00091         super(LanguageSelector, self).__init__(context, request)
00092         self.__parent__ = view
00093         self.context = context
00094         self.request = request
00095         self.view = view
00096         self.manager = manager
00097         self.tool = getToolByName(context, 'portal_languages', None)
00098         portal_tool = getToolByName(context, 'portal_url', None)
00099         self.portal_url = None
00100         if portal_tool is not None:
00101             self.portal_url = portal_tool.getPortalObject().absolute_url()

Here is the caller graph for this function:


Member Function Documentation

Definition at line 105 of file selector.py.

00105 
00106     def available(self):
00107         if self.tool is not None:
00108             # Ask the language tool. Using getattr here for BBB with older
00109             # versions of the tool.
00110             showSelector = getattr(aq_base(self.tool), 'showSelector', None)
00111             if showSelector is not None:
00112                 return self.tool.showSelector() # Call with aq context
00113             # BBB
00114             return bool(self.tool.use_cookie_negotiation)
00115         return False

Here is the caller graph for this function:

Returns list of languages.

Definition at line 116 of file selector.py.

00116 
00117     def languages(self):
00118         """Returns list of languages."""
00119         if self.tool is None:
00120             return []
00121 
00122         bound = self.tool.getLanguageBindings()
00123         current = bound[0]
00124 
00125         def merge(lang, info):
00126             info["code"]=lang
00127             if lang == current:
00128                 info['selected'] = True
00129             else:
00130                 info['selected'] = False
00131             return info
00132 
00133         return [merge(lang, info) for (lang,info) in
00134                     self.tool.getAvailableLanguageInformation().items()
00135                     if info["selected"]]

Do we use flags?.

Definition at line 136 of file selector.py.

00136 
00137     def showFlags(self):
00138         """Do we use flags?."""
00139         if self.tool is not None:
00140             return self.tool.showFlags()
00141         return False

Definition at line 102 of file selector.py.

00102 
00103     def update(self):
00104         pass

Here is the caller graph for this function:


Member Data Documentation

Definition at line 91 of file selector.py.

Definition at line 92 of file selector.py.

Definition at line 95 of file selector.py.

Definition at line 98 of file selector.py.

tuple plone.app.i18n.locales.browser.selector.LanguageSelector.render = ZopeTwoPageTemplateFile('languageselector.pt') [static]

Definition at line 87 of file selector.py.

Definition at line 93 of file selector.py.

Definition at line 96 of file selector.py.

Definition at line 94 of file selector.py.


The documentation for this class was generated from the following file: