From cbd1b5d3e5833051b9c8d166f89bfdda76bf8bd3 Mon Sep 17 00:00:00 2001 From: bwarsaw Date: Fri, 2 Mar 2001 00:56:51 +0000 Subject: __onefile(): The qrunner framework now sets up the language context for each processed message. It does this by getting the preferred language of the sender of the message (defaulting to the list's preferred language if the sender isn't a member of the list). Next, it saves the previous global language context in a local variable, sets the context to the message's preferred language and disposes of the message. Then it restores the original language context. It also sets the message's metadata (key: `lang') to contain the language name for the language context in case any handler modules need access to it. --- Mailman/Queue/Runner.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'Mailman/Queue/Runner.py') diff --git a/Mailman/Queue/Runner.py b/Mailman/Queue/Runner.py index cf766f807..c896fb4c4 100644 --- a/Mailman/Queue/Runner.py +++ b/Mailman/Queue/Runner.py @@ -25,6 +25,7 @@ from Mailman import mm_cfg from Mailman import Utils from Mailman import Errors from Mailman import MailList +from Mailman import i18n from Mailman.pythonlib.StringIO import StringIO from Mailman.Queue.Switchboard import Switchboard @@ -121,7 +122,23 @@ class Runner: return # Now process this message, keeping track of any subprocesses that may # have been spawned. We'll reap those later. - keepqueued = self._dispose(mlist, msg, msgdata) + # + # We also want to set up the language context for this message. The + # context will be the preferred language for the user if a member of + # the list, or the list's preferred language. However, we must take + # special care to reset the defaults, otherwise subsequent messages + # may be translated incorrectly. BAW: I'm not sure I like this + # approach, but I can't think of anything better right now. + otranslation = i18n.get_translation() + sender = msg.get_sender() + lang = mlist.GetPreferredLanguage(sender) + i18n.set_language(lang) + msgdata['lang'] = lang + try: + keepqueued = self._dispose(mlist, msg, msgdata) + finally: + i18n.set_translation(otranslation) + # Keep tabs on any child processes that got spawned. kids = msgdata.get('_kids') if kids: self._kids.update(kids) -- cgit v1.2.3-70-g09d2