From 9e9639704d08f0506c3e48a08991d06e994c41c4 Mon Sep 17 00:00:00 2001 From: Jayanth Gudimella Date: Thu, 5 Jun 2025 10:57:07 +0530 Subject: [PATCH 1/2] feat: add Hindi (hi) localization support --- src/pendulum/locales/hi/__init__.py | 0 src/pendulum/locales/hi/custom.py | 21 +++ src/pendulum/locales/hi/locale.py | 221 ++++++++++++++++++++++++++++ tests/localization/test_hi.py | 70 +++++++++ 4 files changed, 312 insertions(+) create mode 100644 src/pendulum/locales/hi/__init__.py create mode 100644 src/pendulum/locales/hi/custom.py create mode 100644 src/pendulum/locales/hi/locale.py create mode 100644 tests/localization/test_hi.py diff --git a/src/pendulum/locales/hi/__init__.py b/src/pendulum/locales/hi/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/pendulum/locales/hi/custom.py b/src/pendulum/locales/hi/custom.py new file mode 100644 index 00000000..f8b06ff7 --- /dev/null +++ b/src/pendulum/locales/hi/custom.py @@ -0,0 +1,21 @@ +""" +hi custom locale file. +""" + +translations = { + "units": {"few_second": "कुछ सेकंड"}, + # Relative time + "ago": "{} पहले", + "from_now": "{} में", + "after": "{0} बाद", + "before": "{0} पहले", + # Date formats + "date_formats": { + "LTS": "h:mm:ss A", + "LT": "h:mm A", + "L": "MM/DD/YYYY", + "LL": "MMMM D, YYYY", + "LLL": "MMMM D, YYYY h:mm A", + "LLLL": "dddd, MMMM D, YYYY h:mm A", + }, +} diff --git a/src/pendulum/locales/hi/locale.py b/src/pendulum/locales/hi/locale.py new file mode 100644 index 00000000..e5383dba --- /dev/null +++ b/src/pendulum/locales/hi/locale.py @@ -0,0 +1,221 @@ +from pendulum.locales.hi.custom import translations as custom_translations + + +""" +hi locale file. + +It has been generated automatically and must not be modified directly. +""" + + +locale = { + 'plural': lambda n: 'one' if ((n == n and ((n == 0))) or (n == n and ((n == 1)))) else 'other', + 'ordinal': lambda n: 'few' if (n == n and ((n == 4))) else 'many' if (n == n and ((n == 6))) else 'one' if (n == n and ((n == 1))) else 'two' if (n == n and ((n == 2) or (n == 3))) else 'other', + 'translations': { + 'days': { + 'abbreviated': { + 0: 'सोम', + 1: 'मंगल', + 2: 'बुध', + 3: 'गुरु', + 4: 'शुक्र', + 5: 'शनि', + 6: 'रवि', + }, + 'narrow': { + 0: 'सो', + 1: 'मं', + 2: 'बु', + 3: 'गु', + 4: 'शु', + 5: 'श', + 6: 'र', + }, + 'short': { + 0: 'सो', + 1: 'मं', + 2: 'बु', + 3: 'गु', + 4: 'शु', + 5: 'श', + 6: 'र', + }, + 'wide': { + 0: 'सोमवार', + 1: 'मंगलवार', + 2: 'बुधवार', + 3: 'गुरुवार', + 4: 'शुक्रवार', + 5: 'शनिवार', + 6: 'रविवार', + }, + }, + 'months': { + 'abbreviated': { + 1: 'जन॰', + 2: 'फ़र॰', + 3: 'मार्च', + 4: 'अप्रैल', + 5: 'मई', + 6: 'जून', + 7: 'जुल॰', + 8: 'अग॰', + 9: 'सित॰', + 10: 'अक्तू॰', + 11: 'नव॰', + 12: 'दिस॰', + }, + 'narrow': { + 1: 'ज', + 2: 'फ़', + 3: 'मा', + 4: 'अ', + 5: 'म', + 6: 'जू', + 7: 'जु', + 8: 'अ', + 9: 'सि', + 10: 'अ', + 11: 'न', + 12: 'दि', + }, + 'wide': { + 1: 'जनवरी', + 2: 'फ़रवरी', + 3: 'मार्च', + 4: 'अप्रैल', + 5: 'मई', + 6: 'जून', + 7: 'जुलाई', + 8: 'अगस्त', + 9: 'सितंबर', + 10: 'अक्तूबर', + 11: 'नवंबर', + 12: 'दिसंबर', + }, + }, + 'units': { + 'year': { + 'one': '{0} वर्ष', + 'other': '{0} वर्ष', + }, + 'month': { + 'one': '{0} महीना', + 'other': '{0} महीने', + }, + 'week': { + 'one': '{0} सप्ताह', + 'other': '{0} सप्ताह', + }, + 'day': { + 'one': '{0} दिन', + 'other': '{0} दिन', + }, + 'hour': { + 'one': '{0} घंटा', + 'other': '{0} घंटे', + }, + 'minute': { + 'one': '{0} मिनट', + 'other': '{0} मिनट', + }, + 'second': { + 'one': '{0} सेकंड', + 'other': '{0} सेकंड', + }, + 'microsecond': { + 'one': '{0} माइक्रोसेकंड', + 'other': '{0} माइक्रोसेकंड', + }, + }, + 'relative': { + 'year': { + 'future': { + 'other': '{0} वर्ष में', + 'one': '{0} वर्ष में', + }, + 'past': { + 'other': '{0} वर्ष पहले', + 'one': '{0} वर्ष पहले', + }, + }, + 'month': { + 'future': { + 'other': '{0} माह में', + 'one': '{0} माह में', + }, + 'past': { + 'other': '{0} माह पहले', + 'one': '{0} माह पहले', + }, + }, + 'week': { + 'future': { + 'other': '{0} सप्ताह में', + 'one': '{0} सप्ताह में', + }, + 'past': { + 'other': '{0} सप्ताह पहले', + 'one': '{0} सप्ताह पहले', + }, + }, + 'day': { + 'future': { + 'other': '{0} दिन में', + 'one': '{0} दिन में', + }, + 'past': { + 'other': '{0} दिन पहले', + 'one': '{0} दिन पहले', + }, + }, + 'hour': { + 'future': { + 'other': '{0} घंटे में', + 'one': '{0} घंटे में', + }, + 'past': { + 'other': '{0} घंटे पहले', + 'one': '{0} घंटे पहले', + }, + }, + 'minute': { + 'future': { + 'other': '{0} मिनट में', + 'one': '{0} मिनट में', + }, + 'past': { + 'other': '{0} मिनट पहले', + 'one': '{0} मिनट पहले', + }, + }, + 'second': { + 'future': { + 'other': '{0} सेकंड में', + 'one': '{0} सेकंड में', + }, + 'past': { + 'other': '{0} सेकंड पहले', + 'one': '{0} सेकंड पहले', + }, + }, + }, + 'day_periods': { + "midnight": "मध्यरात्रि", + "am": "AM", + "noon": "दोपहर", + "pm": "PM", + "morning1": "सुबह में", + "afternoon1": "दोपहर में", + "evening1": "शाम में", + "night1": "रात में", + }, + 'week_data': { + 'min_days': 1, + 'first_day': 0, + 'weekend_start': 5, + 'weekend_end': 6, + }, + }, + 'custom': custom_translations +} diff --git a/tests/localization/test_hi.py b/tests/localization/test_hi.py new file mode 100644 index 00000000..3c103e07 --- /dev/null +++ b/tests/localization/test_hi.py @@ -0,0 +1,70 @@ +from __future__ import annotations + +import pendulum + + +locale = "hi" + + +def test_diff_for_humans(): + with pendulum.travel_to(pendulum.datetime(2025, 6, 4), freeze=True): + diff_for_humans() + + +def diff_for_humans(): + d = pendulum.now().subtract(seconds=1) + assert d.diff_for_humans(locale=locale) == 'कुछ सेकंड पहले' + + d = pendulum.now().subtract(seconds=2) + assert d.diff_for_humans(locale=locale) == 'कुछ सेकंड पहले' + + d = pendulum.now().subtract(seconds=21) + assert d.diff_for_humans(locale=locale) == '21 सेकंड पहले' + + d = pendulum.now().subtract(minutes=1) + assert d.diff_for_humans(locale=locale) == '1 मिनट पहले' + + d = pendulum.now().subtract(minutes=2) + assert d.diff_for_humans(locale=locale) == '2 मिनट पहले' + + d = pendulum.now().subtract(hours=1) + assert d.diff_for_humans(locale=locale) == '1 घंटे पहले' + + d = pendulum.now().subtract(hours=2) + assert d.diff_for_humans(locale=locale) == '2 घंटे पहले' + + d = pendulum.now().subtract(days=1) + assert d.diff_for_humans(locale=locale) == '1 दिन पहले' + + d = pendulum.now().subtract(days=2) + assert d.diff_for_humans(locale=locale) == '2 दिन पहले' + + d = pendulum.now().subtract(weeks=1) + assert d.diff_for_humans(locale=locale) == '1 सप्ताह पहले' + + d = pendulum.now().subtract(weeks=2) + assert d.diff_for_humans(locale=locale) == '2 सप्ताह पहले' + + d = pendulum.now().subtract(months=1) + assert d.diff_for_humans(locale=locale) == '1 माह पहले' + + d = pendulum.now().subtract(months=2) + assert d.diff_for_humans(locale=locale) == '2 माह पहले' + + d = pendulum.now().subtract(years=1) + assert d.diff_for_humans(locale=locale) == '1 वर्ष पहले' + + d = pendulum.now().subtract(years=2) + assert d.diff_for_humans(locale=locale) == '2 वर्ष पहले' + + d = pendulum.now().add(seconds=1) + assert d.diff_for_humans(locale=locale) == 'कुछ सेकंड में' + + d = pendulum.now().add(seconds=1) + d2 = pendulum.now() + assert d.diff_for_humans(d2, locale=locale) == 'कुछ सेकंड बाद' + assert d2.diff_for_humans(d, locale=locale) == 'कुछ सेकंड पहले' + + assert d.diff_for_humans(d2, True, locale=locale) == 'कुछ सेकंड' + assert d2.diff_for_humans(d.add(seconds=1), True, + locale=locale) == 'कुछ सेकंड' From 22c2662ec4be0f5942d1f22e519ac657100761ee Mon Sep 17 00:00:00 2001 From: Jayanth Gudimella Date: Thu, 5 Jun 2025 12:46:01 +0530 Subject: [PATCH 2/2] fix: formatting of tests/localization/test_hi.py to use double quote strings --- tests/localization/test_hi.py | 41 +++++++++++++++++------------------ 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/tests/localization/test_hi.py b/tests/localization/test_hi.py index 3c103e07..9abcd8b4 100644 --- a/tests/localization/test_hi.py +++ b/tests/localization/test_hi.py @@ -13,58 +13,57 @@ def test_diff_for_humans(): def diff_for_humans(): d = pendulum.now().subtract(seconds=1) - assert d.diff_for_humans(locale=locale) == 'कुछ सेकंड पहले' + assert d.diff_for_humans(locale=locale) == "कुछ सेकंड पहले" d = pendulum.now().subtract(seconds=2) - assert d.diff_for_humans(locale=locale) == 'कुछ सेकंड पहले' + assert d.diff_for_humans(locale=locale) == "कुछ सेकंड पहले" d = pendulum.now().subtract(seconds=21) - assert d.diff_for_humans(locale=locale) == '21 सेकंड पहले' + assert d.diff_for_humans(locale=locale) == "21 सेकंड पहले" d = pendulum.now().subtract(minutes=1) - assert d.diff_for_humans(locale=locale) == '1 मिनट पहले' + assert d.diff_for_humans(locale=locale) == "1 मिनट पहले" d = pendulum.now().subtract(minutes=2) - assert d.diff_for_humans(locale=locale) == '2 मिनट पहले' + assert d.diff_for_humans(locale=locale) == "2 मिनट पहले" d = pendulum.now().subtract(hours=1) - assert d.diff_for_humans(locale=locale) == '1 घंटे पहले' + assert d.diff_for_humans(locale=locale) == "1 घंटे पहले" d = pendulum.now().subtract(hours=2) - assert d.diff_for_humans(locale=locale) == '2 घंटे पहले' + assert d.diff_for_humans(locale=locale) == "2 घंटे पहले" d = pendulum.now().subtract(days=1) - assert d.diff_for_humans(locale=locale) == '1 दिन पहले' + assert d.diff_for_humans(locale=locale) == "1 दिन पहले" d = pendulum.now().subtract(days=2) - assert d.diff_for_humans(locale=locale) == '2 दिन पहले' + assert d.diff_for_humans(locale=locale) == "2 दिन पहले" d = pendulum.now().subtract(weeks=1) - assert d.diff_for_humans(locale=locale) == '1 सप्ताह पहले' + assert d.diff_for_humans(locale=locale) == "1 सप्ताह पहले" d = pendulum.now().subtract(weeks=2) - assert d.diff_for_humans(locale=locale) == '2 सप्ताह पहले' + assert d.diff_for_humans(locale=locale) == "2 सप्ताह पहले" d = pendulum.now().subtract(months=1) - assert d.diff_for_humans(locale=locale) == '1 माह पहले' + assert d.diff_for_humans(locale=locale) == "1 माह पहले" d = pendulum.now().subtract(months=2) - assert d.diff_for_humans(locale=locale) == '2 माह पहले' + assert d.diff_for_humans(locale=locale) == "2 माह पहले" d = pendulum.now().subtract(years=1) - assert d.diff_for_humans(locale=locale) == '1 वर्ष पहले' + assert d.diff_for_humans(locale=locale) == "1 वर्ष पहले" d = pendulum.now().subtract(years=2) - assert d.diff_for_humans(locale=locale) == '2 वर्ष पहले' + assert d.diff_for_humans(locale=locale) == "2 वर्ष पहले" d = pendulum.now().add(seconds=1) - assert d.diff_for_humans(locale=locale) == 'कुछ सेकंड में' + assert d.diff_for_humans(locale=locale) == "कुछ सेकंड में" d = pendulum.now().add(seconds=1) d2 = pendulum.now() - assert d.diff_for_humans(d2, locale=locale) == 'कुछ सेकंड बाद' - assert d2.diff_for_humans(d, locale=locale) == 'कुछ सेकंड पहले' + assert d.diff_for_humans(d2, locale=locale) == "कुछ सेकंड बाद" + assert d2.diff_for_humans(d, locale=locale) == "कुछ सेकंड पहले" - assert d.diff_for_humans(d2, True, locale=locale) == 'कुछ सेकंड' - assert d2.diff_for_humans(d.add(seconds=1), True, - locale=locale) == 'कुछ सेकंड' + assert d.diff_for_humans(d2, True, locale=locale) == "कुछ सेकंड" + assert d2.diff_for_humans(d.add(seconds=1), True, locale=locale) == "कुछ सेकंड"