
Provides english word inflection, notation conversion, grammar helpers and internationlization support
1.0.0b15 | Added length checking to ensure blank strings are not being passed to various methods 6/20/11 |
---|---|
1.0.0b14 | Fixed a bug in singularization that would affect words containing the substring mice or lice 2/24/11 |
1.0.0b13 | Fixed the pluralization of video 8/10/10 |
1.0.0b12 | Updated singularize() and pluralize() to be able to handle underscore_CamelCase 8/6/10 |
1.0.0b11 | Fixed custom camelCase to underscore_notation rules 6/23/10 |
1.0.0b10 | Removed e flag from preg_replace() calls 6/8/10 |
1.0.0b9 | Fixed a bug with camelize() and human-friendly strings 6/8/10 |
1.0.0b8 | Added the stem() method 5/27/10 |
1.0.0b7 | Added the $return_error parameter to pluralize() and singularize() 3/30/10 |
1.0.0b6 | Added missing compose() method 3/3/10 |
1.0.0b5 | Fixed reset() to properly reset the singularization and pluralization rules 10/28/09 |
1.0.0b4 | Added caching for various methods - provided significant performance boost to ORM 6/15/09 |
1.0.0b3 | Changed replacement values in preg_replace() calls to be properly escaped 6/11/09 |
1.0.0b2 | Fixed a bug where some words would lose capitalization with pluralize() and singularize() 1/25/09 |
1.0.0b | The initial implementation 9/25/07 |
Adds a custom camelCase to underscore_notation and underscore_notation to camelCase rule
void addCamelUnderscoreRule( string $camel_case, string $underscore_notation )
string | $camel_case | The lower camelCase version of the string |
string | $underscore_notation | The underscore_notation version of the string |
Adds a custom mapping of a non-humanized string to a humanized string for humanize()
void addHumanizeRule( string $non_humanized_string, string $humanized_string )
string | $non_humanized_string | The non-humanized string |
string | $humanized_string | The humanized string |
Adds a custom singular to plural and plural to singular rule for pluralize() and singularize()
void addSingularPluralRule( string $singular, string $plural )
string | $singular | The singular version of the noun |
string | $plural | The plural version of the noun |
Converts an underscore_notation, human-friendly or camelCase string to camelCase
string camelize( string $string, boolean $upper )
string | $string | The string to convert |
boolean | $upper | If the camel case should be UpperCamelCase |
The converted string
Composes text using fText if loaded
string compose( string $message, mixed $component [, ... ] )
string | $message | The message to compose |
mixed | $component [, ... ] | A string or number to insert into the message |
The composed and possible translated message
Makes an underscore_notation, camelCase, or human-friendly string into a human-friendly string
string humanize( string $string )
string | $string | The string to humanize |
The converted string
Returns the singular or plural form of the word or based on the quantity specified
string inflectOnQuantity( mixed $quantity, string $singular_form, string $plural_form=NULL, boolean $use_words_for_single_digits=FALSE )
mixed | $quantity | The quantity (integer) or an array of objects to count |
string | $singular_form | The string to be returned for when $quantity = 1 |
string | $plural_form | The string to be returned for when $quantity != 1, use %d to place the quantity in the string |
boolean | $use_words_for_single_digits | If the numbers 0 to 9 should be written out as words |
Returns the passed terms joined together using rule 2 from Strunk & White's 'The Elements of Style'
string joinArray( array $strings, string $type )
array | $strings | An array of strings to be joined together |
string | $type | The type of join to perform, 'and' or 'or' |
The terms joined together
Returns the plural version of a singular noun
string pluralize( string $singular_noun, boolean $return_error=FALSE )
string | $singular_noun | The singular noun to pluralize |
boolean | $return_error | If this is TRUE and the noun can't be pluralized, FALSE will be returned instead |
The pluralized noun
Allows replacing the joinArray() function with a user defined function
This would be most useful for changing joinArray() to work with languages other than English.
void registerJoinArrayCallback( callback $callback )
callback | $callback | The function to replace joinArray() with - should accept the same parameters and return the same type |
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Resets the configuration of the class
void reset( )
Returns the singular version of a plural noun
string singularize( string $plural_noun, boolean $return_error=FALSE )
string | $plural_noun | The plural noun to singularize |
boolean | $return_error | If this is TRUE and the noun can't be pluralized, FALSE will be returned instead |
The singularized noun
Uses the Porter Stemming algorithm to create the stem of a word, which is useful for searching
See http://tartarus.org/~martin/PorterStemmer/ for details about the algorithm.
string stem( string $word )
string | $word | The word to get the stem of |
The stem of the word
Converts a camelCase, human-friendly or underscore_notation string to underscore_notation
string underscorize( string $string )
string | $string | The string to convert |
The converted string