Skip to content

Commit

Permalink
Make email templates translatable
Browse files Browse the repository at this point in the history
  • Loading branch information
Leats committed Sep 19, 2022
1 parent 1ac41d7 commit 46e8179
Show file tree
Hide file tree
Showing 179 changed files with 1,432 additions and 1,015 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Expand Up @@ -7,6 +7,11 @@ Version 3.2.1

*Unreleased*

Internationalization
^^^^^^^^^^^^^^^^^^^^

- Make email templates translatable (:issue:`5263`, :pr:`5488`, thanks :user:`Leats`)

Improvements
^^^^^^^^^^^^

Expand Down
7 changes: 4 additions & 3 deletions indico/modules/auth/controllers.py
Expand Up @@ -29,7 +29,7 @@
from indico.modules.users import User, user_management_settings
from indico.modules.users.controllers import RHUserBase
from indico.modules.users.models.affiliations import Affiliation
from indico.util.i18n import _
from indico.util.i18n import _, force_locale
from indico.util.marshmallow import LowercaseString, ModelField, not_empty
from indico.util.passwords import validate_secure_password
from indico.util.signing import secure_serializer
Expand Down Expand Up @@ -137,8 +137,9 @@ def _send_confirmation(email, salt, endpoint, template, template_args=None, url_
url_args = url_args or {}
token = secure_serializer.dumps(data or email, salt=salt)
url = url_for(endpoint, token=token, _external=True, **url_args)
template_module = get_template_module(template, email=email, url=url, **template_args)
send_email(make_email(email, template=template_module))
with force_locale(None) if 'user' not in template_args else template_args['user'].force_user_locale():
template_module = get_template_module(template, email=email, url=url, **template_args)
send_email(make_email(email, template=template_module))
flash(_('We have sent you a verification email. Please check your mailbox within the next hour and open '
'the link in that email.'))
return redirect(url_for(endpoint, **url_args))
Expand Down
Expand Up @@ -5,7 +5,7 @@
{%- endblock %}

{% block header_recipient -%}
{{ user.first_name }}
{% trans name=user.first_name %}Dear {{ name }},{% endtrans %}
{%- endblock %}

{% block body -%}
Expand Down
Expand Up @@ -5,12 +5,12 @@
{%- endblock %}

{% block header_recipient -%}
{% trans %}user{% endtrans %}
{% trans %}Dear user,{% endtrans %}
{%- endblock %}

{% block body -%}
{%- trans notrimmed -%}
You started the Indico profile creation process. To continue, you need to verify
You started the Indico profile creation process. To continue, you need to verify
that {{ email }} is indeed your email address.

Please click the following link to continue the registration process:
Expand Down
Expand Up @@ -104,7 +104,7 @@ <h4 class="{% if month.is_current %}current-month{% endif %}">
<a class="icon-calendar" href="{{ url_for('events.export_event_ical', event) }}" title="{% trans %}Export{% endtrans %}"></a>
{% if session.user and event in session.user.favorite_events %}
<i class="icon-star" title="{% trans %}You have favorited this event.{% endtrans %}"></i>
{% endif%}
{% endif %}
</span>
<span class="list-name">
<span class="date {% if happening_now(event) %}today{% endif %}">
Expand Down
2 changes: 1 addition & 1 deletion indico/modules/designer/templates/_list.html
Expand Up @@ -85,7 +85,7 @@
{% endif %}
{% if not event and tpl.type.name == 'badge' and not tpl.is_ticket %}
{% set inherited_default = default_badge == tpl and tpl.category != target and
not target.default_badge_template%}
not target.default_badge_template %}
{% set global_default = default_badge == tpl and target.is_root %}
<a class="i-button icon-tag icon-only borderless hide-if-locked toggle-default
{{ 'default-on-category' if default_badge == tpl }}
Expand Down
8 changes: 5 additions & 3 deletions indico/modules/events/abstracts/controllers/reviewing.py
Expand Up @@ -204,9 +204,11 @@ def _get_recipients(self, visibility):

