diff --git a/ihatemoney/babel.cfg b/ihatemoney/babel.cfg index f0234b326..874f5a100 100644 --- a/ihatemoney/babel.cfg +++ b/ihatemoney/babel.cfg @@ -1,3 +1,2 @@ [python: **.py] -[jinja2: **/templates/**.html] -extensions=jinja2.ext.autoescape,jinja2.ext.with_ +[jinja2: **/templates/**] diff --git a/ihatemoney/emails.py b/ihatemoney/emails.py index 46d996dce..a4ba8c8e3 100644 --- a/ihatemoney/emails.py +++ b/ihatemoney/emails.py @@ -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): @@ -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) diff --git a/ihatemoney/templates/invitation_mail.en.j2 b/ihatemoney/templates/invitation_mail.en.j2 deleted file mode 100644 index bb38b9aa0..000000000 --- a/ihatemoney/templates/invitation_mail.en.j2 +++ /dev/null @@ -1,13 +0,0 @@ -Hi, - -Someone using the email address {{ g.project.contact_email }} invited you to share your expenses for "{{ g.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: {{ url_for(".join_project", _external=True, project_id=g.project.id, token=g.project.generate_token()) }}. - -Once logged-in, you can use the following link which is easier to remember: {{ url_for(".list_bills", _external=True) }} -If your cookie gets deleted or if you log out, you will need to log back in using the first link. - -Enjoy, -See you :-) diff --git a/ihatemoney/templates/invitation_mail.fr.j2 b/ihatemoney/templates/invitation_mail.fr.j2 deleted file mode 100644 index 0cf02f439..000000000 --- a/ihatemoney/templates/invitation_mail.fr.j2 +++ /dev/null @@ -1,12 +0,0 @@ -Salut, - -Quelqu'un dont l'adresse email est {{ g.project.contact_email }} vous a invité à partager vos dépenses pour « {{ g.project.name }} ». - -Il suffit de renseigner qui a payé pour quoi, pour qui, combien ça a coûté, et on s’occupe du reste. - -Vous pouvez vous connecter grâce à ce lien : {{ url_for(".join_project", _external=True, project_id=g.project.id, token=g.project.generate_token()) }}. - -Une fois connecté, vous pourrez utiliser le lien suivant qui est plus facile à mémoriser : {{ url_for(".list_bills", _external=True) }} -Si vous êtes déconnecté volontairement ou non, vous devrez utiliser à nouveau le premier lien. - -Have fun ! diff --git a/ihatemoney/templates/invitation_mail.j2 b/ihatemoney/templates/invitation_mail.j2 new file mode 100644 index 000000000..ae3faf2cd --- /dev/null +++ b/ihatemoney/templates/invitation_mail.j2 @@ -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 %} \ No newline at end of file diff --git a/ihatemoney/templates/password_reminder.en.j2 b/ihatemoney/templates/password_reminder.en.j2 deleted file mode 100644 index 845ff790c..000000000 --- a/ihatemoney/templates/password_reminder.en.j2 +++ /dev/null @@ -1,8 +0,0 @@ -Hi, - -You requested to reset the password of the following project: "{{ project.name }}". -You can reset it here: {{ url_for(".reset_password", _external=True, token=project.generate_token(token_type="reset")) }}. -This link is only valid for one hour. - -Hope this helps, -Some weird guys (with beards) diff --git a/ihatemoney/templates/password_reminder.fr.j2 b/ihatemoney/templates/password_reminder.fr.j2 deleted file mode 100644 index 4603a9630..000000000 --- a/ihatemoney/templates/password_reminder.fr.j2 +++ /dev/null @@ -1,7 +0,0 @@ -Salut, - -Vous avez demandé à réinitialiser le mot de passe du projet suivant : "{{ project.name }}". -Vous pouvez le réinitialiser ici : {{ url_for(".reset_password", _external=True, token=project.generate_token(token_type="reset")) }}. -Ce lien est seulement valide pendant 1 heure. - -Faites-en bon usage ! diff --git a/ihatemoney/templates/password_reminder.j2 b/ihatemoney/templates/password_reminder.j2 new file mode 100644 index 000000000..adcb901d7 --- /dev/null +++ b/ihatemoney/templates/password_reminder.j2 @@ -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 %} \ No newline at end of file diff --git a/ihatemoney/templates/reminder_mail.en.j2 b/ihatemoney/templates/reminder_mail.en.j2 deleted file mode 100644 index 7ab071a91..000000000 --- a/ihatemoney/templates/reminder_mail.en.j2 +++ /dev/null @@ -1,9 +0,0 @@ -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: {{ url_for("main.list_bills", _external=True) }} (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: -{{ url_for("main.invite", _external=True) }} - -Enjoy, diff --git a/ihatemoney/templates/reminder_mail.fr.j2 b/ihatemoney/templates/reminder_mail.fr.j2 deleted file mode 100644 index 11e0e1496..000000000 --- a/ihatemoney/templates/reminder_mail.fr.j2 +++ /dev/null @@ -1,9 +0,0 @@ -Salut, - -Vous venez de créer le projet "{{ project.name }}" pour partager vos dépenses. - -Vous pouvez y accéder ici : {{ url_for("main.list_bills", _external=True) }} (l'identifiant est {{ project.id }}). -Si vous voulez partager ce projet avec vos amis, vous pouvez soit leur transmettre l'identifiant et le code d'accès, soit leur envoyer une invitation personnelle grâce au lien suivant : -{{ url_for("main.invite", _external=True) }} - -Faites-en bon usage ! diff --git a/ihatemoney/templates/reminder_mail.j2 b/ihatemoney/templates/reminder_mail.j2 new file mode 100644 index 000000000..7041737bd --- /dev/null +++ b/ihatemoney/templates/reminder_mail.j2 @@ -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 %} \ No newline at end of file diff --git a/ihatemoney/utils.py b/ihatemoney/utils.py index 491eaf077..1e155e63d 100644 --- a/ihatemoney/utils.py +++ b/ihatemoney/utils.py @@ -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, ) @@ -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. diff --git a/ihatemoney/web.py b/ihatemoney/web.py index b94a66d77..97ccf86e1 100644 --- a/ihatemoney/web.py +++ b/ihatemoney/web.py @@ -64,7 +64,6 @@ limiter, list_of_dicts2csv, list_of_dicts2json, - render_localized_template, send_email, ) @@ -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) @@ -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, @@ -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"))