Skip to content

Commit d40ab96

Browse files
authored
feat: add Hindi (hi) localization support (#902)
* feat: add Hindi (hi) localization support * fix: formatting of tests/localization/test_hi.py to use double quote strings
1 parent fc386be commit d40ab96

File tree

4 files changed

+311
-0
lines changed

4 files changed

+311
-0
lines changed

src/pendulum/locales/hi/__init__.py

Whitespace-only changes.

src/pendulum/locales/hi/custom.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
hi custom locale file.
3+
"""
4+
5+
translations = {
6+
"units": {"few_second": "कुछ सेकंड"},
7+
# Relative time
8+
"ago": "{} पहले",
9+
"from_now": "{} में",
10+
"after": "{0} बाद",
11+
"before": "{0} पहले",
12+
# Date formats
13+
"date_formats": {
14+
"LTS": "h:mm:ss A",
15+
"LT": "h:mm A",
16+
"L": "MM/DD/YYYY",
17+
"LL": "MMMM D, YYYY",
18+
"LLL": "MMMM D, YYYY h:mm A",
19+
"LLLL": "dddd, MMMM D, YYYY h:mm A",
20+
},
21+
}

src/pendulum/locales/hi/locale.py

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
from pendulum.locales.hi.custom import translations as custom_translations
2+
3+
4+
"""
5+
hi locale file.
6+
7+
It has been generated automatically and must not be modified directly.
8+
"""
9+
10+
11+
locale = {
12+
'plural': lambda n: 'one' if ((n == n and ((n == 0))) or (n == n and ((n == 1)))) else 'other',
13+
'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',
14+
'translations': {
15+
'days': {
16+
'abbreviated': {
17+
0: 'सोम',
18+
1: 'मंगल',
19+
2: 'बुध',
20+
3: 'गुरु',
21+
4: 'शुक्र',
22+
5: 'शनि',
23+
6: 'रवि',
24+
},
25+
'narrow': {
26+
0: 'सो',
27+
1: 'मं',
28+
2: 'बु',
29+
3: 'गु',
30+
4: 'शु',
31+
5: 'श',
32+
6: 'र',
33+
},
34+
'short': {
35+
0: 'सो',
36+
1: 'मं',
37+
2: 'बु',
38+
3: 'गु',
39+
4: 'शु',
40+
5: 'श',
41+
6: 'र',
42+
},
43+
'wide': {
44+
0: 'सोमवार',
45+
1: 'मंगलवार',
46+
2: 'बुधवार',
47+
3: 'गुरुवार',
48+
4: 'शुक्रवार',
49+
5: 'शनिवार',
50+
6: 'रविवार',
51+
},
52+
},
53+
'months': {
54+
'abbreviated': {
55+
1: 'जन॰',
56+
2: 'फ़र॰',
57+
3: 'मार्च',
58+
4: 'अप्रैल',
59+
5: 'मई',
60+
6: 'जून',
61+
7: 'जुल॰',
62+
8: 'अग॰',
63+
9: 'सित॰',
64+
10: 'अक्तू॰',
65+
11: 'नव॰',
66+
12: 'दिस॰',
67+
},
68+
'narrow': {
69+
1: 'ज',
70+
2: 'फ़',
71+
3: 'मा',
72+
4: 'अ',
73+
5: 'म',
74+
6: 'जू',
75+
7: 'जु',
76+
8: 'अ',
77+
9: 'सि',
78+
10: 'अ',
79+
11: 'न',
80+
12: 'दि',
81+
},
82+
'wide': {
83+
1: 'जनवरी',
84+
2: 'फ़रवरी',
85+
3: 'मार्च',
86+
4: 'अप्रैल',
87+
5: 'मई',
88+
6: 'जून',
89+
7: 'जुलाई',
90+
8: 'अगस्त',
91+
9: 'सितंबर',
92+
10: 'अक्तूबर',
93+
11: 'नवंबर',
94+
12: 'दिसंबर',
95+
},
96+
},
97+
'units': {
98+
'year': {
99+
'one': '{0} वर्ष',
100+
'other': '{0} वर्ष',
101+
},
102+
'month': {
103+
'one': '{0} महीना',
104+
'other': '{0} महीने',
105+
},
106+
'week': {
107+
'one': '{0} सप्ताह',
108+
'other': '{0} सप्ताह',
109+
},
110+
'day': {
111+
'one': '{0} दिन',
112+
'other': '{0} दिन',
113+
},
114+
'hour': {
115+
'one': '{0} घंटा',
116+
'other': '{0} घंटे',
117+
},
118+
'minute': {
119+
'one': '{0} मिनट',
120+
'other': '{0} मिनट',
121+
},
122+
'second': {
123+
'one': '{0} सेकंड',
124+
'other': '{0} सेकंड',
125+
},
126+
'microsecond': {
127+
'one': '{0} माइक्रोसेकंड',
128+
'other': '{0} माइक्रोसेकंड',
129+
},
130+
},
131+
'relative': {
132+
'year': {
133+
'future': {
134+
'other': '{0} वर्ष में',
135+
'one': '{0} वर्ष में',
136+
},
137+
'past': {
138+
'other': '{0} वर्ष पहले',
139+
'one': '{0} वर्ष पहले',
140+
},
141+
},
142+
'month': {
143+
'future': {
144+
'other': '{0} माह में',
145+
'one': '{0} माह में',
146+
},
147+
'past': {
148+
'other': '{0} माह पहले',
149+
'one': '{0} माह पहले',
150+
},
151+
},
152+
'week': {
153+
'future': {
154+
'other': '{0} सप्ताह में',
155+
'one': '{0} सप्ताह में',
156+
},
157+
'past': {
158+
'other': '{0} सप्ताह पहले',
159+
'one': '{0} सप्ताह पहले',
160+
},
161+
},
162+
'day': {
163+
'future': {
164+
'other': '{0} दिन में',
165+
'one': '{0} दिन में',
166+
},
167+
'past': {
168+
'other': '{0} दिन पहले',
169+
'one': '{0} दिन पहले',
170+
},
171+
},
172+
'hour': {
173+
'future': {
174+
'other': '{0} घंटे में',
175+
'one': '{0} घंटे में',
176+
},
177+
'past': {
178+
'other': '{0} घंटे पहले',
179+
'one': '{0} घंटे पहले',
180+
},
181+
},
182+
'minute': {
183+
'future': {
184+
'other': '{0} मिनट में',
185+
'one': '{0} मिनट में',
186+
},
187+
'past': {
188+
'other': '{0} मिनट पहले',
189+
'one': '{0} मिनट पहले',
190+
},
191+
},
192+
'second': {
193+
'future': {
194+
'other': '{0} सेकंड में',
195+
'one': '{0} सेकंड में',
196+
},
197+
'past': {
198+
'other': '{0} सेकंड पहले',
199+
'one': '{0} सेकंड पहले',
200+
},
201+
},
202+
},
203+
'day_periods': {
204+
"midnight": "मध्यरात्रि",
205+
"am": "AM",
206+
"noon": "दोपहर",
207+
"pm": "PM",
208+
"morning1": "सुबह में",
209+
"afternoon1": "दोपहर में",
210+
"evening1": "शाम में",
211+
"night1": "रात में",
212+
},
213+
'week_data': {
214+
'min_days': 1,
215+
'first_day': 0,
216+
'weekend_start': 5,
217+
'weekend_end': 6,
218+
},
219+
},
220+
'custom': custom_translations
221+
}

tests/localization/test_hi.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from __future__ import annotations
2+
3+
import pendulum
4+
5+
6+
locale = "hi"
7+
8+
9+
def test_diff_for_humans():
10+
with pendulum.travel_to(pendulum.datetime(2025, 6, 4), freeze=True):
11+
diff_for_humans()
12+
13+
14+
def diff_for_humans():
15+
d = pendulum.now().subtract(seconds=1)
16+
assert d.diff_for_humans(locale=locale) == "कुछ सेकंड पहले"
17+
18+
d = pendulum.now().subtract(seconds=2)
19+
assert d.diff_for_humans(locale=locale) == "कुछ सेकंड पहले"
20+
21+
d = pendulum.now().subtract(seconds=21)
22+
assert d.diff_for_humans(locale=locale) == "21 सेकंड पहले"
23+
24+
d = pendulum.now().subtract(minutes=1)
25+
assert d.diff_for_humans(locale=locale) == "1 मिनट पहले"
26+
27+
d = pendulum.now().subtract(minutes=2)
28+
assert d.diff_for_humans(locale=locale) == "2 मिनट पहले"
29+
30+
d = pendulum.now().subtract(hours=1)
31+
assert d.diff_for_humans(locale=locale) == "1 घंटे पहले"
32+
33+
d = pendulum.now().subtract(hours=2)
34+
assert d.diff_for_humans(locale=locale) == "2 घंटे पहले"
35+
36+
d = pendulum.now().subtract(days=1)
37+
assert d.diff_for_humans(locale=locale) == "1 दिन पहले"
38+
39+
d = pendulum.now().subtract(days=2)
40+
assert d.diff_for_humans(locale=locale) == "2 दिन पहले"
41+
42+
d = pendulum.now().subtract(weeks=1)
43+
assert d.diff_for_humans(locale=locale) == "1 सप्ताह पहले"
44+
45+
d = pendulum.now().subtract(weeks=2)
46+
assert d.diff_for_humans(locale=locale) == "2 सप्ताह पहले"
47+
48+
d = pendulum.now().subtract(months=1)
49+
assert d.diff_for_humans(locale=locale) == "1 माह पहले"
50+
51+
d = pendulum.now().subtract(months=2)
52+
assert d.diff_for_humans(locale=locale) == "2 माह पहले"
53+
54+
d = pendulum.now().subtract(years=1)
55+
assert d.diff_for_humans(locale=locale) == "1 वर्ष पहले"
56+
57+
d = pendulum.now().subtract(years=2)
58+
assert d.diff_for_humans(locale=locale) == "2 वर्ष पहले"
59+
60+
d = pendulum.now().add(seconds=1)
61+
assert d.diff_for_humans(locale=locale) == "कुछ सेकंड में"
62+
63+
d = pendulum.now().add(seconds=1)
64+
d2 = pendulum.now()
65+
assert d.diff_for_humans(d2, locale=locale) == "कुछ सेकंड बाद"
66+
assert d2.diff_for_humans(d, locale=locale) == "कुछ सेकंड पहले"
67+
68+
assert d.diff_for_humans(d2, True, locale=locale) == "कुछ सेकंड"
69+
assert d2.diff_for_humans(d.add(seconds=1), True, locale=locale) == "कुछ सेकंड"

0 commit comments

Comments
 (0)