[Moin-devel] Notification message in user's preferred language
Lele Gaifax
lele at seldati.it
Mon Mar 18 09:42:11 EST 2002
Hi all,
a few days ago Jurgen applied some changes to allow the selection of a
preferred language, so that MoinMoin can send its notification in the
proper language. Strangely, he did not apply the changes for
Page.py. Was there anything wrong?
Assuming he simply missed it, here below there is my last cut :)
thanx&bye,
lele.
-------------- next part --------------
Index: Page.py
===================================================================
RCS file: /cvsroot/moin/MoinMoin/Page.py,v
retrieving revision 1.108
diff -u -r1.108 Page.py
--- Page.py 13 Mar 2002 03:21:48 -0000 1.108
+++ Page.py 18 Mar 2002 17:33:47 -0000
@@ -645,55 +645,69 @@
# add the address only if the user has subscribed to the page and
# the user is not the current editor
userlist = user.getUserList()
- emails = []
+ emails_for_lang = {}
for uid in userlist:
if uid == user.current.id: continue # no self notification
subscriber = user.User(uid)
if not subscriber.email: continue # skip empty email address
- if subscriber.isSubscribedTo(pageList):
- emails.append(subscriber.email)
+ if subscriber.isSubscribedTo(pageList):
+ if subscriber.language:
+ pref_lang = subscriber.language
+ else:
+ pref_lang = 'en'
+ # end if
+
+ if emails_for_lang.has_key(pref_lang):
+ emails_for_lang[pref_lang].append(subscriber.email)
+ else:
+ emails_for_lang[pref_lang] = [subscriber.email]
+ # end if
+ # end if
+ # end for
- if emails:
- # send email to all subscribers; note that text must be in
- # English for all users, since currently we cannot (easily)
- # send the text in the recipient's language.
- # !!! TODO: make this possible
- mailBody = ("Dear Wiki user,\n\n"
- 'You have subscribed to a wiki page or wiki category on "%(sitename)s" for change notification.\n\n'
- "The following page has been changed by %(editor)s:\n"
- "%(pagelink)s\n\n") % {
- 'editor': user.current.name or os.environ.get('REMOTE_ADDR', "<unknown>"),
+ emails_results = []
+ if len (emails_for_lang):
+ # send email to all subscribers
+ for lang in emails_for_lang.keys():
+ mailBody = _("Dear Wiki user,\n\n"
+ 'You have subscribed to a wiki page or wiki category on "%(sitename)s" for change notification.\n\n'
+ "The following page has been changed by %(editor)s:\n"
+ "%(pagelink)s\n\n", lang) % {
+ 'editor': user.current.name or _("Someone coming from '%s'", lang) % os.environ.get('REMOTE_ADDR', _("<unknown>", lang)),
'pagelink': webapi.getQualifiedURL(self.url()),
'sitename': config.sitename or webapi.getBaseURL(),
- }
+ }
- if comment:
- mailBody = mailBody + \
- "The comment on the change is:\n%s\n\n" % comment
+ if comment:
+ mailBody = mailBody + \
+ _("The comment on the change is:\n%s\n\n", lang) % comment
- # get a list of old revisions, and append a diff
- oldversions = wikiutil.getBackupList(config.backup_dir, self.page_name)
- if not oldversions:
- mailBody = mailBody + \
- "No older revisions of the page stored, diff not available."
- else:
- page_file, backup_file, lines = wikiutil.pagediff(self.page_name, oldversions[0])
- if lines and len(lines) > 2:
- mailBody = "%s%s\n%s" % (
- mailBody, ("-" * 78), string.join(lines[2:], ''))
+ # get a list of old revisions, and append a diff
+ oldversions = wikiutil.getBackupList(config.backup_dir, self.page_name)
+ if not oldversions:
+ mailBody = mailBody + \
+ _("No older revisions of the page stored, diff not available.", lang)
else:
- mailBody = mailBody + "No differences found!\n"
+ page_file, backup_file, lines = wikiutil.pagediff(self.page_name, oldversions[0])
+ if lines and len(lines) > 2:
+ mailBody = "%s%s\n%s\n%s" % (
+ mailBody,
+ _("Here below the diff between the two latest revisions of the page", lang),
+ ("-" * 78), string.join(lines[2:], ''))
+ else:
+ mailBody = mailBody + _("No differences found!\n", lang)
- msg = _('\n'
- 'Sent a mail notification to these addresses: %s\n'
- '<br>Result was: ') % string.join(emails, ", ")
- msg = msg + util.sendmail(emails,
- '[%(sitename)s] Update of "%(pagename)s"' % {
- 'sitename': config.sitename or "Wiki",
- 'pagename': self.page_name,
- },
- mailBody, mail_from=user.current.email)
+ emails_results.append ('[' + lang + '] ' + string.join (emails_for_lang[lang], ',') + ':' +
+ util.sendmail(emails_for_lang[lang],
+ _('[%(sitename)s] Update of "%(pagename)s"', lang) % {
+ 'sitename': config.sitename or "Wiki",
+ 'pagename': self.page_name,
+ },
+ mailBody, mail_from=user.current.email))
+ # end for
+
+ msg = _('\nSent a mail notification to these addresses: %s\n') % string.join(emails_results, "\n")
return msg
return _('Nobody subscribed to this page, no mail sent.')
-------------- next part --------------
--
nickname: Lele Gaifax | Quando vivro' di quello che ho pensato ieri
real: Emanuele Gaifas | comincero' ad aver paura di chi mi copia.
email: lele at seldati.it | -- Fortunato Depero, 1929.
More information about the Moin-devel
mailing list