Use a per language dict for emails i18n
This commit is contained in:
parent
e4aef0bfaf
commit
bd07988549
@ -62,28 +62,32 @@ def send_notification(config, flats):
|
|||||||
return
|
return
|
||||||
|
|
||||||
i18n = {
|
i18n = {
|
||||||
"subject": [
|
"en": {
|
||||||
f"{len(flats)} new flats found!",
|
"subject": f"{len(flats)} new flats found!",
|
||||||
f"{len(flats)} nouvelles annonces disponibles !",
|
"hello": "Hello dear user",
|
||||||
],
|
"following_new_flats": "The following new flats have been found:",
|
||||||
"hello": ["Hello dear user", "Bonjour cher utilisateur"],
|
"area": "area",
|
||||||
"following_new_flats": [
|
"cost": "cost",
|
||||||
"The following new flats have been found:",
|
"signature": "Hope you'll find what you were looking for.",
|
||||||
"Voici les nouvelles annonces :",
|
},
|
||||||
],
|
"fr": {
|
||||||
"area": ["area", "surface"],
|
"subject": f"{len(flats)} nouvelles annonces disponibles !",
|
||||||
"cost": ["cost", "coût"],
|
"hello": "Bonjour cher utilisateur",
|
||||||
"signature": ["Hope you'll find what you were looking for.", "Bonne recherche"],
|
"following_new_flats": "Voici les nouvelles annonces :",
|
||||||
|
"area": "surface",
|
||||||
|
"cost": "coût",
|
||||||
|
"signature": "Bonne recherche",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
l = 1 if config["notification_lang"] == "fr" else 0
|
trs = i18n.get(config["notification_lang"], "en")
|
||||||
|
|
||||||
txt = i18n["hello"][l] + ",\n\n\n\n"
|
txt = trs["hello"] + ",\n\n\n\n"
|
||||||
html = f"""
|
html = f"""
|
||||||
<html>
|
<html>
|
||||||
<head></head>
|
<head></head>
|
||||||
<body>
|
<body>
|
||||||
<p>{i18n["hello"][l]}!</p>
|
<p>{trs["hello"]}!</p>
|
||||||
<p>{i18n["following_new_flats"][l]}
|
<p>{trs["following_new_flats"]}
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
"""
|
"""
|
||||||
@ -101,9 +105,9 @@ def send_notification(config, flats):
|
|||||||
title,
|
title,
|
||||||
website_url,
|
website_url,
|
||||||
flat_id,
|
flat_id,
|
||||||
i18n["area"][l],
|
trs["area"],
|
||||||
area,
|
area,
|
||||||
i18n["cost"][l],
|
trs["cost"],
|
||||||
cost,
|
cost,
|
||||||
currency,
|
currency,
|
||||||
)
|
)
|
||||||
@ -117,16 +121,16 @@ def send_notification(config, flats):
|
|||||||
website_url,
|
website_url,
|
||||||
flat_id,
|
flat_id,
|
||||||
title,
|
title,
|
||||||
i18n["area"][l],
|
trs["area"],
|
||||||
area,
|
area,
|
||||||
i18n["cost"][l],
|
trs["cost"],
|
||||||
cost,
|
cost,
|
||||||
currency,
|
currency,
|
||||||
)
|
)
|
||||||
|
|
||||||
html += "</ul>"
|
html += "</ul>"
|
||||||
|
|
||||||
signature = f"\n{i18n['signature'][l]}\n\nBye!\nFlatisfy"
|
signature = f"\n{trs['signature']}\n\nBye!\nFlatisfy"
|
||||||
txt += signature
|
txt += signature
|
||||||
html += signature.replace("\n", "<br>")
|
html += signature.replace("\n", "<br>")
|
||||||
|
|
||||||
@ -137,7 +141,7 @@ def send_notification(config, flats):
|
|||||||
send_email(
|
send_email(
|
||||||
config["smtp_server"],
|
config["smtp_server"],
|
||||||
config["smtp_port"],
|
config["smtp_port"],
|
||||||
i18n["subject"][l],
|
trs["subject"],
|
||||||
config["smtp_from"],
|
config["smtp_from"],
|
||||||
config["smtp_to"],
|
config["smtp_to"],
|
||||||
txt,
|
txt,
|
||||||
|
Loading…
Reference in New Issue
Block a user