Skip to content

Commit

Permalink
Add Laotian locale (#1105)
Browse files Browse the repository at this point in the history
Co-authored-by: Jad Chaar <jadchaar@users.noreply.github.com>
  • Loading branch information
cyriaka90 and jadchaar committed May 1, 2022
1 parent 1904804 commit f98ad73
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 0 deletions.
2 changes: 2 additions & 0 deletions arrow/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@
"ka-ge",
"kk",
"kk-kz",
# "lo",
# "lo-la",
"am",
"am-et",
}
108 changes: 108 additions & 0 deletions arrow/locales.py
Original file line number Diff line number Diff line change
Expand Up @@ -3971,6 +3971,114 @@ def _format_relative(
return relative_string


class LaotianLocale(Locale):

names = ["lo", "lo-la"]

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 = [
"",
"ມັງກອນ", # mangkon
"ກຸມພາ", # kumpha
"ມີນາ", # mina
"ເມສາ", # mesa
"ພຶດສະພາ", # phudsapha
"ມິຖຸນາ", # mithuna
"ກໍລະກົດ", # kolakod
"ສິງຫາ", # singha
"ກັນຍາ", # knaia
"ຕຸລາ", # tula
"ພະຈິກ", # phachik
"ທັນວາ", # thanuaa
]
month_abbreviations = [
"",
"ມັງກອນ",
"ກຸມພາ",
"ມີນາ",
"ເມສາ",
"ພຶດສະພາ",
"ມິຖຸນາ",
"ກໍລະກົດ",
"ສິງຫາ",
"ກັນຍາ",
"ຕຸລາ",
"ພະຈິກ",
"ທັນວາ",
]

day_names = [
"",
"ວັນຈັນ", # vanchan
"ວັນອັງຄານ", # vnoangkhan
"ວັນພຸດ", # vanphud
"ວັນພະຫັດ", # vanphahad
"ວັນ​ສຸກ", # vansuk
"ວັນເສົາ", # vansao
"ວັນອາທິດ", # vnoathid
]
day_abbreviations = [
"",
"ວັນຈັນ",
"ວັນອັງຄານ",
"ວັນພຸດ",
"ວັນພະຫັດ",
"ວັນ​ສຸກ",
"ວັນເສົາ",
"ວັນອາທິດ",
]

BE_OFFSET = 543

def year_full(self, year: int) -> str:
"""Lao always use Buddhist Era (BE) which is CE + 543"""
year += self.BE_OFFSET
return f"{year:04d}"

def year_abbreviation(self, year: int) -> str:
"""Lao always use Buddhist Era (BE) which is CE + 543"""
year += self.BE_OFFSET
return f"{year:04d}"[2:]

def _format_relative(
self,
humanized: str,
timeframe: TimeFrameLiteral,
delta: Union[float, int],
) -> str:
"""Lao normally doesn't have any space between words"""
if timeframe == "now":
return humanized

direction = self.past if delta < 0 else self.future
relative_string = direction.format(humanized)

if timeframe == "seconds":
relative_string = relative_string.replace(" ", "")

return relative_string


class BengaliLocale(Locale):

names = ["bn", "bn-bd", "bn-in"]
Expand Down
2 changes: 2 additions & 0 deletions tests/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2470,6 +2470,8 @@ def locale_list_no_weeks() -> List[str]:
"ka-ge",
"kk",
"kk-kz",
# "lo",
# "lo-la",
]

return tested_langs
Expand Down
57 changes: 57 additions & 0 deletions tests/test_locales.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,63 @@ def test_ordinal_number(self):
assert self.locale.ordinal_number(1) == "1a"


@pytest.mark.usefixtures("lang_locale")
class TestLaotianLocale:
def test_year_full(self):
assert self.locale.year_full(2015) == "2558"

def test_year_abbreviation(self):
assert self.locale.year_abbreviation(2015) == "58"

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("1 ຊົ່ວໂມງ", "hour", 1)
assert result == "ໃນ 1 ຊົ່ວໂມງ"
result = self.locale._format_relative("{0} ຊົ່ວໂມງ", "hours", 2)
assert result == "ໃນ {0} ຊົ່ວໂມງ"
result = self.locale._format_relative("ວິນາທີ", "seconds", 42)
assert result == "ໃນວິນາທີ"

def test_format_relative_future(self):
result = self.locale._format_relative("1 ຊົ່ວໂມງ", "hour", -1)
assert result == "1 ຊົ່ວໂມງ ກ່ອນຫນ້ານີ້"

def test_format_timeframe(self):
# minute(s)
assert self.locale._format_timeframe("minute", 1) == "ນາທີ"
assert self.locale._format_timeframe("minute", -1) == "ນາທີ"
assert self.locale._format_timeframe("minutes", 7) == "7 ນາທີ"
assert self.locale._format_timeframe("minutes", -20) == "20 ນາທີ"
# day(s)
assert self.locale._format_timeframe("day", 1) == "ມື້"
assert self.locale._format_timeframe("day", -1) == "ມື້"
assert self.locale._format_timeframe("days", 7) == "7 ມື້"
assert self.locale._format_timeframe("days", -20) == "20 ມື້"
# week(s)
assert self.locale._format_timeframe("week", 1) == "ອາທິດ"
assert self.locale._format_timeframe("week", -1) == "ອາທິດ"
assert self.locale._format_timeframe("weeks", 7) == "7 ອາທິດ"
assert self.locale._format_timeframe("weeks", -20) == "20 ອາທິດ"
# month(s)
assert self.locale._format_timeframe("month", 1) == "ເດືອນ"
assert self.locale._format_timeframe("month", -1) == "ເດືອນ"
assert self.locale._format_timeframe("months", 7) == "7 ເດືອນ"
assert self.locale._format_timeframe("months", -20) == "20 ເດືອນ"
# year(s)
assert self.locale._format_timeframe("year", 1) == "ປີ"
assert self.locale._format_timeframe("year", -1) == "ປີ"
assert self.locale._format_timeframe("years", 7) == "7 ປີ"
assert self.locale._format_timeframe("years", -20) == "20 ປີ"

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()) == "ວັນເສົາ"


@pytest.mark.usefixtures("lang_locale")
class TestThaiLocale:
def test_year_full(self):
Expand Down

0 comments on commit f98ad73

Please sign in to comment.