Description
Symfony version(s) affected: 4.3.4
Description
We have a service that calls the translator with dynamically created key and we sometimes have to use empty strings (or the translator will return the key if the key is not found in the translation file).
But using an empty string throws an exception as per https://bugs.php.net/bug.php?id=78484
How to reproduce
# test+intl-icu.yaml
empty: ''
$translator->trans('fr_FR', 'empty', 'test');
Root cause to reproduce the IntlException: Constructor failed
exception
new MessageFormatter('fr_FR', '');
Possible Solution
I don't know if the PHP core team plans to change this behavior but it can easily worked around in Symfony\Component\Translation\Translator::trans()
: if $catalogue->get($id, $domain)
returns an empty string then just return an empty string instead of calling $this->formatter->formatIntl()
or $this->formatter->format()
.
I can submit a PR is needed