Yii 1.1: cgrammar

Simple helper for natural, grammatically correct langage (plurals etc)
2 followers

UPDATE: I have renamed this class HGrammar to prevent any conflict.

This extension is a simple helper class which I use to make sure text generated by my application is natural.

Plurals - no need to put bracket(s) after your word(s). Lists - produce a nice, simple and clean list from an array. Vowels - Words beginning with a vowel are prefixed with a/an.

Resources

Documentation

Requirements

  • Yii 1.0 or above

Installation

  • Extract the release file under protected/components or I actually use protected/helpers

Usage

Examples:

[php]

// PLURALS
echo HGrammar::plural($commentCount,'comment'); 
// Output: 'comment' if commentCount is 1, otherwise 'comments'

// LISTS
$people = array('John','Trevor','Qiang');
echo HGrammar::commaList($people);
// Output: 'John, Trevor and Qiang'. 

See PHPDoc for Vowels function

Change Log

July 1, 2010

  • Initial release.

July 2, 2010

  • Changed class name to HGrammar instead of CGrammar

Total 2 comments

#161 report it
Dana at 2010/08/23 06:13pm
Brilliant =)

This one is going to come in very handy!

#329 report it
DarkNSF at 2010/07/08 08:12am
Excellent Idea!

Never a fan of adding an if block for (count == 1).

Leave a comment

Please to leave your comment.

Create extension
Downloads