## $Id: language.py 7678 2012-02-22 11:37:37Z henrik $ ## ## Copyright (C) 2012 Uli Fouquet & Henrik Bettermann ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## import grokcore.component from zope.component import getUtility from zope.publisher.interfaces.browser import IBrowserRequest from zope.i18n.interfaces import IUserPreferredLanguages from waeup.sirp.configuration import ConfigurationContainer from waeup.sirp.interfaces import ISIRPUtils class SIRPLanguage(grokcore.component.Adapter): """Set preferred languages""" grokcore.component.context(IBrowserRequest) grokcore.component.implements(IUserPreferredLanguages) def getPreferredLanguages(self): portal_language = getUtility(ISIRPUtils).PORTAL_LANGUAGE # This an adapter for the request, so self.context is the request. request = self.context # Extract the preferred language from a cookie: lang = request.cookies.get('sirp.language', portal_language) # According to IUserPreferredLanguages, we must return a list. return [lang]