bug #33437 Fix #33427 (sylfabre)

This PR was merged into the 4.3 branch.

Discussion
----------

Fix #33427

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #33427
| License       | MIT
| Doc PR        | none

Fix #33427 by checking if the message returned by the intl-icu catalog is empty. If yes then the translator returns an empty string instead of running `formatIntl()` which uses the constructor of `MessageFormatter` which throws an exception with empty strings.

Commits
-------

414dcebfc4 Fix #33427
This commit is contained in:
Fabien Potencier 2019-09-03 18:15:52 +02:00
commit 8798c87def
2 changed files with 10 additions and 0 deletions

View File

@ -28,6 +28,11 @@ class IntlFormatter implements IntlFormatterInterface
*/
public function formatIntl(string $message, string $locale, array $parameters = []): string
{
// MessageFormatter constructor throws an exception if the message is empty
if ('' === $message) {
return '';
}
if (!$formatter = $this->cache[$locale][$message] ?? null) {
if (!($this->hasMessageFormatter ?? $this->hasMessageFormatter = class_exists(\MessageFormatter::class))) {
throw new LogicException('Cannot parse message translation: please install the "intl" PHP extension or the "symfony/polyfill-intl-messageformatter" package.');

View File

@ -82,6 +82,11 @@ _MSG_;
'{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree',
[4560, 123, 4560 / 123],
],
[
'',
'',
[],
],
];
}