Skip to content

Commit

Permalink
Add Macedonian in Latin. (#1200)
Browse files Browse the repository at this point in the history
* add macedonian latin.

* add mk-latn name.
  • Loading branch information
krisfremen authored Nov 5, 2024
1 parent 016fb9e commit 0a01d34
Show file tree
Hide file tree
Showing 2 changed files with 245 additions and 5 deletions.
99 changes: 99 additions & 0 deletions arrow/locales.py
Original file line number Diff line number Diff line change
Expand Up @@ -1924,6 +1924,105 @@ class MacedonianLocale(SlavicBaseLocale):
]


class MacedonianLatinLocale(SlavicBaseLocale):
names = ["mk-latn", "mk-mk-latn"]

past = "pred {0}"
future = "za {0}"

timeframes: ClassVar[Mapping[TimeFrameLiteral, Union[str, Mapping[str, str]]]] = {
"now": "sega",
"second": "edna sekunda",
"seconds": {
"singular": "{0} sekunda",
"dual": "{0} sekundi",
"plural": "{0} sekundi",
},
"minute": "edna minuta",
"minutes": {
"singular": "{0} minuta",
"dual": "{0} minuti",
"plural": "{0} minuti",
},
"hour": "eden saat",
"hours": {"singular": "{0} saat", "dual": "{0} saati", "plural": "{0} saati"},
"day": "eden den",
"days": {"singular": "{0} den", "dual": "{0} dena", "plural": "{0} dena"},
"week": "edna nedela",
"weeks": {
"singular": "{0} nedela",
"dual": "{0} nedeli",
"plural": "{0} nedeli",
},
"month": "eden mesec",
"months": {
"singular": "{0} mesec",
"dual": "{0} meseci",
"plural": "{0} meseci",
},
"year": "edna godina",
"years": {
"singular": "{0} godina",
"dual": "{0} godini",
"plural": "{0} godini",
},
}

meridians = {"am": "dp", "pm": "pp", "AM": "pretpladne", "PM": "popladne"}

month_names = [
"",
"Januari",
"Fevruari",
"Mart",
"April",
"Maj",
"Juni",
"Juli",
"Avgust",
"Septemvri",
"Oktomvri",
"Noemvri",
"Dekemvri",
]
month_abbreviations = [
"",
"Jan",
"Fev",
"Mar",
"Apr",
"Maj",
"Jun",
"Jul",
"Avg",
"Sep",
"Okt",
"Noe",
"Dek",
]

day_names = [
"",
"Ponedelnik",
"Vtornik",
"Sreda",
"Chetvrtok",
"Petok",
"Sabota",
"Nedela",
]
day_abbreviations = [
"",
"Pon",
"Vt",
"Sre",
"Chet",
"Pet",
"Sab",
"Ned",
]


class GermanBaseLocale(Locale):
past = "vor {0}"
future = "in {0}"
Expand Down
151 changes: 146 additions & 5 deletions tests/test_locales.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ def test_locale_validation(self):
assert locale_cls.future is not None

def test_locale_name_validation(self):
import re

for locale_cls in self.locales.values():
for locale_name in locale_cls.names:
assert len(locale_name) == 2 or len(locale_name) == 5
assert locale_name.islower()
# Not a two-letter code
if len(locale_name) > 2:
assert "-" in locale_name
assert locale_name.count("-") == 1
pattern = r"^[a-z]{2}(-[a-z]{2})?(?:-latn|-cyrl)?$"
assert re.match(pattern, locale_name)

def test_duplicated_locale_name(self):
with pytest.raises(LookupError):
Expand Down Expand Up @@ -909,6 +908,148 @@ def test_multi_describe_mk(self):
assert describe(seconds60, only_distance=True) == "1 секунда"


@pytest.mark.usefixtures("lang_locale")
class TestMacedonianLatinLocale:
def test_singles_mk(self):
assert self.locale._format_timeframe("second", 1) == "edna sekunda"
assert self.locale._format_timeframe("minute", 1) == "edna minuta"
assert self.locale._format_timeframe("hour", 1) == "eden saat"
assert self.locale._format_timeframe("day", 1) == "eden den"
assert self.locale._format_timeframe("week", 1) == "edna nedela"
assert self.locale._format_timeframe("month", 1) == "eden mesec"
assert self.locale._format_timeframe("year", 1) == "edna godina"

