Back to index

plone3  3.1.7
Public Member Functions
plone.i18n.negotiator.negotiator.Negotiator Class Reference
Inheritance diagram for plone.i18n.negotiator.negotiator.Negotiator:
Inheritance graph
[legend]
Collaboration diagram for plone.i18n.negotiator.negotiator.Negotiator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def getLanguage

Detailed Description

Definition at line 13 of file negotiator.py.


Constructor & Destructor Documentation

Definition at line 17 of file negotiator.py.

00017 
00018     def __init__(self):
00019         super(Negotiator, self).__init__()
00020         self.append(DefaultLanguage)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

def plone.i18n.negotiator.negotiator.Negotiator.getLanguage (   self,
  langs,
  request 
)

Definition at line 21 of file negotiator.py.

00021 
00022     def getLanguage(self, langs, request):
00023         # langs are the available languages from the translation domains
00024         userlangs = []
00025 
00026         for plugin_registration in self:
00027             plugin = plugin_registration(request)
00028             userlangs = plugin.getPreferredLanguages()
00029             # Stop once we got a result from a plugin
00030             if userlangs is not None:
00031                 break
00032 
00033         if userlangs is None:
00034             return None
00035 
00036         # Restrict the languages based on site-wide policy
00037         allowed = queryUtility(IContentLanguageAvailability)
00038         if allowed is not None:
00039             langs = [str(lang) for lang in allowed.getAvailableLanguages()]
00040 
00041         langs = normalize_langs(langs)
00042         fallback = queryUtility(ILanguageFallback)
00043 
00044         for lang in userlangs:
00045             if lang in langs:
00046                 return langs.get(lang)
00047 
00048             # If the user asked for a specific variation, but we don't
00049             # have it available we may serve the most generic one,
00050             # according to the spec (eg: user asks for ('en-us',
00051             # 'de'), but we don't have 'en-us', then 'en' is preferred
00052             # to 'de').
00053             if fallback is not None:
00054                 fallbacks = fallback.fallback(lang)
00055                 for fb in fallbacks:
00056                     if fb in langs:
00057                         return fb
00058 
00059         return None

The documentation for this class was generated from the following file: