Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

pypm install z3c.language.negotiator

How to install z3c.language.negotiator

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install z3c.language.negotiator
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
1.1.3 Available View build log
1.1.2 Available View build log
Windows (64-bit)
1.1.3 Available View build log
1.1.2 Available View build log
Mac OS X (10.5+)
1.1.3 Available View build log
1.1.2 Available View build log
Linux (32-bit)
1.1.3 Available View build log
1.1.2 Available View build log
Linux (64-bit)
1.1.3 Available View build log
1.1.2 Available View build log
ZPL 2.1
Lastest release
version 1.1.3 on Jan 5th, 2011

This package provides a persistent INegotiator utility implementation.

Detailed Documentation


This package provides a local implementation of the INegotiator interface defined in zope.i18n.interfaces. The negotiator implementation offers some additional usefull attributes which are explained later. This INegotiator is also used in the z3c.language.switch package.

Let's setup a negotiator:

>>> from z3c.language.negotiator import app
>>> negotiator = app.Negotiator()

Such a negotiator provides the following interfaces:

>>> from zope.i18n.interfaces import INegotiator
>>> from z3c.language.negotiator.interfaces import INegotiatorManager
>>> INegotiator.providedBy(negotiator)
>>> INegotiatorManager.providedBy(negotiator)

By default a negotiator has the following values:

>>> negotiator.policy
'session --> browser --> server'
>>> negotiator.serverLanguage
>>> negotiator.offeredLanguages

If we set a policy with a wrong value, we will get a ValueError:

>>> negotiator.policy = u'wrong'
Traceback (most recent call last):
ValueError: ('Not a valid policy name.', u'wrong')

Register the negotiator as a global utility:

>>> import zope.component
>>> zope.component.provideUtility(negotiator, INegotiator)

Now we can use the vocabulary and see what offered languages are available:

>>> from z3c.language.negotiator import vocabulary
>>> vocab = vocabulary.OfferedLanguagesVocabulary(None)
>>> vocab
<z3c.language.negotiator.vocabulary.OfferedLanguagesVocabulary object at ...>
>>> vocab._terms

Add some offered languages and check the vocabulary again:

>>> negotiator.offeredLanguages = [u'de', u'fr']
>>> negotiator.offeredLanguages
[u'de', u'fr']

Try to get the utility and ceck the offeredLanguages again:

>>> util = zope.component.getUtility(INegotiator)
>>> util.offeredLanguages
[u'de', u'fr']

Now check the vocabulary again:

>>> vocab = vocabulary.OfferedLanguagesVocabulary(None)
>>> vocab._terms[0].value
>>> vocab._terms[0].token
>>> vocab._terms[0].title
>>> vocab._terms[1].value
>>> vocab._terms[1].token
>>> vocab._terms[1].title

See tests.py for more tests.

1.1.3 (2010-10-01)
  • Cache ONLY for the session setting. Others turned out as a bad idea.

System Message: WARNING/2 (<string>, line 105)

Bullet list ends without a blank line; unexpected unindent.

It's pretty straightforward now, we're caching session data lookups because those lookups are sooo slow. Would be better done in z3c.language.session, but there's nothing persistent.

1.1.2 (2010-08-05)
  • Fixed an issue with the cache:

System Message: WARNING/2 (<string>, line 114)

Bullet list ends without a blank line; unexpected unindent.

The cache just ignored the languages parameter. The first request saved a specific language (e.g. de-de) to the cache, but the second did not have that available in languages, still the cached value was returned. Worst case the uncached method is called.

1.1.1 (2010-07-21)
  • added language choice caching, is by default turned off
  • test coverage is now 100%
1.1.0 (2009-11-29)
  • adjust dependencies, reflect changes in zope packages
  • clanup tests, remove unused tests and skip using zope.app.testing
1.0.1 (2008-01-24)
  • Bug: Corrected meta data.
1.0.0 (2008-01-21)
  • Restructure: Removed the two vocabularies

System Message: WARNING/2 (<string>, line 147)

Bullet list ends without a blank line; unexpected unindent.

AvailableTranslationDomainLanguagesVocabulary and AvailableTranslationDomainLanguagesVocabularyForZ3C which depend on the zope.app.i18n implementation. Note these vocabularies are not persistent and if you will need it, let's implement this in another package. This allows us to skip all dependencies to zope.app.i18n.

  • Restructure: Moved zope.language.negotiator to it's namespace package.

Subscribe to package updates

Last updated Jan 5th, 2011

Download Stats

Last month:6

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.