Skip to content

Commit

Permalink
Add Tamil locale (#1004)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChingYi-AX committed Jul 9, 2021
1 parent 37b45da commit c53113a
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 0 deletions.
3 changes: 3 additions & 0 deletions arrow/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,7 @@
"or-in",
"lb",
"lb-lu",
"ta",
"ta-in",
"ta-lk",
}
88 changes: 88 additions & 0 deletions arrow/locales.py
Original file line number Diff line number Diff line change
Expand Up @@ -5341,3 +5341,91 @@ def _format_timeframe(self, timeframe: TimeFrameLiteral, delta: int) -> str:
"uMgqibelo",
"iSonto",
]


class TamilLocale(Locale):

names = ["ta", "ta-in", "ta-lk"]

past = "{0} நேரத்திற்கு முன்பு"
future = "இல் {0}"

timeframes = {
"now": "இப்போது",
"second": "ஒரு இரண்டாவது",
"seconds": "{0} விநாடிகள்",
"minute": "ஒரு நிமிடம்",
"minutes": "{0} நிமிடங்கள்",
"hour": "ஒரு மணி",
"hours": "{0} மணிநேரம்",
"day": "ஒரு நாள்",
"days": "{0} நாட்கள்",
"week": "ஒரு வாரம்",
"weeks": "{0} வாரங்கள்",
"month": "ஒரு மாதம்",
"months": "{0} மாதங்கள்",
"year": "ஒரு ஆண்டு",
"years": "{0} ஆண்டுகள்",
}

month_names = [
"",
"சித்திரை",
"வைகாசி",
"ஆனி",
"ஆடி",
"ஆவணி",
"புரட்டாசி",
"ஐப்பசி",
"கார்த்திகை",
"மார்கழி",
"தை",
"மாசி",
"பங்குனி",
]

month_abbreviations = [
"",
"ஜன",
"பிப்",
"மார்",
"ஏப்",
"மே",
"ஜூன்",
"ஜூலை",
"ஆக",
"செப்",
"அக்",
"நவ",
"டிச",
]

day_names = [
"",
"திங்கட்கிழமை",
"செவ்வாய்க்கிழமை",
"புதன்கிழமை",
"வியாழக்கிழமை",
"வெள்ளிக்கிழமை",
"சனிக்கிழமை",
"ஞாயிற்றுக்கிழமை",
]

day_abbreviations = [
"",
"திங்கட்",
"செவ்வாய்",
"புதன்",
"வியாழன்",
"வெள்ளி",
"சனி",
"ஞாயிறு",
]

def _ordinal_number(self, n: int) -> str:
if n == 1:
return f"{n}வது"
elif n >= 0:
return f"{n}ஆம்"
else:
return ""
6 changes: 6 additions & 0 deletions tests/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2407,6 +2407,9 @@ def locale_list_no_weeks():
"se-se",
"lb",
"lb-lu",
"ta",
"ta-in",
"ta-lk",
]

return tested_langs
Expand Down Expand Up @@ -2464,6 +2467,9 @@ def locale_list_with_weeks():
"ms-bn",
"lb",
"lb-lu",
"ta",
"ta-in",
"ta-lk",
]

return tested_langs
Expand Down
44 changes: 44 additions & 0 deletions tests/test_locales.py
Original file line number Diff line number Diff line change
Expand Up @@ -1788,3 +1788,47 @@ def test_weekday(self):
dt = arrow.Arrow(2015, 4, 11, 17, 30, 00)
assert self.locale.day_name(dt.isoweekday()) == "Samschdeg"
assert self.locale.day_abbreviation(dt.isoweekday()) == "Sam"


@pytest.mark.usefixtures("lang_locale")
class TestTamilLocale:
def test_format_timeframe(self):
assert self.locale._format_timeframe("now", 0) == "இப்போது"
assert self.locale._format_timeframe("second", 1) == "ஒரு இரண்டாவது"
assert self.locale._format_timeframe("seconds", 3) == "3 விநாடிகள்"
assert self.locale._format_timeframe("minute", 1) == "ஒரு நிமிடம்"
assert self.locale._format_timeframe("minutes", 4) == "4 நிமிடங்கள்"
assert self.locale._format_timeframe("hour", 1) == "ஒரு மணி"
assert self.locale._format_timeframe("hours", 23) == "23 மணிநேரம்"
assert self.locale._format_timeframe("day", 1) == "ஒரு நாள்"
assert self.locale._format_timeframe("days", 12) == "12 நாட்கள்"
assert self.locale._format_timeframe("week", 1) == "ஒரு வாரம்"
assert self.locale._format_timeframe("weeks", 12) == "12 வாரங்கள்"
assert self.locale._format_timeframe("month", 1) == "ஒரு மாதம்"
assert self.locale._format_timeframe("months", 2) == "2 மாதங்கள்"
assert self.locale._format_timeframe("year", 1) == "ஒரு ஆண்டு"
assert self.locale._format_timeframe("years", 2) == "2 ஆண்டுகள்"

def test_ordinal_number(self):
assert self.locale._ordinal_number(0) == "0ஆம்"
assert self.locale._ordinal_number(1) == "1வது"
assert self.locale._ordinal_number(3) == "3ஆம்"
assert self.locale._ordinal_number(11) == "11ஆம்"
assert self.locale._ordinal_number(-1) == ""

def test_format_relative_now(self):
result = self.locale._format_relative("இப்போது", "now", 0)
assert result == "இப்போது"

def test_format_relative_past(self):
result = self.locale._format_relative("ஒரு மணி", "hour", 1)
assert result == "இல் ஒரு மணி"

def test_format_relative_future(self):
result = self.locale._format_relative("ஒரு மணி", "hour", -1)
assert result == "ஒரு மணி நேரத்திற்கு முன்பு"

def test_weekday(self):
dt = arrow.Arrow(2015, 4, 11, 17, 30, 00)
assert self.locale.day_name(dt.isoweekday()) == "சனிக்கிழமை"
assert self.locale.day_abbreviation(dt.isoweekday()) == "சனி"

0 comments on commit c53113a

Please sign in to comment.