views:

176

answers:

3

I'm looking for something like this:

{% trans "There are %{flowers}n flowers in the vase" < flowers:3 %}

Now obviously syntax is fake, but it should be sufficient to demonstrate what I'm looking for.

Should I cook something of my own? It looks like a common usecase, so I was quite surprised that quick web search didn't return anything helpful.

I'm actually starting to loathe working with Django templating system... While I understand that it's designed to enforce separation of application logic from view, it's doing it by being intrusive on my workflow. I should be able to quickly prototype and only when I need to work with designer, and only then, should I have to be more strict about something like this.

+1  A: 

Use {% blocktrans %} instead of {% trans %}.

PiotrLegnica
+2  A: 

I'm not absolutely sure what you're trying to do (what's < flowers:3 supposed to do?), but have you looked at blocktrans?

{% blocktrans count flowers|length as counter %}
    There is one flower in the vase.
{% plural %}
    There are {{ counter }} flowers in the vase.
{% endblocktrans %}
piquadrat
Equal to "... %s ... " % substitution.. Just thought yet another "%" would be ambiguous. Now of course blocktrans is exactly what I need. Can't figure how I missed it? Oh well, got to be more careful next time. Thank you for your help!
deno
A: 

You may find the module inflect.py useful, although it would mean departing from the templating system.

import inflect
p = inflect.engine()
p.num(numflowers, show=False)
return 'There %s %s %s in the vase.' % (
              p.pl('is'),
              p.numwords(numflowers),
              p.pl('flower'))

with numflowers = 1

'There is one flower in the vase.'

with numflowers = 2

'There are two flowers in the vase.'
pwdyson