Skip to content

Real message translation fails with ICU MessageFormat #46723

Closed
@mx03

Description

@mx03

Symfony version(s) affected

5.4.9

Description

When using real messages the message dont get parsed with ICU MessageFormat.

How to reproduce

Example from https://symfony.com/doc/current/translation/message_format.html is used:

<?php
require_once __DIR__ . '/vendor/autoload.php';

$translator = new Symfony\Component\Translation\Translator("de");

// prints "Ryan has invited you for his party!"
echo $translator->trans('{organizer_gender, select,
    female {{organizer_name} has invited you for her party!}
    male   {{organizer_name} has invited you for his party!}
    other  {{organizer_name} have invited you for their party!}
}', [
    'organizer_name' => 'Ryan',
    'organizer_gender' => 'male',
]);

Expected:

Ryan has invited you for his party!

Result:

{male, select,
    female {{Ryan} has invited you for her party!}
    male   {{Ryan} has invited you for his party!}
    other  {{Ryan} have invited you for their party!}
}

With a resource:

require_once __DIR__ . '/vendor/autoload.php';

$translator = new Symfony\Component\Translation\Translator("de");

$translator->addLoader('mo', new Symfony\Component\Translation\Loader\MoFileLoader());
$translator->addResource('mo', __DIR__."/messages+intl-icu.de.mo", "de", "messages+intl-icu");

// prints "Ryan has invited you for his party!"
echo $translator->trans('{organizer_gender, select,
    female {{organizer_name} has invited you for her party!}
    male   {{organizer_name} has invited you for his party!}
    other  {{organizer_name} have invited you for their party!}
}', [
    'organizer_name' => 'Ryan',
    'organizer_gender' => 'male',
]);

Source(mo file):

{organizer_gender, select,
    female {{organizer_name} has invited you for her party!}
    male   {{organizer_name} has invited you for his party!}
    other  {{organizer_name} have invited you for their party!}
}

Translation(mo file):

{organizer_gender, select,
    female {{organizer_name} a ..!}
    male   {{organizer_name} b ..!}
    other  {{organizer_name} c ..!}
}

Result:

Ryan b ..!

Possible Solution

No response

Additional Context

No response

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