Description
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 %}