This repository has been archived by the owner on Dec 17, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved z3c.language.switch to it's own top level package
- Loading branch information
Showing
22 changed files
with
1,517 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
======= | ||
CHANGES | ||
======= | ||
|
||
Version 0.5.0 (unreleased) | ||
-------------------------- | ||
|
||
- Moved zope.language.switch to it's namespace package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This package provides an implementation wich let's you implement your own i18n | ||
aware content types. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<data-files zopeskel/etc/package-includes> | ||
z3c.language.switch-*.zcml | ||
</data-files> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 * |
Oops, something went wrong.