def _send_notification(self, recipients, comment):
for recipient in recipients:
tpl = get_template_module('events/abstracts/emails/comment.html', event=self.event, abstract=self.abstract,
submitter=session.user, comment=comment, recipient=recipient)
email = make_email(to_list=recipient.email, template=tpl, html=True)
with recipient.force_user_locale():
tpl = get_template_module('events/abstracts/emails/comment.html', event=self.event,
abstract=self.abstract, submitter=session.user, comment=comment,
recipient=recipient)
email = make_email(to_list=recipient.email, template=tpl, html=True)
send_email(email, self.event, 'Abstracts', session.user)

def _process(self):
Expand Down
@@ -1,4 +1,4 @@
{% extends 'emails/base.txt' %}
{% extends 'emails/base_i18n.txt' %}

{% block subject -%}
{{ subject }}
Expand All @@ -11,10 +11,9 @@
{%- endblock %}

{% block footer_title -%}
Call for Abstracts
{% trans %}Call for Abstracts{% endtrans %}
{%- endblock %}

{% block footer_url -%}
{{ event.external_url }}
{%- endblock %}

6 changes: 3 additions & 3 deletions indico/modules/events/abstracts/templates/emails/base.html
@@ -1,11 +1,11 @@
{% extends 'emails/base.html' %}
{% extends 'emails/base_i18n.html' %}

{% block header %}{% endblock %}

{% block footer %}{% endblock %}

{% block subject -%}
{% block subject_message %}Call for Abstracts{% endblock %}
{% block subject_message %}{% trans %}Call for Abstracts{% endtrans %}{% endblock %}
{%- block subject_name %}{% endblock %}
{%- endblock %}

Expand Down Expand Up @@ -34,7 +34,7 @@ <h3 style="margin: 0; margin-top: 10px; padding-top: 10px; border-top: 1px solid
{% endblock %}
</div>
<div style="text-align: center; padding: 10px; background: #ebebeb; font-size: small; color: #999;">
Indico :: Call for Abstracts
Indico :: {% trans %}Call for Abstracts{% endtrans %}
</div>
</div>
{% endblock %}
16 changes: 10 additions & 6 deletions indico/modules/events/abstracts/templates/emails/comment.html
@@ -1,21 +1,25 @@
{% extends 'events/abstracts/emails/base.html' %}

{% block subject_message %}New abstract comment{% endblock %}
{% block subject_message %}{% trans %}New abstract comment{% endtrans %}{% endblock %}

{% block header_subtitle %}New abstract comment{% endblock %}
{% block header_subtitle %}{% trans %}New abstract comment{% endtrans %}{% endblock %}

{% block header_subtitle_ref %}ref #{{ abstract.friendly_id }}{% endblock %}
{% block header_subtitle_ref %}{% trans id=abstract.friendly_id %}ref #{{ id }}{% endtrans %}{% endblock %}

{% block content_header %}
<p>Dear {{ recipient.first_name }},</p>
<p>{{ submitter.full_name }} commented on the abstract <strong>{{ abstract.title }}</strong>:</p>
<p>{% trans name=recipient.first_name %}Dear {{ name }},{% endtrans %}</p>
<p>
{%- trans name=submitter.full_name, title=abstract.title, strong='<strong>'|safe, endstrong='</strong>'|safe -%}
{{ name }} commented on the abstract {{ strong }}{{ title }}{{ endstrong }}:
{%- endtrans -%}
</p>
<blockquote style="border-left: 5px solid #dfdfdf; padding-left: 10px; font-style: italic; color: #999;">
{{ comment }}
</blockquote>
{% endblock %}

{% block content_body %}
<p>You can view this comment on the abstract page:</p>
<p>{% trans %}You can view this comment on the abstract page:{% endtrans %}</p>
<p>
<a href="{{ url_for('abstracts.display_abstract', abstract, management=false, _external=true) }}">
{{- url_for('abstracts.display_abstract', abstract, management=false, _external=true) -}}
Expand Down
@@ -1,24 +1,27 @@
{% extends 'events/abstracts/emails/default_notification.txt' %}

