Skip to content
This repository has been archived by the owner on Dec 17, 2020. It is now read-only.

Commit

Permalink
Moved z3c.language.switch to it's own top level package
Browse files Browse the repository at this point in the history
  • Loading branch information
projekt01 committed Nov 16, 2007
1 parent c091aba commit 9c7a398
Show file tree
Hide file tree
Showing 22 changed files with 1,517 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CHANGES.txt
@@ -0,0 +1,8 @@
=======
CHANGES
=======

Version 0.5.0 (unreleased)
--------------------------

- Moved zope.language.switch to it's namespace package
2 changes: 2 additions & 0 deletions README.txt
@@ -0,0 +1,2 @@
This package provides an implementation wich let's you implement your own i18n
aware content types.
52 changes: 52 additions & 0 deletions bootstrap.py
@@ -0,0 +1,52 @@
##############################################################################
#
# Copyright (c) 2007 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""Bootstrap a buildout-based project
Simply run this script in a directory containing a buildout.cfg.
The script accepts buildout command-line options, so you can
use the -c option to specify an alternate configuration file.
$Id:$
"""

import os, shutil, sys, tempfile, urllib2

tmpeggs = tempfile.mkdtemp()

ez = {}
exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
).read() in ez
ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)

import pkg_resources

cmd = 'from setuptools.command.easy_install import main; main()'
if sys.platform == 'win32':
cmd = '"%s"' % cmd # work around spawn lamosity on windows

ws = pkg_resources.working_set
assert os.spawnle(
os.P_WAIT, sys.executable, sys.executable,
'-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
dict(os.environ,
PYTHONPATH=
ws.find(pkg_resources.Requirement.parse('setuptools')).location
),
) == 0

ws.add_entry(tmpeggs)
ws.require('zc.buildout')
import zc.buildout.buildout
zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
shutil.rmtree(tmpeggs)
17 changes: 17 additions & 0 deletions buildout.cfg
@@ -0,0 +1,17 @@
[buildout]
develop = .
externals/z3c.language.negotiator
externals/z3c.language.session
parts = test checker coverage

[test]
recipe = zc.recipe.testrunner
eggs = z3c.language.switch [test]

[checker]
recipe = lovely.recipe:importchecker
path = src/z3c/language/switch

[coverage]
recipe = zc.recipe.egg
eggs = z3c.coverage
78 changes: 78 additions & 0 deletions setup.py
@@ -0,0 +1,78 @@
##############################################################################
#
# Copyright (c) 2007 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""Setup
$Id:$
"""
import os
from setuptools import setup, find_packages

def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()

setup (
name='z3c.language.switch',
version='0.5.0dev',
author = "Roger Ineichen and the Zope Community",
author_email = "zope3-dev@zope.org",
description = "Zope3 i18n language switch.",
long_description=(
read('README.txt')
+ '\n\n' +
read('CHANGES.txt')
),
license = "ZPL 2.1",
keywords = "zope3 z3c i18n language switch",
classifiers = [
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: Zope Public License',
'Programming Language :: Python',
'Natural Language :: English',
'Operating System :: OS Independent',
'Topic :: Internet :: WWW/HTTP',
'Framework :: Zope3'],
url = 'http://cheeseshop.python.org/pypi/z3c.language.switch',
packages = find_packages('src'),
include_package_data = True,
package_dir = {'':'src'},
namespace_packages = ['z3c', 'z3c.language'],
extras_require = dict(
test = [
'zope.app.testing',
'zope.testing',
'z3c.testing',
'z3c.coverage',
],
),
install_requires = [
'setuptools',
'z3c.i18n',
'z3c.language.session',
'zope.app.component',
'zope.component',
'zope.i18n',
'zope.interface',
'zope.security',
'zope.event',
'zope.publisher',
'zope.schema',
'zope.session',
'zope.lifecycleevent',
'zope.app.generations',
],
dependency_links = ['http://download.zope.org/distribution'],
zip_safe = False,
)
123 changes: 123 additions & 0 deletions src/z3c/language/switch/README.txt
@@ -0,0 +1,123 @@
======
README
======

Let's show how z3c.language.switch works:

Imports and placeless setup:

>>> import zope.component
>>> from zope.app.testing import placelesssetup
>>> from z3c.language.switch import II18nLanguageSwitch
>>> from z3c.language.switch.testing import IContentObject
>>> from z3c.language.switch.testing import II18nContentObject
>>> from z3c.language.switch.testing import I18nContentObject
>>> from z3c.language.switch.testing import I18nContentObjectLanguageSwitch
>>> from z3c.language.switch.testing import ContentObject
>>> placelesssetup.setUp()

Setup test object:

>>> en_title = u'en_title'
>>> obj = I18nContentObject(en_title)
>>> obj.title
u'en_title'

Add additional languages:

>>> de_title = u'de_title'
>>> fr_title = u'fr_title'
>>> deObj = obj.addLanguage('de', de_title)
>>> frObj = obj.addLanguage('fr', fr_title)

Switch default language:

>>> obj.title
u'en_title'

>>> obj.setDefaultLanguage('de')
>>> obj.title
u'de_title'

Remove the 'en' language object:

>>> obj._data.keys()
['de', 'en', 'fr']
>>> obj.removeLanguage('en')
>>> obj._data.keys()
['de', 'fr']

Remove default language object will end in a ValueError error:

>>> obj.removeLanguage('de')
Traceback (most recent call last):
...
ValueError: cannot remove default language (de)

Remove nonexistent language object will end in a ValueError error:

>>> obj.removeLanguage('undefined')
Traceback (most recent call last):
...
ValueError: cannot remove nonexistent language (undefined)

Set default language to a non existent language will end in a ValueError:

>>> obj.setDefaultLanguage('en')
Traceback (most recent call last):
...
ValueError: cannot set nonexistent language (en) as default

Access the language directly via the II18nLanguageSwitch adapter,
first register the adapter for the I18nContentObject:

>>> zope.component.provideAdapter(I18nContentObjectLanguageSwitch,
... (II18nContentObject,), provides=II18nLanguageSwitch)

The adapter is set to the default language in the init method:

>>> adapted = II18nLanguageSwitch(obj)
>>> adapted.title
u'de_title'

Change the default language and access the title again, the title should not
switch to another language:

>>> obj.setDefaultLanguage('fr')
>>> adapted.title
u'de_title'

Switch the language to 'fr' via the adapter:

>>> adapted.setLanguage('fr')
>>> adapted.title
u'fr_title'

Finally, clean up::

>>> placelesssetup.tearDown()


AvailableLanguagesVocabulary
----------------------------

Use this vocabulary for get the available languages from the object
itself.

>>> from z3c.language.switch import vocabulary
>>> vocab = vocabulary.AvailableLanguagesVocabulary(obj)
>>> len(vocab._terms)
2

>>> vocab._terms[0].value
'de'
>>> vocab._terms[0].token
'de'
>>> vocab._terms[0].title
'de'
>>> vocab._terms[1].value
'fr'
>>> vocab._terms[1].token
'fr'
>>> vocab._terms[1].title
'fr'
3 changes: 3 additions & 0 deletions src/z3c/language/switch/SETUP.cfg
@@ -0,0 +1,3 @@
<data-files zopeskel/etc/package-includes>
z3c.language.switch-*.zcml
</data-files>
18 changes: 18 additions & 0 deletions src/z3c/language/switch/__init__.py
@@ -0,0 +1,18 @@
##############################################################################
#
# Copyright (c) 2005 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""
$Id$
"""

from z3c.language.switch.interfaces import *

0 comments on commit 9c7a398

Please sign in to comment.