Posted by Owen Barton on August 27, 2008 at 10:27pm
| 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
| Attachment | Size |
|---|---|
| pluralize.patch | 3.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
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.#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.