Skip to content

Commit

Permalink
The subject of the email can now be translated.
Browse files Browse the repository at this point in the history
  • Loading branch information
illagrenan committed May 16, 2017
1 parent 01d0714 commit 03345da
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion django_cbtp_email/mail_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from django.core.mail import EmailMessage
from django.template.loader import render_to_string
from django.utils import translation
from django.utils.encoding import force_text
from premailer import Premailer

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -38,6 +39,7 @@ def send_mail(subject,
to = [to]

with translation.override(language):
translated_subject = force_text(subject)
html_message = render_to_string(template_path, context)

if premailer:
Expand All @@ -49,7 +51,7 @@ def send_mail(subject,

html_message = premailer.transform()

mail = EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, html_message, to=to, from_email=from_email)
mail = EmailMessage(settings.EMAIL_SUBJECT_PREFIX + translated_subject, html_message, to=to, from_email=from_email)
if template_variant == "html":
mail.content_subtype = "html"

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def read_md(file_name):
# https://hynek.me/articles/sharing-your-labor-of-love-pypi-quick-and-dirty/
setup(
name='django_cbtp_email',
version='0.1.3',
version='0.1.4',
description=' Class-based mailer for Django using templates with inlined CSS.',

# ########################################################################
Expand Down

0 comments on commit 03345da

Please sign in to comment.