<count>

A convenience tag used to output a count summary with a correctly localized and pluralised label. Works with any kind of collection such as an ActiveRecord association or an array.

Usage

<count:comments/> -> <span class="count">1 Comment</span>

<count:viewings/> -> <span class="count">3 Viewings</span>

The label can be customised using the label attribute, e.g.

<count:comments label="blog post comment"/> -> <span class="count">12 blog post comments</span>

You can pass a summary attribute, which will generate a complete localized sentence. It allows 2 options:

  • boolean (e.g. <count>): it will lookup the ‘tags.count.default’ key in the locale file. If the lookup fails, it will fallback to the english default sentences consistent with the count.
  • String (e.g. <count>): it will lookup the ‘tags.count.offer’ key in the locale file. If the lookup fails, it will fallback to the english default sentences consistent with the count.

Examples

it:
  tags:
    count:
      default:
        zero: "Non ci sono {{label}}"
        one: "C'è solo 1 {{label}}"
        other: "Ci sono {{count}} {{label}}"
      choice:
        zero: "Non ci sono {{label}} da scegliere"
        one: "Puoi scegliere solo una {{label}}"
        other: "Puoi scegliere tra {{count}} {{label}}"

with :en locale and boolean summary (internal defaults)

<count:comments summary/> -> <span class="count">There is 1 Comment</span>
<count:viewings summary/> -> <span class="count">There are 3 Viewings</span>

(note: just add the locale english strings to use like the following examples)

with :it locale and boolean summary (key “tags.count.default”)

<count:comments summary/>
-> count => 0 -> <span class="count">Non ci sono Commenti</span>
-> count => 1 -> <span class="count">C'è solo 1 Commento</span>
-> count => 5 -> <span class="count">Ci sono 5 Commenti</span>

with :it locale and summary=”choice” (key “tags.count.choice”)

<count:comments summary="choice"/>
-> count => 0 -> <span class="count">Non ci sono Commenti da scegliere</span>
-> count => 1 -> <span class="count">Puoi scegliere solo 1 Commento</span>
-> count => 5 -> <span class="count">Puoi scegliere tra 5 Commenti</span>

Additional Notes

  • The prefix attribute is deprecated: use summary instead.

  • Use the lowercase attribute to force the generated label to be lowercase:

      <count:comments lowercase/> -> <span class="count">1 comment</span>
    
  • Use the if-any attribute to output nothing if the count is zero. This can be followed by an <else> tag to handle the empty case:

      <count:comments if-any/><else>There are no comments</else>
    

Show Source


Edit this page