1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8//this script may only be included - so its better to die if called directly.
9if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
10	header("location: index.php");
11	exit;
12}
13
14/**
15 * \brief Smarty plugin to return plural or singular form of given word based on count
16 * Usage format {pluralize word_count=2 singular_form="mouse" plural_form="mice"}
17 *
18 */
19function smarty_function_pluralize($params, &$smarty)
20{
21	if (empty($params['singular_form']) || ! isset($params['word_count'])) {
22		return;
23	}
24
25	if (empty($params['plural_form'])) {
26		$params['plural_form'] = $params['singular_form'] . 's';
27	}
28
29	return ($params['word_count'] == 1) ? $params['singular_form'] : $params['plural_form'];
30}
31