I have googled this for very long time but with no results. I`m beginner to Django so I don't know all features it have. But this problem is very important for client :-( Could you help me, please?
So, I have this model defined:
from django.utils.translation import ugettext_lazy as _
class Product(Model):
#translation for model and set db table name
class Meta:
verbose_name = _('product')
verbose_name_plural = _('products')
...
Now, because of czech language, I need these written in admin list:
Everywhere else, I'm using ungettext
sucessfully. However, I don't know, how to get count in Meta. I have found this as abstract (but seems to be useless):
class Model(DjangoModel):
class Meta:
abstract = True
def get_description(self):
return ungettext(self.verbose_name, self.verbose_name_plural, self.count) % \
{'count':self.count, 'name':self.name}
Source is from django internationalization: counter is not available when marking strings for pluralization
Maybe, at the end would be fine to show language definition (tried to add/remove %s from msgid
):
msgid "%s product"
msgid_plural "%s products"
msgstr[0] "%s 1 výrobek"
msgstr[1] "%s 2 výrobky"
msgstr[2] "%s 5 výrobků"
If you need more info for question, sure I will provide it.
Thank you a lot in advance.
UPDATE
Please, be sure, that I'm using following in the .po file:
"Plural-Forms: nplurals=3; plural=((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2);\n"
Once more, anywhere else but admin models, IT IS working. It's quetion not how to run multi pluralization in general, but how to change anything in admin (e.g. new abstract model etc.) to run it there...
You need to put in your .po file:
"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n"
Then, in your template you use the plural form passing a valid counter. Gettext have all information needed:
After getting deep into Django sources, this is not possible to do it in admin usecases without overriding many of functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With