Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Translator] support blocks (callbacks) in ICU translation messages #57389

Copy link
Copy link
Open
@dkarlovi

Description

@dkarlovi
Issue body actions

Description

ICU v2 supports formatter "functions". This looks like this

{$variable_name :function_name param1=a param2=b}

It comes with built in formatters, with custom ones expected by the spec.

Idea

Translator could use this to create a new formatter called block, which would essentially be a callback, example message

faq_msg=For more information, make sure to check the {$link :block label=FAQ}

When translating, this would look like

$translator->translate('faq_msg', ['link' => fn($label) =>'<a href="#">$label</a>' ]);

This would mean the translator would basically allow calling custom callbacks to format blocks within the message, passing the params into the callback (the param would most often be translations for the inside of the block).

Integration with Twig

This would really shine when we integrate this with twig, the above callback would be auto-implemented by Twig like so:

{% trans 'faq_msg' %}
{% block link %}<a href="#">{{ label }}</a>{% endblock %}
{% endtrans %}

The idea is, Twig's (existing or new) translation block would hook into the callback and use the nested blocks as named callbacks, used to format the translated message blocks.

Example

More complex example to show how it might be made more complex, but still relatively simple to use and powerful:

For more information, make sure to check the {$faq_link :block label="Frequently Asked Questions" alt="FAQ"} or check our {$kb_link :block label="Knowledge Base"}
{% trans 'faq_msg' %}
{% block faq_link %}<a href="#">{{ label }} <img="faq.png" alt="{{ alt }}" /></a>{% endblock %}
{% block kb_link %}<a href="#">{{ label }}</a>{% endblock %}
{% endtrans %}

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.