{% block subject -%}
Abstract Acceptance notification (#{abstract_id})
{% trans %}Abstract Acceptance notification (#{abstract_id}){% endtrans %}
{%- endblock %}

{% block body -%}
We're pleased to announce that your abstract "{abstract_title}" with ID #{abstract_id} has been accepted in track "{abstract_track}" ({contribution_type}).
{# TODO: How to handle the placeholders with the translation? #}
{% trans notrimmed -%}
We're pleased to announce that your abstract "{abstract_title}" with ID #{abstract_id} has been accepted in track "{abstract_track}" ({contribution_type}).

See below a summary of your submitted abstract:
Conference: {event_title}
Submitted by: {submitter_name}
Title: {abstract_title}
Primary Authors: {primary_authors}
Co-authors: {co_authors}
Track classification: {abstract_track}
Presentation type: {contribution_type}
See below a summary of your submitted abstract:
Conference: {event_title}
Submitted by: {submitter_name}
Title: {abstract_title}
Primary Authors: {primary_authors}
Co-authors: {co_authors}
Track classification: {abstract_track}
Presentation type: {contribution_type}

For a more detailed summary please visit the page of your abstract:
{abstract_url}
For a more detailed summary please visit the page of your abstract:
{abstract_url}

Kind regards,
The organizers of {event_title}
Kind regards,
The organizers of {event_title}
{%- endtrans %}
{%- endblock %}
@@ -1,15 +1,17 @@
{% extends 'events/abstracts/emails/default_notification.txt' %}

{% block subject -%}
Invitation to submit an abstract
{% trans %}Invitation to submit an abstract{% endtrans %}
{%- endblock %}

{% block body -%}
You have been invited to submit an abstract.
In order to submit your abstract please follow the link below:
{% trans notrimmed -%}
You have been invited to submit an abstract.
In order to submit your abstract please follow the link below:

{invitation_url}
{invitation_url}

Kind regards,
The organizers of {event_title}
Kind regards,
The organizers of {event_title}
{%- endtrans %}
{%- endblock %}
@@ -1,12 +1,14 @@
{% extends 'events/abstracts/emails/default_notification.txt' %}

{% block subject -%}
Abstract Merge notification (#{abstract_id})
{% trans %}Abstract Merge notification (#{abstract_id}){% endtrans %}
{%- endblock %}

{% block body -%}
Your abstract "{abstract_title}" with ID #{abstract_id} has been merged into "{target_abstract_title}".
{% trans notrimmed -%}
Your abstract "{abstract_title}" with ID #{abstract_id} has been merged into "{target_abstract_title}".

Kind regards,
The organizers of {event_title}
Kind regards,
The organizers of {event_title}
{%- endtrans %}
{%- endblock %}
Expand Up @@ -4,7 +4,7 @@

{% macro get_body() -%}
{%- filter dedent -%}
Dear {submitter_name},
{% trans %}Dear {submitter_name},{% endtrans %}

{% block body %}{% endblock %}
{%- endfilter -%}
Expand Down
@@ -1,12 +1,14 @@
{% extends 'events/abstracts/emails/default_notification.txt' %}

{% block subject -%}
Abstract Rejection notification (#{abstract_id})
{% trans %}Abstract Rejection notification (#{abstract_id}){% endtrans %}
{%- endblock %}

{% block body -%}
We're sorry to let you know that your abstract "{abstract_title}" with ID #{abstract_id} has been rejected.
{% trans notrimmed -%}
We're sorry to let you know that your abstract "{abstract_title}" with ID #{abstract_id} has been rejected.

Kind regards,
The organizers of {event_title}
Kind regards,
The organizers of {event_title}
{%- endtrans %}
{%- endblock %}
@@ -1,12 +1,14 @@
{% extends 'events/abstracts/emails/default_notification.txt' %}

{% block subject -%}
Abstract Submission confirmation (#{abstract_id})
{% trans %}Abstract Submission confirmation (#{abstract_id}){% endtrans %}
{%- endblock %}

{% block body -%}
We've received your abstract "{abstract_title}" to which we have assigned id #{abstract_id}.
{% trans notrimmed -%}
We've received your abstract "{abstract_title}" to which we have assigned id #{abstract_id}.

Kind regards,
The organizers of {event_title}
Kind regards,
The organizers of {event_title}
{%- endtrans %}
{%- endblock %}
Expand Up @@ -11,7 +11,7 @@
<div id="rule-widget-{{ field.id }}" class="js-rule-list-widget">
<ul class="rule-list flexcol"></ul>
{% call message_box('info', classes='no-rules-placeholder') %}
{% trans %}No rules have been added{% endtrans%}
{% trans %}No rules have been added{% endtrans %}
{% endcall %}
<div class="toolbar f-j-end">
<div class="group">
Expand Down
20 changes: 12 additions & 8 deletions indico/modules/events/agreements/notifications.py
Expand Up @@ -24,19 +24,23 @@ def make_email_template(template, agreement, email_body=None):

@email_sender
def notify_agreement_new(agreement, email_body=None, cc_addresses=None, from_address=None):
template = make_email_template('events/agreements/emails/agreement_new.html', agreement, email_body)
return make_email(agreement.person_email, cc_list=cc_addresses, from_address=from_address,
template=template, html=True)
with agreement.event.force_event_locale():
template = make_email_template('events/agreements/emails/agreement_new.html', agreement, email_body)
return make_email(agreement.person_email, cc_list=cc_addresses, from_address=from_address,
template=template, html=True)


@email_sender
def notify_agreement_reminder(agreement, email_body=None, cc_addresses=None, from_address=None):
template = make_email_template('events/agreements/emails/agreement_reminder.html', agreement, email_body)
return make_email(agreement.person_email, cc_list=cc_addresses, from_address=from_address,
template=template, html=True)
with agreement.event.force_event_locale():
template = make_email_template('events/agreements/emails/agreement_reminder.html', agreement, email_body)
return make_email(agreement.person_email, cc_list=cc_addresses, from_address=from_address,
template=template, html=True)


@email_sender
def notify_new_signature_to_manager(agreement):
template = get_template_module('events/agreements/emails/new_signature_email_to_manager.txt', agreement=agreement)
return make_email(agreement.event.all_manager_emails, template=template)
with agreement.event.force_event_locale():
template = get_template_module('events/agreements/emails/new_signature_email_to_manager.txt',
agreement=agreement)
return make_email(agreement.event.all_manager_emails, template=template)
@@ -1,28 +1,28 @@
{% extends 'emails/base.html' %}
{% extends 'emails/base_i18n.html' %}

{% block header_recipient -%}
{person_name}
{% trans %}Dear {person_name},{% endtrans %}
{%- endblock %}

{% block body %}
{% block body_text %}
There is an agreement you are requested to sign for the event:<br>
{% trans %}There is an agreement you are requested to sign for the event:{% endtrans %}<br>
<strong>{{ event.title }}</strong><br><br>

{% block body_agreement_request %}
You can sign it on the following page:
{% trans %}You can sign it on the following page:{% endtrans %}
{% endblock %}<br>
{agreement_link}
{% endblock %}

{% if session %}
<br><br>
Best regards<br>
{% trans %}Best regards{% endtrans %}<br>
{{ session.user.full_name }}
{% endif %}
{%- endblock %}

{% block footer_title %}Agreements{% endblock %}
{% block footer_title %}{% trans %}Agreements{% endtrans %}{% endblock %}
{% block footer %}
{# Show default footer if sent from command line #}
{% if not session.user %}
Expand Down
@@ -1,5 +1,5 @@
{% extends 'emails/base.html' %}
{% block subject %}Agreement signature required{% endblock %}
{% extends 'emails/base_i18n.html' %}
{% block subject %}{% trans %}Agreement signature required{% endtrans %}{% endblock %}
{% block header %}{% endblock %}
{% block footer %}{% endblock %}

Expand Down
@@ -1,2 +1,2 @@
{% extends 'events/agreements/emails/agreement_new.html' %}
{% block subject %}Agreement signature required - Reminder{% endblock %}
{% block subject %}{% trans %}Agreement signature required - Reminder{% endtrans %}{% endblock %}

0 comments on commit 46e8179

Please sign in to comment.