Back to index

plone3  3.1.7
cookie.py
Go to the documentation of this file.
00001 from zope.component import queryUtility
00002 from zope.i18n.interfaces import ILanguageAvailability
00003 from zope.i18n.interfaces import IUserPreferredLanguages
00004 from zope.interface import implements
00005 
00006 
00007 class CookieLanguage(object):
00008 
00009     implements(IUserPreferredLanguages)
00010 
00011     def __init__(self, request):
00012         self.request = request
00013 
00014     def getPreferredLanguages(self):
00015         """Return a sequence of user preferred languages."""
00016         langs = []
00017 
00018         cookie = self.request.cookies.get('I18N_LANGUAGE', None)
00019         available = queryUtility(ILanguageAvailability)
00020         if available is None:
00021             return None
00022 
00023         if cookie in [str(lang) for lang in available.getAvailableLanguages()]:
00024             return [cookie]
00025 
00026         return None