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

AttachmentSize
pluralize.patch3.85 KB

#1

Owen Barton - August 27, 2008 - 22:29

BTW - these are based on the RoR inflector...

Also, code is cleaned up according to Drupal coding standards.

#2

NancyDru - August 28, 2008 - 15:36

Thanks, Owen. Before I commit it, we do require an update for the documentation as well.

#3

Owen Barton - August 28, 2008 - 16:43
Status:needs review» reviewed & tested by the community

Added docs to http://drupal.org/node/213368

#4

NancyDru - August 28, 2008 - 20:16
Status:reviewed & tested by the community» fixed

I saw that. Thank you.

Committed to both branches.

#5

Anonymous (not verified) - September 11, 2008 - 20:22
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

#6

jpmckinney - October 21, 2009 - 20:41
Version:HEAD» 6.x-1.x-dev
Category:feature request» bug report
Status:closed» needs review

The following:

<?php
 
foreach ($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 $plural variable used earlier in the pluralize_en function.

Also, the foreach should be foreach ($irregular as $singular => $plural), based on the format of $irregular.

Same goes for the singularize_en function. Here is a patch to fix that.

AttachmentSize
300820-fix.patch 2.45 KB
 
 

Drupal is a registered trademark of Dries Buytaert.