[Zope-Checkins] CVS: Zope3/lib/python/Zope/I18n - INegotiator.py:1.1.2.1 IUserPreferedLanguages.py:1.1.2.1 Negotiator.py:1.1.2.1

Andreas Jung andreas@digicool.com
Thu, 17 Jan 2002 17:40:50 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/I18n
In directory cvs.zope.org:/tmp/cvs-serv30450

Added Files:
      Tag: Zope-3x-branch
	INegotiator.py IUserPreferedLanguages.py Negotiator.py 
Log Message:
initial support for language negotiation


=== Added File Zope3/lib/python/Zope/I18n/INegotiator.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""

Revision information: $Id: INegotiator.py,v 1.1.2.1 2002/01/17 22:40:50 andreasjung Exp $
"""

from Interface import Interface

class INegotiator(Interface):

    """ The INegotiater defines an interface for a service for language 
       negotiation
    """
  
    def getLanguage(user_languages,  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.

        Arguments:

        user_languages -- sequence of languages (not necessarily ordered)

        env  -- environment passed to the service to determine a sequence
                of user prefered languages

        """



=== Added File Zope3/lib/python/Zope/I18n/IUserPreferedLanguages.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""

Revision information: $Id: IUserPreferedLanguages.py,v 1.1.2.1 2002/01/17 22:40:50 andreasjung Exp $
"""

from Interface import Interface

class IUserPreferedLanguages(Interface):

    """ This interfaces allows to obtain language negotiation dependant 
        informations about user prefered languages.
    """
  
    def getLanguages():

        """getLanguages returns a sequence of user prefered languages

        Arguments:
        
        None

        """



=== Added File Zope3/lib/python/Zope/I18n/Negotiator.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""

Revision information: $Id: Negotiator.py,v 1.1.2.1 2002/01/17 22:40:50 andreasjung Exp $
"""

from Zope.I18n.INegotiator import INegotiator
from Zope.I18n.IUserPreferedLanguages import IUserPreferedLanguages
from Zope.ComponentArchitecture import getAdapter

class Negotiator:

    __implements__ = INegotiator

    def getLanguage(self, object_langs, env):

        # XXX: we don't have an adapter right now. so
        # we expect 'env' implements the IUserPreferedLanguages
        # interface

        adapter  = getAdapter(env, IUserPreferedLanguages)
        user_langs = adapter.getLanguages()

        for lang in user_langs:
            if lang in object_langs:
                return lang

        return None


negotiator = Negotiator()