Smarty
[ class tree: Smarty ] [ index: Smarty ] [ all elements ]

Source for file modifier.plural.php

Documentation is available at modifier.plural.php

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

Documentation generated on Wed, 29 Jul 2015 13:57:09 +0000 by phpDocumentor 1.5.0-lsces