def test_meridians_mk(self):
assert self.locale.meridian(7, "A") == "pretpladne"
assert self.locale.meridian(18, "A") == "popladne"
assert self.locale.meridian(10, "a") == "dp"
assert self.locale.meridian(22, "a") == "pp"

def test_describe_mk(self):
assert self.locale.describe("second", only_distance=True) == "edna sekunda"
assert self.locale.describe("second", only_distance=False) == "za edna sekunda"
assert self.locale.describe("minute", only_distance=True) == "edna minuta"
assert self.locale.describe("minute", only_distance=False) == "za edna minuta"
assert self.locale.describe("hour", only_distance=True) == "eden saat"
assert self.locale.describe("hour", only_distance=False) == "za eden saat"
assert self.locale.describe("day", only_distance=True) == "eden den"
assert self.locale.describe("day", only_distance=False) == "za eden den"
assert self.locale.describe("week", only_distance=True) == "edna nedela"
assert self.locale.describe("week", only_distance=False) == "za edna nedela"
assert self.locale.describe("month", only_distance=True) == "eden mesec"
assert self.locale.describe("month", only_distance=False) == "za eden mesec"
assert self.locale.describe("year", only_distance=True) == "edna godina"
assert self.locale.describe("year", only_distance=False) == "za edna godina"

def test_relative_mk(self):
# time
assert self.locale._format_relative("sega", "now", 0) == "sega"
assert self.locale._format_relative("1 sekunda", "seconds", 1) == "za 1 sekunda"
assert self.locale._format_relative("1 minuta", "minutes", 1) == "za 1 minuta"
assert self.locale._format_relative("1 saat", "hours", 1) == "za 1 saat"
assert self.locale._format_relative("1 den", "days", 1) == "za 1 den"
assert self.locale._format_relative("1 nedela", "weeks", 1) == "za 1 nedela"
assert self.locale._format_relative("1 mesec", "months", 1) == "za 1 mesec"
assert self.locale._format_relative("1 godina", "years", 1) == "za 1 godina"
assert (
self.locale._format_relative("1 sekunda", "seconds", -1) == "pred 1 sekunda"
)
assert (
self.locale._format_relative("1 minuta", "minutes", -1) == "pred 1 minuta"
)
assert self.locale._format_relative("1 saat", "hours", -1) == "pred 1 saat"
assert self.locale._format_relative("1 den", "days", -1) == "pred 1 den"
assert self.locale._format_relative("1 nedela", "weeks", -1) == "pred 1 nedela"
assert self.locale._format_relative("1 mesec", "months", -1) == "pred 1 mesec"
assert self.locale._format_relative("1 godina", "years", -1) == "pred 1 godina"

def test_plurals_mk(self):
# Seconds
assert self.locale._format_timeframe("seconds", 0) == "0 sekundi"
assert self.locale._format_timeframe("seconds", 1) == "1 sekunda"
assert self.locale._format_timeframe("seconds", 2) == "2 sekundi"
assert self.locale._format_timeframe("seconds", 4) == "4 sekundi"
assert self.locale._format_timeframe("seconds", 5) == "5 sekundi"
assert self.locale._format_timeframe("seconds", 21) == "21 sekunda"
assert self.locale._format_timeframe("seconds", 22) == "22 sekundi"
assert self.locale._format_timeframe("seconds", 25) == "25 sekundi"

# Minutes
assert self.locale._format_timeframe("minutes", 0) == "0 minuti"
assert self.locale._format_timeframe("minutes", 1) == "1 minuta"
assert self.locale._format_timeframe("minutes", 2) == "2 minuti"
assert self.locale._format_timeframe("minutes", 4) == "4 minuti"
assert self.locale._format_timeframe("minutes", 5) == "5 minuti"
assert self.locale._format_timeframe("minutes", 21) == "21 minuta"
assert self.locale._format_timeframe("minutes", 22) == "22 minuti"
assert self.locale._format_timeframe("minutes", 25) == "25 minuti"

