Skip to content

Commit

Permalink
Fixing Plural of Years and Days in Hebrew (#1042)
Browse files Browse the repository at this point in the history
  • Loading branch information
guyernest authored Sep 21, 2021
1 parent a4f1797 commit 9b45719
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
22 changes: 10 additions & 12 deletions arrow/locales.py
Original file line number Diff line number Diff line change
Expand Up @@ -3370,15 +3370,15 @@ class HebrewLocale(Locale):
"minute": "ื“ืงื”",
"minutes": "{0} ื“ืงื•ืช",
"hour": "ืฉืขื”",
"hours": {"2": "ืฉืขืชื™ื™ื", "general": "{0} ืฉืขื•ืช"},
"hours": {"2": "ืฉืขืชื™ื™ื", "ten": "{0} ืฉืขื•ืช", "higher": "{0} ืฉืขื•ืช"},
"day": "ื™ื•ื",
"days": {"2": "ื™ื•ืžื™ื™ื", "general": "{0} ื™ืžื™ื"},
"days": {"2": "ื™ื•ืžื™ื™ื", "ten": "{0} ื™ืžื™ื", "higher": "{0} ื™ื•ื"},
"week": "ืฉื‘ื•ืข",
"weeks": {"2": "ืฉื‘ื•ืขื™ื™ื", "general": "{0} ืฉื‘ื•ืขื•ืช"},
"weeks": {"2": "ืฉื‘ื•ืขื™ื™ื", "ten": "{0} ืฉื‘ื•ืขื•ืช", "higher": "{0} ืฉื‘ื•ืขื•ืช"},
"month": "ื—ื•ื“ืฉ",
"months": {"2": "ื—ื•ื“ืฉื™ื™ื", "general": "{0} ื—ื•ื“ืฉื™ื"},
"months": {"2": "ื—ื•ื“ืฉื™ื™ื", "ten": "{0} ื—ื•ื“ืฉื™ื", "higher": "{0} ื—ื•ื“ืฉื™ื"},
"year": "ืฉื ื”",
"years": {"2": "ืฉื ืชื™ื™ื", "general": "{0} ืฉื ื™ื"},
"years": {"2": "ืฉื ืชื™ื™ื", "ten": "{0} ืฉื ื™ื", "higher": "{0} ืฉื ื”"},
}

meridians = {
Expand Down Expand Up @@ -3422,18 +3422,16 @@ class HebrewLocale(Locale):
day_names = ["", "ืฉื ื™", "ืฉืœื™ืฉื™", "ืจื‘ื™ืขื™", "ื—ืžื™ืฉื™", "ืฉื™ืฉื™", "ืฉื‘ืช", "ืจืืฉื•ืŸ"]
day_abbreviations = ["", "ื‘ืณ", "ื’ืณ", "ื“ืณ", "ื”ืณ", "ื•ืณ", "ืฉืณ", "ืืณ"]

def _format_timeframe(
self, timeframe: TimeFrameLiteral, delta: Union[float, int]
) -> str:
"""Hebrew couple of <timeframe> aware"""
def _format_timeframe(self, timeframe: TimeFrameLiteral, delta: int) -> str:
form = self.timeframes[timeframe]
delta = abs(trunc(delta))

delta = abs(delta)
if isinstance(form, Mapping):
if delta == 2:
form = form["2"]
elif delta == 0 or 2 < delta <= 10:
form = form["ten"]
else:
form = form["general"]
form = form["higher"]

return form.format(delta)

Expand Down
16 changes: 16 additions & 0 deletions tests/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2656,6 +2656,22 @@ def test_years(self, locale_list_no_weeks):
assert arw.dehumanize(year_ago_string, locale=lang) == year_ago
assert arw.dehumanize(year_future_string, locale=lang) == year_future

def test_gt_than_10_years(self, locale_list_no_weeks):

for lang in locale_list_no_weeks:

arw = arrow.Arrow(2000, 1, 10, 5, 55, 0)
year_ago = arw.shift(years=-25)
year_future = arw.shift(years=25)

year_ago_string = year_ago.humanize(arw, locale=lang, granularity=["year"])
year_future_string = year_future.humanize(
arw, locale=lang, granularity=["year"]
)

assert arw.dehumanize(year_ago_string, locale=lang) == year_ago
assert arw.dehumanize(year_future_string, locale=lang) == year_future

def test_mixed_granularity(self, locale_list_no_weeks):

for lang in locale_list_no_weeks:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_locales.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ def test_couple_of_timeframe(self):
assert self.locale._format_timeframe("day", 1) == "ื™ื•ื"
assert self.locale._format_timeframe("days", 2) == "ื™ื•ืžื™ื™ื"
assert self.locale._format_timeframe("days", 3) == "3 ื™ืžื™ื"
assert self.locale._format_timeframe("days", 80) == "80 ื™ื•ื"

assert self.locale._format_timeframe("hour", 1) == "ืฉืขื”"
assert self.locale._format_timeframe("hours", 2) == "ืฉืขืชื™ื™ื"
Expand All @@ -744,6 +745,7 @@ def test_couple_of_timeframe(self):
assert self.locale._format_timeframe("year", 1) == "ืฉื ื”"
assert self.locale._format_timeframe("years", 2) == "ืฉื ืชื™ื™ื"
assert self.locale._format_timeframe("years", 5) == "5 ืฉื ื™ื"
assert self.locale._format_timeframe("years", 15) == "15 ืฉื ื”"

def test_describe_multi(self):
describe = self.locale.describe_multi
Expand Down

0 comments on commit 9b45719

Please sign in to comment.