Skip to content
Snippets Groups Projects
Commit 8ab34d88 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Normalise locales

parent 8ff5623c
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
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
[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"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment