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 2 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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ ihatemoney/budget.db
.python-version
.coverage*
prof
*.ipynb
*/.ipynb_checkpoints/
Copy link
Member

Choose a reason for hiding this comment

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

I believe these should be better in your global ~/.gitignore file maybe?

Copy link
Author

Choose a reason for hiding this comment

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

didnt know that was possible! fixed

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

Copy link
Member

Choose a reason for hiding this comment

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

I don't believe we need the extra spaces here. Any reason you added them?

Copy link
Author

Choose a reason for hiding this comment

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

fixed


Hi,

Someone using the email address {{ g.project.contact_email }} invited you to share your expenses for "{{ g.project.name }}".
Expand Down
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