@@ -253,16 +253,39 @@ all the forms as a string separated by a pipe (``|``)::
253253To translate pluralized messages, use the
254254:method: `Symfony\\ Component\\ Translation\\ Translator::transChoice ` method::
255255
256+ // the %count% placeholder is assigned to the second argument...
256257 $translator->transChoice(
257258 'There is one apple|There are %count% apples',
259+ 10
260+ );
261+
262+ // ...but you can define more placeholders if needed
263+ $translator->transChoice(
264+ 'Hurry up %name%! There is one apple left.|There are %count% apples left.',
258265 10,
259- array('%count%' => 10)
266+ // no need to include %count% here; Symfony does that for you
267+ array('%name%' => $user->getName())
260268 );
261269
262270The second argument (``10 `` in this example) is the *number * of objects being
263271described and is used to determine which translation to use and also to populate
264272the ``%count% `` placeholder.
265273
274+ .. versionadded :: 3.2
275+
276+ Before Symfony 3.2, the placeholder used to select the plural (``%count% ``
277+ in this example) must be included in the third optional argument of the
278+ ``transChoice() `` method::
279+
280+ $translator->transChoice(
281+ 'There is one apple|There are %count% apples',
282+ 10,
283+ array('%count%' => 10)
284+ );
285+
286+ Starting from Symfony 3.2, when the only placeholder is ``%count% ``, you
287+ don't have to pass this third argument.
288+
266289Based on the given number, the translator chooses the right plural form.
267290In English, most words have a singular form when there is exactly one object
268291and a plural form for all other numbers (0, 2, 3...). So, if ``count `` is
@@ -366,11 +389,25 @@ use for translation::
366389 $translator->transChoice(
367390 '{0} There are no apples|{1} There is one apple|]1,Inf[ There are %count% apples',
368391 10,
369- array('%count%' => 10 ),
392+ array(),
370393 'messages',
371394 'fr_FR'
372395 );
373396
397+ .. note ::
398+
399+ Starting from Symfony 3.2, the third argument of ``transChoice() `` is
400+ optional when the only placeholder in use is ``%count% ``. In previous
401+ Symfony versions you needed to define it always::
402+
403+ $translator->transChoice(
404+ '{0} There are no apples|{1} There is one apple|]1,Inf[ There are %count% apples',
405+ 10,
406+ array('%count%' => 10),
407+ 'messages',
408+ 'fr_FR'
409+ );
410+
374411Retrieving the Message Catalogue
375412--------------------------------
376413
0 commit comments