# Hours
assert self.locale._format_timeframe("hours", 0) == "0 saati"
assert self.locale._format_timeframe("hours", 1) == "1 saat"
assert self.locale._format_timeframe("hours", 2) == "2 saati"
assert self.locale._format_timeframe("hours", 4) == "4 saati"
assert self.locale._format_timeframe("hours", 5) == "5 saati"
assert self.locale._format_timeframe("hours", 21) == "21 saat"
assert self.locale._format_timeframe("hours", 22) == "22 saati"
assert self.locale._format_timeframe("hours", 25) == "25 saati"

# Days
assert self.locale._format_timeframe("days", 0) == "0 dena"
assert self.locale._format_timeframe("days", 1) == "1 den"
assert self.locale._format_timeframe("days", 2) == "2 dena"
assert self.locale._format_timeframe("days", 3) == "3 dena"
assert self.locale._format_timeframe("days", 21) == "21 den"

# Weeks
assert self.locale._format_timeframe("weeks", 0) == "0 nedeli"
assert self.locale._format_timeframe("weeks", 1) == "1 nedela"
assert self.locale._format_timeframe("weeks", 2) == "2 nedeli"
assert self.locale._format_timeframe("weeks", 4) == "4 nedeli"
assert self.locale._format_timeframe("weeks", 5) == "5 nedeli"
assert self.locale._format_timeframe("weeks", 21) == "21 nedela"
assert self.locale._format_timeframe("weeks", 22) == "22 nedeli"
assert self.locale._format_timeframe("weeks", 25) == "25 nedeli"

# Months
assert self.locale._format_timeframe("months", 0) == "0 meseci"
assert self.locale._format_timeframe("months", 1) == "1 mesec"
assert self.locale._format_timeframe("months", 2) == "2 meseci"
assert self.locale._format_timeframe("months", 4) == "4 meseci"
assert self.locale._format_timeframe("months", 5) == "5 meseci"
assert self.locale._format_timeframe("months", 21) == "21 mesec"
assert self.locale._format_timeframe("months", 22) == "22 meseci"
assert self.locale._format_timeframe("months", 25) == "25 meseci"

# Years
assert self.locale._format_timeframe("years", 1) == "1 godina"
assert self.locale._format_timeframe("years", 2) == "2 godini"
assert self.locale._format_timeframe("years", 5) == "5 godini"

def test_multi_describe_mk(self):
describe = self.locale.describe_multi

fulltest = [("years", 5), ("weeks", 1), ("hours", 1), ("minutes", 6)]
assert describe(fulltest) == "za 5 godini 1 nedela 1 saat 6 minuti"
seconds4000_0days = [("days", 0), ("hours", 1), ("minutes", 6)]
assert describe(seconds4000_0days) == "za 0 dena 1 saat 6 minuti"
seconds4000 = [("hours", 1), ("minutes", 6)]
assert describe(seconds4000) == "za 1 saat 6 minuti"
assert describe(seconds4000, only_distance=True) == "1 saat 6 minuti"
seconds3700 = [("hours", 1), ("minutes", 1)]
assert describe(seconds3700) == "za 1 saat 1 minuta"
seconds300_0hours = [("hours", 0), ("minutes", 5)]
assert describe(seconds300_0hours) == "za 0 saati 5 minuti"
seconds300 = [("minutes", 5)]
assert describe(seconds300) == "za 5 minuti"
seconds60 = [("minutes", 1)]
assert describe(seconds60) == "za 1 minuta"
assert describe(seconds60, only_distance=True) == "1 minuta"
seconds60 = [("seconds", 1)]
assert describe(seconds60) == "za 1 sekunda"
assert describe(seconds60, only_distance=True) == "1 sekunda"


@pytest.mark.usefixtures("time_2013_01_01")
@pytest.mark.usefixtures("lang_locale")
class TestHebrewLocale:
Expand Down

0 comments on commit 0a01d34

Please sign in to comment.