D
D
Dmitry Shelygin2020-06-27 20:36:51
Internationalization and localization
Dmitry Shelygin, 2020-06-27 20:36:51

How to translate only custom errors to DRF?

DRF out of the box can give errors in Russian, if you specify Accept-Language: ru.
I need to translate my custom errors.
The documentation says the following:

If you're only translating custom error messages that exist inside your project codebase you don't need to copy the REST framework source django.po file into a LOCALE_PATHS folder, and can instead simply run Django's standard makemessages process.

Accordingly, what I did:
1. Wrapped the texts of errors in 2. In the settings indicated 3. Fulfilled A .po file was created and here the first problem is immediately. In this file, in addition to my texts, there is also a huge pile of dzhang texts that I do not need to translate, because. they are already translated by dzhanga. I would like not to redefine the ru translation, but to supplement it. Any ideas? Next I ran , this built the .mo file. And hence the second problem. My errors have been translated, of course, but the standard DRF errors are now not in Russian (eg "This field is required", "Authentication credentials were not provided", etc.). _('Error message')
LOCALE_PATHS
python manage.py makemessages -l ru
python manage.py compilemessages

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Shelygin, 2020-07-08
@JustJew

It was necessary to simply exclude texts from packages using the --ignore key

python manage.py makemessages -l ru --ignore=env
python manage.py compilemessages -l ru --ignore=env

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question