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

Fix translation emails #1101

Closed
wants to merge 1 commit 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ihatemoney/babel.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
[python: **.py]
[jinja2: **/templates/**.html]
extensions=jinja2.ext.autoescape,jinja2.ext.with_
[jinja2: **/templates/**]
6 changes: 3 additions & 3 deletions ihatemoney/emails.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from flask import g
from flask import g, render_template
from flask_babel import gettext as _
from flask_mail import Message

from ihatemoney.utils import render_localized_template, send_email
from ihatemoney.utils import send_email


def send_creation_email(project):
Expand All @@ -12,7 +12,7 @@ def send_creation_email(project):
project=project.name,
)

message_body = render_localized_template("reminder_mail", project=project)
message_body = render_template("reminder_mail.j2", project=project)

msg = Message(message_title, body=message_body, recipients=[project.contact_email])
return send_email(msg)
13 changes: 0 additions & 13 deletions ihatemoney/templates/invitation_mail.en.j2

This file was deleted.

12 changes: 0 additions & 12 deletions ihatemoney/templates/invitation_mail.fr.j2

This file was deleted.

19 changes: 19 additions & 0 deletions ihatemoney/templates/invitation_mail.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% trans
contact_email=g.project.contact_email,
project_name=g.project_name,
join_link=url_for(".join_project", _external=True, project_id=g.project.id, token=g.project.generate_token()),
short_link=url_for(".list_bills", _external=True)
%}Hi,

Someone using the email address {{ contact_email }} invited you to share your expenses for "{{ project_name }}".

It's as simple as saying what did you pay for, for whom, and how much did it cost you, we are caring about the rest.

You can log in using this link: {{ join_link }}.

Once logged-in, you can use the following link which is easier to remember: {{ short_link }}
If your cookie gets deleted or if you log out, you will need to log back in using the first link.

Enjoy,
See you :-)
{% endtrans %}
8 changes: 0 additions & 8 deletions ihatemoney/templates/password_reminder.en.j2

This file was deleted.

7 changes: 0 additions & 7 deletions ihatemoney/templates/password_reminder.fr.j2

This file was deleted.

9 changes: 9 additions & 0 deletions ihatemoney/templates/password_reminder.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% trans
project_name=project.name,
reset_link=url_for(".reset_password", _external=True, token=project.generate_token(token_type="reset"))
%}Hi,

You requested to reset the password of the following project: "{{ project_name }}".
You can reset it here: {{ reset_link }}.
This link is only valid for one hour.
{% endtrans %}
9 changes: 0 additions & 9 deletions ihatemoney/templates/reminder_mail.en.j2

This file was deleted.

9 changes: 0 additions & 9 deletions ihatemoney/templates/reminder_mail.fr.j2

This file was deleted.

16 changes: 16 additions & 0 deletions ihatemoney/templates/reminder_mail.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% trans
project_id=g.project.id,
project_name=g.project_name,
project_link=url_for("main.list_bills", _external=True),
invite_link=url_for("main.invite", _external=True)
%}
Hi,

You have just (or someone else using your email address) created the project "{{ project_name }}" to share your expenses.

You can access it here: {{ project_link }} (the identifier is {{ project_id }}).
If you want to share this project with your friends, you can share the identifier and the shared password with them or send them invitations with the following link:
{{ invite_link }}

Enjoy,
{% endtrans %}
19 changes: 3 additions & 16 deletions ihatemoney/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ def flash_email_error(error_message, category="danger"):
error_extension = f" or contact the administrator at {admin_email}."

flash(
# .format needed for pybabel https://github.com/python-babel/babel/issues/715
_(
f"{error_message} Please check the email configuration of the server{error_extension}"
),
"{error_message} Please check the email configuration of the server{error_extension}"
).format(error_message=error_message, error_extension=error_extension),
category=category,
)

Expand Down Expand Up @@ -412,20 +413,6 @@ def render_localized_currency(code, detailed=True):
return f"{code} − {symbol}{details}"


def render_localized_template(template_name_prefix, **context):
"""Like render_template(), but selects the right template according to the
current user language. Fallback to English if a template for the
current language does not exist.
"""
fallback = "en"
templates = [
f"{template_name_prefix}.{lang}.j2"
for lang in (get_locale().language, fallback)
]
# render_template() supports a list of templates to try in order
return render_template(templates, **context)


def format_form_errors(form, prefix):
"""Format all form errors into a single string, with a string prefix in
front. Useful for flashing the result.
Expand Down
11 changes: 7 additions & 4 deletions ihatemoney/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
limiter,
list_of_dicts2csv,
list_of_dicts2json,
render_localized_template,
send_email,
)

Expand Down Expand Up @@ -355,7 +354,7 @@ def remind_password():
# send a link to reset the password
remind_message = Message(
"password recovery",
body=render_localized_template("password_reminder", project=project),
body=render_template("password_reminder.j2", project=project),
recipients=[project.contact_email],
)
success = send_email(remind_message)
Expand Down Expand Up @@ -584,7 +583,7 @@ def invite():
if request.method == "POST":
if form.validate():
# send the email
message_body = render_localized_template("invitation_mail")
message_body = render_template("invitation_mail.j2")
message_title = _(
"You have been invited to share your " "expenses for %(project)s",
project=g.project.name,
Expand Down Expand Up @@ -797,7 +796,11 @@ def change_lang(lang):
session["lang"] = lang
session.update()
else:
flash(_(f"{lang} is not a supported language"), category="warning")
flash(
# .format needed for pybabel https://github.com/python-babel/babel/issues/715
_("{lang} is not a supported language").format(lang=lang),
category="warning",
)

return redirect(request.headers.get("Referer") or url_for(".home"))

Expand Down