Search code examples
pythongenshi

Genshi pluralisation


Anyone know how I could show entry/entries as appropriate, in the following fragment of Genshi syntax?

  <span py:if="c.page.item_count">
    ${c.page.item_count} entries.
  </span>

Thanks!


Solution

  • Not pretty, but should work

    <span py:if="c.page.item_count">
      ${c.page.item_count} ${['entries','entry'][c.page.item_count==1]}.
    </span>
    

    or

    <span py:if="c.page.item_count">
      ${c.page.item_count} ${'entry' if c.page.item_count==1 else 'entries'}.
    </span>