Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango - multiple pluralization in admin model
    text
    copied!<p>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?</p> <p>So, I have this model defined:</p> <pre><code>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') ... </code></pre> <p>Now, because of czech language, I need these written in admin list:</p> <ul> <li>0 výrobků</li> <li>1 výrobek</li> <li>2-4 výrobky</li> <li>5- výrobků</li> </ul> <p>Everywhere else, I'm using <code>ungettext</code> sucessfully. However, I don't know, how to get count in Meta. I have found this as abstract (but seems to be useless):</p> <pre><code>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} </code></pre> <p>Source is from <a href="https://stackoverflow.com/questions/10517683/django-internationalization-counter-is-not-available-when-marking-strings-for-p">django internationalization: counter is not available when marking strings for pluralization</a></p> <p>Maybe, at the end would be fine to show language definition (tried to add/remove %s from <code>msgid</code>):</p> <pre><code>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ů" </code></pre> <p>If you need more info for question, sure I will provide it.</p> <p>Thank you a lot in advance.</p> <p><strong>UPDATE</strong><br> Please, be sure, that I'm using following in the .po file:</p> <pre><code>"Plural-Forms: nplurals=3; plural=((n==1) ? 0 : (n&gt;=2 &amp;&amp; n&lt;=4) ? 1 : 2);\n" </code></pre> <p>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...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload