Skip to content

[Translator] Empty string #33427

Closed
Closed
@sylfabre

Description

@sylfabre

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions