You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have found a serious bug in Symfony translate 3.2.0+ that causes an InvalidArgumentException to be thrown on a common use case involving PO files.
Esentially when a translation has 2 plural forms (e.g. "There is 1 apple" and "There are 2 apples") in a PO file that are not set in a target language an exception is thrown, rather than an empty string returned as in previous versions.
I am attaching a minimal test case.
PO file:
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"
# Untranslated (breaks) (this is the way most standard tools like gettext will represent an untranslated entry)
msgid "There is currently 1 issue"
msgid_plural "There are currently %count% issues"
msgstr[0] ""
msgstr[1] ""
PHP code:
require __DIR__.'/vendor/autoload.php';
$translate = new \Symfony\Component\Translation\Translator('de_DE');
$translate->addLoader('pofile', new \Symfony\Component\Translation\Loader\PoFileLoader());
$translate->addResource('pofile', __DIR__.'/test.po', 'de_DE');
// This works fineecho$translate->transChoice('There are currently %count% bugs', 0) . "\n";
echo$translate->transChoice('There are currently %count% bugs', 1) . "\n";
// This crashes with an InvalidArgumentExceptionecho$translate->transChoice('There are currently %count% issues', 0) . "\n";
Looking at the code, the bug was introduced in #17662.
I have created a PR, #24594, to work around this bug, it handles this case, and also cases where 3 or more plural forms are empty in a PO file (see #24359).
The PR is based against the 3.2 branch. If that's incorrect let me know and I'll rebase it.
Happy to provide further details if needed.
Bjorn
The text was updated successfully, but these errors were encountered:
…anslated plural forms from .po files (BjornTwachtmann)
This PR was squashed before being merged into the 3.3 branch (closes#24594).
Discussion
----------
[Translation] Fix InvalidArgumentException when using untranslated plural forms from .po files
| Q | A
| ------------- | ---
| Branch? | 3.2
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #24593
| License | MIT
This PR fixes the bug in #24593. It's not the absolutely ideal way to address the issue, but I don't see how else to handle it without either dropping support for pips in translation strings, or rearchitecting the code that feeds translations to the MessageSelector as pipe separated in the first place.
Commits
-------
fea815b [Translation] Fix InvalidArgumentException when using untranslated plural forms from .po files
I have found a serious bug in Symfony translate 3.2.0+ that causes an InvalidArgumentException to be thrown on a common use case involving PO files.
Esentially when a translation has 2 plural forms (e.g. "There is 1 apple" and "There are 2 apples") in a PO file that are not set in a target language an exception is thrown, rather than an empty string returned as in previous versions.
I am attaching a minimal test case.
PO file:
PHP code:
Looking at the code, the bug was introduced in #17662.
I have created a PR, #24594, to work around this bug, it handles this case, and also cases where 3 or more plural forms are empty in a PO file (see #24359).
The PR is based against the 3.2 branch. If that's incorrect let me know and I'll rebase it.
Happy to provide further details if needed.
Bjorn
The text was updated successfully, but these errors were encountered: