Back to index

plone3  3.1.7
path.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 PathLanguage(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         paths = self.request.get('TraversalRequestNameStack')
00018 
00019         available = queryUtility(ILanguageAvailability)
00020         if available is not None:
00021             langs = [str(lang) for lang in available.getAvailableLanguages()]
00022 
00023         langs = [path for path in paths if path in langs]
00024 
00025         return langs and langs or None