Description
Symfony version(s) affected: >=4.3.3
Description
When attempting to translate entries from .po files that are in plural form, translation fails and the original input string (with substitutions) is returned rather than the translated form.
How to reproduce
The following script and .po file illustrate the problem. They work correctly in symfony/translate 4.3.2 and are broken in >=4.3.3
test.po
msgid "Bug Free"
msgstr "Fehler Frei"
msgid "There is currently 1 bug"
msgid_plural "There are currently %count% bugs"
msgstr[0] "Es gibt derzeit ein Fehler"
msgstr[1] "Es gibt derzeit %count% Fehler"
test.php
<?php
require __DIR__.'/vendor/autoload.php';
$translate = new \Symfony\Component\Translation\Translator('de_DE');
$translate->addLoader('pofile', new \Symfony\Component\Translation\Loader\PoFileLoader());
$pofile = __DIR__.'/test.po';
$translate->addResource('pofile', $pofile, 'de_DE');
// This should translate to German, but just outputs the input string since v4.3.3
echo $translate->trans('There is currently 1 bug') . "\n";
echo $translate->trans('There are currently %count% bugs', ['%count%' => 3]) . "\n";
//This still works fine and outputs German in both cases (singular form)
echo $translate->trans('Bug Free') . "\n";
Possible Solution
This bug appears to have been introduced in #31266 . Reverting that code restores the original behaviour. Honestly I'm very confused as to how this was meant to work. Symfony, post this change, appears to be expecting you to ask for translations of plural forms as follows: $translate->trans('There is currently 1 bug|There are currently %count% bugs', ['%count%' => 3])
. This is clearly unacceptable as it a) breaks existing behaviour (which is also standard behaviour across any app that uses .po files) in a patch release, and b) requires the calling code to know details of Symfony's internal representation of a translation.