Created
November 25, 2009 12:28
-
-
Save pal/242674 to your computer and use it in GitHub Desktop.
Pluralizer Helper for CakePHP. Makes for easier use of the Inflector.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Pluralizes a singular term based on a count. | |
* | |
* This function will take a count and a singular term and pluralize | |
* the term if the count is not equal to 1. | |
* | |
* Example usage: | |
* <code> | |
* You have <?php echo $plural->ize($message_count, 'message'); ?> messages. | |
* </code> | |
* | |
* @param int $count total count of items | |
* @param string $singular_term the singular term | |
* @return string the count and the singular or plural form of the supplied term | |
* @link http://debuggable.com/posts/cakephp-pluralize-helper:480f4dfe-fbf8-464a-95da-4764cbdd56cb Original source | |
*/ | |
class PluralHelper extends AppHelper { | |
function ize($count, $singular_term) { | |
if ($count != 1) { | |
return $count . ' ' . Inflector::pluralize($singular_term); | |
} | |
return $count . ' ' . $singular_term; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment