1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
<?php
namespace Bitweaver\Plugins;
/**
* @package Plugins
* @author Bimal Poudel
* @copyright since 2006, Bimal Poudel
* @support https://www.odesk.com/o/profiles/users/_~~657b70cc7f2c616a/
* @contact http://www.sanjaal.com
* @company Sanjaal Corps
*/
/*
* Makes a word plural, with easy guessing only.
* http://www.factmonster.com/ipka/A0886509.html
* @url http://www.smarty.net/forums/viewtopic.php?t=18399
* @example {'page'|plural:2}
*/
function smarty_modifier_plural($word = '', $counter = 0)
{
# What to append to the word to make it plural?
$plural_marker = 's';
# Words ending in [ o ]
if(preg_match('/o$/', $word))
{
$plural_marker = 'es';
}
# Words ending in [ y ]
# frequency => frequencies, copy => copies, company => companies
# cookie => cookies
if(preg_match('/y$/', $word))
{
$plural_marker = 'ies';
# Remove the last letter: [ y ]
$word = substr($word, 0, strlen($word) - 1);
}
# Words having [ oo ] in the second last letters.
# foot => feet, goose => geese
if(preg_match('/oo([a-z])?$/', $word, $data))
{
$plural_marker = 'ee' . $data[1];
$word = substr($word, 0, strlen($word) - 3);
}
$plural = $word . (($counter != 1) ? $plural_marker : '');
return $plural;
}
|