Skip to content

[String] Fix #54611 pluralization of -on ending words + singularization of -a ending foreign words #54634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions src/Symfony/Component/Inflector/Tests/InflectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function singularizeProvider()
['atlases', ['atlas', 'atlase', 'atlasis']],
['axes', ['ax', 'axe', 'axis']],
['babies', 'baby'],
['bacteria', ['bacterion', 'bacterium']],
['bacteria', 'bacterium'],
['bases', ['bas', 'base', 'basis']],
['batches', ['batch', 'batche']],
['beaux', 'beau'],
Expand All @@ -48,6 +48,7 @@ public static function singularizeProvider()
['bureaux', 'bureau'],
['buses', ['bus', 'buse', 'busis']],
['bushes', ['bush', 'bushe']],
['buttons', 'button'],
['calves', ['calf', 'calve', 'calff']],
['cars', 'car'],
['cassettes', ['cassett', 'cassette']],
Expand All @@ -58,10 +59,12 @@ public static function singularizeProvider()
['circuses', ['circus', 'circuse', 'circusis']],
['cliffs', 'cliff'],
['committee', 'committee'],
['corpora', 'corpus'],
['coupons', 'coupon'],
['crises', ['cris', 'crise', 'crisis']],
['criteria', ['criterion', 'criterium']],
['criteria', 'criterion'],
['cups', 'cup'],
['coupons', 'coupon'],
['curricula', 'curriculum'],
['data', 'data'],
['days', 'day'],
['discos', 'disco'],
Expand All @@ -87,6 +90,7 @@ public static function singularizeProvider()
['funguses', ['fungus', 'funguse', 'fungusis']],
['garages', ['garag', 'garage']],
['geese', 'goose'],
['genera', 'genus'],
['halves', ['half', 'halve', 'halff']],
['hats', 'hat'],
['heroes', ['hero', 'heroe']],
Expand All @@ -107,6 +111,8 @@ public static function singularizeProvider()
['lives', 'life'],
['matrices', ['matrex', 'matrix', 'matrice']],
['matrixes', 'matrix'],
['media', 'medium'],
['memoranda', 'memorandum'],
['men', 'man'],
['mice', 'mouse'],
['moves', 'move'],
Expand All @@ -120,7 +126,7 @@ public static function singularizeProvider()
['parties', 'party'],
['people', 'person'],
['persons', 'person'],
['phenomena', ['phenomenon', 'phenomenum']],
['phenomena', 'phenomenon'],
['photos', 'photo'],
['pianos', 'piano'],
['plateaux', 'plateau'],
Expand All @@ -144,7 +150,7 @@ public static function singularizeProvider()
['spies', 'spy'],
['staves', ['staf', 'stave', 'staff']],
['stories', 'story'],
['strata', ['straton', 'stratum']],
['strata', 'stratum'],
['suitcases', ['suitcas', 'suitcase', 'suitcasis']],
['syllabi', 'syllabus'],
['tags', 'tag'],
Expand Down Expand Up @@ -195,7 +201,9 @@ public static function pluralizeProvider()
['bureau', ['bureaus', 'bureaux']],
['bus', 'buses'],
['bush', 'bushes'],
['button', 'buttons'],
['calf', ['calfs', 'calves']],
['campus', 'campuses'],
['car', 'cars'],
['cassette', 'cassettes'],
['cave', 'caves'],
Expand All @@ -205,10 +213,11 @@ public static function pluralizeProvider()
['circus', 'circuses'],
['cliff', 'cliffs'],
['committee', 'committees'],
['coupon', 'coupons'],
['crisis', 'crises'],
['criteria', 'criterion'],
['criterion', 'criteria'],
['cup', 'cups'],
['coupon', 'coupons'],
['curriculum', 'curricula'],
['data', 'data'],
['day', 'days'],
['disco', 'discos'],
Expand All @@ -232,10 +241,12 @@ public static function pluralizeProvider()
['half', ['halfs', 'halves']],
['hat', 'hats'],
['hero', 'heroes'],
['hippocampus', 'hippocampi'],
['hippopotamus', 'hippopotami'], // hippopotamuses
['hoax', 'hoaxes'],
['hoof', ['hoofs', 'hooves']],
['house', 'houses'],
['icon', 'icons'],
['index', ['indicies', 'indexes']],
['ion', 'ions'],
['iris', 'irises'],
Expand All @@ -248,6 +259,8 @@ public static function pluralizeProvider()
['louse', 'lice'],
['man', 'men'],
['matrix', ['matricies', 'matrixes']],
['medium', 'media'],
['memorandum', 'memoranda'],
['mouse', 'mice'],
['move', 'moves'],
['movie', 'movies'],
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Inflector/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"php": ">=7.2.5",
"symfony/deprecation-contracts": "^2.1|^3",
"symfony/polyfill-php80": "^1.16",
"symfony/string": "^5.3.10|^6.0"
"symfony/string": "^5.4.41|^6.4.9"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Inflector\\": "" },
Expand Down
59 changes: 34 additions & 25 deletions src/Symfony/Component/String/Inflector/EnglishInflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,32 @@ final class EnglishInflector implements InflectorInterface
// Fourth entry: Whether the suffix may succeed a consonant
// Fifth entry: singular suffix, normal

