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: translatability of work anniversary reminders (backport #2092) #2124

Merged
Merged
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
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
Loading