2010/6/15 Emiliano Martinez Contreras <[email protected]>:
> Hi Anand,
>
> Thanks for the quick reply. In my main sitemanager app what I do is use a
> cookie to find out the language of the visitor, according to that cookie a
> locale template path is chosen, so what I have is a hook which I then add as
> a preprocessor:
>
> +++
>
> def render_hook():
>     cookies = web.cookies(lang="en")
>     lang = cookies.lang
>
>     if lang in settings.VALID_LANGS:
>         locales_path = os.path.join(settings.TEMPLATES_PATH, "%s/"%(lang))
>
>     else:
>         locales_path = os.path.join(settings.TEMPLATES_PATH,"en/")
>
>     web.ctx.render = web.template.render(locales_path, globals={'session':
> web.ctx.session})

Try changing it to:

def render_hook():
    cookies = web.cookies(lang="en")
    lang = cookies.lang
    if lang not in settings.VALID_LANGS:
        lang = "en"
    web.ctx.render = getattr(render, lang)

render = web.template.render(settings.TEMPLATES_PATH)

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.

Reply via email to