[Zope-Checkins] CVS: Zope3/lib/python/Zope/I18n - INegotiator.py:1.3 Negotiator.py:1.3
Barry Warsaw
barry@wooz.org
Wed, 12 Jun 2002 11:55:33 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/I18n
In directory cvs.zope.org:/tmp/cvs-serv17024/lib/python/Zope/I18n
Modified Files:
INegotiator.py Negotiator.py
Log Message:
Code and comment cleanup.
Also changed `object_langs' -> `langs', and added an XXX comment
=== Zope3/lib/python/Zope/I18n/INegotiator.py 1.2 => 1.3 ===
class INegotiator(Interface):
- """ The INegotiater defines an interface for a service for language
- negotiation
+ """A language negotiation service.
"""
- def getLanguage(object_langs, env):
- """getLanguage implements a decision making algorithm to decide
- what language should be used based on the available languages
- for an object and a list of user prefered languages.
+ def getLanguage(langs, env):
+ """Return the matching language to use.
+
+ The decision of which language to use is based on the list of
+ available languages, and the given user environment. An
+ IUserPreferredLanguages adapter for the environment is obtained and
+ the list of acceptable languages is retrieved from the environment.
+
+ If no match is found between the list of available languages and the
+ list of acceptable languages, None is returned.
Arguments:
- object_langs -- sequence of languages (not necessarily ordered)
+ langs -- sequence of languages (not necessarily ordered)
env -- environment passed to the service to determine a sequence
of user prefered languages
-
"""
+ # XXX I'd like for there to be a symmetric interface method, one in
+ # which an adaptor is gotten for both the first arg and the second
+ # arg. I.e. getLanguage(obj, env)
+ # But this isn't a good match for the iTranslationService.translate()
+ # method. :(
=== Zope3/lib/python/Zope/I18n/Negotiator.py 1.2 => 1.3 ===
from Zope.I18n.INegotiator import INegotiator
-from Zope.I18n.IUserPreferedLanguages import IUserPreferedLanguages
+from Zope.I18n.IUserPreferredLanguages import IUserPreferredLanguages
+from Zope.I18n.ILanguageAvailability import ILanguageAvailability
from Zope.ComponentArchitecture import getAdapter
class Negotiator:
__implements__ = INegotiator
- def getLanguage(self, object_langs, env):
-
- adapter = getAdapter(env, IUserPreferedLanguages)
- user_langs = adapter.getLanguages()
-
- for lang in user_langs:
- if lang in object_langs:
+ def getLanguage(self, langs, env):
+ envadaptor = getAdapter(env, IUserPreferredLanguages)
+ userlangs = envadaptor.getPreferredLanguages()
+ # Prioritize on the user preferred languages. Return the first user
+ # preferred language that the object has available.
+ for lang in userlangs:
+ if lang in langs:
return lang
-
return None