diff --git a/src/pretix/base/services/mail.py b/src/pretix/base/services/mail.py index 0d8849b24..a815179ad 100644 --- a/src/pretix/base/services/mail.py +++ b/src/pretix/base/services/mail.py @@ -512,16 +512,17 @@ def mail_send_task(self, **kwargs) -> bool: # Attach calendar files if outgoing_mail.should_attach_ical and outgoing_mail.order: - fname = re.sub('[^a-zA-Z0-9 ]', '-', unidecode(pgettext('attachment_filename', 'Calendar invite'))) - icals = get_private_icals( - outgoing_mail.event, - [outgoing_mail.orderposition] if outgoing_mail.orderposition else outgoing_mail.order.positions.all() - ) - for i, cal in enumerate(icals): - name = '{}{}.ics'.format(fname, f'-{i + 1}' if i > 0 else '') - content = cal.serialize() - mimetype = 'text/calendar' - email.attach(name, content, mimetype) + with language(outgoing_mail.order.locale, outgoing_mail.event.settings.region): + fname = re.sub('[^a-zA-Z0-9 ]', '-', unidecode(pgettext('attachment_filename', 'Calendar invite'))) + icals = get_private_icals( + outgoing_mail.event, + [outgoing_mail.orderposition] if outgoing_mail.orderposition else outgoing_mail.order.positions.all() + ) + for i, cal in enumerate(icals): + name = '{}{}.ics'.format(fname, f'-{i + 1}' if i > 0 else '') + content = cal.serialize() + mimetype = 'text/calendar' + email.attach(name, content, mimetype) invoices_to_mark_transmitted = [] for inv in outgoing_mail.should_attach_invoices.all(): diff --git a/src/tests/base/test_mail.py b/src/tests/base/test_mail.py index 8c19e7950..8ccf0965b 100644 --- a/src/tests/base/test_mail.py +++ b/src/tests/base/test_mail.py @@ -562,3 +562,32 @@ def test_escaped_braces_mail_services(env): for part in (html, plain, djmail.outbox[0].subject): assert "EUR" not in part assert "-{currency}-" in part + + +@pytest.mark.django_db +def test_attached_ical_localization(env, order): + event, _, _ = env + + descriptions = {"de": "german description", "en": "english description"} + event.settings.mail_attach_ical_description = LazyI18nString(descriptions) + event.settings.mail_attach_ical = True + event.settings.mail_attach_ical_paid_only = False + + for locale, description in descriptions.items(): + order.locale = locale + order.save() + + djmail.outbox = [] + + mail( + "dummy@dummy.dummy", + "", + LazyI18nString(""), + event=event, + order=order, + attach_ical=True + ) + + assert len(djmail.outbox) == 1 + assert len(djmail.outbox[0].attachments) == 1 + assert description in djmail.outbox[0].attachments[0][1]