Hi,
Zhang Huangbin wrote:
> I want to change render for language switch without logout/restart
> webpy[1] app, but it works only in Safari, not work in IE and Firefox
> 3.
I don't know how web.py is working internally but I'm pretty sure what
you are doing is not what you want. If you really want to switch
languages between requests (which is perfectly okay and many people do
that), please don't install and uninstall translators but use a proxy.
Something like this:
@contextfilter
def template_gettext(context, string):
language = context['LANGUAGE']
return get_translator_for(language).ugettext(string)
@contextfilter
def template_context(context, s, p, n):
language = context['LANGUAGE']
return get_translator_for(language).ungettext(s, p, n)
That way you only have to set the LANGUAGE variable in the template
context and the jinja system will pick up that with the proxying. This
also means that because get_translator_for is called for every call to
either ngettext or gettext (or _ for that matter), you have to ensure
that the call is as cheap as possible.
You can ensure that by making get_translator_for keeping the translators
in a global dict once loaded. If you need help with that, have a look
at how existing implementations do that.
The Plurk Solace system is doing that for example. The sourcecode is
available on bitbucket[1].
It's very likely that the thing you are doing is breaking in all
browsers just that caching is hiding the problem.
[1]: http://bitbucket.org/plurk/solace
Regards,
Armin
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pocoo-libs" 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/pocoo-libs?hl=en
-~----------~----~----~----~------~----~------~--~---