[z3-five] Problem overriding IUserPreferredLanguages
Doyon, Jean-Francois
Jean-Francois.Doyon at CCRS.NRCan.gc.ca
Sat Apr 29 00:24:20 CEST 2006
Hello,
First of all, note that is my very first forry into Five/Zope 3 ... (Though
I know 2.7 well!) I'm using 2.9.2 right now.
I'm trying to use my own system of determining the language to use, based on
the URL.
Using Five/i18n.py and http://codespeak.net/z3/five/i18n.html, I've created
a very small product to start with:
i18n.py:
from zope.interface import implements
from zope.i18n.interfaces import IUserPreferredLanguages
class PathLanguages(object):
implements(IUserPreferredLanguages)
def __init__(self, context):
self.context = context
def getPreferredLanguages(self):
request = self.context
stack = request['TraversalRequestNameStack']
if stack and len(stack) > 0 and stack[-1] in ['en', 'fr']:
# A language entry is in the path
lang = stack.pop(-1)
# Rewrite the path so all links will have the language path
entry
base_parts = request['VIRTUAL_URL_PARTS'][1]
request.setVirtualRoot([base_parts] + [lang])
return [lang]
else:
return ['en']
And overrides.zcml:
<configure xmlns="http://namespaces.zope.org/zope"
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:five="http://namespaces.zope.org/five">
<adapter for="zope.publisher.interfaces.http.IHTTPRequest"
provides="zope.i18n.interfaces.IUserPreferredLanguages"
factory=".i18n.PathLanguages" />
</configure>
But this seems to do absolutely nothing :(
I've tried adding raises or prints in the code and so on, but as best I can
tell, it never gets called. The __init__ for the Product is empty.
Basically, it's my first Five product, and it's only supposed to set the
language, but I can't even get it to do that.
Anyone care to point me in the right direction?
Thanks in advance for the help ...
Jean-François Doyon
Internet Service Development and Systems Support / Spécialiste de
dèveloppements internet et soutien technique
Canada Centre for Remote Sensing/Centre Canadien de télédétection
Natural Resources Canada/Ressources Naturelles Canada
http://atlas.gc.ca
Tel./Tél.: (613) 992-4902
Fax: (613) 947-2410
More information about the z3-five
mailing list