// bacteria (bacterium), criteria (criterion), phenomena (phenomenon)
['a', 1, true, true, ['on', 'um']],
// bacteria (bacterium)
['airetcab', 8, true, true, 'bacterium'],

// corpora (corpus)
['aroproc', 7, true, true, 'corpus'],

// criteria (criterion)
['airetirc', 8, true, true, 'criterion'],

// curricula (curriculum)
['alucirruc', 9, true, true, 'curriculum'],

// genera (genus)
['areneg', 6, true, true, 'genus'],

// media (medium)
['aidem', 5, true, true, 'medium'],

// memoranda (memorandum)
['adnaromem', 9, true, true, 'memorandum'],

// phenomena (phenomenon)
['anemonehp', 9, true, true, 'phenomenon'],

// strata (stratum)
['atarts', 6, true, true, 'stratum'],

// nebulae (nebula)
['ea', 2, true, true, 'a'],
Expand Down Expand Up @@ -141,7 +165,7 @@ final class EnglishInflector implements InflectorInterface
// shoes (shoe)
['se', 2, true, true, ['', 'e']],

// status (status)
// status (status)
['sutats', 6, true, true, 'status'],

// tags (tag)
Expand Down Expand Up @@ -241,7 +265,7 @@ final class EnglishInflector implements InflectorInterface
// albums (album)
['mubla', 5, true, true, 'albums'],

// bacteria (bacterium), criteria (criterion), phenomena (phenomenon)
// bacteria (bacterium), curricula (curriculum), media (medium), memoranda (memorandum), phenomena (phenomenon), strata (stratum)
['mu', 2, true, true, 'a'],

// men (man), women (woman)
Expand All @@ -250,20 +274,11 @@ final class EnglishInflector implements InflectorInterface
// people (person)
['nosrep', 6, true, true, ['persons', 'people']],

// bacteria (bacterium), criteria (criterion), phenomena (phenomenon)
['noi', 3, true, true, 'ions'],

// coupon (coupons)
['nop', 3, true, true, 'pons'],

// seasons (season), treasons (treason), poisons (poison), lessons (lesson)
['nos', 3, true, true, 'sons'],

// icons (icon)
['noc', 3, true, true, 'cons'],
// criteria (criterion)
['noiretirc', 9, true, true, 'criteria'],

// bacteria (bacterium), criteria (criterion), phenomena (phenomenon)
['no', 2, true, true, 'a'],
// phenomena (phenomenon)
['nonemonehp', 10, true, true, 'phenomena'],

// echoes (echo)
['ohce', 4, true, true, 'echoes'],
Expand Down Expand Up @@ -404,9 +419,6 @@ final class EnglishInflector implements InflectorInterface
'erawdrah',
];

