Add functions to pluralize and singularize English nouns
Owen Barton - August 27, 2008 - 22:27
| Project: | Helpers |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
These are originally from http://www.phpclasses.org/browse/file/12343.html and work surprisingly well (considering the messiness of the English language!).
They were licenced under the LGPL, so I hereby relicensing this copy under the ordinary GPL according to section 3 of the LGPL ;)
http://www.opensource.org/licenses/lgpl-2.1.php
| Attachment | Size |
|---|---|
| pluralize.patch | 3.85 KB |

#1
BTW - these are based on the RoR inflector...
Also, code is cleaned up according to Drupal coding standards.
#2
Thanks, Owen. Before I commit it, we do require an update for the documentation as well.
#3
Added docs to http://drupal.org/node/213368
#4
I saw that. Thank you.
Committed to both branches.
#5
Automatically closed -- issue fixed for two weeks with no activity.
#6
The following:
<?phpforeach ($irregular as $plural => $singular) {
if (preg_match('/('.$plural.')$/i', $word, $arr)) {
return preg_replace('/('.$plural.')$/i', substr($arr[0], 0, 1).substr($singular, 1), $word);
}
}
?>
overwrites the
$pluralvariable used earlier in thepluralize_enfunction.Also, the
foreachshould beforeach ($irregular as $singular => $plural), based on the format of$irregular.Same goes for the
singularize_enfunction. Here is a patch to fix that.