pluralizer Allows pluralization for dynamic data labels

  1. Requirements
  2. Installation
  3. Usage

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 pluralize() JavaScript function that acts on the contents of the widget.


Yii 1.0 or above


Extract the release file under protected/widgets


The widget takes a contents array as a parameter. Every element of contents can be of type 'plain', 'pluralize', or '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: ~~~ [html]

<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>


Whenever the contents of the #value span changes, run the JavaScript function 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.

3 0
Yii Version: 1.1
License: BSD-2-Clause
Category: User Interface
Tags: grammar
Developed by: BadgerPriest
Created on: Jun 15, 2011
Last updated: 13 years ago


show all