## $Id: language.py 7811 2012-03-08 19:00:51Z uli $ ## ## 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.kofa.configuration import ConfigurationContainer from waeup.kofa.interfaces import IKOFAUtils class KOFALanguage(grokcore.component.Adapter): """Set preferred languages""" grokcore.component.context(IBrowserRequest) grokcore.component.implements(IUserPreferredLanguages) def getPreferredLanguages(self): portal_language = getUtility(IKOFAUtils).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('kofa.language', portal_language) # According to IUserPreferredLanguages, we must return a list. return [lang]