From b33da8485c1de74ee6a19eae8da3fefc84868c26 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Tue, 16 Jan 2024 16:22:04 +0000 Subject: [PATCH] Include local names on holiday list Closes: #106 --- agenda/holidays.py | 13 +++++++++++-- agenda/types.py | 10 ++++++++++ templates/holiday_list.html | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/agenda/holidays.py b/agenda/holidays.py index 08782b0..08b1a13 100644 --- a/agenda/holidays.py +++ b/agenda/holidays.py @@ -60,15 +60,24 @@ def get_nyse_holidays( def get_holidays(country: str, start_date: date, end_date: date) -> list[Holiday]: """Get holidays.""" found: list[Holiday] = [] + uc_country = country.upper() + + holiday_country = getattr(holidays, uc_country) + default_language = holiday_country.default_language + for year in range(start_date.year, end_date.year + 1): - hols = holidays.country_holidays(country.upper(), years=year, language="en_US") + en_hols = holidays.country_holidays(uc_country, years=year, language="en_US") + local_lang = holidays.country_holidays( + uc_country, years=year, language=default_language + ) found += [ Holiday( date=hol_date, name=title, + local_name=local_lang[hol_date], country=country.lower(), ) - for hol_date, title in hols.items() + for hol_date, title in en_hols.items() if start_date < hol_date < end_date ] diff --git a/agenda/types.py b/agenda/types.py index 578c145..4bcfa5b 100644 --- a/agenda/types.py +++ b/agenda/types.py @@ -91,6 +91,16 @@ class Holiday: name: str country: str date: datetime.date + local_name: str | None = None + + @property + def display_name(self) -> str: + """Format name for display.""" + return ( + f"{self.name} ({self.local_name})" + if self.local_name and self.local_name != self.name + else self.name + ) emojis = { diff --git a/templates/holiday_list.html b/templates/holiday_list.html index 9968e9f..a8d3e73 100644 --- a/templates/holiday_list.html +++ b/templates/holiday_list.html @@ -14,7 +14,7 @@ {% endif %} {{ country.flag }} {{ country.name }} - {{ item.name }} + {{ item.display_name }} {% endfor %}