Skip to content

Commit 74bc0a1

Browse files
authored
Dehumanize Support for Czech and Slovak Locales (#1079)
1 parent a2ebb7e commit 74bc0a1

File tree

4 files changed

+82
-28
lines changed

4 files changed

+82
-28
lines changed

arrow/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@
110110
"da-dk",
111111
"ml",
112112
"hi",
113+
"cs",
114+
"cs-cz",
115+
"sk",
116+
"sk-sk",
113117
"fa",
114118
"fa-ir",
115119
"mr",

arrow/locales.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3067,44 +3067,51 @@ class CzechLocale(Locale):
30673067

30683068
timeframes: ClassVar[Mapping[TimeFrameLiteral, Union[str, Mapping[str, str]]]] = {
30693069
"now": "Teď",
3070-
"second": {"past": "vteřina", "future": "vteřina", "zero": "vteřina"},
3070+
"second": {"past": "vteřina", "future": "vteřina"},
30713071
"seconds": {
3072+
"zero": "vteřina",
30723073
"past": "{0} sekundami",
30733074
"future-singular": "{0} sekundy",
30743075
"future-paucal": "{0} sekund",
30753076
},
3076-
"minute": {"past": "minutou", "future": "minutu", "zero": "{0} minut"},
3077+
"minute": {"past": "minutou", "future": "minutu"},
30773078
"minutes": {
3079+
"zero": "{0} minut",
30783080
"past": "{0} minutami",
30793081
"future-singular": "{0} minuty",
30803082
"future-paucal": "{0} minut",
30813083
},
3082-
"hour": {"past": "hodinou", "future": "hodinu", "zero": "{0} hodin"},
3084+
"hour": {"past": "hodinou", "future": "hodinu"},
30833085
"hours": {
3086+
"zero": "{0} hodin",
30843087
"past": "{0} hodinami",
30853088
"future-singular": "{0} hodiny",
30863089
"future-paucal": "{0} hodin",
30873090
},
3088-
"day": {"past": "dnem", "future": "den", "zero": "{0} dnů"},
3091+
"day": {"past": "dnem", "future": "den"},
30893092
"days": {
3093+
"zero": "{0} dnů",
30903094
"past": "{0} dny",
30913095
"future-singular": "{0} dny",
30923096
"future-paucal": "{0} dnů",
30933097
},
3094-
"week": {"past": "týdnem", "future": "týden", "zero": "{0} týdnů"},
3098+
"week": {"past": "týdnem", "future": "týden"},
30953099
"weeks": {
3100+
"zero": "{0} týdnů",
30963101
"past": "{0} týdny",
30973102
"future-singular": "{0} týdny",
30983103
"future-paucal": "{0} týdnů",
30993104
},
3100-
"month": {"past": "měsícem", "future": "měsíc", "zero": "{0} měsíců"},
3105+
"month": {"past": "měsícem", "future": "měsíc"},
31013106
"months": {
3107+
"zero": "{0} měsíců",
31023108
"past": "{0} měsíci",
31033109
"future-singular": "{0} měsíce",
31043110
"future-paucal": "{0} měsíců",
31053111
},
3106-
"year": {"past": "rokem", "future": "rok", "zero": "{0} let"},
3112+
"year": {"past": "rokem", "future": "rok"},
31073113
"years": {
3114+
"zero": "{0} let",
31083115
"past": "{0} lety",
31093116
"future-singular": "{0} roky",
31103117
"future-paucal": "{0} let",
@@ -3190,44 +3197,51 @@ class SlovakLocale(Locale):
31903197

31913198
timeframes: ClassVar[Mapping[TimeFrameLiteral, Union[str, Mapping[str, str]]]] = {
31923199
"now": "Teraz",
3193-
"second": {"past": "sekundou", "future": "sekundu", "zero": "{0} sekúnd"},
3200+
"second": {"past": "sekundou", "future": "sekundu"},
31943201
"seconds": {
3202+
"zero": "{0} sekúnd",
31953203
"past": "{0} sekundami",
31963204
"future-singular": "{0} sekundy",
31973205
"future-paucal": "{0} sekúnd",
31983206
},
3199-
"minute": {"past": "minútou", "future": "minútu", "zero": "{0} minút"},
3207+
"minute": {"past": "minútou", "future": "minútu"},
32003208
"minutes": {
3209+
"zero": "{0} minút",
32013210
"past": "{0} minútami",
32023211
"future-singular": "{0} minúty",
32033212
"future-paucal": "{0} minút",
32043213
},
3205-
"hour": {"past": "hodinou", "future": "hodinu", "zero": "{0} hodín"},
3214+
"hour": {"past": "hodinou", "future": "hodinu"},
32063215
"hours": {
3216+
"zero": "{0} hodín",
32073217
"past": "{0} hodinami",
32083218
"future-singular": "{0} hodiny",
32093219
"future-paucal": "{0} hodín",
32103220
},
3211-
"day": {"past": "dňom", "future": "deň", "zero": "{0} dní"},
3221+
"day": {"past": "dňom", "future": "deň"},
32123222
"days": {
3223+
"zero": "{0} dní",
32133224
"past": "{0} dňami",
32143225
"future-singular": "{0} dni",
32153226
"future-paucal": "{0} dní",
32163227
},
3217-
"week": {"past": "týždňom", "future": "týždeň", "zero": "{0} týždňov"},
3228+
"week": {"past": "týždňom", "future": "týždeň"},
32183229
"weeks": {
3230+
"zero": "{0} týždňov",
32193231
"past": "{0} týždňami",
32203232
"future-singular": "{0} týždne",
32213233
"future-paucal": "{0} týždňov",
32223234
},
3223-
"month": {"past": "mesiacom", "future": "mesiac", "zero": "{0} mesiacov"},
3235+
"month": {"past": "mesiacom", "future": "mesiac"},
32243236
"months": {
3237+
"zero": "{0} mesiacov",
32253238
"past": "{0} mesiacmi",
32263239
"future-singular": "{0} mesiace",
32273240
"future-paucal": "{0} mesiacov",
32283241
},
3229-
"year": {"past": "rokom", "future": "rok", "zero": "{0} rokov"},
3242+
"year": {"past": "rokom", "future": "rok"},
32303243
"years": {
3244+
"zero": "{0} rokov",
32313245
"past": "{0} rokmi",
32323246
"future-singular": "{0} roky",
32333247
"future-paucal": "{0} rokov",

tests/test_arrow.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,6 +2410,10 @@ def locale_list_no_weeks() -> List[str]:
24102410
"da-dk",
24112411
"ml",
24122412
"hi",
2413+
"cs",
2414+
"cs-cz",
2415+
"sk",
2416+
"sk-sk",
24132417
"fa",
24142418
"fa-ir",
24152419
"mr",
@@ -2511,6 +2515,10 @@ def locale_list_with_weeks() -> List[str]:
25112515
"pt",
25122516
"pt-pt",
25132517
"pt-br",
2518+
"cs",
2519+
"cs-cz",
2520+
"sk",
2521+
"sk-sk",
25142522
"tl",
25152523
"tl-ph",
25162524
"vi",
@@ -2954,6 +2962,34 @@ def test_slavic_locales(self, slavic_locales: List[str]):
29542962
assert arw.dehumanize(past_string, locale=lang) == past
29552963
assert arw.dehumanize(future_string, locale=lang) == future
29562964

2965+
def test_czech_slovak(self):
2966+
2967+
# Relevant units for Slavic locale plural logic
2968+
units = [
2969+
0,
2970+
1,
2971+
2,
2972+
5,
2973+
]
2974+
2975+
# Only need to test on seconds as logic holds for all slavic plural units
2976+
for lang in ["cs"]:
2977+
for unit in units:
2978+
arw = arrow.Arrow(2000, 2, 18, 1, 50, 30)
2979+
2980+
past = arw.shift(minutes=-1 * unit, days=-1)
2981+
future = arw.shift(minutes=unit, days=1)
2982+
2983+
past_string = past.humanize(
2984+
arw, locale=lang, granularity=["minute", "day"]
2985+
)
2986+
future_string = future.humanize(
2987+
arw, locale=lang, granularity=["minute", "day"]
2988+
)
2989+
2990+
assert arw.dehumanize(past_string, locale=lang) == past
2991+
assert arw.dehumanize(future_string, locale=lang) == future
2992+
29572993

29582994
class TestArrowIsBetween:
29592995
def test_start_before_end(self):

tests/test_locales.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -613,62 +613,62 @@ def test_format_timeframe(self):
613613

614614
# Second(s)
615615
assert self.locale._format_timeframe("second", -1) == "vteřina"
616-
assert self.locale._format_timeframe("second", 0) == "vteřina"
617616
assert self.locale._format_timeframe("second", 1) == "vteřina"
617+
assert self.locale._format_timeframe("seconds", 0) == "vteřina"
618618
assert self.locale._format_timeframe("seconds", -2) == "2 sekundami"
619619
assert self.locale._format_timeframe("seconds", -5) == "5 sekundami"
620620
assert self.locale._format_timeframe("seconds", 2) == "2 sekundy"
621621
assert self.locale._format_timeframe("seconds", 5) == "5 sekund"
622622

623623
# Minute(s)
624624
assert self.locale._format_timeframe("minute", -1) == "minutou"
625-
assert self.locale._format_timeframe("minute", 0) == "0 minut"
626625
assert self.locale._format_timeframe("minute", 1) == "minutu"
626+
assert self.locale._format_timeframe("minutes", 0) == "0 minut"
627627
assert self.locale._format_timeframe("minutes", -2) == "2 minutami"
628628
assert self.locale._format_timeframe("minutes", -5) == "5 minutami"
629629
assert self.locale._format_timeframe("minutes", 2) == "2 minuty"
630630
assert self.locale._format_timeframe("minutes", 5) == "5 minut"
631631

632632
# Hour(s)
633633
assert self.locale._format_timeframe("hour", -1) == "hodinou"
634-
assert self.locale._format_timeframe("hour", 0) == "0 hodin"
635634
assert self.locale._format_timeframe("hour", 1) == "hodinu"
635+
assert self.locale._format_timeframe("hours", 0) == "0 hodin"
636636
assert self.locale._format_timeframe("hours", -2) == "2 hodinami"
637637
assert self.locale._format_timeframe("hours", -5) == "5 hodinami"
638638
assert self.locale._format_timeframe("hours", 2) == "2 hodiny"
639639
assert self.locale._format_timeframe("hours", 5) == "5 hodin"
640640

641641
# Day(s)
642642
assert self.locale._format_timeframe("day", -1) == "dnem"
643-
assert self.locale._format_timeframe("day", 0) == "0 dnů"
644643
assert self.locale._format_timeframe("day", 1) == "den"
644+
assert self.locale._format_timeframe("days", 0) == "0 dnů"
645645
assert self.locale._format_timeframe("days", -2) == "2 dny"
646646
assert self.locale._format_timeframe("days", -5) == "5 dny"
647647
assert self.locale._format_timeframe("days", 2) == "2 dny"
648648
assert self.locale._format_timeframe("days", 5) == "5 dnů"
649649

650650
# Weeks(s)
651651
assert self.locale._format_timeframe("week", -1) == "týdnem"
652-
assert self.locale._format_timeframe("week", 0) == "0 týdnů"
653652
assert self.locale._format_timeframe("week", 1) == "týden"
653+
assert self.locale._format_timeframe("weeks", 0) == "0 týdnů"
654654
assert self.locale._format_timeframe("weeks", -2) == "2 týdny"
655655
assert self.locale._format_timeframe("weeks", -5) == "5 týdny"
656656
assert self.locale._format_timeframe("weeks", 2) == "2 týdny"
657657
assert self.locale._format_timeframe("weeks", 5) == "5 týdnů"
658658

659659
# Month(s)
660660
assert self.locale._format_timeframe("month", -1) == "měsícem"
661-
assert self.locale._format_timeframe("month", 0) == "0 měsíců"
662661
assert self.locale._format_timeframe("month", 1) == "měsíc"
662+
assert self.locale._format_timeframe("months", 0) == "0 měsíců"
663663
assert self.locale._format_timeframe("months", -2) == "2 měsíci"
664664
assert self.locale._format_timeframe("months", -5) == "5 měsíci"
665665
assert self.locale._format_timeframe("months", 2) == "2 měsíce"
666666
assert self.locale._format_timeframe("months", 5) == "5 měsíců"
667667

668668
# Year(s)
669669
assert self.locale._format_timeframe("year", -1) == "rokem"
670-
assert self.locale._format_timeframe("year", 0) == "0 let"
671670
assert self.locale._format_timeframe("year", 1) == "rok"
671+
assert self.locale._format_timeframe("years", 0) == "0 let"
672672
assert self.locale._format_timeframe("years", -2) == "2 lety"
673673
assert self.locale._format_timeframe("years", -5) == "5 lety"
674674
assert self.locale._format_timeframe("years", 2) == "2 roky"
@@ -697,55 +697,55 @@ def test_format_timeframe(self):
697697
assert self.locale._format_timeframe("seconds", -5) == "5 sekundami"
698698
assert self.locale._format_timeframe("seconds", -2) == "2 sekundami"
699699
assert self.locale._format_timeframe("second", -1) == "sekundou"
700-
assert self.locale._format_timeframe("second", 0) == "0 sekúnd"
700+
assert self.locale._format_timeframe("seconds", 0) == "0 sekúnd"
701701
assert self.locale._format_timeframe("second", 1) == "sekundu"
702702
assert self.locale._format_timeframe("seconds", 2) == "2 sekundy"
703703
assert self.locale._format_timeframe("seconds", 5) == "5 sekúnd"
704704

705705
assert self.locale._format_timeframe("minutes", -5) == "5 minútami"
706706
assert self.locale._format_timeframe("minutes", -2) == "2 minútami"
707707
assert self.locale._format_timeframe("minute", -1) == "minútou"
708-
assert self.locale._format_timeframe("minute", 0) == "0 minút"
708+
assert self.locale._format_timeframe("minutes", 0) == "0 minút"
709709
assert self.locale._format_timeframe("minute", 1) == "minútu"
710710
assert self.locale._format_timeframe("minutes", 2) == "2 minúty"
711711
assert self.locale._format_timeframe("minutes", 5) == "5 minút"
712712

713713
assert self.locale._format_timeframe("hours", -5) == "5 hodinami"
714714
assert self.locale._format_timeframe("hours", -2) == "2 hodinami"
715715
assert self.locale._format_timeframe("hour", -1) == "hodinou"
716-
assert self.locale._format_timeframe("hour", 0) == "0 hodín"
716+
assert self.locale._format_timeframe("hours", 0) == "0 hodín"
717717
assert self.locale._format_timeframe("hour", 1) == "hodinu"
718718
assert self.locale._format_timeframe("hours", 2) == "2 hodiny"
719719
assert self.locale._format_timeframe("hours", 5) == "5 hodín"
720720

721721
assert self.locale._format_timeframe("days", -5) == "5 dňami"
722722
assert self.locale._format_timeframe("days", -2) == "2 dňami"
723723
assert self.locale._format_timeframe("day", -1) == "dňom"
724-
assert self.locale._format_timeframe("day", 0) == "0 dní"
724+
assert self.locale._format_timeframe("days", 0) == "0 dní"
725725
assert self.locale._format_timeframe("day", 1) == "deň"
726726
assert self.locale._format_timeframe("days", 2) == "2 dni"
727727
assert self.locale._format_timeframe("days", 5) == "5 dní"
728728

729729
assert self.locale._format_timeframe("weeks", -5) == "5 týždňami"
730730
assert self.locale._format_timeframe("weeks", -2) == "2 týždňami"
731731
assert self.locale._format_timeframe("week", -1) == "týždňom"
732-
assert self.locale._format_timeframe("week", 0) == "0 týždňov"
732+
assert self.locale._format_timeframe("weeks", 0) == "0 týždňov"
733733
assert self.locale._format_timeframe("week", 1) == "týždeň"
734734
assert self.locale._format_timeframe("weeks", 2) == "2 týždne"
735735
assert self.locale._format_timeframe("weeks", 5) == "5 týždňov"
736736

737737
assert self.locale._format_timeframe("months", -5) == "5 mesiacmi"
738738
assert self.locale._format_timeframe("months", -2) == "2 mesiacmi"
739739
assert self.locale._format_timeframe("month", -1) == "mesiacom"
740-
assert self.locale._format_timeframe("month", 0) == "0 mesiacov"
740+
assert self.locale._format_timeframe("months", 0) == "0 mesiacov"
741741
assert self.locale._format_timeframe("month", 1) == "mesiac"
742742
assert self.locale._format_timeframe("months", 2) == "2 mesiace"
743743
assert self.locale._format_timeframe("months", 5) == "5 mesiacov"
744744

745745
assert self.locale._format_timeframe("years", -5) == "5 rokmi"
746746
assert self.locale._format_timeframe("years", -2) == "2 rokmi"
747747
assert self.locale._format_timeframe("year", -1) == "rokom"
748-
assert self.locale._format_timeframe("year", 0) == "0 rokov"
748+
assert self.locale._format_timeframe("years", 0) == "0 rokov"
749749
assert self.locale._format_timeframe("year", 1) == "rok"
750750
assert self.locale._format_timeframe("years", 2) == "2 roky"
751751
assert self.locale._format_timeframe("years", 5) == "5 rokov"

0 commit comments

Comments
 (0)