Skip to content

Commit

Permalink
fix: translatability of work anniversary reminders (frappe#2092)
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra authored Aug 27, 2024
1 parent 67ce4df commit 4c2c964
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions hrms/controllers/employee_reminders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 4c2c964

Please sign in to comment.