Skip to content

Documentation is confusing about use of {placeholders} in translations #19593

Open
@php4fan

Description

@php4fan

I was looking at the documentation about translations here:
https://symfony.com/doc/5.x/translation.html#basic-translation

and I was looking for the part about parameters, or should I say placeholders. What I mean with parameters/placeholders is when you have a phrase somephrase whose translation is "Hello {username} and you call:

$translator->trans('somephrase', ['username' => 'John']) ;

ane the result is "Hello John".

I think those are called Placeholders.

So, the only place where the page above says something about that is here:
https://symfony.com/doc/5.x/translation.html#message-format

To manage these situations, Symfony follows the ICU MessageFormat syntax by using PHP's MessageFormatter class. Read more about this in How to Translate Messages using the ICU MessageFormat.

So, I follow that link and it says:

In order to use the ICU Message Format, the message domain has to be suffixed with +intl-icu:

and then it explains, among other things, how placeholders work, besides pluralization and other stuff.

This seems to be very clear: in order to use placeholders, as well as pluralization and other features, the message domains has to be suffixed with +intl-icu

However, I have tried using basic translations with placeholders with the default domain messages without any suffix, and placeholders work. I don't know about pluralization and other stuff.

So, the documentation wrongly suggests that, in order to be able to use placeholders, you need to suffix the domain names with that string, but that's not true.

I don't know if that's true for other features such as pluralization; if that's the case, then it's not clear.

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