Download & Extend

Add functions to pluralize and singularize English nouns

Project:Helpers
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

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

Comments

#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

Status:needs review» reviewed & tested by the community

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

#4

Status:reviewed & tested by the community» fixed

I saw that. Thank you.

Committed to both branches.

#5

Status:fixed» closed (fixed)

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

#6

Version:master» 6.x-1.x-dev
Category:feature request» bug report
Status:closed (fixed)» 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

#7

pluralize_en is currently returning false in development version when it should not.

#8

Might this have to do with multi-byte characters?

#9

Not sure about the other stuff, but the overwriting issue noticed by jpmckinney is still a problem in the current development version. In this case using singularize_en, we've got:

<?php
  $singular
= array (
   
'/(quiz)zes$/i' => '\\1',
   
'/(matr)ices$/i' => '\\1ix',
    ...

  foreach (
$irregular as $plural => $singular) {
    ...

  foreach (
$singular as $rule => $replacement) {
    ...
?>

By the time we get to "foreach ($singular as $rule => $replacement)" the value of $singular has already been overwritten by "foreach ($irregular as $plural => $singular)".

jpmckinney's patch fixes this issue.

nobody click here