/**
* {@inheritdoc}
*/
public function singularize(string $plural): array
{
$pluralRev = strrev($plural);
Expand Down Expand Up @@ -438,7 +450,7 @@ public function singularize(string $plural): array
if ($j === $suffixLength) {
// Is there any character preceding the suffix in the plural string?
if ($j < $pluralLength) {
$nextIsVowel = false !== strpos('aeiou', $lowerPluralRev[$j]);
$nextIsVowel = str_contains('aeiou', $lowerPluralRev[$j]);

if (!$map[2] && $nextIsVowel) {
// suffix may not succeed a vowel but next char is one
Expand Down Expand Up @@ -483,9 +495,6 @@ public function singularize(string $plural): array
return [$plural];
}

/**
* {@inheritdoc}
*/
public function pluralize(string $singular): array
{
$singularRev = strrev($singular);
Expand Down Expand Up @@ -518,7 +527,7 @@ public function pluralize(string $singular): array
if ($j === $suffixLength) {
// Is there any character preceding the suffix in the plural string?
if ($j < $singularLength) {
$nextIsVowel = false !== strpos('aeiou', $lowerSingularRev[$j]);
$nextIsVowel = str_contains('aeiou', $lowerSingularRev[$j]);

if (!$map[2] && $nextIsVowel) {
// suffix may not succeed a vowel but next char is one
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function singularizeProvider()
['atlases', ['atlas', 'atlase', 'atlasis']],
['axes', ['ax', 'axe', 'axis']],
['babies', 'baby'],
['bacteria', ['bacterion', 'bacterium']],
['bacteria', 'bacterium'],
['bases', ['bas', 'base', 'basis']],
['batches', ['batch', 'batche']],
['beaux', 'beau'],
Expand All @@ -46,6 +46,7 @@ public static function singularizeProvider()
['bureaux', 'bureau'],
['buses', ['bus', 'buse', 'busis']],
['bushes', ['bush', 'bushe']],
['buttons', 'button'],
['calves', ['calf', 'calve', 'calff']],
['cars', 'car'],
['cassettes', ['cassett', 'cassette']],
Expand All @@ -57,10 +58,12 @@ public static function singularizeProvider()
['cliffs', 'cliff'],
['codes', 'code'],
['committee', 'committee'],
['corpora', 'corpus'],
['coupons', 'coupon'],
['crises', ['cris', 'crise', 'crisis']],
['criteria', ['criterion', 'criterium']],
['criteria', 'criterion'],
['cups', 'cup'],
['coupons', 'coupon'],
['curricula', 'curriculum'],
['data', 'data'],
['days', 'day'],
['discos', 'disco'],
Expand All @@ -86,6 +89,7 @@ public static function singularizeProvider()
['funguses', ['fungus', 'funguse', 'fungusis']],
['garages', ['garag', 'garage']],
['geese', 'goose'],
['genera', 'genus'],
['halves', ['half', 'halve', 'halff']],
['hats', 'hat'],
['heroes', ['hero', 'heroe']],
Expand All @@ -106,6 +110,8 @@ public static function singularizeProvider()
['lives', 'life'],
['matrices', ['matrex', 'matrix', 'matrice']],
['matrixes', 'matrix'],
['media', 'medium'],
['memoranda', 'memorandum'],
['men', 'man'],
['mice', 'mouse'],
['moves', 'move'],
Expand All @@ -120,7 +126,7 @@ public static function singularizeProvider()
['parties', 'party'],
['people', 'person'],
['persons', 'person'],
['phenomena', ['phenomenon', 'phenomenum']],
['phenomena', 'phenomenon'],
['photos', 'photo'],
['pianos', 'piano'],
['plateaux', 'plateau'],
Expand All @@ -146,7 +152,7 @@ public static function singularizeProvider()
['status', 'status'],
['statuses', 'status'],
['stories', 'story'],
['strata', ['straton', 'stratum']],
['strata', 'stratum'],
['suitcases', ['suitcas', 'suitcase', 'suitcasis']],
['syllabi', 'syllabus'],
['tags', 'tag'],
Expand Down Expand Up @@ -200,7 +206,9 @@ public static function pluralizeProvider()
['bureau', ['bureaus', 'bureaux']],
['bus', 'buses'],
['bush', 'bushes'],
['button', 'buttons'],
['calf', ['calfs', 'calves']],
['campus', 'campuses'],
['car', 'cars'],
['cassette', 'cassettes'],
['cave', 'caves'],
Expand All @@ -210,10 +218,11 @@ public static function pluralizeProvider()
['circus', 'circuses'],
['cliff', 'cliffs'],
['committee', 'committees'],
['coupon', 'coupons'],
['crisis', 'crises'],
['criteria', 'criterion'],
['criterion', 'criteria'],
['cup', 'cups'],
['coupon', 'coupons'],
['curriculum', 'curricula'],
['data', 'data'],
['day', 'days'],
['disco', 'discos'],
Expand All @@ -237,10 +246,12 @@ public static function pluralizeProvider()
['half', ['halfs', 'halves']],
['hat', 'hats'],
['hero', 'heroes'],
['hippocampus', 'hippocampi'],
['hippopotamus', 'hippopotami'], // hippopotamuses
['hoax', 'hoaxes'],
['hoof', ['hoofs', 'hooves']],
['house', 'houses'],
['icon', 'icons'],
['index', ['indicies', 'indexes']],
['ion', 'ions'],
['iris', 'irises'],
Expand All @@ -253,6 +264,8 @@ public static function pluralizeProvider()
['louse', 'lice'],
['man', 'men'],
['matrix', ['matricies', 'matrixes']],
['medium', 'media'],
['memorandum', 'memoranda'],
['mouse', 'mice'],
['move', 'moves'],
['movie', 'movies'],
Expand Down Expand Up @@ -286,6 +299,7 @@ public static function pluralizeProvider()
['shoe', 'shoes'],
['species', 'species'],
['status', ['status', 'statuses']],
['stratum', 'strata'],
['spy', 'spies'],
['staff', 'staves'],
['story', 'stories'],
Expand Down