Skip to content

Commit

Permalink
Merge pull request arrow-py#947 from cyriaka90/Croatian
Browse files Browse the repository at this point in the history
Add Croatian locale
  • Loading branch information
krisfremen authored Apr 1, 2021
2 parents cf8a0cc + 45ad112 commit d515e74
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
94 changes: 94 additions & 0 deletions arrow/locales.py
Original file line number Diff line number Diff line change
Expand Up @@ -4390,4 +4390,98 @@ class SwahiliLocale(Locale):
]


class CroatianLocale(Locale):

names = ["hr", "hr-hr"]

past = "prije {0}"
future = "za {0}"
and_word = "i"

timeframes: ClassVar[Mapping[TimeFrameLiteral, Union[str, Mapping[str, str]]]] = {
"now": "upravo sad",
"second": "sekundu",
"seconds": {"double": "{0} sekunde", "higher": "{0} sekundi"},
"minute": "minutu",
"minutes": {"double": "{0} minute", "higher": "{0} minuta"},
"hour": "sat",
"hours": {"double": "{0} sata", "higher": "{0} sati"},
"day": "jedan dan",
"days": {"double": "{0} dana", "higher": "{0} dana"},
"week": "tjedan",
"weeks": {"double": "{0} tjedna", "higher": "{0} tjedana"},
"month": "mjesec",
"months": {"double": "{0} mjeseca", "higher": "{0} mjeseci"},
"year": "godinu",
"years": {"double": "{0} godine", "higher": "{0} godina"},
}

month_names = [
"",
"siječanj",
"veljača",
"ožujak",
"travanj",
"svibanj",
"lipanj",
"srpanj",
"kolovoz",
"rujan",
"listopad",
"studeni",
"prosinac",
]

month_abbreviations = [
"",
"siječ",
"velj",
"ožuj",
"trav",
"svib",
"lip",
"srp",
"kol",
"ruj",
"list",
"stud",
"pros",
]

day_names = [
"",
"ponedjeljak",
"utorak",
"srijeda",
"četvrtak",
"petak",
"subota",
"nedjelja",
]

day_abbreviations = [
"",
"po",
"ut",
"sr",
"če",
"pe",
"su",
"ne",
]

def _format_timeframe(
self, timeframe: TimeFrameLiteral, delta: Union[float, int]
) -> str:
form = self.timeframes[timeframe]
delta = abs(delta)
if isinstance(form, Mapping):
if 1 < delta <= 4:
form = form["double"]
else:
form = form["higher"]

return form.format(delta)


_locales: Dict[str, Type[Locale]] = _map_locales()
27 changes: 27 additions & 0 deletions tests/test_locales.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,33 @@ def test_ordinal_number_tl(self):
assert self.locale.ordinal_number(114) == "ika-114"


@pytest.mark.usefixtures("lang_locale")
class TestCroatianLocale:
def test_format_timeframe(self):
assert self.locale._format_timeframe("now", 0) == "upravo sad"
assert self.locale._format_timeframe("second", 1) == "sekundu"
assert self.locale._format_timeframe("seconds", 3) == "3 sekunde"
assert self.locale._format_timeframe("seconds", 30) == "30 sekundi"
assert self.locale._format_timeframe("minute", 1) == "minutu"
assert self.locale._format_timeframe("minutes", 4) == "4 minute"
assert self.locale._format_timeframe("minutes", 40) == "40 minuta"
assert self.locale._format_timeframe("hour", 1) == "sat"
assert self.locale._format_timeframe("hours", 23) == "23 sati"
assert self.locale._format_timeframe("day", 1) == "jedan dan"
assert self.locale._format_timeframe("days", 12) == "12 dana"
assert self.locale._format_timeframe("month", 1) == "mjesec"
assert self.locale._format_timeframe("months", 2) == "2 mjeseca"
assert self.locale._format_timeframe("months", 11) == "11 mjeseci"
assert self.locale._format_timeframe("year", 1) == "godinu"
assert self.locale._format_timeframe("years", 2) == "2 godine"
assert self.locale._format_timeframe("years", 12) == "12 godina"

def test_weekday(self):
dt = arrow.Arrow(2015, 4, 11, 17, 30, 00)
assert self.locale.day_name(dt.isoweekday()) == "subota"
assert self.locale.day_abbreviation(dt.isoweekday()) == "su"


@pytest.mark.usefixtures("lang_locale")
class TestEstonianLocale:
def test_format_timeframe(self):
Expand Down

0 comments on commit d515e74

Please sign in to comment.