internationalize notification mail

svn path=/plone.app.discussion/trunk/; revision=39572
This commit is contained in:
Vincent Fretin 2010-08-31 18:07:51 +00:00
parent 87ce946947
commit f5bed31131

View File

@ -7,6 +7,8 @@ from zope.annotation.interfaces import IAnnotatable
from zope.component.factory import Factory from zope.component.factory import Factory
from zope.component import queryUtility from zope.component import queryUtility
from zope.i18n import translate
from zope.i18nmessageid import Message
from zope.interface import implements from zope.interface import implements
from Acquisition import aq_parent, Implicit from Acquisition import aq_parent, Implicit
@ -25,6 +27,7 @@ from OFS.Traversable import Traversable
from plone.registry.interfaces import IRegistry from plone.registry.interfaces import IRegistry
from plone.app.discussion import PloneAppDiscussionMessageFactory as _
from plone.app.discussion.interfaces import IComment from plone.app.discussion.interfaces import IComment
from plone.app.discussion.interfaces import IConversation from plone.app.discussion.interfaces import IConversation
from plone.app.discussion.interfaces import IDiscussionSettings from plone.app.discussion.interfaces import IDiscussionSettings
@ -43,8 +46,9 @@ except:
from OFS.Traversable import Traversable as WorkflowAware from OFS.Traversable import Traversable as WorkflowAware
PLONE_4 = False PLONE_4 = False
MAIL_NOTIFICATION_MESSAGE = Template("A comment with the title '%title' " MAIL_NOTIFICATION_MESSAGE = _(u"mail_notification_message",
"has been posted here: %link") default=u"A comment with the title '%(title)s' "
"has been posted here: %(link)s")
class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable, class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable,
@ -193,10 +197,11 @@ def notify_user(obj, event):
for comment in conversation.getComments(): for comment in conversation.getComments():
if obj != comment and \ if obj != comment and \
comment.author_notification and comment.author_email: comment.author_notification and comment.author_email:
subject = "A comment has been posted." subject = _(u"A comment has been posted.")
message = MAIL_NOTIFICATION_MESSAGE.substitute( message = translate(Message(MAIL_NOTIFICATION_MESSAGE,
title=obj.title, mapping={'title': obj.title,
link=content_object.absolute_url()) 'link': content_object.absolute_url()}),
context=obj.REQUEST)
mail_host.send(message, comment.author_email, sender, subject) mail_host.send(message, comment.author_email, sender, subject)
def notify_moderator(obj, event): def notify_moderator(obj, event):
@ -239,10 +244,11 @@ def notify_moderator(obj, event):
# Compose email # Compose email
#comment = conversation.getComments().next() #comment = conversation.getComments().next()
subject = "A comment has been posted." subject = _(u"A comment has been posted.")
message = MAIL_NOTIFICATION_MESSAGE.substitute( message = translate(Message(MAIL_NOTIFICATION_MESSAGE,
title=obj.title, mapping={'title': obj.title,
link=content_object.absolute_url()) 'link': content_object.absolute_url()}),
context=obj.REQUEST)
# Send email # Send email
if PLONE_4: if PLONE_4: