Source for file inflections.php
Documentation is available at inflections.php
* File containing the Inflections class and default inflections
* @version $Id: inflector.php 195 2006-04-03 22:27:26Z haas $
* @copyright (c) 2005 John Peterson
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Start Default Inflections
Inflections::singular('/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i', '\1\2sis');
# End Default Inflections
* Implement the Trax naming convention
* Inflections is never instantiated.
public static $plurals = array();
public static $singulars = array();
public static $uncountables = array();
# Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression.
# The replacement should always be a string that may include references to the matched data from the rule.
function plural($rule, $replacement) {
array_unshift(self::$plurals, array("rule" => $rule, "replacement" => $replacement));
# Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression.
# The replacement should always be a string that may include references to the matched data from the rule.
function singular($rule, $replacement) {
array_unshift(self::$singulars, array("rule" => $rule, "replacement" => $replacement));
# Specifies a new irregular that applies to both pluralization and singularization at the same time. This can only be used
# for strings, not regular expressions. You simply pass the irregular in singular and plural form.
# Inflections::irregular('octopus', 'octopi')
# Inflections::irregular('person', 'people')
# Add uncountable words that shouldn't be attempted inflected.
# Inflections::uncountable("money")
# Inflections::uncountable("money", "information")
# Inflections::uncountable(array("money", "information", "rice"))
foreach($args as $word) {
self::$uncountables[] = $word;
# Clears the loaded inflections within a given scope (functionault is :all). Give the scope as a symbol of the inflection type,
# the options are: "plurals", "singulars", "uncountables"
# Inflections::clear("all")
# Inflections::clear("plurals")
function clear($scope = "all") {
self::$plurals = self::$singulars = self::$uncountables = array();
|