Yii CRUD generator and plural forms

yii logoYii framework has a really nice CRUD generator that can speed up building back-end applications, which tend to be rather similar and therefore repetitive. If you prepare reasonable taxonomy of the underlying database tables, it also manages the page headers pretty well. If your table is called album, for instance, it will generate a page for editing albums with a header “Edit Album #1”, an index page called “List Albums” or the management page called “Manage Albums”. As you can see, it will even handle the plural forms. However, this works fine for English projects, but may not be desirable for other languages.

What I usually do is find the method called pluralize() in framework/gii/CCodeModel.php and basically disable the method by changing it like this:

public function pluralize($name)
		return $name; # this disables the method no matter where it gets used
			'/(m)ove$/i' => '\1oves',
			'/(f)oot$/i' => '\1eet',
			'/(c)hild$/i' => '\1hildren',
			'/(h)uman$/i' => '\1umans',
			'/(m)an$/i' => '\1en',
			'/(s)taff$/i' => '\1taff',
			'/(t)ooth$/i' => '\1eeth',
			'/(p)erson$/i' => '\1eople',
			'/([m|l])ouse$/i' => '\1ice',
			'/(x|ch|ss|sh|us|as|is|os)$/i' => '\1es',
			'/([^aeiouy]|qu)y$/i' => '\1ies',
			'/(?:([^f])fe|([lr])f)$/i' => '\1\2ves',
			'/(shea|lea|loa|thie)f$/i' => '\1ves',
			'/([ti])um$/i' => '\1a',
			'/(tomat|potat|ech|her|vet)o$/i' => '\1oes',
			'/(bu)s$/i' => '\1ses',
			'/(ax|test)is$/i' => '\1es',
			'/s$/' => 's',
		foreach($rules as $rule=>$replacement)
				return preg_replace($rule,$replacement,$name);
		return $name.'s';

Another way of dealing with this is to remove the generated names based on the table names completely. You can edit the files like:


prior to making use of the CRUD generator, and change the H1 headers and the labels to something more generic (i.e. simply “Edit”, “View”, “Update row #1”).