Skip to content

Commit

Permalink
bug #52526 Add some more non-countable English nouns (paullallier)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

Add some more non-countable English nouns

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | N/A
| License       | MIT

`@acirulis` spotted that equipment was missing here: api-platform/core#5957

I've added that and a few more non-countable nouns that I think are reasonably likely to be used by someone.  Arguably, time and work could also be here since they are normally non-countable, but there cases where times and works would be correct too.

And I corrected vocal to vowel, which is the correct English term

I'm not sure if this needs extra tests - happy to add if needed.

Commits
-------

cd6a28c Add some more non-countable English nouns
  • Loading branch information
fabpot committed Nov 18, 2023
2 parents 823cc1f + cd6a28c commit abff175
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions src/Symfony/Component/String/Inflector/EnglishInflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class EnglishInflector implements InflectorInterface
private const PLURAL_MAP = [
// First entry: plural suffix, reversed
// Second entry: length of plural suffix
// Third entry: Whether the suffix may succeed a vocal
// Third entry: Whether the suffix may succeed a vowel
// Fourth entry: Whether the suffix may succeed a consonant
// Fifth entry: singular suffix, normal

Expand Down Expand Up @@ -162,7 +162,7 @@ final class EnglishInflector implements InflectorInterface
private const SINGULAR_MAP = [
// First entry: singular suffix, reversed
// Second entry: length of singular suffix
// Third entry: Whether the suffix may succeed a vocal
// Third entry: Whether the suffix may succeed a vowel
// Fourth entry: Whether the suffix may succeed a consonant
// Fifth entry: plural suffix, normal

Expand Down Expand Up @@ -343,15 +343,30 @@ final class EnglishInflector implements InflectorInterface
// deer
'reed',

// equipment
'tnempiuqe',

// feedback
'kcabdeef',

// fish
'hsif',

// health
'htlaeh',

// history
'yrotsih',

// info
'ofni',

// information
'noitamrofni',

// money
'yenom',

// moose
'esoom',

Expand All @@ -363,6 +378,9 @@ final class EnglishInflector implements InflectorInterface

// species
'seiceps',

// traffic
'ciffart',
];

/**
Expand Down Expand Up @@ -399,14 +417,14 @@ public function singularize(string $plural): array
if ($j === $suffixLength) {
// Is there any character preceding the suffix in the plural string?
if ($j < $pluralLength) {
$nextIsVocal = false !== strpos('aeiou', $lowerPluralRev[$j]);
$nextIsVowel = false !== strpos('aeiou', $lowerPluralRev[$j]);

if (!$map[2] && $nextIsVocal) {
// suffix may not succeed a vocal but next char is one
if (!$map[2] && $nextIsVowel) {
// suffix may not succeed a vowel but next char is one
break;
}

if (!$map[3] && !$nextIsVocal) {
if (!$map[3] && !$nextIsVowel) {
// suffix may not succeed a consonant but next char is one
break;
}
Expand Down Expand Up @@ -479,14 +497,14 @@ public function pluralize(string $singular): array
if ($j === $suffixLength) {
// Is there any character preceding the suffix in the plural string?
if ($j < $singularLength) {
$nextIsVocal = false !== strpos('aeiou', $lowerSingularRev[$j]);
$nextIsVowel = false !== strpos('aeiou', $lowerSingularRev[$j]);

if (!$map[2] && $nextIsVocal) {
// suffix may not succeed a vocal but next char is one
if (!$map[2] && $nextIsVowel) {
// suffix may not succeed a vowel but next char is one
break;
}

if (!$map[3] && !$nextIsVocal) {
if (!$map[3] && !$nextIsVowel) {
// suffix may not succeed a consonant but next char is one
break;
}
Expand Down

0 comments on commit abff175

Please sign in to comment.