예제 #1
0
 def getLanguage(self):
     """View for to check if a session has a i18n language value."""
     _fallback = 'en'
     
     try:
         session = ILanguageSession(self.request)
         return session.getLanguage()
     except AttributeError:
         return _fallback
예제 #2
0
 def hasLanguage(self):
     """View for to check if a session has a i18n language value."""
     try:
         session = ILanguageSession(self.request)
         lang = session.getLanguage()
         if lang:
             return True
         else:
             return False
     except zope.component.ComponentLookupError:
         return False
예제 #3
0
    def setLanguage(self):
        """Set the given language in the request to the session.
        
        You can do it via the javascript sessionlanguage.js with the
        javascript method setLanguage:
        
        javascript:setLanguage('@@setLanguage','de')
        
        Or send the request to the view '@@setLanguage'. There has to be a 
        variable 'language' and 'nextURL' in the request like
        """
        nextURL = '.'

        if "language" in self.request:
            lang = self.request['language']
        
        if "nextURL" in self.request:
            nextURL = self.request['nextURL']

        if lang:
            session = ILanguageSession(self.request)
            session.setLanguage(lang)

        self.request.response.redirect(nextURL)