From d87ad914cf45233c41eb573da312ba00f17cef9a Mon Sep 17 00:00:00 2001 From: zdenop Date: Wed, 24 Aug 2022 10:33:07 +0200 Subject: [PATCH] add Slovak locale (#575) * add Slovak locale * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix proble in Slovak locale * add test for Slovak locale * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update test_sk.py Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Bartosz Sokorski --- pendulum/locales/sk/__init__.py | 0 pendulum/locales/sk/custom.py | 20 +++ pendulum/locales/sk/locale.py | 266 ++++++++++++++++++++++++++++++++ tests/localization/test_sk.py | 113 ++++++++++++++ 4 files changed, 399 insertions(+) create mode 100644 pendulum/locales/sk/__init__.py create mode 100644 pendulum/locales/sk/custom.py create mode 100644 pendulum/locales/sk/locale.py create mode 100644 tests/localization/test_sk.py diff --git a/pendulum/locales/sk/__init__.py b/pendulum/locales/sk/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/pendulum/locales/sk/custom.py b/pendulum/locales/sk/custom.py new file mode 100644 index 00000000..71afb15b --- /dev/null +++ b/pendulum/locales/sk/custom.py @@ -0,0 +1,20 @@ +""" +sk custom locale file. +""" + +translations = { + # Relative time + "ago": "pred {}", + "from_now": "o {}", + "after": "{0} po", + "before": "{0} pred", + # Date formats + "date_formats": { + "LTS": "HH:mm:ss", + "LT": "HH:mm", + "LLLL": "dddd, D. MMMM YYYY HH:mm", + "LLL": "D. MMMM YYYY HH:mm", + "LL": "D. MMMM YYYY", + "L": "DD.MM.YYYY", + }, +} diff --git a/pendulum/locales/sk/locale.py b/pendulum/locales/sk/locale.py new file mode 100644 index 00000000..8d3459ff --- /dev/null +++ b/pendulum/locales/sk/locale.py @@ -0,0 +1,266 @@ +from .custom import translations as custom_translations + + +""" +sk locale file. + +It has been generated automatically and must not be modified directly. +""" + + +locale = { + "plural": lambda n: "few" + if ((n == n and (n >= 2 and n <= 4)) and (0 == 0 and (0 == 0))) + else "many" + if (not (0 == 0 and (0 == 0))) + else "one" + if ((n == n and (n == 1)) and (0 == 0 and (0 == 0))) + else "other", + "ordinal": lambda n: "other", + "translations": { + "days": { + "abbreviated": { + 0: "ne", + 1: "po", + 2: "ut", + 3: "st", + 4: "št", + 5: "pi", + 6: "so", + }, + "narrow": { + 0: "n", + 1: "p", + 2: "u", + 3: "s", + 4: "š", + 5: "p", + 6: "s", + }, + "short": { + 0: "ne", + 1: "po", + 2: "ut", + 3: "st", + 4: "št", + 5: "pi", + 6: "so", + }, + "wide": { + 0: "nedeľa", + 1: "pondelok", + 2: "utorok", + 3: "streda", + 4: "štvrtok", + 5: "piatok", + 6: "sobota", + }, + }, + "months": { + "abbreviated": { + 1: "jan", + 2: "feb", + 3: "mar", + 4: "apr", + 5: "máj", + 6: "jún", + 7: "júl", + 8: "aug", + 9: "sep", + 10: "okt", + 11: "nov", + 12: "dec", + }, + "narrow": { + 1: "j", + 2: "f", + 3: "m", + 4: "a", + 5: "m", + 6: "j", + 7: "j", + 8: "a", + 9: "s", + 10: "o", + 11: "n", + 12: "d", + }, + "wide": { + 1: "januára", + 2: "februára", + 3: "marca", + 4: "apríla", + 5: "mája", + 6: "júna", + 7: "júla", + 8: "augusta", + 9: "septembra", + 10: "októbra", + 11: "novembra", + 12: "decembra", + }, + }, + "units": { + "year": { + "one": "{0} rok", + "few": "{0} roky", + "many": "{0} roka", + "other": "{0} rokov", + }, + "month": { + "one": "{0} mesiac", + "few": "{0} mesiace", + "many": "{0} mesiaca", + "other": "{0} mesiacov", + }, + "week": { + "one": "{0} týždeň", + "few": "{0} týždne", + "many": "{0} týždňa", + "other": "{0} týždňov", + }, + "day": { + "one": "{0} deň", + "few": "{0} dni", + "many": "{0} dňa", + "other": "{0} dní", + }, + "hour": { + "one": "{0} hodina", + "few": "{0} hodiny", + "many": "{0} hodiny", + "other": "{0} hodín", + }, + "minute": { + "one": "{0} minúta", + "few": "{0} minúty", + "many": "{0} minúty", + "other": "{0} minút", + }, + "second": { + "one": "{0} sekunda", + "few": "{0} sekundy", + "many": "{0} sekundy", + "other": "{0} sekúnd", + }, + "microsecond": { + "one": "{0} mikrosekunda", + "few": "{0} mikrosekundy", + "many": "{0} mikrosekundy", + "other": "{0} mikrosekúnd", + }, + }, + "relative": { + "year": { + "future": { + "other": "o {0} rokov", + "one": "o {0} rok", + "few": "o {0} roky", + "many": "o {0} roka", + }, + "past": { + "other": "pred {0} rokmi", + "one": "pred {0} rokom", + "few": "pred {0} rokmi", + "many": "pred {0} roka", + }, + }, + "month": { + "future": { + "other": "o {0} mesiacov", + "one": "o {0} mesiac", + "few": "o {0} mesiace", + "many": "o {0} mesiaca", + }, + "past": { + "other": "pred {0} mesiacmi", + "one": "pred {0} mesiacom", + "few": "pred {0} mesiacmi", + "many": "pred {0} mesiaca", + }, + }, + "week": { + "future": { + "other": "o {0} týždňov", + "one": "o {0} týždeň", + "few": "o {0} týždne", + "many": "o {0} týždňa", + }, + "past": { + "other": "pred {0} týždňami", + "one": "pred {0} týždňom", + "few": "pred {0} týždňami", + "many": "pred {0} týždňa", + }, + }, + "day": { + "future": { + "other": "o {0} dní", + "one": "o {0} deň", + "few": "o {0} dni", + "many": "o {0} dňa", + }, + "past": { + "other": "pred {0} dňami", + "one": "pred {0} dňom", + "few": "pred {0} dňami", + "many": "pred {0} dňa", + }, + }, + "hour": { + "future": { + "other": "o {0} hodín", + "one": "o {0} hodinu", + "few": "o {0} hodiny", + "many": "o {0} hodiny", + }, + "past": { + "other": "pred {0} hodinami", + "one": "pred {0} hodinou", + "few": "pred {0} hodinami", + "many": "pred {0} hodinou", + }, + }, + "minute": { + "future": { + "other": "o {0} minút", + "one": "o {0} minútu", + "few": "o {0} minúty", + "many": "o {0} minúty", + }, + "past": { + "other": "pred {0} minútami", + "one": "pred {0} minútou", + "few": "pred {0} minútami", + "many": "pred {0} minúty", + }, + }, + "second": { + "future": { + "other": "o {0} sekúnd", + "one": "o {0} sekundu", + "few": "o {0} sekundy", + "many": "o {0} sekundy", + }, + "past": { + "other": "pred {0} sekundami", + "one": "pred {0} sekundou", + "few": "pred {0} sekundami", + "many": "pred {0} sekundy", + }, + }, + }, + "day_periods": { + "midnight": "o polnoci", + "am": "AM", + "noon": "napoludnie", + "pm": "PM", + "morning1": "ráno", + "morning2": "dopoludnia", + "afternoon1": "popoludní", + "evening1": "večer", + "night1": "v noci", + }, + }, + "custom": custom_translations, +} diff --git a/tests/localization/test_sk.py b/tests/localization/test_sk.py new file mode 100644 index 00000000..df44a3a5 --- /dev/null +++ b/tests/localization/test_sk.py @@ -0,0 +1,113 @@ +from __future__ import annotations + +import pendulum + + +locale = "sk" + + +def test_diff_for_humans(): + with pendulum.test(pendulum.datetime(2016, 8, 29)): + diff_for_humans() + + +def diff_for_humans(): + d = pendulum.now().subtract(seconds=1) + assert d.diff_for_humans(locale=locale) == "pred 1 sekundou" + + d = pendulum.now().add(seconds=1) + assert d.diff_for_humans(locale=locale) == "o 1 sekundu" + + d = pendulum.now().add(seconds=2) + assert d.diff_for_humans(locale=locale) == "o 2 sekundy" + + d = pendulum.now().add(seconds=5) + assert d.diff_for_humans(locale=locale) == "o 5 sekúnd" + + d = pendulum.now().subtract(seconds=20) + assert d.diff_for_humans(locale=locale) == "pred 20 sekundami" + + d = pendulum.now().subtract(minutes=1) + assert d.diff_for_humans(locale=locale) == "pred 1 minútou" + + d = pendulum.now().subtract(minutes=2) + assert d.diff_for_humans(locale=locale) == "pred 2 minútami" + + d = pendulum.now().add(minutes=5) + assert d.diff_for_humans(locale=locale) == "o 5 minút" + + d = pendulum.now().subtract(hours=1) + assert d.diff_for_humans(locale=locale) == "pred 1 hodinou" + + d = pendulum.now().subtract(hours=2) + assert d.diff_for_humans(locale=locale) == "pred 2 hodinami" + + d = pendulum.now().subtract(hours=5) + assert d.diff_for_humans(locale=locale) == "pred 5 hodinami" + + d = pendulum.now().subtract(days=1) + assert d.diff_for_humans(locale=locale) == "pred 1 dňom" + + d = pendulum.now().subtract(days=2) + assert d.diff_for_humans(locale=locale) == "pred 2 dňami" + + d = pendulum.now().subtract(weeks=1) + assert d.diff_for_humans(locale=locale) == "pred 1 týždňom" + + d = pendulum.now().subtract(weeks=2) + assert d.diff_for_humans(locale=locale) == "pred 2 týždňami" + + d = pendulum.now().subtract(months=1) + assert d.diff_for_humans(locale=locale) == "pred 1 mesiacom" + + d = pendulum.now().subtract(months=2) + assert d.diff_for_humans(locale=locale) == "pred 2 mesiacmi" + + d = pendulum.now().subtract(months=5) + assert d.diff_for_humans(locale=locale) == "pred 5 mesiacmi" + + d = pendulum.now().subtract(years=1) + assert d.diff_for_humans(locale=locale) == "pred 1 rokom" + + d = pendulum.now().subtract(years=2) + assert d.diff_for_humans(locale=locale) == "pred 2 rokmi" + + d = pendulum.now().subtract(years=5) + assert d.diff_for_humans(locale=locale) == "pred 5 rokmi" + + d = pendulum.now().add(seconds=1) + d2 = pendulum.now() + assert d.diff_for_humans(d2, locale=locale) == "1 sekunda po" + assert d2.diff_for_humans(d, locale=locale) == "1 sekunda pred" + + assert d.diff_for_humans(d2, True, locale=locale) == "1 sekunda" + assert d2.diff_for_humans(d.add(seconds=1), True, locale=locale) == "2 sekundy" + + d = pendulum.now().add(seconds=20) + d2 = pendulum.now() + assert d.diff_for_humans(d2, locale=locale) == "20 sekúnd po" + assert d2.diff_for_humans(d, locale=locale) == "20 sekúnd pred" + + d = pendulum.now().add(seconds=10) + d2 = pendulum.now() + assert d.diff_for_humans(d2, True, locale=locale) == "10 sekúnd" + assert d2.diff_for_humans(d.add(seconds=1), True, locale=locale) == "11 sekúnd" + + +def test_format(): + d = pendulum.datetime(2016, 8, 29, 7, 3, 6, 123456) + assert d.format("dddd", locale=locale) == "pondelok" + assert d.format("ddd", locale=locale) == "po" + assert d.format("MMMM", locale=locale) == "augusta" + assert d.format("MMM", locale=locale) == "aug" + assert d.format("A", locale=locale) == "AM" + assert d.format("Qo", locale=locale) == "3" + assert d.format("Mo", locale=locale) == "8" + assert d.format("Do", locale=locale) == "29" + + assert d.format("LT", locale=locale) == "07:03" + assert d.format("LTS", locale=locale) == "07:03:06" + assert d.format("L", locale=locale) == "29.08.2016" + assert d.format("LL", locale=locale) == "29. augusta 2016" + assert d.format("LLL", locale=locale) == "29. augusta 2016 07:03" + assert d.format("LLLL", locale=locale) == "pondelok, 29. augusta 2016 07:03"