#36142: django.shortcuts.get_object_or_404 does not support translation for
error
messages (i18n)
-------------------------------------+-------------------------------------
Reporter: justbackend | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: | Version: 5.2
Internationalization |
Severity: Normal | Resolution:
Keywords: i18 | Triage Stage: Accepted
Internationalization |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz):
* stage: Unreviewed => Accepted
* version: 5.1 => 5.2
Old description:
> {{{
> class WheatProvidingViewSet(viewsets.ModelViewSet):
> queryset = WheatProviding.objects.all()
> serializer_class = WheatProvidingSerializer
>
> def destroy(self, request, *args, **kwargs):
> instance = self.get_object()
> }}}
>
> The code above demonstrates a Django REST Framework (DRF) ModelViewSet.
> When a non-existent ID is provided, the destroy method raises a 404 Not
> Found error. However, the error message is not translated.
>
> The root cause of this issue is that ModelViewSet relies on Django’s
> get_object_or_404 function, which does not support internationalization
> (i18n) for its error messages.
>
> Could you consider adding support for translations in the
> get_object_or_404 function? This enhancement would allow DRF to natively
> support localized error messages, improving its usability in multilingual
> applications.
New description:
{{{
class WheatProvidingViewSet(viewsets.ModelViewSet):
queryset = WheatProviding.objects.all()
serializer_class = WheatProvidingSerializer
def destroy(self, request, *args, **kwargs):
instance = self.get_object()
}}}
The code above demonstrates a Django REST Framework (DRF) ModelViewSet.
When a non-existent ID is provided, the destroy method raises a 404 Not
Found error. However, the error message is not translated.
The root cause of this issue is that ModelViewSet relies on Django’s
get_object_or_404 function, which does not support internationalization
(i18n) for its error messages.
Could you consider adding support for translations in the
get_object_or_404 function? This enhancement would allow DRF to natively
support localized error messages, improving its usability in multilingual
applications.
--
Comment:
I think that localizing that message makes sense as it is potentially
user-facing, as the use case in the ticket description shows.
--
Ticket URL: <https://code.djangoproject.com/ticket/36142#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/01070194a6eeea8a-26620377-513a-4a1f-bb80-52301605d5dc-000000%40eu-central-1.amazonses.com.