Ignore:
Timestamp:
Feb 11, 2010 4:39:58 PM (14 years ago)
Author:
kroman0
Message:

Added translation for email subject

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.plonecomments/trunk/quintagroup/plonecomments/utils.py

    r1640 r1717  
    11import smtplib 
    2 from Products.CMFPlone import MessageFactory 
     2from zope.i18n import translate 
     3from zope.i18nmessageid import MessageFactory 
     4_ = MessageFactory("quintagroup.plonecomments") 
    35from Products.CMFCore.utils import getToolByName 
    4 from Products.CMFPlone import PloneMessageFactory as _ 
    56from config import warning 
    67 
     
    108109    creator_name = reply.getOwnerTuple()[1] 
    109110    admin_email = context.portal_url.getPortalObject().getProperty('email_from_address') 
    110  
     111    translate = getToolByName(context, 'translation_service').translate 
    111112    subject = '' 
    112113    if state == 'enable_approve_user_notification': 
    113         subject = 'Your comment on %s is now published' % getParent(context).Title() 
     114        subject = translate(_(u"approve_user_notification_subject", 
     115            default=u"Your comment on ${title} is now published", 
     116            mapping={u"title" : getParent(context).Title()}), 
     117            context=context.REQUEST) 
    114118        if user_email: 
    115119            template = 'notify_comment_template' 
     
    123127 
    124128    elif state == 'enable_rejected_user_notification': 
    125         subject = 'Your comment on %s was not approved' % getParent(context).Title() 
     129        subject = translate(_(u"rejected_user_notification_subject", 
     130            default=u"Your comment on ${title} was not approved", 
     131            mapping={u"title" : getParent(context).Title()}), 
     132            context=context.REQUEST) 
    126133        if user_email: 
    127134            template = 'rejected_comment_template' 
     
    136143    elif state == 'enable_reply_user_notification': 
    137144        template = 'reply_notify_template' 
    138         subject = 'Someone replied to your comment on %s' % getParent(context).Title() 
     145        subject = translate(_(u"reply_user_notification_subject", 
     146            default=u"Someone replied to your comment on ${title}", 
     147            mapping={u"title" : getParent(context).Title()}), 
     148            context=context.REQUEST) 
    139149        di_parrent = getDIParent(reply) 
    140150        if di_parrent: 
     
    159169                  'obj':reply_parent, 
    160170                  'organization_name':organization_name} 
    161             subject = '[%s] New comment added' % organization_name 
     171            subject = translate(_(u"published_notification_subject", 
     172                default=u"[${organization_name}] New comment added", 
     173                mapping={u"organization_name" : organization_name}), 
     174                context=context.REQUEST) 
    162175        else: 
    163176            args = {} 
     
    171184                  'obj':reply_parent, 
    172185                  'organization_name':organization_name} 
    173             subject = '[%s] New comment awaits moderation' % organization_name 
     186            subject = translate(_(u"approve_notification_subject", 
     187                default=u"[${organization_name}] New comment awaits moderation", 
     188                mapping={u"organization_name" : organization_name}), 
     189                context=context.REQUEST) 
    174190        else: 
    175191            args = {} 
     
    192208                    'comment_id':comment_id, 
    193209                    'comment_desc':comment.description, 
    194                     'comment_text':comment.text 
    195                     } 
    196             subject = '[%s] A comment on "%s" has been reported for abuse.' \ 
    197                             % (organization_name, getParent(context).Title()) 
     210                    'comment_text':comment.text} 
     211            subject = translate(_(u"report_abuse_subject", 
     212                default=u"[${organization_name}] A comment on ${title} has been reported for abuse.", 
     213                mapping={u"organization_name" : organization_name, u"title" : getParent(context).Title()}), 
     214                context=context.REQUEST) 
    198215        else: 
    199216            args = {} 
     
    205222        host = context.plone_utils.getMailHost() 
    206223        try: 
    207             host.secureSend(msg, user_email, admin_email, 
    208                             subject = subject, 
    209                             subtype = 'plain', 
    210                             debug = False, 
    211                             charset = charset) 
    212         except smtplib.SMTPRecipientsRefused: 
    213             log.error(_('SMTPRecipientsRefused: Could not send the email ' 
    214             'notification. Have you configured an email server for Plone?')) 
     224            host.secureSend(msg, user_email, admin_email, subject = subject, 
     225                            subtype = 'plain', debug = False, charset = charset) 
     226        except (smtplib.SMTPRecipientsRefused,smtplib.SMTPServerDisconnected): 
     227            setStatusMsg(None, context, 
     228                _('Could not send the email notification. Have you configured an email server for Plone?')) 
    215229 
    216230def setStatusMsg(state, context, msg): 
Note: See TracChangeset for help on using the changeset viewer.