Nice information, so we can go ahead working with activate() :-)

Let me ask you one more question: in your code, i see you're using
django.util.translation.get_language(), it's not a documented function and
according to django policies it can be changed or removed in any new
release.
Perhaps it's better using request.LANGUAGE_CODE?

2009/8/13 Jarek Zgoda <jarek.zg...@redefine.pl>

>
> Wiadomość napisana w dniu 2009-08-12, o godz. 17:11, przez Andrea Zilio:
>
> > I'm sorry, can you explain a little bit this problem? Or where I can
> > get info about it?
> >
> > On Aug 12, 3:48 pm, Jarek Zgoda <jarek.zg...@redefine.pl> wrote:
> >> Wiadomość napisana w dniu 2009-08-12, o godz. 13:00, przez Enrico
> >> Sartorello:
> >>
> >>> i'm facing a problem developing with Django a Web Application: in
> >>> response to some events (for example, after an admin action) i
> >>> need to
> >>> sendemailsto some users of my site.
> >>
> >>> The problem arises when i want theseemailsto be translated in any
> >>> user-specific language: the Request object i have just contains the
> >>> language infos of the user that trigger the event, so it's not
> >>> what i
> >>> need.
> >>> Generally, LocaleMiddleware behaviour can't do that job, because is
> >>> based on sessions and cookies of a particular user.
> >>> Roughly speaking i need (at least) a way to manually decide which is
> >>> the language to apply for translations.
> >>
> >> OnceIneededtosendemailsinHungarianfromEnglishapplication and
> >> this worked.
> >>
> >> Before translating any string you need to know which language to use.
> >> If you have this information handy somewhere you can just switch the
> >> translation catalog safely in separated process environments
> >> (FastCGI,
> >> WSGI). As translation.activate() is process-wide, this approach is
> >> not
> >> safe in multithreaded environment if using static translation (not
> >> request-based).
>
>
> The problem: translate some text to language other than specified in
> request or statically in settings (but of course already known).
> The solution:
>
> def to_german():
>     cur_lang = translation.get_language()
>     try:
>         translation.activate('de')
>         german_text = translation.ugettext(u'This is some text')
>     finally:
>         translation.activate(cur_lang)
>     return german_text
>
> I stand corrected that translation activation **is** thread safe and
> does not affect code running in another threads (mod_python might be
> the cause of my problems).
>
> --
> Artificial intelligence stands no chance against natural stupidity
>
> Jarek Zgoda, R&D, Redefine
> jarek.zg...@redefine.pl
>
>
> >
>


-- 
Enrico Sartorello

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to