Repository: fossasia/open-event-server

Issue:
Make subjects of all mails translatable
Currently session state mails and subjects of all mails are not translatable. Please make it possible to translate them.

For example, where are the strings for this email? Where can this be translated?

```
        },
        'canceled': {
            'subject': 'Canceled! Your submission for {event_name} titled {session_name} has been Canceled',
            'message': "Hello,<br/><br/>"
            "This is an automatic message from {app_name}.<br/><br/>"
            "Your session status for the submission {session_name} for {event_name} was changed to \"Canceled\".<br/><br/>"
            "The status change was done by event organizers. If there are questions about this change please contact the organizers.<br/><br/>"
            "You can also check the status and details of your submission on the session page {session_cfs_link}. You need to be logged in to view it.<br/><br/>"
            "More details about the event are on the event page at {event_link}.<br/><br/>"
            "Thank you.<br/>"
            "{frontend_link}",
        },
```

_Originally posted by @mariobehling in https://github.com/fossasia/open-event-server/issues/8321#issuecomment-954752178_


Discussion:
After the last PR in the mails "New order for" there is a quote sign in front of eventyay (appName).

![Screenshot from 2021-11-10 15-35-12](https://user-images.githubusercontent.com/1583873/141132851-3af91908-c4e6-4235-95e2-fbebf78477b8.png)

will correct this in this PR
The subject of mails is translatable in the translation system, but it does not show up in the subject of recipients if an email is in German for example. Therefore reopening this.

![Screenshot from 2021-11-20 07-02-12](https://user-images.githubusercontent.com/1583873/142716343-1b03a722-2a28-4197-87ca-f11e29835d31.png)

Kindly asign me this issue
@anjali1102 We don't assign issues to external contributors. Please start working on the issue and make a draft PR. We'll help you along the way.
Subjects still are not translatable after the last PR got merged. There are no additional translation options in Weblate. Mails of orders in other languages have the content in another language than English, but the subject is still not translated.
https://stackoverflow.com/questions/17380165/python-gettext-different-languages-at-same-time

Resolving patch:
diff --git a/app/api/helpers/system_mails.py b/app/api/helpers/system_mails.py
--- a/app/api/helpers/system_mails.py
+++ b/app/api/helpers/system_mails.py
@@ -3,7 +3,8 @@
 Register a mail here before using it
 """
 
-from flask_babel import lazy_gettext
+from flask_babel import lazy_gettext as _
+
 
 class MailType:
     USER_REGISTER = 'user_registration'
@@ -60,7 +61,9 @@ def entries():
     MailType.SESSION_STATE_CHANGE: {
         'recipient': 'Speaker',
         'pending': {
-            'subject': lazy_gettext('Your speaker submission for {event_name} titled {session_name}'),
+            'subject': _(
+                'Your speaker submission for {event_name} titled {session_name}'
+            ),
             'message': "Hello,<br/><br/>"
             "This is an automatic message from {app_name}.<br/><br/>"
             "We have received your submission {session_name} for {event_name}<br/><br/>"
@@ -71,7 +74,9 @@ def entries():
             "{frontend_link}",
         },
         'accepted': {
-            'subject': lazy_gettext('Accepted! Congratulations Your submission for {event_name} titled {session_name} has been Accepted'),
+            'subject': _(
+                'Accepted! Congratulations Your submission for {event_name} titled {session_name} has been Accepted'
+            ),
             'message': "Hello,<br/><br/>"
             "This is an automatic message from {app_name}.<br/><br/>"
             "Your session status for the submission {session_name} for {event_name} was changed to \"Accepted\". Congratulations!<br/><br/>"
@@ -82,7 +87,9 @@ def entries():
             "{frontend_link}",
         },
         'confirmed': {
-            'subject': lazy_gettext('Confirmed! Congratulations Your submission for {event_name} titled {session_name} has been Confirmed'),
+            'subject': _(
+                'Confirmed! Congratulations Your submission for {event_name} titled {session_name} has been Confirmed'
+            ),
             'message': "Hello,<br/><br/>"
             "This is an automatic message from {app_name}.<br/><br/>"
             "Your session status for the submission {session_name} for {event_name} was changed to \"Confirmed\". Congratulations!<br/><br/>"
@@ -93,7 +100,9 @@ def entries():
             "{frontend_link}",
         },
         'rejected': {
-            'subject': lazy_gettext('Not Accepted. Your submission for {event_name} titled {session_name} was not accepted'),
+            'subject': _(
+                'Not Accepted. Your submission for {event_name} titled {session_name} was not accepted'
+            ),
             'message': "Hello,<br/><br/>"
             "This is an automatic message from {app_name}.<br/><br/>"
             "Unfortunately your submission {session_name} for {event_name} was not accepted. Your session status was changed to \"Rejected\".<br/><br/>"
@@ -104,7 +113,9 @@ def entries():
             "{frontend_link}",
         },
         'canceled': {
-            'subject': lazy_gettext('Canceled! Your submission for {event_name} titled {session_name} has been Canceled'),
+            'subject': _(
+                'Canceled! Your submission for {event_name} titled {session_name} has been Canceled'
+            ),
             'message': "Hello,<br/><br/>"
             "This is an automatic message from {app_name}.<br/><br/>"
             "Your session status for the submission {session_name} for {event_name} was changed to \"Canceled\".<br/><br/>"
@@ -115,7 +126,9 @@ def entries():
             "{frontend_link}",
         },
         'withdrawn': {
-            'subject': lazy_gettext('Withdrawn! Your submission for {event_name} titled {session_name} has been Withdrawn'),
+            'subject': _(
+                'Withdrawn! Your submission for {event_name} titled {session_name} has been Withdrawn'
+            ),
             'message': "Hello,<br/><br/>"
             "This is an automatic message from {app_name}.<br/><br/>"
             "Your session status for the submission {session_name} for {event_name} was changed to \"Withdrawn\".<br/><br/>"
@@ -128,131 +141,153 @@ def entries():
     },
     MailType.TICKET_SALES_END: {
         'recipient': 'Owner, Organizer',
-        'subject': lazy_gettext('Ticket Sales Period for One or Several Tickets for {event_name} Ended'),
+        'subject': _(
+            'Ticket Sales Period for One or Several Tickets for {event_name} Ended'
+        ),
         'template': 'email/ticket_sales_end.html',
     },
     MailType.TICKET_SALES_END_TOMORROW: {
         'recipient': 'Owner, Organizer',
-        'subject': lazy_gettext('Ticket Sales Period for One or Several Tickets for {event_name} Ending in 24 Hours'),
+        'subject': _(
+            'Ticket Sales Period for One or Several Tickets for {event_name} Ending in 24 Hours'
+        ),
         'template': 'email/ticket_sales_end_tomorrow.html',
     },
     MailType.TICKET_SALES_END_NEXT_WEEK: {
         'recipient': 'Owner, Organizer',
-        'subject': lazy_gettext('Ticket Sales Period fors One or Several Tickets for {event_name} Ending in 7 Days'),
+        'subject': _(
+            'Ticket Sales Period fors One or Several Tickets for {event_name} Ending in 7 Days'
+        ),
         'template': 'email/ticket_sales_end_next_week.html',
     },
     MailType.NEW_SESSION: {
         'recipient': 'Owner, Organizer',
-        'subject': lazy_gettext('New session proposal for {session.event.name} titled {session.title}'),
+        'subject': _(
+            'New session proposal for {session.event.name} titled {session.title}'
+        ),
         'template': 'email/new_session.html',
     },
     MailType.USER_REGISTER: {
         'recipient': 'User',
-        'subject': lazy_gettext('Welcome to {app_name}. Please verify your account'),
+        'subject': _('Welcome to {app_name}. Please verify your account'),
         'template': 'email/user_register.html',
     },
     MailType.USER_CONFIRM: {
         'recipient': 'User',
-        'subject': lazy_gettext('Email Confirmation to Create Account for {app_name}'),
+        'subject': _('Email Confirmation to Create Account for {app_name}'),
         'template': 'email/user_confirm.html',
     },
     MailType.USER_CHANGE_EMAIL: {
         'recipient': 'User',
-        'subject': lazy_gettext('Your email has been already changed'),
+        'subject': _('Your email has been already changed'),
         'template': 'email/user_change_email.html',
     },
     MailType.PASSWORD_RESET: {
         'recipient': 'User',
-        'subject': lazy_gettext('{app_name}: Password Reset'),
+        'subject': _('{app_name}: Password Reset'),
         'template': 'email/password_reset.html',
     },
     MailType.PASSWORD_RESET_AND_VERIFY: {
         'recipient': 'User',
-        'subject': lazy_gettext('{app_name}: Reset your password and verify your account'),
+        'subject': _('{app_name}: Reset your password and verify your account'),
         'template': 'email/password_reset_and_verify.html',
     },
     MailType.PASSWORD_CHANGE: {
         'recipient': 'User',
-        'subject': lazy_gettext('{app_name}: Password Change'),
+        'subject': _('{app_name}: Password Change'),
         'template': 'email/password_change.html',
     },
     MailType.EVENT_ROLE: {
         'recipient': 'User',
-        'subject': lazy_gettext('Invitation to be {role} at Event: {event}'),
+        'subject': _('Invitation to be {role} at Event: {event}'),
         'template': 'email/event_role.html',
     },
     MailType.SPEAKER_INVITE: {
         'recipient': 'User',
-        'subject': lazy_gettext('Invitation to be speaker at Session: {session}'),
+        'subject': _('Invitation to be speaker at Session: {session}'),
         'template': 'email/speaker_invite.html',
     },
     MailType.GROUP_ROLE: {
         'recipient': 'User',
-        'subject': lazy_gettext('Invitation to be {role} at Group: {group}'),
+        'subject': _('Invitation to be {role} at Group: {group}'),
         'template': 'email/group_role.html',
     },
     MailType.TICKET_PURCHASED: {
         'recipient': 'User',
-        'subject': lazy_gettext('See you at {event_name} on {event_date} at {event_time} ({invoice_id}) '),
+        'subject': _(
+            'See you at {event_name} on {event_date} at {event_time} ({invoice_id}) '
+        ),
         'template': 'email/ticket_purchased.html',
     },
     MailType.TICKET_PURCHASED_ATTENDEE: {
         'recipient': 'Attendee',
-        'subject': lazy_gettext('Your tickets for {event_name} on {event_date} at {event_time} ({invoice_id}) '),
+        'subject': _(
+            'Your tickets for {event_name} on {event_date} at {event_time} ({invoice_id}) '
+        ),
         'template': 'email/ticket_purchased_attendee.html',
     },
     MailType.TICKET_PURCHASED_ORGANIZER: {
         'recipient': 'Owner, Organizer, Coorganizer',
-        'subject': lazy_gettext('New order for {event_name} on {event_date} by {buyer_name}, {buyer_email} ({invoice_id}) '),
+        'subject': _(
+            'New order for {event_name} on {event_date} by {buyer_name}, {buyer_email} ({invoice_id}) '
+        ),
         'template': 'email/ticket_purchased_organizer.html',
     },
     MailType.TICKET_CANCELLED: {
         'recipient': 'User',
-        'subject': lazy_gettext('Your order for {event_name} has been cancelled ({invoice_id})'),
+        'subject': _('Your order for {event_name} has been cancelled ({invoice_id})'),
         'template': 'email/ticket_cancelled.html',
     },
     MailType.EVENT_EXPORTED: {
         'recipient': 'User',
-        'subject': lazy_gettext('Event {event_name} has been exported'),
+        'subject': _('Event {event_name} has been exported'),
         'template': 'email/event_exported.html',
     },
     MailType.EVENT_EXPORT_FAIL: {
         'recipient': 'User',
-        'subject': lazy_gettext('Export of event {event_name} failed'),
+        'subject': _('Export of event {event_name} failed'),
         'template': 'email/event_export_fail.html',
     },
     MailType.MONTHLY_PAYMENT: {
         'recipient': 'Owner',
-        'subject': lazy_gettext('Your invoice for {event_name} for {date} is available on {app_name}'),
+        'subject': _(
+            'Your invoice for {event_name} for {date} is available on {app_name}'
+        ),
         'sent_at': '1st day of the month',
         'template': 'email/monthly_payment_email.html',
     },
     MailType.MONTHLY_PAYMENT_FOLLOWUP: {
         'recipient': 'Owner',
-        'subject': lazy_gettext('Reminder: Your invoice for {event_name} for {date} is available on {app_name}'),
+        'subject': _(
+            'Reminder: Your invoice for {event_name} for {date} is available on {app_name}'
+        ),
         'sent_at': '15th day of the month',
         'template': 'email/monthly_payment_followup_email.html',
     },
     MailType.MONTHLY_PAYMENT_PRE_DUE: {
         'recipient': 'Owner',
-        'subject': lazy_gettext('Reminder: Your invoice for {event_name} for {date} is available on {app_name}'),
+        'subject': _(
+            'Reminder: Your invoice for {event_name} for {date} is available on {app_name}'
+        ),
         'sent_at': '27th day of the month',
         'template': 'email/monthly_payment_pre_due_email.html',
     },
     MailType.MONTHLY_PAYMENT_POST_DUE: {
         'recipient': 'Owner',
-        'subject': lazy_gettext('Please pay your overdue invoice for {event_name} for {date} on {app_name}'),
+        'subject': _(
+            'Please pay your overdue invoice for {event_name} for {date} on {app_name}'
+        ),
         'sent_at': '30th day of the month',
         'template': 'email/monthly_payment_post_due_email.html',
     },
     MailType.EVENT_IMPORTED: {
         'recipient': 'User',
-        'subject': lazy_gettext('Event {event_name} has been imported'),
+        'subject': _('Event {event_name} has been imported'),
         'template': 'email/event_imported.html',
     },
     MailType.EVENT_IMPORT_FAIL: {
         'recipient': 'User',
-        'subject': lazy_gettext('Import of event failed'),
+        'subject': _('Import of event failed'),
         'template': 'email/event_import_fail.html',
     },
     MailType.CONTACT_ORGANIZERS: {
@@ -265,27 +300,27 @@ def entries():
     },
     MailType.TEST_MAIL: {
         'recipient': 'User',
-        'subject': lazy_gettext('Test Mail Subject'),
+        'subject': _('Test Mail Subject'),
         'message': ("This is a  <strong> Test </strong> E-mail."),
     },
     MailType.VIDEO_MODERATOR_INVITE: {
         'recipient': 'User',
-        'subject': lazy_gettext('Video Moderator of video {video_name} at event {event_name}'),
+        'subject': _('Video Moderator of video {video_name} at event {event_name}'),
         'template': 'email/video_stream_moderator.html',
     },
     MailType.ANNOUNCE_EVENT: {
         'recipient': 'User',
-        'subject': lazy_gettext('Join {event_name} from {group_name} on {event_date}'),
+        'subject': _('Join {event_name} from {group_name} on {event_date}'),
         'template': 'email/announce_event.html',
     },
     MailType.AFTER_EVENT: {
         'recipient': 'Owner, Organizer, Coorganizer',
-        'subject': lazy_gettext('{event_name} is over. Thank you for using {app_name}!'),
+        'subject': _('{event_name} is over. Thank you for using {app_name}!'),
         'template': 'email/after_event.html',
     },
     MailType.AFTER_EVENT_SPEAKER: {
         'recipient': 'User',
-        'subject': lazy_gettext('{event_name} is over. Thank you for participating!'),
+        'subject': _('{event_name} is over. Thank you for participating!'),
         'template': 'email/after_event_speaker.html',
     },
 }


Test patch: