[Zope] Re: Change language with PTS

Josef Meile jmeile at hotmail.com
Mon Sep 4 16:56:09 EDT 2006


Hi Peter,

First at all, I think Localizer may be easier to do this task, it has
Built-in Cookie and traversal url support. You may also define your own
language selection method. If you still want to try this with PTS, then read
the following lines.
	
> Now, perhaps this works if my browser setting was 'sv' but it isn't. I
> actually don't want to use the browser setting at all, I want to
> control with via my own cookie and url traversal stuff.
To set the language you want with PTS, you have to set the
HTTP_ACCEPT_LANGUAGE as follows:

REQUEST.set('HTTP_ACCEPT_LANGUAGE',lang)

where lang could be 'sv'. Please note that you have to do this at the
beginning your your ZPT Template or DTML method. I have had problem when
doing this in the middle of the code.

I think cookies could also work, but I haven't tested the code myself. You
will need to set them via the request object like this:

REQUEST.RESPONSE.setCookie('lang','sv', max_age=something)
lang = REQUEST.cookies['lang']

PTS doesn't support traversal url. Anyway, you can still achieve this with
Access Rules. There is an outdated how-to that can give you an idea on how
to do this:

How To build multilingual sites with SiteAccess:
http://www.zope.org/Members/jdavid/MultilingualSiteAccess

There you will see that SiteAccess is mentioned, which is deprecated;
however, I think this Product was replaced by SiteRoot and Access Rules
(somebody correct me if I'm wrong). You may need to google about this.

As mentioned in that How-To, it was superseded by Localizer, so, you may
look at the source code of this product as well. 

Regards
Josef



More information about the Zope mailing list