In DRF all default error messages are already translated. But I need to translate my own error messages. What I did:
- Put all my error messages into
_()
, where_
isgettext
- In settings set
LOCALE_PATHS
tolocale
folder - Ran
python manage.py makemessages -l ru
That created .po file and here goes the first trouble. In the .po file are my messages and besides that there are a lot of default Django messages which I don't want to translate. (I do not want to override the translation, I want to extend it)
I translated my messages in the .po file, then I ran python manage.py compilemessages
which created .mo file. And here is the second trouble.
All my messages are now translated, but default DRF messages (they were not in the .po file, there were Django messages, not DRF) are not already translated, they are only in English (e.g. Authentication credentials were not provided
, This field is required
, etc.)