I have a model with field that is called phone
. In russian it will look like this:
телефон
Sometimes when I try to make queries application will throw me that kind of error messages:
User with field phone already exists
If I set LANGUAGE_CODE
in settings to ru-RU
, then I have add Meta
class which has proper verbose name, previous exception will now throw that kind of message:
Пользователь с таким телефон уже существует
Which is not right.
In context of this message the field phone
should be called телефоном
. It has extra letters in the end.
In some languages, like russian, words will have different endings depending on context of sentence.
I'm trying to use gettext
and generated po
file where it has these lines of code:
#: .\main\models\users.py:77
msgid "phone"
msgstr ""
However, I don't know how to write multiple cases of translation in this code.
Is it possible to make different cases of translation of field names? Is it possible to override not found error specially for this model?
==================UPDATE=========================
I have found standard Django message that is being used for this exception message:
#, python-format
msgid "%(model_name)s with this %(field_label)s already exists."
msgstr "%(model_name)s с таким %(field_label)s уже существует."
Is it possible to override this message specifically for this phone
field??
This is a flaw in Django and should be reported there. It violates the golden rule of software localization "never concatenate translatable strings".
The original msgid should be changed into something like this:
#, python-format
msgid "An object of type '%(model_name)s' with the field label '%(field_label)s' already exists."
msgstr ""
You cannot fix that in your application. And, by the way, not only Russian but probably all languages that have a definite article and genders will be affected by that flaw.