This widget enables you to correctly pluralize labels for dynamic data fields.
For example, suppose you have pages for events, that display messages such as "There are 100 people attending". Maybe you also have an AJAX button on each page that lets users join an event, adding 1 to the count. If an event has "1 person attending", it would be nice for the label to change to "2 people attending" when a user joins the event. This widget facilitates this by providing a
Yii 1.0 or above
Extract the release file under
The widget takes a
contents array as a parameter. Every element of
contents can be of type
'value'. See below for a usage example:
$this->widget('application.widgets.pluralizer.pluralizer', array( 'contents' => array( array('plain', 'There'), array('pluralize', 'are', 'is'), array('value', count($attendees)), array('pluralize', 'people', 'person'), array('plain', 'attending!'), ) ));
The widget converts this into HTML of the following form:
<span class="pluralizer-container"> There <span class="singular hidden">is</span> <span class="plural">are</span> <span class="value">100</span> <span class="singular hidden">person</span> <span class="plural">people</span> attending! </span>
Whenever the contents of the
pluralize() to adjust the pluralization of each element.
You can place any number of instances of this widget on a page, and
pluralize() will adjust each the pluralization within each container according to its value.