Skip to content

Commit 582fb95

Browse files
committed
fix: Proper usage of ngettext
1 parent 23c411c commit 582fb95

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

Diff for: rest_framework/exceptions.py

+8-14
Original file line numberDiff line numberDiff line change
@@ -226,30 +226,24 @@ def __init__(self, media_type, detail=None, code=None):
226226
class Throttled(APIException):
227227
status_code = status.HTTP_429_TOO_MANY_REQUESTS
228228
default_detail = _('Request was throttled.')
229-
extra_detail_singular = _('Expected available in {wait} second.')
230-
extra_detail_plural = _('Expected available in {wait} seconds.')
231229
default_code = 'throttled'
232230

233231
def __init__(self, wait=None, detail=None, code=None):
234232
if detail is None:
235233
detail = force_str(self.default_detail)
236234
if wait is not None:
237235
wait = math.ceil(wait)
238-
detail = " ".join(
239-
(
240-
detail,
241-
force_str(
242-
ngettext(
243-
self.extra_detail_singular,
244-
self.extra_detail_plural,
245-
wait,
246-
).format(wait=wait)
247-
),
248-
)
249-
)
236+
detail = " ".join((detail, force_str(self.extra_detail(wait))))
250237
self.wait = wait
251238
super().__init__(detail, code)
252239

240+
def extra_detail(self, wait):
241+
return ngettext(
242+
'Expected available in {wait} second.',
243+
'Expected available in {wait} seconds.',
244+
wait,
245+
).format(wait=wait)
246+
253247

254248
def server_error(request, *args, **kwargs):
255249
"""

0 commit comments

Comments
 (0)