diff --git a/calendarweek/calendarweek.py b/calendarweek/calendarweek.py index 319d2f9914161ad56c8b9da05f2aa2c980cade14..538e249fa93228d4c623589f577853efb23d57af 100644 --- a/calendarweek/calendarweek.py +++ b/calendarweek/calendarweek.py @@ -6,6 +6,8 @@ from datetime import date, datetime, timedelta import locale from typing import Optional, Sequence, Tuple, Union +from .util import normalise_locale + @dataclass class CalendarWeek: @@ -18,28 +20,28 @@ class CalendarWeek: def day_names(cls, loc: Optional[str] = None) -> Tuple[str]: """ Return a tuple of day names for the selected locale. """ - with calendar.different_locale(loc): + with calendar.different_localenormalise_locale(loc): return tuple(calendar.day_name) @classmethod def day_abbrs(cls, loc: Optional[str] = None) -> Tuple[str]: """ Return a tuple of day name abbreviations for the selected locale. """ - with calendar.different_locale(loc): + with calendar.different_localenormalise_locale(loc): return tuple(calendar.day_abbr) @classmethod def month_names(cls, loc: Optional[str] = None) -> Tuple[str]: """ Return a tuple of month names for the selected locale. """ - with calendar.different_locale(loc): + with calendar.different_localenormalise_locale(loc): return tuple(calendar.month_name[1:]) @classmethod def month_abbrs(cls, loc: Optional[str] = None) -> Tuple[str]: """ Return a tuple of month name abbreviations for the selected locale. """ - with calendar.different_locale(loc): + with calendar.different_localenormalise_locale(loc): return tuple(calendar.month_abbr[1:]) @classmethod diff --git a/calendarweek/util.py b/calendarweek/util.py new file mode 100644 index 0000000000000000000000000000000000000000..3d8c10eae8d052157027cd6d65eee227363033d0 --- /dev/null +++ b/calendarweek/util.py @@ -0,0 +1,10 @@ +from locale import locale_alias, locale_encoding_alias +from typing import Optional + + +def normalise_locale(loc: str, enc: Optional[str] = None) -> str: + loc = locale_alias.get(loc, loc) + if enc: + enc = locale_encoding_alias.get(enc.replace("-", ""), enc) + loc = loc.split(".")[0] + "." + enc + return loc diff --git a/pyproject.toml b/pyproject.toml index 55f4cd0da4c69639ef7ac9ead86eff1853e7fb1b..f43ff2769f7fa4c086860ad4f5ccbb2054a312e3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "calendarweek" -version = "0.3.1" +version = "0.4.0" description = "Utilities for working with calendar weeks in Python and Django" authors = ["Dominik George <nik@naturalnet.de>", "Jonathan Weth <git@jonathanweth.de>"] license = "MIT"