From 9aa8e5e309675a77079116149a2e52edfb628ba1 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 28 Aug 2024 10:52:17 +0530 Subject: [PATCH] fix: translatability of work anniversary reminders (backport #2092) (#2124) (cherry picked from commit 4c2c964382fa6b0e7f6836a4a708ca063a288863) Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com> --- hrms/controllers/employee_reminders.py | 37 +++++++++++--------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/hrms/controllers/employee_reminders.py b/hrms/controllers/employee_reminders.py index 38fa5488dc..7b6995c4ba 100644 --- a/hrms/controllers/employee_reminders.py +++ b/hrms/controllers/employee_reminders.py @@ -237,33 +237,26 @@ def send_work_anniversary_reminders(): def get_work_anniversary_reminder_text(anniversary_persons: list) -> str: if len(anniversary_persons) == 1: anniversary_person = anniversary_persons[0]["name"] - # Number of years completed at the company completed_years = getdate().year - anniversary_persons[0]["date_of_joining"].year - anniversary_person += f" completed {get_pluralized_years(completed_years)}" - else: - person_names_with_years = [] - names_grouped_by_years = {} - - for person in anniversary_persons: - # Number of years completed at the company - completed_years = getdate().year - person["date_of_joining"].year - names_grouped_by_years.setdefault(completed_years, []).append(person["name"]) - - for key, value in names_grouped_by_years.items(): - person_names = comma_sep(value, frappe._("{0} & {1}"), False) - person_names_with_years.append(f"{person_names} completed {get_pluralized_years(key)}") + return _("Today {0} completed {1} year(s) at our Company! 🎉").format( + _(anniversary_person), completed_years + ) - # converts ["Jim", "Rim", "Dim"] to Jim, Rim & Dim - anniversary_person = comma_sep(person_names_with_years, frappe._("{0} & {1}"), False) - reminder_text = _("Today {0} at our Company! 🎉").format(_(anniversary_person)) + names_grouped_by_years = {} - return reminder_text + for person in anniversary_persons: + # Number of years completed at the company + completed_years = getdate().year - person["date_of_joining"].year + names_grouped_by_years.setdefault(completed_years, []).append(person["name"]) + person_names_with_years = [ + _("{0} completed {1} year(s)").format(comma_sep(person_names, _("{0} & {1}"), False), years) + for years, person_names in names_grouped_by_years.items() + ] -def get_pluralized_years(years): - if years == 1: - return "1 year" - return f"{years} years" + # converts ["Jim", "Rim", "Dim"] to Jim, Rim & Dim + anniversary_person = comma_sep(person_names_with_years, _("{0} & {1}"), False) + return _("Today {0} at our Company! 🎉").format(_(anniversary_person)) def send_work_anniversary_reminder(