Skip to content

[Translator][Idea] Using expressions in the translator #17610

Closed
@sstok

Description

@sstok

This is a rather crazy idea I got a while back. It's somewhat related to #17158
The original issue was to allow translation strings in other translations, but this has some issues with compatibility.

So I came-up with something much more advanced and less likely to cause conflicts.

I was already planning on building this in time as a component and Bundle, but having it in the Symfony core would be a better fit (if possible).

The idea is to allow Expressions in a translator string.

Example:

Hello {$ user.gender == 'male' ? 'Sir' : 'Madam' $},

{$ trans('something') $}

Today date is {$ 'now'|date('d-m-Y') $}.

I think it's very unlikely for anyone to have this in the translator keys 😄 but it will open a whole new level of possibilities. The only main challenge is performance, caching is almost mandatory here.

We can store the translation-expression as compiled down PHP for fast execution or convert the whole translation to an expression like:

'Hello ' ~ (user.gender == 'male' ? 'Sir' : 'Madam') ~ ',

Today date is ' ~ (date_format('now', 'd-m-Y')) ~'.'

Which can be stored using the expression engines caching system.

Suggestions and comments are more then welcome 👍

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRFCRFC = Request For Comments (proposals about features that you want to be discussed)Translation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions