Skip to content

[Translation] Fix example of using ICU message directly in code #16905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions translation/message_format.rst
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ you to use literal text in the select statements:
It's possible to translate ICU MessageFormat messages directly in code,
without having to define them in any file::

use Symfony\Component\Translation\MessageCatalogueInterface;

$invitation = '{organizer_gender, select,
female {{organizer_name} has invited you to her party!}
male {{organizer_name} has invited you to his party!}
Expand All @@ -195,10 +197,15 @@ you to use literal text in the select statements:
}';

// prints "Ryan has invited you to his party!"
echo $translator->trans($invitation, [
'organizer_name' => 'Ryan',
'organizer_gender' => 'male',
]);
echo $translator->trans(
$invitation,
[
'organizer_name' => 'Ryan',
'organizer_gender' => 'male',
],
// Appends the required suffix "+intl-icu" to the domain
'messages'.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX
);

.. _component-translation-pluralization:

Expand Down