Skip to content

Commit 49921e5

Browse files
committed
feat: add Gujarati (gu) localization support
Add complete Gujarati locale with: - Day names (abbreviated, narrow, short, wide) - Month names (abbreviated, narrow, wide) - Unit translations (year, month, week, day, hour, minute, second, microsecond) - Relative time expressions (past and future) - Day periods (midnight, am, noon, pm, morning, afternoon, evening, night) - Custom translations for relative time strings and date formats - Full test coverage for diff_for_humans() Translations sourced from CLDR data via Babel library. Follows the same pattern as the Hindi (hi) locale added in #902.
1 parent 0a88aec commit 49921e5

4 files changed

Lines changed: 311 additions & 0 deletions

File tree

src/pendulum/locales/gu/__init__.py

Whitespace-only changes.

src/pendulum/locales/gu/custom.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
gu 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": "DD/MM/YYYY",
17+
"LL": "D MMMM YYYY",
18+
"LLL": "D MMMM YYYY, h:mm A",
19+
"LLLL": "dddd, D MMMM YYYY, h:mm A",
20+
},
21+
}

src/pendulum/locales/gu/locale.py

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
from pendulum.locales.gu.custom import translations as custom_translations
2+
3+
4+
"""
5+
gu 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: 'one',
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_gu.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 = "gu"
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)