Pluralization
Pluralization is a complex problem, as different languages have a variety of complex rules for pluralization. By using a "pipe" character, you may distinguish singular and plural forms of a string:
'apples' => 'There is one apple|There are many apples',
You may even create more complex pluralization rules which specify translation strings for multiple number ranges:
'apples' => '{0} There are none|[1,19] There are some|[20,*] There are many',
After defining a translation string that has pluralization options, you may use the trans_choice
function to retrieve the line for a given "count". In this example,
since the count is greater than one, the plural form of the translation
string is returned:
echo trans_choice('messages.apples', 10);
You may also define placeholder attributes in pluralization strings.
These placeholders may be replaced by passing an array as the third
argument to the trans_choice
function:
'minutes_ago' => '{1} :value minute ago|[2,*] :value minutes ago',
echo trans_choice('time.minutes_ago', 5, ['value' => 5]);
If you would like to display the integer value that was passed to the trans_choice
function, you may use the :count
placeholder:
'apples' => '{0} There are none|{1} There is one|[2,*] There are :count',