Copyright © Stillat.com—A site by John Koster

The plural helper method will attempt to return a plural version of the given $value. It does this through a series of specialized internal functions, that will not be covered in great detail here. This helper method will apply general rules to strings ending in common character sequences, handle special cases and will not attempt some very specific strings. The change in a word, such as to show tense, or the number of items, is called an inflection.

doctrine/inflector

Previous versions of Laravel managed word inflections itself. Starting with version 5, Laravel now uses the doctrine/inflector package. This package is used by the Illuminate\Support\Pluralizer class, which is utilized by both the plural and the singular method.

Signature

Te signature of the plural method is:

public static function plural(
        $value,
        $count = 2
    );

Example Use

The method takes the $value that should be pluralized, and the $count of the items. If the $count is equal to 1, the original $value is returned.

use Illuminate\Support\Str;

// cow
echo Str::plural('cow', 1);

// cows
echo Str::plural('cows');

// person
echo Str::plural('person', 1);

// people
echo Str::plural('person');

Assuming the following messages array:

// The user's messages.
$messages = [
    'You have a meeting on Saturday.',
    'Your inbox is 90% full',
    'Do not eat yellow snow'
];

We could display the number of messages to the user like so:

use Illuminate\Support\Str;

$messageCount = count($messages);

echo 'You have '.$messageCount.' unread '. 
     Str::plural('message',$messageCount);

If the user had one message, the above example would output:

You have 1 unread message.

Since the $messages array has 3 items in it, the user would see this:

You have 3 unread messages.

plural Special Cases

Any words, or word endings, in the following table will not be affected by the plural method. This is either because the resulting word is already plural, or because there is no inflection available. Word endings are denoted by the prefix *:

The following table lists the words that are not inflected by the plural method. This is either because the resulting word is already pluralized, or because there are no clear inflection rules available, or they handled separately (see the plural Special cases table).

Special Cases Special Cases Special Cases Special Cases
Amoyese bison Borghese bream
breeches britches buffalo cantus
carp chassis clippers code
caoitus Congoese contretemps corps
data debris diabetese djinn
eland elk equipment Faroese
flounder Foochowese Furniture gallows
Genevese Genoese Glibertese graffiti
headquarters herpes hijinks Hottentotese
information innings jackanapes Kiplingese
Kongoese Lucchese Luggage mackerel
Maltese *media mews moose
mumps Nankingese news nexus
Niasese Pekingese Piedmontese pincers
Postoiese pliers Portuguese proceedings
rabies rice rhinoceros salmon
Sarawakese scissors seabass sea-bass
series Shavese shears siemens
species staff swine testes
trousers trout tuna Vermontese
Wenchowese whitting wildebeest Yengeese

In addition to the general words that are not inflected by the plural method, the following tables list the word patterns or values that will also not be inflected by this method:

Words Not Inflected Words Not Inflected Words Not Inflected Words Not Inflected
*nese *rese *lese *mese
*deer *fish *measles *ois
*pox *sheep *ss people
cookie police

There are also many special cases handled by the plural method. These are generally words that do not have a clear pragmatic method of handling the process of converting the word to its plural equivalent:

Singular Form Plural Form
atlas atlases
axe axes
beef beefs
brother brothers
cafe cafes
chateau chateaux
niveau niveaux
child children
cookie cookies
corpus corpuses
cow cows
criterion criteria
curriculum curricula
demo demos
domino dominos
echo echoes
foot feet
fungus fungi
ganglion ganglions
genie genies
genus genera
graffito graffiti
hippopotamus hippopotami
hoof hoofs
human humans
iris irises
larva larvae
leaf leaves
loaf loaves
man men
medium media
memorandum memoranda
money monies
mongoose mongooses
motto mottoes
move moves
mythos mythoi
niche niches
nucleus nuclei
numen numina
occiput occiputs
octopus octopuses
opus opuses
ox oxen
passerby passersby
penis penises
person people
plateau plateaux
runner-up runners-up
sex sexes
soliloquy soliloquies
son-in-law sons-in-law
syllabus syllabi
testis testes
thief thieves
tooth teeth
tornado tornadoes
trilby trilbys
turf turfs
volcano volcanoes

Global str_plural Helper Function

The str_plural function is a shortcut to calling Str::plural. This function is declared in the global namespace.

John Koster

Join the mailing list to receive awesome blog posts, product updates and more

Cancel Reply

Discussion

To join the discussion leave your name, email and comment below.

Be the first to leave a reply!

Subscribe to the Mailing List

Join the mailing to list to receive product and blog post updates