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

CommentFileSizeAuthor
#6 300820-fix.patch2.45 KBjpmckinney
pluralize.patch3.85 KBOwen Barton
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Owen Barton’s picture

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

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

NancyDru’s picture

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

Owen Barton’s picture

Status: Needs review » Reviewed & tested by the community
NancyDru’s picture

Status: Reviewed & tested by the community » Fixed

I saw that. Thank you.

Committed to both branches.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

jpmckinney’s picture

Version: master » 6.x-1.x-dev
Category: feature » bug
Status: Closed (fixed) » Needs review
FileSize
2.45 KB

The following:

  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.

ice5nake’s picture

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

moonray’s picture

Might this have to do with multi-byte characters?

noah’s picture

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:

  $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.