Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invite email translation now happens on the fly #1250

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ ihatemoney/budget.db
.idea
.python-version
.coverage*
prof
prof
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, do not remove the newline at the end of files :-)

3 changes: 3 additions & 0 deletions ihatemoney/templates/translation_template.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% trans %}
{{ untranslated_text }}
{% endtrans %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

4 changes: 4 additions & 0 deletions ihatemoney/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ def render_localized_template(template_name_prefix, **context):
# render_template() supports a list of templates to try in order
return render_template(templates, **context)

def translate_template_text(text, **context):
"""Passes `text` to a basic Jinja translation template. A generalizable solution for translating outgoing emails."""

return render_template("translation_template.j2", untranslated_text=text, **context)

def format_form_errors(form, prefix):
"""Format all form errors into a single string, with a string prefix in
Expand Down
4 changes: 3 additions & 1 deletion ihatemoney/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
list_of_dicts2csv,
list_of_dicts2json,
render_localized_template,
translate_template_text,
send_email,
)

Expand Down Expand Up @@ -601,7 +602,8 @@ def invite():
if request.method == "POST":
if form.validate():
# send the email
message_body = render_localized_template("invitation_mail")
untranslated_body = render_template("invitation_mail.j2")
message_body = translate_template_text(untranslated_body)
message_title = _(
"You have been invited to share your expenses for %(project)s",
project=g.project.name,
Expand Down